+
+ public class Xcls_navigation_holder : Object
+ {
+ public Gtk.Box el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_navigation_holder(Editor _owner )
+ {
+ _this = _owner;
+ _this.navigation_holder = this;
+ this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
+
+ // my vars (dec)
+
+ // set gobject values
+ this.el.width_request = 120;
+ this.el.hexpand = true;
+ this.el.vexpand = true;
+ this.el.visible = false;
+ var child_1 = new Xcls_Box28( _this );
+ child_1.ref();
+ this.el.append( child_1.el );
+ new Xcls_navigationwindow( _this );
+ this.el.append( _this.navigationwindow.el );
+ }
+
+ // user defined functions
+ }
+ public class Xcls_Box28 : Object
+ {
+ public Gtk.Box el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_Box28(Editor _owner )
+ {
+ _this = _owner;
+ this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
+
+ // my vars (dec)
+
+ // set gobject values
+ }
+
+ // user defined functions
+ }
+
+ public class Xcls_navigationwindow : Object
+ {
+ public Gtk.ScrolledWindow el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_navigationwindow(Editor _owner )
+ {
+ _this = _owner;
+ _this.navigationwindow = this;
+ this.el = new Gtk.ScrolledWindow();
+
+ // my vars (dec)
+
+ // set gobject values
+ this.el.hexpand = true;
+ this.el.vexpand = true;
+ this.el.visible = true;
+ new Xcls_navigation( _this );
+ this.el.child = _this.navigation.el;
+ }
+
+ // user defined functions
+ }
+ public class Xcls_navigation : Object
+ {
+ public Gtk.ColumnView el;
+ private Editor _this;
+
+
+ // my vars (def)
+ public int last_selected_line;
+ public Gtk.Widget? selected_row;
+
+ // ctor
+ public Xcls_navigation(Editor _owner )
+ {
+ _this = _owner;
+ _this.navigation = this;
+ new Xcls_navigationselmodel( _this );
+ this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
+
+ // my vars (dec)
+ this.last_selected_line = -1;
+ this.selected_row = null;
+
+ // set gobject values
+ this.el.name = "editor-navigation";
+ var child_2 = new Xcls_ColumnViewColumn31( _this );
+ child_2.ref();
+ this.el.append_column( child_2.el );
+ var child_3 = new Xcls_GestureClick40( _this );
+ child_3.ref();
+ this.el.add_controller( child_3.el );
+ }
+
+ // user defined functions
+ public Gtk.Widget? getRowWidgetAt (double x, double y, out string pos) {
+
+ pos = "";
+ var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
+ //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
+ if (w == null) {
+ return null;
+ }
+
+ var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
+ if (row == null) {
+ return null;
+ }
+
+ //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
+
+
+
+ //GLib.debug("row number is %d", rn);
+ //GLib.debug("click %d, %d", (int)x, (int)y);
+ // above or belw
+ Graphene.Rect bounds;
+ row.compute_bounds(this.el, out bounds);
+ //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
+ // (int)bounds.get_x(), (int)bounds.get_y(),
+ // (int)bounds.get_width(), (int)bounds.get_height()
+ // );
+ var ypos = y - bounds.get_y();
+ //GLib.debug("rel ypos = %d", (int)ypos);
+ var rpos = 100.0 * (ypos / bounds.get_height());
+ //GLib.debug("rel pos = %d %%", (int)rpos);
+ pos = "over";
+
+ if (rpos > 80) {
+ pos = "below";
+ } else if (rpos < 20) {
+ pos = "above";
+ }
+ return row;
+ }
+ public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
+
+ if (!_this.navigation_holder.el.visible && syms.size > 0) {
+ _this.navigation_holder.el.show();
+ _this.paned.el.position =
+ _this.paned.el.get_width() - 200;
+ }
+ //_this.navliststore.el.remove_all();
+
+
+ var ls = new GLib.ListStore(typeof(Lsp.DocumentSymbol));
+
+ foreach(var sym in syms) {
+ ls.append(sym);
+ }
+ // if syms updated is empty, but we already have one..
+ if (_this.navliststore.el.get_n_items() > 0 && ls.get_n_items() < 1) {
+ return;
+ }
+ Lsp.DocumentSymbol.copyList(ls, _this.navliststore.el);
+ //_this.navliststore.el.append(sym);
+ this.last_selected_line = -1;
+ GLib.Idle.add(() => {
+ _this.navigationsort.collapseOnLoad();
+ Gtk.TextIter iter;
+ _this.buffer.el.get_iter_at_offset (
+ out iter, _this.buffer.el.cursor_position);
+
+ GLib.debug("idle update scroll %d, %d", iter.get_line(),
+ iter.get_line_offset());
+ this.updateSelectedLine(
+ (uint)iter.get_line(),
+ (uint)iter.get_line_offset()
+ );
+ return false;
+ });
+
+ }
+ public int getRowAt (double x, double y, out string pos) {
+
+ pos = "";
+ var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
+ //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
+ if (w == null) {
+ return -1;
+ }
+
+ var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
+ if (row == null) {
+ return -1;
+ }
+
+ //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
+
+ var rn = 0;
+ var cr = row;
+
+ while (cr.get_prev_sibling() != null) {
+ rn++;
+ cr = cr.get_prev_sibling();
+ }
+
+ //GLib.debug("row number is %d", rn);
+ //GLib.debug("click %d, %d", (int)x, (int)y);
+ // above or belw
+ Graphene.Rect bounds;
+ row.compute_bounds(this.el, out bounds);
+ //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
+ // (int)bounds.get_x(), (int)bounds.get_y(),
+ // (int)bounds.get_width(), (int)bounds.get_height()
+ // );
+ var ypos = y - bounds.get_y();
+ //GLib.debug("rel ypos = %d", (int)ypos);
+ var rpos = 100.0 * (ypos / bounds.get_height());
+ //GLib.debug("rel pos = %d %%", (int)rpos);
+ pos = "over";
+
+ if (rpos > 80) {
+ pos = "below";
+ } else if (rpos < 20) {
+ pos = "above";
+ }
+ return rn;
+ }
+ public void updateSelectedLine (uint line, uint chr) {
+ if (line == this.last_selected_line) {
+ return;
+ }
+ GLib.debug("select line %d", (int)line);
+ this.last_selected_line = (int)line;
+
+
+ var new_row = -1;
+ var sym = _this.navliststore.symbolAtLine(line, chr);
+ if (sym != null) {
+ new_row = _this.navigationsort.getRowFromSymbol(sym);
+ GLib.debug("select line %d - row found %d", (int)line, new_row);
+ } else {
+ GLib.debug(" no symbol found at line %d", (int)line);
+ }
+
+ if (this.selected_row != null) {
+ GLib.debug(" remove selected row");
+ this.selected_row.remove_css_class("selected-row");
+ }
+ this.selected_row = null;
+ if (new_row > -1) {
+ this.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);
+ var row = sym.get_data<Gtk.Widget>("widget");
+ if (row != null) {
+ GLib.debug(" Add selected row");
+
+ row.add_css_class("selected-row");
+ this.selected_row = row;
+
+
+ } else {
+ GLib.debug("could not find widget on row %d", new_row);
+ }
+
+ }
+
+
+ }
+ }
+ public class Xcls_ColumnViewColumn31 : Object
+ {
+ public Gtk.ColumnViewColumn el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_ColumnViewColumn31(Editor _owner )
+ {
+ _this = _owner;
+ var child_1 = new Xcls_SignalListItemFactory32( _this );
+ child_1.ref();
+ this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
+
+ // my vars (dec)
+
+ // set gobject values
+ this.el.expand = true;
+ }
+
+ // user defined functions
+ }
+ public class Xcls_SignalListItemFactory32 : Object
+ {
+ public Gtk.SignalListItemFactory el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_SignalListItemFactory32(Editor _owner )
+ {
+ _this = _owner;
+ this.el = new Gtk.SignalListItemFactory();
+
+ // my vars (dec)
+
+ // set gobject values
+
+ //listeners
+ this.el.setup.connect( (listitem) => {
+
+ var expand = new Gtk.TreeExpander();
+
+ expand.set_indent_for_depth(true);
+ expand.set_indent_for_icon(true);
+ var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
+ var icon = new Gtk.Image();
+ var lbl = new Gtk.Label("");
+ lbl.use_markup = true;
+ lbl.ellipsize = Pango.EllipsizeMode.END;
+
+ icon.margin_end = 4;
+ lbl.justify = Gtk.Justification.LEFT;
+ lbl.xalign = 0;
+
+ // listitem.activatable = true; ??
+
+ hbox.append(icon);
+ hbox.append(lbl);
+ expand.set_child(hbox);
+ ((Gtk.ListItem)listitem).set_child(expand);
+
+ });
+ this.el.bind.connect( (listitem) => {
+
+ // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
+
+ //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
+ var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
+
+
+ var hbox = (Gtk.Box) expand.child;
+
+
+ var img = (Gtk.Image) hbox.get_first_child();
+ var lbl = (Gtk.Label) img.get_next_sibling();
+
+ var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
+ var sym = (Lsp.DocumentSymbol) lr.get_item();
+
+ sym.set_data<Gtk.Widget>("widget", expand.get_parent());
+ expand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>("symbol", sym);
+
+ //GLib.debug("save sym on %s", expand.get_parent().get_parent().get_type().name());
+
+ //GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
+
+ expand.set_hide_expander( sym.children.get_n_items() < 1);
+ expand.set_list_row(lr);
+ //this.in_bind = true;
+ // default is to expand
+
+ //this.in_bind = false;
+
+ sym.bind_property("symbol_icon",
+ img, "icon_name",
+ GLib.BindingFlags.SYNC_CREATE);
+
+ hbox.css_classes = { sym.symbol_icon };
+
+ sym.bind_property("name",
+ lbl, "label",
+ GLib.BindingFlags.SYNC_CREATE);
+ // should be better?- --line no?
+ sym.bind_property("tooltip",
+ lbl, "tooltip_markup",
+ GLib.BindingFlags.SYNC_CREATE);
+ // bind image...
+
+ });
+ }
+
+ // user defined functions
+ }
+
+
+ public class Xcls_navigationselmodel : Object
+ {
+ public Gtk.NoSelection el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_navigationselmodel(Editor _owner )
+ {
+ _this = _owner;
+ _this.navigationselmodel = this;
+ new Xcls_navigationsort( _this );
+ this.el = new Gtk.NoSelection( _this.navigationsort.el );
+
+ // my vars (dec)
+
+ // set gobject values
+ }
+
+ // user defined functions
+ }
+ public class Xcls_navigationsort : Object
+ {
+ public Gtk.SortListModel el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_navigationsort(Editor _owner )
+ {
+ _this = _owner;
+ _this.navigationsort = this;
+ var child_1 = new Xcls_TreeListModel35( _this );
+ child_1.ref();
+ var child_2 = new Xcls_TreeListRowSorter37( _this );
+ child_2.ref();
+ this.el = new Gtk.SortListModel( child_1.el, child_2.el );
+
+ // my vars (dec)
+
+ // set gobject values
+ }
+
+ // user defined functions
+ public void collapseOnLoad () {
+ for (var i=0;i < this.el.get_n_items(); i++) {
+ var tr = (Gtk.TreeListRow)this.el.get_item(i);
+ var sym = (Lsp.DocumentSymbol)tr.get_item();
+ switch (sym.kind) {
+ case Lsp.SymbolKind.Enum:
+ tr.expanded = false;
+ break;
+ default:
+ //tr.expanded = true;
+ break;
+ }
+ }
+
+
+
+
+ }
+ public int getRowFromSymbol (Lsp.DocumentSymbol sym) {
+
+ for (var i=0;i < this.el.get_n_items(); i++) {
+ var tr = (Gtk.TreeListRow)this.el.get_item(i);
+
+ if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ public Lsp.DocumentSymbol? getSymbolAt (uint row) {
+
+ var tr = (Gtk.TreeListRow)this.el.get_item(row);
+
+ var a = tr.get_item();;
+ GLib.debug("get_item (2) = %s", a.get_type().name());
+
+
+ return (Lsp.DocumentSymbol)tr.get_item();
+
+ }
+ }
+ public class Xcls_TreeListModel35 : Object
+ {
+ public Gtk.TreeListModel el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_TreeListModel35(Editor _owner )
+ {
+ _this = _owner;
+ new Xcls_navliststore( _this );
+ this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
+
+ return ((Lsp.DocumentSymbol)item).children;
+}
+ );
+
+ // my vars (dec)
+
+ // set gobject values
+
+ //listeners
+ this.el.items_changed.connect( (position, removed, added) => {
+ GLib.debug("tree item changed %d , %d , %d",(int) position, (int)removed, (int) added);
+ if (added < 1) {
+ return;
+ }
+ //var sym = (Lsp.DocumentSymbol) this.el.get_item(position);
+ var row = this.el.get_row(position);
+
+ GLib.debug("got %s", row.get_item().get_type().name());
+
+
+ });
+ }
+
+ // user defined functions
+ }
+ public class Xcls_navliststore : Object
+ {
+ public GLib.ListStore el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_navliststore(Editor _owner )
+ {
+ _this = _owner;
+ _this.navliststore = this;
+ this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
+
+ // my vars (dec)
+
+ // set gobject values
+ }
+
+ // user defined functions
+ public Lsp.DocumentSymbol? symbolAtLine (uint line, uint chr) {
+
+
+ for(var i = 0; i < this.el.get_n_items();i++) {
+ var el = (Lsp.DocumentSymbol)this.el.get_item(i);
+ //GLib.debug("Check sym %s : %d-%d",
+ // el.name , (int)el.range.start.line,
+ // (int)el.range.end.line
+ //);
+ var ret = el.containsLine(line,chr);
+ if (ret != null) {
+ return ret;
+ }
+
+ }
+
+ return null;
+ }
+ }
+
+
+ public class Xcls_TreeListRowSorter37 : Object
+ {
+ public Gtk.TreeListRowSorter el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_TreeListRowSorter37(Editor _owner )
+ {
+ _this = _owner;
+ var child_1 = new Xcls_StringSorter38( _this );
+ child_1.ref();
+ this.el = new Gtk.TreeListRowSorter( child_1.el );
+
+ // my vars (dec)
+
+ // set gobject values
+ }
+
+ // user defined functions
+ }
+ public class Xcls_StringSorter38 : Object
+ {
+ public Gtk.StringSorter el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_StringSorter38(Editor _owner )
+ {
+ _this = _owner;
+ var child_1 = new Xcls_PropertyExpression39( _this );
+ child_1.ref();
+ this.el = new Gtk.StringSorter( child_1.el );
+
+ // my vars (dec)
+
+ // set gobject values
+ }
+
+ // user defined functions
+ }
+ public class Xcls_PropertyExpression39 : Object
+ {
+ public Gtk.PropertyExpression el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_PropertyExpression39(Editor _owner )
+ {
+ _this = _owner;
+ this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
+
+ // my vars (dec)
+
+ // set gobject values
+ }
+
+ // user defined functions
+ }
+
+
+
+
+
+ public class Xcls_GestureClick40 : Object
+ {
+ public Gtk.GestureClick el;
+ private Editor _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_GestureClick40(Editor _owner )
+ {
+ _this = _owner;
+ this.el = new Gtk.GestureClick();
+
+ // my vars (dec)
+
+ // set gobject values
+
+ //listeners
+ this.el.pressed.connect( (n_press, x, y) => {
+ string pos;
+ var row = _this.navigation.getRowWidgetAt(x,y, out pos );
+
+ if (row == null) {
+ GLib.debug("no row selected items");
+ return;
+ }
+ GLib.debug("got click on %s", row.get_type().name());
+ //Lsp.DocumentSymbol
+ var sym = row.get_data<Lsp.DocumentSymbol>("symbol");
+ if (sym == null) {
+ return;
+ }
+ /*
+ "range" : {
+ "start" : {
+ "line" : 1410,
+ "character" : 8
+ },
+ "end" : {
+ "line" : 1410,
+ "character" : 39
+ }
+ },
+ */
+ GLib.debug("goto line %d", (int)sym.range.start.line);
+ _this.scroll_to_line((int)sym.range.start.line);
+ Gtk.TextIter iter;
+ _this.buffer.el.get_iter_at_line_offset(out iter,
+ (int)sym.range.start.line,
+ (int)sym.range.start.character
+ );
+ _this.buffer.el.place_cursor(iter);
+
+ });
+ }
+
+ // user defined functions
+ }
+
+
+
+
+