From b636f6f61dcdde417220188d5838d78e79a66ce8 Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 7 Feb 2024 17:23:29 +0800 Subject: [PATCH] expanding tree when error buttons pressed --- src/Builder4/MainWindow.bjs | 60 ++++++++++++++----- src/Builder4/MainWindow.vala | 59 ++++++++++++++----- src/Builder4/ValaCompileErrors.bjs | 46 +++++---------- src/Builder4/ValaCompileErrors.vala | 89 ++++++++++++----------------- src/Builder4/WindowLeftTree.bjs | 3 +- src/Builder4/WindowLeftTree.vala | 1 + 6 files changed, 148 insertions(+), 110 deletions(-) diff --git a/src/Builder4/MainWindow.bjs b/src/Builder4/MainWindow.bjs index 8c49c04d4..34980b1d4 100644 --- a/src/Builder4/MainWindow.bjs +++ b/src/Builder4/MainWindow.bjs @@ -6,6 +6,7 @@ "# Project.Project project" : "null", "# WindowState windowstate" : "", "# bool winloading" : false, + "# default_height" : 850, "$ type" : "Gtk.WindowType.TOPLEVEL", "$ xns" : "Gtk", "* ctor" : "new Gtk.ApplicationWindow(BuilderApplication.singleton({}))", @@ -15,7 +16,6 @@ "" ], "border_width" : 0, - "default_height" : 850, "default_width" : 1200, "id" : "MainWindow", "items" : [ @@ -952,9 +952,18 @@ "listeners" : { "bind" : [ "(listitem) => {", - "\t var lb = (Gtk.Label) (listitem as Gtk.ListItem).get_child();", - "\t var item = (listitem as Gtk.ListItem).get_item() as WindowState;", - "\t ", + "\tvar li = (listitem as Gtk.ListItem);", + "\tif (li == null) {", + "\t\treturn;", + "\t}", + "\t var lb = (Gtk.Label) li.get_child() as Gtk.Label;", + "\t if (lb == null) {", + "\t \treturn;", + " \t}", + "\t var item = li.get_item() as WindowState;", + "\t if (item == null) {", + "\t \treturn;", + " \t}", "\t lb.label = item.project.name;", "", "", @@ -965,14 +974,20 @@ ], "setup" : [ "(listitem) => {", + "", + "\tvar li = (listitem as Gtk.ListItem);", + "\tif (li == null) {", + "\t\treturn;", + "\t}", + "", "\tvar lbl = new Gtk.Label(\"\");", - " \t(listitem as Gtk.ListItem).set_child(lbl);", + " \tli.set_child(lbl);", " \tlbl.justify = Gtk.Justification.LEFT;", " \tlbl.xalign = 0;", " \tlbl.use_markup = true;", "\tlbl.ellipsize = Pango.EllipsizeMode.START;", " ", - "\t(listitem as Gtk.ListItem).activatable = true;", + "\tli.activatable = true;", "}", "" ] @@ -996,10 +1011,22 @@ "listeners" : { "bind" : [ "(listitem) => {", - " var lb = (Gtk.Label) (listitem as Gtk.ListItem).get_child();", - " var item = (listitem as Gtk.ListItem).get_item() as WindowState;", - " ", - " lb.label = item.file.relpath;", + "\tvar li = (listitem as Gtk.ListItem);", + "\tif (li == null) {", + "\t\treturn;", + "\t}", + "\t var lb = (Gtk.Label) li.get_child() as Gtk.Label;", + "\t if (lb == null) {", + "\t \treturn;", + " \t}", + "\t var item = li.get_item() as WindowState;", + "\t if (item == null) {", + "\t \treturn;", + " \t}", + " \t", + " \t ", + " ", + " \tlb.label = item.file.relpath;", "", "", " ", @@ -1009,14 +1036,18 @@ ], "setup" : [ "(listitem) => {", + "\tvar li = (listitem as Gtk.ListItem);", + "\tif (li == null) {", + "\t\treturn;", + "\t}", "\tvar lbl = new Gtk.Label(\"\");", - " \t(listitem as Gtk.ListItem).set_child(lbl);", + " \tli.set_child(lbl);", " \tlbl.justify = Gtk.Justification.LEFT;", " \tlbl.xalign = 0;", " \tlbl.use_markup = true;", "\tlbl.ellipsize = Pango.EllipsizeMode.START;", " ", - "\t(listitem as Gtk.ListItem).activatable = true;", + "\tli.activatable = true;", "}", "" ] @@ -1410,7 +1441,10 @@ "\t BuilderApplication.removeWindow(this);", "\t ", "\t if (BuilderApplication.windows.size < 1) {", - "\t\tthis.windowstate.file.getLanguageServer().exit();", + "\t \ttry {", + "\t\t\tthis.windowstate.file.getLanguageServer().exit();", + "\t\t} catch(Error e) {}", + "\t\t", "\t\tBuilderApplication.singleton( null ).quit();", "\t }", "\treturn true;", diff --git a/src/Builder4/MainWindow.vala b/src/Builder4/MainWindow.vala index 6b62b112d..62dc1f94a 100644 --- a/src/Builder4/MainWindow.vala +++ b/src/Builder4/MainWindow.vala @@ -67,7 +67,6 @@ public class Xcls_MainWindow : Object // set gobject values this.el.title = "Roo Application Builder"; - this.el.default_height = 850; this.el.default_width = 1200; new Xcls_headerbar( _this ); this.el.set_titlebar ( _this.headerbar.el ); @@ -90,7 +89,10 @@ public class Xcls_MainWindow : Object BuilderApplication.removeWindow(this); if (BuilderApplication.windows.size < 1) { - this.windowstate.file.getLanguageServer().exit(); + try { + this.windowstate.file.getLanguageServer().exit(); + } catch(Error e) {} + BuilderApplication.singleton( null ).quit(); } return true; @@ -2178,19 +2180,34 @@ public class Xcls_MainWindow : Object //listeners this.el.setup.connect( (listitem) => { + + var li = (listitem as Gtk.ListItem); + if (li == null) { + return; + } + var lbl = new Gtk.Label(""); - (listitem as Gtk.ListItem).set_child(lbl); + li.set_child(lbl); lbl.justify = Gtk.Justification.LEFT; lbl.xalign = 0; lbl.use_markup = true; lbl.ellipsize = Pango.EllipsizeMode.START; - (listitem as Gtk.ListItem).activatable = true; + li.activatable = true; }); this.el.bind.connect( (listitem) => { - var lb = (Gtk.Label) (listitem as Gtk.ListItem).get_child(); - var item = (listitem as Gtk.ListItem).get_item() as WindowState; - + var li = (listitem as Gtk.ListItem); + if (li == null) { + return; + } + var lb = (Gtk.Label) li.get_child() as Gtk.Label; + if (lb == null) { + return; + } + var item = li.get_item() as WindowState; + if (item == null) { + return; + } lb.label = item.project.name; @@ -2250,20 +2267,36 @@ public class Xcls_MainWindow : Object //listeners this.el.setup.connect( (listitem) => { + var li = (listitem as Gtk.ListItem); + if (li == null) { + return; + } var lbl = new Gtk.Label(""); - (listitem as Gtk.ListItem).set_child(lbl); + li.set_child(lbl); lbl.justify = Gtk.Justification.LEFT; lbl.xalign = 0; lbl.use_markup = true; lbl.ellipsize = Pango.EllipsizeMode.START; - (listitem as Gtk.ListItem).activatable = true; + li.activatable = true; }); this.el.bind.connect( (listitem) => { - var lb = (Gtk.Label) (listitem as Gtk.ListItem).get_child(); - var item = (listitem as Gtk.ListItem).get_item() as WindowState; - - lb.label = item.file.relpath; + var li = (listitem as Gtk.ListItem); + if (li == null) { + return; + } + var lb = (Gtk.Label) li.get_child() as Gtk.Label; + if (lb == null) { + return; + } + var item = li.get_item() as WindowState; + if (item == null) { + return; + } + + + + lb.label = item.file.relpath; diff --git a/src/Builder4/ValaCompileErrors.bjs b/src/Builder4/ValaCompileErrors.bjs index 5ec52a2f7..3ae7261ed 100644 --- a/src/Builder4/ValaCompileErrors.bjs +++ b/src/Builder4/ValaCompileErrors.bjs @@ -3,6 +3,7 @@ "gen_extended" : false, "items" : [ { + "# Gee.HashMap? rows" : "null", "# Xcls_MainWindow window" : "", "$ xns" : "Gtk", "* ctor" : "new Gtk.Popover()", @@ -152,6 +153,11 @@ "\tvar lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();", "\tvar np = (Palete.CompileError) lr.get_item();", "\t", + "\tif (np.diag == null) {", + "\t\t_this.rows.set(np.file.path, lr);", + "\t", + "\t}", + "", "\t", "\t//GLib.debug(\"change %s to %s\", lbl.label, np.name);", "\tlbl.label = np.linemsg;", @@ -289,17 +295,7 @@ " \t GLib.debug(\"errors : none available\");", " \treturn;", "\t}", - " \t//this.el.present();", - " //this.el.popup();", - " ", - " //print(\"looking for %s\\n\", id);", - " // loop through parent childnre", - " ", - " ", - " ; //<< very important!!!", - " ", - " // store.set_sort_column_id(0,Gtk.SortType.ASCENDING);", - " ", + " \t ", " var win = this.window.el;", " var w = win.get_width();", " var h = win.get_height();", @@ -315,28 +311,13 @@ " GLib.debug(\"set size\");", " this.el.set_size_request( int.max(100, new_w), int.max(100, h-120));", " ", - "", - " // this.el.set_relative_to(onbtn);", - "\t//Gtk.Allocation rect;", - "\t//onbtn.get_allocation(out rect);", - " //this.el.set_pointing_to(rect);", - "\t//this.el.present();", + " ", "\t", "\tGLib.debug(\"call popup\");", " this.el.popup();", - " // only need to load once.", - " \t//if (!this.loaded) {", - " \t\t ", - "\t\t//this.loaded = true;", - "\t //}", - "\t ", - " ", - " ", - " \t//if (expand != null) {", - " //\t_this.compile_tree.el.expand_row( store.get_path(expand) , true);", - "//\t}", - " ", - " // this.hpane.el.set_position( 0);", + " if (this.rows.has_key(this.window.windowstate.file.path)) {", + " \tthis.rows.get(this.window.windowstate.file.path).expanded = true;", + " }", "}", "" ], @@ -361,10 +342,13 @@ "\t\t}", "\t\t", "\t);", - " ", + "\tthis.rows = new Gee.HashMap();", "\t_this.model.el = tm;", "\t_this.sortmodel.el.set_model(tm);", "\t this.tree.el.show();", + "\t if (this.rows.has_key(this.window.windowstate.file.path)) {", + " \tthis.rows.get(this.window.windowstate.file.path).expanded = true;", + " }", "}" ] } diff --git a/src/Builder4/ValaCompileErrors.vala b/src/Builder4/ValaCompileErrors.vala index 2a9f1d507..caf2d6509 100644 --- a/src/Builder4/ValaCompileErrors.vala +++ b/src/Builder4/ValaCompileErrors.vala @@ -19,6 +19,7 @@ public class Xcls_ValaCompileErrors : Object public Xcls_model model; // my vars (def) + public Gee.HashMap? rows; public Xcls_MainWindow window; public bool loaded; @@ -29,6 +30,7 @@ public class Xcls_ValaCompileErrors : Object this.el = new Gtk.Popover(); // my vars (dec) + this.rows = null; this.loaded = false; // set gobject values @@ -61,10 +63,13 @@ public class Xcls_ValaCompileErrors : Object } ); - + this.rows = new Gee.HashMap(); _this.model.el = tm; _this.sortmodel.el.set_model(tm); this.tree.el.show(); + if (this.rows.has_key(this.window.windowstate.file.path)) { + this.rows.get(this.window.windowstate.file.path).expanded = true; + } } public void show ( ) { GLib.debug("errors : show"); @@ -74,17 +79,7 @@ public class Xcls_ValaCompileErrors : Object GLib.debug("errors : none available"); return; } - //this.el.present(); - //this.el.popup(); - - //print("looking for %s\n", id); - // loop through parent childnre - - - ; //<< very important!!! - - // store.set_sort_column_id(0,Gtk.SortType.ASCENDING); - + var win = this.window.el; var w = win.get_width(); var h = win.get_height(); @@ -100,28 +95,13 @@ public class Xcls_ValaCompileErrors : Object GLib.debug("set size"); this.el.set_size_request( int.max(100, new_w), int.max(100, h-120)); - - // this.el.set_relative_to(onbtn); - //Gtk.Allocation rect; - //onbtn.get_allocation(out rect); - //this.el.set_pointing_to(rect); - //this.el.present(); + GLib.debug("call popup"); this.el.popup(); - // only need to load once. - //if (!this.loaded) { - - //this.loaded = true; - //} - - - - //if (expand != null) { - // _this.compile_tree.el.expand_row( store.get_path(expand) , true); - // } - - // this.hpane.el.set_position( 0); + if (this.rows.has_key(this.window.windowstate.file.path)) { + this.rows.get(this.window.windowstate.file.path).expanded = true; + } } public class Xcls_compile_view : Object { @@ -143,14 +123,14 @@ public class Xcls_ValaCompileErrors : Object // set gobject values this.el.homogeneous = false; this.el.hexpand = false; - var child_1 = new Xcls_ScrolledWindow3( _this ); + var child_1 = new Xcls_ScrolledWindow2( _this ); child_1.ref(); this.el.append( child_1.el ); } // user defined functions } - public class Xcls_ScrolledWindow3 : Object + public class Xcls_ScrolledWindow2 : Object { public Gtk.ScrolledWindow el; private Xcls_ValaCompileErrors _this; @@ -159,7 +139,7 @@ public class Xcls_ValaCompileErrors : Object // my vars (def) // ctor - public Xcls_ScrolledWindow3(Xcls_ValaCompileErrors _owner ) + public Xcls_ScrolledWindow2(Xcls_ValaCompileErrors _owner ) { _this = _owner; this.el = new Gtk.ScrolledWindow(); @@ -202,10 +182,10 @@ public class Xcls_ValaCompileErrors : Object // set gobject values this.el.hexpand = true; this.el.vexpand = true; - var child_2 = new Xcls_ColumnViewColumn11( _this ); + var child_2 = new Xcls_ColumnViewColumn10( _this ); child_2.ref(); this.el.append_column ( child_2.el ); - var child_3 = new Xcls_GestureClick13( _this ); + var child_3 = new Xcls_GestureClick12( _this ); child_3.ref(); this.el.add_controller( child_3.el ); } @@ -259,7 +239,7 @@ public class Xcls_ValaCompileErrors : Object _this = _owner; _this.sortmodel = this; new Xcls_model( _this ); - var child_2 = new Xcls_TreeListRowSorter8( _this ); + var child_2 = new Xcls_TreeListRowSorter7( _this ); child_2.ref(); this.el = new Gtk.SortListModel( _this.model.el, child_2.el ); @@ -316,7 +296,7 @@ public class Xcls_ValaCompileErrors : Object // user defined functions } - public class Xcls_TreeListRowSorter8 : Object + public class Xcls_TreeListRowSorter7 : Object { public Gtk.TreeListRowSorter el; private Xcls_ValaCompileErrors _this; @@ -325,10 +305,10 @@ public class Xcls_ValaCompileErrors : Object // my vars (def) // ctor - public Xcls_TreeListRowSorter8(Xcls_ValaCompileErrors _owner ) + public Xcls_TreeListRowSorter7(Xcls_ValaCompileErrors _owner ) { _this = _owner; - var child_1 = new Xcls_StringSorter9( _this ); + var child_1 = new Xcls_StringSorter8( _this ); child_1.ref(); this.el = new Gtk.TreeListRowSorter( child_1.el ); @@ -339,7 +319,7 @@ public class Xcls_ValaCompileErrors : Object // user defined functions } - public class Xcls_StringSorter9 : Object + public class Xcls_StringSorter8 : Object { public Gtk.StringSorter el; private Xcls_ValaCompileErrors _this; @@ -348,10 +328,10 @@ public class Xcls_ValaCompileErrors : Object // my vars (def) // ctor - public Xcls_StringSorter9(Xcls_ValaCompileErrors _owner ) + public Xcls_StringSorter8(Xcls_ValaCompileErrors _owner ) { _this = _owner; - var child_1 = new Xcls_PropertyExpression10( _this ); + var child_1 = new Xcls_PropertyExpression9( _this ); child_1.ref(); this.el = new Gtk.StringSorter( child_1.el ); @@ -362,7 +342,7 @@ public class Xcls_ValaCompileErrors : Object // user defined functions } - public class Xcls_PropertyExpression10 : Object + public class Xcls_PropertyExpression9 : Object { public Gtk.PropertyExpression el; private Xcls_ValaCompileErrors _this; @@ -371,7 +351,7 @@ public class Xcls_ValaCompileErrors : Object // my vars (def) // ctor - public Xcls_PropertyExpression10(Xcls_ValaCompileErrors _owner ) + public Xcls_PropertyExpression9(Xcls_ValaCompileErrors _owner ) { _this = _owner; this.el = new Gtk.PropertyExpression( typeof(Palete.CompileError), null, "linemsg" ); @@ -388,7 +368,7 @@ public class Xcls_ValaCompileErrors : Object - public class Xcls_ColumnViewColumn11 : Object + public class Xcls_ColumnViewColumn10 : Object { public Gtk.ColumnViewColumn el; private Xcls_ValaCompileErrors _this; @@ -397,10 +377,10 @@ public class Xcls_ValaCompileErrors : Object // my vars (def) // ctor - public Xcls_ColumnViewColumn11(Xcls_ValaCompileErrors _owner ) + public Xcls_ColumnViewColumn10(Xcls_ValaCompileErrors _owner ) { _this = _owner; - var child_1 = new Xcls_SignalListItemFactory12( _this ); + var child_1 = new Xcls_SignalListItemFactory11( _this ); child_1.ref(); this.el = new Gtk.ColumnViewColumn( "Compile Result", child_1.el ); @@ -413,7 +393,7 @@ public class Xcls_ValaCompileErrors : Object // user defined functions } - public class Xcls_SignalListItemFactory12 : Object + public class Xcls_SignalListItemFactory11 : Object { public Gtk.SignalListItemFactory el; private Xcls_ValaCompileErrors _this; @@ -422,7 +402,7 @@ public class Xcls_ValaCompileErrors : Object // my vars (def) // ctor - public Xcls_SignalListItemFactory12(Xcls_ValaCompileErrors _owner ) + public Xcls_SignalListItemFactory11(Xcls_ValaCompileErrors _owner ) { _this = _owner; this.el = new Gtk.SignalListItemFactory(); @@ -470,6 +450,11 @@ public class Xcls_ValaCompileErrors : Object var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item(); var np = (Palete.CompileError) lr.get_item(); + if (np.diag == null) { + _this.rows.set(np.file.path, lr); + + } + //GLib.debug("change %s to %s", lbl.label, np.name); lbl.label = np.linemsg; @@ -496,7 +481,7 @@ public class Xcls_ValaCompileErrors : Object } - public class Xcls_GestureClick13 : Object + public class Xcls_GestureClick12 : Object { public Gtk.GestureClick el; private Xcls_ValaCompileErrors _this; @@ -505,7 +490,7 @@ public class Xcls_ValaCompileErrors : Object // my vars (def) // ctor - public Xcls_GestureClick13(Xcls_ValaCompileErrors _owner ) + public Xcls_GestureClick12(Xcls_ValaCompileErrors _owner ) { _this = _owner; this.el = new Gtk.GestureClick(); diff --git a/src/Builder4/WindowLeftTree.bjs b/src/Builder4/WindowLeftTree.bjs index 9167aed60..081140778 100644 --- a/src/Builder4/WindowLeftTree.bjs +++ b/src/Builder4/WindowLeftTree.bjs @@ -4,6 +4,7 @@ "items" : [ { "# Xcls_MainWindow? main_window" : "null", + "# int last_error_counter" : "-1", "$ xns" : "Gtk", "@ bool before_node_change" : "()", "@ void changed" : "()", @@ -12,7 +13,6 @@ "bool hexpand" : true, "bool vexpand" : true, "id" : "WindowLeftTree", - "int last_error_counter" : "-1", "items" : [ { "$ xns" : "Gtk", @@ -1671,6 +1671,7 @@ "| JsRender.JsRender getActiveFile" : [ "() {", " return this.main_window.windowstate.file;", + " ", "}", "" ], diff --git a/src/Builder4/WindowLeftTree.vala b/src/Builder4/WindowLeftTree.vala index 8b0a0b01c..a80ebcf40 100644 --- a/src/Builder4/WindowLeftTree.vala +++ b/src/Builder4/WindowLeftTree.vala @@ -160,6 +160,7 @@ public class Xcls_WindowLeftTree : Object } public JsRender.JsRender getActiveFile () { return this.main_window.windowstate.file; + } public class Xcls_ListView1 : Object { -- 2.39.2