3 public class Editor : Object
8 public static Editor singleton()
10 if (_Editor == null) {
11 _Editor= new Editor();
15 public Xcls_paned paned;
16 public Xcls_save_button save_button;
17 public Xcls_helper helper;
18 public Xcls_close_btn close_btn;
19 public Xcls_RightEditor RightEditor;
20 public Xcls_view view;
21 public Xcls_buffer buffer;
22 public Xcls_keystate keystate;
23 public Xcls_search_entry search_entry;
24 public Xcls_search_results search_results;
25 public Xcls_nextBtn nextBtn;
26 public Xcls_backBtn backBtn;
27 public Xcls_search_settings search_settings;
28 public Xcls_case_sensitive case_sensitive;
29 public Xcls_regex regex;
30 public Xcls_multiline multiline;
31 public Xcls_navigation_holder navigation_holder;
32 public Xcls_navigationwindow navigationwindow;
33 public Xcls_navigation navigation;
34 public Xcls_navigationselmodel navigationselmodel;
35 public Xcls_navigationsort navigationsort;
36 public Xcls_navliststore navliststore;
39 public int pos_root_x;
40 public Xcls_MainWindow window;
42 public int pos_root_y;
44 public int last_error_counter;
45 public GtkSource.SearchContext searchcontext;
46 public int last_search_end;
47 public signal void save ();
48 public JsRender.JsRender? file;
49 public JsRender.Node node;
50 public JsRender.NodeProp? prop;
51 public string activeEditor;
57 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
63 this.last_error_counter = 0;
64 this.searchcontext = null;
65 this.last_search_end = 0;
69 this.activeEditor = "\"\"";
72 this.el.homogeneous = false;
73 this.el.hexpand = true;
74 this.el.vexpand = true;
75 new Xcls_paned( _this );
76 this.el.append( _this.paned.el );
79 // user defined functions
80 public bool saveContents () {
83 if (_this.file == null) {
89 var str = _this.buffer.toString();
91 _this.buffer.checkSyntax();
95 // LeftPanel.model.changed( str , false);
97 _this.save_button.el.sensitive = false;
99 // find the text for the node..
100 if (_this.file.xtype != "PlainFile") {
101 // in theory these properties have to exist!?!
103 //this.window.windowstate.left_props.reload();
105 _this.file.setSource( str );
114 public void forwardSearch (bool change_focus) {
116 if (this.searchcontext == null) {
120 Gtk.TextIter beg, st,en;
121 bool has_wrapped_around;
122 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
123 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
125 this.last_search_end = 0; // not sure if this should happen
127 if (has_wrapped_around) {
131 this.last_search_end = en.get_offset();
133 this.view.el.grab_focus();
135 this.buffer.el.place_cursor(st);
136 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
140 public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
143 if (this.file != null) {
144 this.file.navigation_tree_updated.disconnect(
145 _this.navigation.show
149 this.file.navigation_tree_updated.connect(
150 _this.navigation.show
152 if (file.xtype != "PlainFile") {
156 // find the text for the node..
157 this.view.load( prop.val );
158 this.updateErrorMarks();
162 this.close_btn.el.show();
165 this.view.load( file.toSource() );
166 this.updateErrorMarks();
167 this.close_btn.el.hide();
168 var ls = file.getLanguageServer();
169 ls.queueDocumentSymbols(file);
170 ////ls.documentSymbols.begin(file, (a,o) => {
171 // _this.navigation.show(ls.documentSymbols.end(o));
178 public void backSearch (bool change_focus) {
180 if (this.searchcontext == null) {
184 Gtk.TextIter beg, st,en;
185 bool has_wrapped_around;
186 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
188 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
189 this.last_search_end = 0;
191 this.last_search_end = en.get_offset();
193 this.view.el.grab_focus();
195 this.buffer.el.place_cursor(st);
196 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
200 public string tempFileContents () {
203 if (_this.file == null) {
206 var str= this.buffer.toString();
207 if (_this.file.xtype == "PlainFile") {
215 GLib.debug("calling validate");
216 // clear the buttons.
217 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
218 return this.file.toSource(); ;
221 var oldcode = _this.prop.val;
222 _this.prop.val = str;
223 var ret = _this.file.toSource();
224 _this.prop.val = oldcode;
228 public void reset () {
233 this.searchcontext = null;
236 public int search (string in_txt) {
238 var s = new GtkSource.SearchSettings();
239 s.case_sensitive = _this.case_sensitive.el.active;
240 s.regex_enabled = _this.regex.el.active;
241 s.wrap_around = false;
243 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
244 this.searchcontext.set_highlight(true);
247 if (_this.multiline.el.active) {
248 txt = in_txt.replace("\\n", "\n");
251 s.set_search_text(txt);
252 Gtk.TextIter beg, st,en;
254 this.buffer.el.get_start_iter(out beg);
255 bool has_wrapped_around;
256 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
257 this.last_search_end = 0;
259 return this.searchcontext.get_occurrences_count();
265 public void updateErrorMarks () {
269 var buf = _this.buffer.el;
272 buf.get_bounds (out start, out end);
277 //GLib.debug("highlight errors");
279 // we should highlight other types of errors..
281 if (_this.window.windowstate.state != WindowState.State.CODEONLY
283 _this.window.windowstate.state != WindowState.State.CODE
285 //GLib.debug("windowstate != CODEONLY?");
291 if (_this.file == null) {
292 GLib.debug("file is null?");
296 var ar = this.file.getErrors();
298 buf.remove_source_marks (start, end, "ERR");
299 buf.remove_source_marks (start, end, "WARN");
300 buf.remove_source_marks (start, end, "DEPR");
301 buf.remove_tag_by_name ("ERR", start, end);
302 buf.remove_tag_by_name ("WARN", start, end);
303 buf.remove_tag_by_name ("DEPR", start, end);
304 this.last_error_counter = file.error_counter ;
305 //GLib.debug("highlight %s : %s has no errors", this.file.relpath, category);
310 // basicaly check if there is no change, then we do not do any update..
311 // we can do this by just using an error counter?
312 // if that's changed then we will do an update, otherwise dont bother.
318 var tlines = buf.get_line_count () +1;
320 if (_this.prop != null) {
321 // this still seems flaky...
323 tlines = _this.prop.end_line;
324 offset = _this.prop.start_line;
325 hoffset = _this.node.node_pad.length + 2; //shift it left by 2 ? ..
330 if (this.last_error_counter == file.error_counter) {
336 buf.remove_source_marks (start, end, "ERR");
337 buf.remove_source_marks (start, end, "WARN");
338 buf.remove_source_marks (start, end, "DEPR");
339 buf.remove_tag_by_name ("ERR", start, end);
340 buf.remove_tag_by_name ("WARN", start, end);
341 buf.remove_tag_by_name ("DEPR", start, end);
343 foreach(var diag in ar) {
345 // print("get inter\n");
346 var eline = (int)diag.range.start.line - offset;
347 var eline_to = (int)diag.range.end.line - offset;
348 //var eline = diag.range.end_line - offset;
349 //GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
350 // err.line ,eline, offset);
353 if (eline > tlines || eline < 0) {
357 buf.get_iter_at_line( out iter, eline);
358 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
359 buf.create_source_mark( msg, diag.category, iter);
361 var spos = (int)diag.range.start.character - hoffset;
362 if (spos < 0) { spos =0 ; }
363 if (spos > iter.get_chars_in_line()) {
364 spos = iter.get_chars_in_line();
366 buf.get_iter_at_line( out iter, eline_to);
367 var epos = (int)diag.range.end.character - hoffset;
368 if (epos < 0) { epos =0 ; }
369 if (epos > iter.get_chars_in_line()) {
370 epos = iter.get_chars_in_line();
374 buf.get_iter_at_line_offset( out start, eline, spos);
376 buf.get_iter_at_line_offset( out end, eline_to,epos);
378 buf.apply_tag_by_name(diag.category, start, end);
380 // GLib.debug("set line %d to %s", eline, msg);
381 //this.marks.set(eline, msg);
383 this.last_error_counter = file.error_counter ;
390 public void scroll_to_line (int line) {
392 GLib.Timeout.add(500, () => {
394 var buf = this.view.el.get_buffer();
396 var sbuf = (GtkSource.Buffer) buf;
400 sbuf.get_iter_at_line(out iter, line);
401 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
405 public class Xcls_paned : Object
408 private Editor _this;
414 public Xcls_paned(Editor _owner )
418 this.el = new Gtk.Paned( Gtk.Orientation.HORIZONTAL );
422 // set gobject values
423 this.el.resize_start_child = false;
424 this.el.shrink_end_child = false;
425 this.el.resize_end_child = false;
426 this.el.shrink_start_child = false;
427 var child_1 = new Xcls_Box2( _this );
429 this.el.start_child = child_1.el;
430 new Xcls_navigation_holder( _this );
431 this.el.end_child = _this.navigation_holder.el;
434 // user defined functions
436 public class Xcls_Box2 : Object
439 private Editor _this;
445 public Xcls_Box2(Editor _owner )
448 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
452 // set gobject values
453 this.el.hexpand = true;
454 var child_1 = new Xcls_Box3( _this );
456 this.el.append( child_1.el );
457 new Xcls_RightEditor( _this );
458 this.el.append( _this.RightEditor.el );
459 var child_3 = new Xcls_Box15( _this );
461 this.el.append ( child_3.el );
464 // user defined functions
466 public class Xcls_Box3 : Object
469 private Editor _this;
475 public Xcls_Box3(Editor _owner )
478 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
482 // set gobject values
483 this.el.homogeneous = false;
484 this.el.hexpand = false;
485 this.el.vexpand = false;
486 new Xcls_save_button( _this );
487 this.el.append( _this.save_button.el );
488 new Xcls_helper( _this );
489 this.el.append( _this.helper.el );
490 var child_3 = new Xcls_Scale6( _this );
492 this.el.append( child_3.el );
493 new Xcls_close_btn( _this );
494 this.el.append( _this.close_btn.el );
497 // user defined functions
499 public class Xcls_save_button : Object
501 public Gtk.Button el;
502 private Editor _this;
508 public Xcls_save_button(Editor _owner )
511 _this.save_button = this;
512 this.el = new Gtk.Button();
516 // set gobject values
517 this.el.vexpand = true;
518 this.el.label = "Save";
521 this.el.clicked.connect( () => {
522 _this.saveContents();
526 // user defined functions
529 public class Xcls_helper : Object
532 private Editor _this;
538 public Xcls_helper(Editor _owner )
542 this.el = new Gtk.Label( null );
546 // set gobject values
547 this.el.margin_end = 4;
548 this.el.margin_start = 4;
549 this.el.justify = Gtk.Justification.LEFT;
550 this.el.hexpand = true;
554 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
555 GLib.debug("using quiery tooltip?");
556 var lbl = new Gtk.Label(this.el.tooltip_markup);
557 lbl.width_request = 500;
558 tooltip.set_custom(lbl);
562 this.el.activate_link.connect( (uri) => {
563 GLib.debug("got uri %s", uri);
564 var ls = _this.file.getLanguageServer();
565 ls.symbol.begin(uri, (a,b) => {
573 // user defined functions
574 public void setHelp (Lsp.Hover? help) {
575 if (help == null || help.contents == null
576 || help.contents.size < 1) {
577 this.el.set_text("");
580 var sig = help.contents.get(0).value.split(" ");
582 for(var i =0; i < sig.length; i++) {
601 str += ("<a href=\"" + GLib.Markup.escape_text(sig[i]) + "\">" +
602 GLib.Markup.escape_text(sig[i])
607 if (help.contents.size > 1) {
608 this.el.tooltip_markup = GLib.Markup.escape_text(help.contents.get(1).value);
610 this.el.tooltip_markup = GLib.Markup.escape_text(help.contents.get(0).value);
612 this.el.set_markup(string.joinv(" ",str));
617 public class Xcls_Scale6 : Object
620 private Editor _this;
626 public Xcls_Scale6(Editor _owner )
629 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
633 // set gobject values
634 this.el.width_request = 150;
635 this.el.has_origin = true;
636 this.el.halign = Gtk.Align.END;
637 this.el.draw_value = false;
639 this.el.sensitive = true;
644 //this.el.set_range(6,30);
645 this.el.set_value ( BuilderApplication.settings.editor_font_size);
646 BuilderApplication.settings.editor_font_size_updated.connect(
648 BuilderApplication.settings.editor_font_size_inchange = true;
649 // GLib.debug("update range");
650 this.el.set_value (BuilderApplication.settings.editor_font_size);
651 BuilderApplication.settings.editor_font_size_inchange = false;
659 this.el.change_value.connect( (st, val ) => {
660 if (BuilderApplication.settings.editor_font_size_inchange) {
663 BuilderApplication.settings.editor_font_size = val;
668 // user defined functions
671 public class Xcls_close_btn : Object
673 public Gtk.Button el;
674 private Editor _this;
680 public Xcls_close_btn(Editor _owner )
683 _this.close_btn = this;
684 this.el = new Gtk.Button();
688 // set gobject values
689 this.el.icon_name = "window-close";
690 this.el.halign = Gtk.Align.END;
691 var child_1 = new Xcls_Image8( _this );
693 this.el.child = child_1.el;
696 this.el.clicked.connect( () => {
697 _this.saveContents();
698 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
702 // user defined functions
704 public class Xcls_Image8 : Object
707 private Editor _this;
713 public Xcls_Image8(Editor _owner )
716 this.el = new Gtk.Image();
720 // set gobject values
721 this.el.icon_name = "window-close";
722 this.el.icon_size = Gtk.IconSize.NORMAL;
725 // user defined functions
730 public class Xcls_RightEditor : Object
732 public Gtk.ScrolledWindow el;
733 private Editor _this;
739 public Xcls_RightEditor(Editor _owner )
742 _this.RightEditor = this;
743 this.el = new Gtk.ScrolledWindow();
747 // set gobject values
748 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
749 this.el.vexpand = true;
750 this.el.overlay_scrolling = false;
751 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
752 new Xcls_view( _this );
753 this.el.child = _this.view.el;
756 // user defined functions
758 public class Xcls_view : Object
760 public GtkSource.View el;
761 private Editor _this;
765 public Gtk.CssProvider css;
768 public Xcls_view(Editor _owner )
772 this.el = new GtkSource.View();
777 // set gobject values
778 this.el.auto_indent = true;
779 this.el.indent_width = 4;
780 this.el.name = "editor-view";
781 this.el.show_line_marks = true;
782 this.el.insert_spaces_instead_of_tabs = true;
783 this.el.show_line_numbers = true;
784 this.el.hexpand = true;
785 this.el.vexpand = true;
786 this.el.has_tooltip = true;
787 this.el.css_classes = { "code-editor" };
788 this.el.tab_width = 4;
789 this.el.highlight_current_line = true;
790 new Xcls_buffer( _this );
791 this.el.buffer = _this.buffer.el;
792 new Xcls_keystate( _this );
793 this.el.add_controller( _this.keystate.el );
794 var child_3 = new Xcls_EventControllerScroll13( _this );
796 this.el.add_controller( child_3.el );
797 var child_4 = new Xcls_GestureClick14( _this );
799 this.el.add_controller( child_4.el );
803 this.el.completion.add_provider(
804 new Palete.CompletionProvider(_this)
807 // hover seems pretty useless.. - ??
808 //var hover = this.el.get_hover();
809 //hover.add_provider(new Palete.HoverProvider(_this));
811 //this.el.completion.unblock_interactive();
812 this.el.completion.select_on_show = true; // select
813 //this.el.completion.remember_info_visibility = true;
816 var attrs = new GtkSource.MarkAttributes();
818 attrs.set_icon_name ( "process-stop");
819 attrs.query_tooltip_text.connect(( mark) => {
820 GLib.debug("tooltip query? %s", mark.name);
821 return strdup( mark.name);
823 attrs.query_tooltip_markup.connect(( mark) => {
824 GLib.debug("tooltip query? %s", mark.name);
825 return strdup( mark.name);
827 this.el.set_mark_attributes ("ERR", attrs, 1);
831 var wattrs = new GtkSource.MarkAttributes();
832 wattrs.set_icon_name ( "process-stop");
833 wattrs.query_tooltip_text.connect(( mark) => {
834 GLib.debug("tooltip query? %s", mark.name);
835 return strdup(mark.name);
837 wattrs.query_tooltip_markup.connect(( mark) => {
838 GLib.debug("tooltip query? %s", mark.name);
839 return strdup(mark.name);
841 this.el.set_mark_attributes ("WARN", wattrs, 1);
845 var dattrs = new GtkSource.MarkAttributes();
847 dattrs.set_icon_name ( "process-stop");
849 dattrs.query_tooltip_text.connect(( mark) => {
850 GLib.debug("tooltip query? %s", mark.name);
851 return strdup(mark.name);
853 //dattrs.query_tooltip_markup.connect(( mark) => {
854 // GLib.debug("tooltip query? %s", mark.name);
855 // return strdup(mark.name);
857 this.el.set_mark_attributes ("DEPR", dattrs, 1);
860 this.el.get_space_drawer().set_matrix(null);
861 this.el.get_space_drawer().set_types_for_locations(
862 GtkSource.SpaceLocationFlags.ALL,
863 GtkSource.SpaceTypeFlags.ALL
865 this.el.get_space_drawer().set_enable_matrix(true);
868 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
870 //GLib.debug("query tooltip");
874 var yoff = (int) _this.RightEditor.el.vadjustment.value;
876 // I think this is problematic - if it's compliing / updating at same time as query.
878 //if (_this.window.statusbar_compile_spinner.el.spinning) {
882 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
884 var l = iter.get_line();
888 // GLib.debug("query tooltip line %d", (int) l);
894 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
895 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
896 tooltip.set_text(_this.buffer.marks.get(l).dup());
904 // this crashes?? - not sure why.
905 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
906 if (marks.is_empty()) {
907 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
909 if (marks.is_empty()) {
910 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
913 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
915 marks.@foreach((m) => {
916 //GLib.debug("got mark %s", m.name);
917 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
919 // true if there is a mark..
920 if (str.length > 0 ) {
921 tooltip.set_text( str );
923 return str.length > 0 ? true : false;
928 // user defined functions
929 public void load (string str) {
931 // show the help page for the active node..
932 //this.get('/Help').show();
934 // this.get('/BottomPane').el.set_current_page(0);
935 GLib.debug("load called - Reset undo buffer");
937 var buf = (GtkSource.Buffer)this.el.get_buffer();
938 buf.begin_irreversible_action();
939 buf.set_text(str, str.length);
940 buf.end_irreversible_action();
942 var lm = GtkSource.LanguageManager.get_default();
944 if (_this.file != null) {
945 lang = _this.file.language;
947 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
948 var lg = _this.file.content_type.length > 0 ?
949 lm.guess_language(_this.file.path, _this.file.content_type) :
950 lm.get_language(lang);
953 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
955 this.el.insert_spaces_instead_of_tabs = true;
957 print("sourcelanguage = %s\n", lg.name);
958 if (lg.name == "Vala") {
959 this.el.insert_spaces_instead_of_tabs = false;
963 this.el.grab_focus();
964 _this.save_button.el.sensitive = false;
965 _this.last_error_counter = -1;
968 public class Xcls_buffer : Object
970 public GtkSource.Buffer el;
971 private Editor _this;
975 public int error_line;
976 public Gee.HashMap<int,string>? xmarks;
977 public bool check_queued;
980 public Xcls_buffer(Editor _owner )
984 this.el = new GtkSource.Buffer( null );
987 this.error_line = -1;
989 this.check_queued = false;
991 // set gobject values
992 this.el.highlight_syntax = true;
993 this.el.highlight_matching_brackets = true;
994 this.el.enable_undo = true;
999 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
1000 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
1001 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
1002 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
1003 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
1004 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
1005 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
1006 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
1009 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
1010 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
1011 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
1014 this.el.cursor_moved.connect( ( ) => {
1017 this.el.get_iter_at_offset (
1018 out iter, this.el.cursor_position);
1020 _this.navigation.updateSelectedLine(
1021 (uint)iter.get_line(),
1022 (uint)iter.get_line_offset()
1024 this.showHelp(iter);
1027 this.el.changed.connect( () => {
1030 _this.save_button.el.sensitive = true;
1031 print("EDITOR CHANGED");
1036 // this.get('/LeftPanel.model').changed( str , false);
1041 // user defined functions
1042 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
1045 this.el.get_bounds (out start, out end);
1047 this.el.remove_source_marks (start, end, type);
1048 GLib.debug("highlight errors");
1050 // we should highlight other types of errors..
1052 if (!obj.has_member(type)) {
1053 GLib.debug("Return has no errors\n");
1057 if (_this.window.windowstate.state != WindowState.State.CODEONLY
1059 _this.window.windowstate.state != WindowState.State.CODE
1061 GLib.debug("windowstate != CODEONLY?");
1066 //this.marks = new Gee.HashMap<int,string>();
1067 var err = obj.get_object_member(type);
1069 if (_this.file == null) {
1070 GLib.debug("file is null?");
1074 var valafn = _this.file.path;
1076 if (_this.file.xtype != "PlainFile") {
1080 var regex = new Regex("\\.bjs$");
1081 // should not happen
1082 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1083 } catch (GLib.RegexError e) {
1090 if (!err.has_member(valafn)) {
1091 GLib.debug("File path has no errors");
1095 var lines = err.get_object_member(valafn);
1098 if (obj.has_member("line_offset")) { // ?? why??
1099 offset = (int)obj.get_int_member("line_offset") + 1;
1103 var tlines = this.el.get_line_count () +1;
1105 if (_this.prop != null) {
1107 tlines = _this.prop.end_line + 1;
1108 offset = _this.prop.start_line + 1;
1114 lines.foreach_member((obj, line, node) => {
1117 // print("get inter\n");
1118 var eline = int.parse(line) - offset;
1119 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
1122 if (eline > tlines || eline < 0) {
1127 this.el.get_iter_at_line( out iter, eline);
1128 //print("mark line\n");
1130 var ar = lines.get_array_member(line);
1131 for (var i = 0 ; i < ar.get_length(); i++) {
1132 if (ar.get_string_element(i) == "Success") {
1135 msg += (msg.length > 0) ? "\n" : "";
1136 msg += ar.get_string_element(i);
1141 msg = "Line: %d".printf(eline+1) + " " + msg;
1142 this.el.create_source_mark(msg, type, iter);
1143 GLib.debug("set line %d to %m", eline, msg);
1144 // this.marks.set(eline, msg);
1153 public bool checkSyntax () {
1156 var str = this.toString();
1159 if (this.error_line > 0) {
1162 this.el.get_bounds (out start, out end);
1164 this.el.remove_source_marks (start, end, null);
1166 if (str.length < 1) {
1167 print("checkSyntax - empty string?\n");
1172 if (_this.file.xtype == "PlainFile") {
1174 // assume it's gtk...
1175 var oldcode =_this.file.toSource();
1176 _this.file.setSource(str);
1177 BuilderApplication.showSpinner("appointment soon","document change pending");
1178 _this.file.getLanguageServer().document_change(_this.file);
1179 _this.file.getLanguageServer().queueDocumentSymbols(_this.file);
1180 _this.file.setSource(oldcode);
1186 if (_this.file == null) {
1194 GLib.debug("calling validate");
1195 // clear the buttons.
1196 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1199 var oldcode = _this.prop.val;
1201 _this.prop.val = str;
1202 _this.node.updated_count++;
1203 _this.file.getLanguageServer().document_change(_this.file);
1204 _this.node.updated_count++;
1205 _this.prop.val = oldcode;
1208 //print("done mark line\n");
1210 return true; // at present allow saving - even if it's invalid..
1212 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1214 this.error_line = validate_res.size;
1216 if (this.error_line < 1) {
1219 var tlines = this.el.get_line_count ();
1221 var valiter = validate_res.map_iterator();
1222 while (valiter.next()) {
1224 // print("get inter\n");
1225 var eline = valiter.get_key();
1226 if (eline > tlines) {
1229 this.el.get_iter_at_line( out iter, eline);
1230 //print("mark line\n");
1231 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1235 public string toString () {
1239 this.el.get_start_iter(out s);
1240 this.el.get_end_iter(out e);
1241 var ret = this.el.get_text(s,e,true);
1242 //print("TO STRING? " + ret);
1245 public void showHelp (Gtk.TextIter iter) {
1246 var back = iter.copy();
1247 back.backward_char();
1249 var forward = iter.copy();
1250 forward.forward_char();
1252 // what's the character at the iter?
1253 var str = back.get_text(iter);
1254 str += iter.get_text(forward);
1255 if (str.strip().length < 1) {
1258 var offset = iter.get_line_offset();
1259 var line = iter.get_line();
1260 if (_this.prop != null) {
1262 line += _this.prop.start_line ;
1263 // this is based on Gtk using tabs (hence 1/2 chars);
1264 offset += _this.node.node_pad.length;
1265 // javascript listeners are indented 2 more spaces.
1266 if (_this.prop.ptype == JsRender.NodePropType.LISTENER) {
1271 var ls = _this.file.getLanguageServer();
1273 _this.file, line, offset,
1276 var res = ls.hover.end(o );
1278 _this.helper.setHelp(res);
1279 } catch (GLib.Error e) {
1286 public class Xcls_keystate : Object
1288 public Gtk.EventControllerKey el;
1289 private Editor _this;
1293 public bool is_control;
1296 public Xcls_keystate(Editor _owner )
1299 _this.keystate = this;
1300 this.el = new Gtk.EventControllerKey();
1303 this.is_control = false;
1305 // set gobject values
1308 this.el.key_released.connect( (keyval, keycode, state) => {
1310 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1311 this.is_control = false;
1313 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1314 GLib.debug("SAVE: ctrl-S pressed");
1315 _this.saveContents();
1319 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1320 GLib.debug("SAVE: ctrl-g pressed");
1321 _this.forwardSearch(true);
1324 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1325 GLib.debug("SAVE: ctrl-f pressed");
1326 _this.search_entry.el.grab_focus();
1327 _this.search_entry.el.select_region(0,-1);
1330 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1331 _this.view.el.show_completion();
1335 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1336 var line = iter.get_line();
1337 var offset = iter.get_line_offset();
1338 GLib.debug("line %d off %d", line ,offset);
1339 if (_this.prop != null) {
1340 line += _this.prop.start_line + 1; // i think..
1341 offset += 12; // should probably be 8 without namespaced
1342 GLib.debug("guess line %d off %d", line ,offset);
1344 //_this.view.el.show_completion();
1345 // print(event.key.keyval)
1352 this.el.key_pressed.connect( (keyval, keycode, state) => {
1354 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1355 this.is_control = true;
1361 // user defined functions
1364 public class Xcls_EventControllerScroll13 : Object
1366 public Gtk.EventControllerScroll el;
1367 private Editor _this;
1371 public double distance;
1374 public Xcls_EventControllerScroll13(Editor _owner )
1377 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1380 this.distance = 0.0f;
1382 // set gobject values
1385 this.el.scroll.connect( (dx, dy) => {
1386 if (!_this.keystate.is_control) {
1389 //GLib.debug("scroll %f", dy);
1391 this.distance += dy;
1393 //GLib.debug("scroll %f / %f", dy, this.distance);
1395 if (this.distance < -1) {
1397 BuilderApplication.settings.editor_font_size ++;
1400 if (this.distance > 1) {
1401 BuilderApplication.settings.editor_font_size --;
1409 // user defined functions
1412 public class Xcls_GestureClick14 : Object
1414 public Gtk.GestureClick el;
1415 private Editor _this;
1421 public Xcls_GestureClick14(Editor _owner )
1424 this.el = new Gtk.GestureClick();
1428 // set gobject values
1431 this.el.pressed.connect( (n_press, x, y) => {
1433 int buffer_x, buffer_y;
1434 var gut = _this.view.el.get_gutter(Gtk.TextWindowType.LEFT);
1436 _this.view.el.window_to_buffer_coords (Gtk.TextWindowType.TEXT,
1437 (int)x - gut.get_width(), (int)y,
1438 out buffer_x, out buffer_y);
1439 _this.view.el.get_iter_at_location (out iter,
1440 buffer_x, buffer_y);;
1443 if (_this.buffer.el.iter_has_context_class(iter, "comment") ||
1444 _this.buffer.el.iter_has_context_class(iter, "string")
1448 _this.buffer.showHelp(iter);
1455 // user defined functions
1460 public class Xcls_Box15 : Object
1463 private Editor _this;
1469 public Xcls_Box15(Editor _owner )
1472 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1476 // set gobject values
1477 this.el.homogeneous = false;
1478 this.el.vexpand = false;
1479 new Xcls_search_entry( _this );
1480 this.el.append( _this.search_entry.el );
1481 new Xcls_search_results( _this );
1482 this.el.append( _this.search_results.el );
1483 new Xcls_nextBtn( _this );
1484 this.el.append( _this.nextBtn.el );
1485 new Xcls_backBtn( _this );
1486 this.el.append( _this.backBtn.el );
1487 var child_5 = new Xcls_MenuButton21( _this );
1489 this.el.append( child_5.el );
1492 // user defined functions
1494 public class Xcls_search_entry : Object
1496 public Gtk.SearchEntry el;
1497 private Editor _this;
1501 public Gtk.CssProvider css;
1504 public Xcls_search_entry(Editor _owner )
1507 _this.search_entry = this;
1508 this.el = new Gtk.SearchEntry();
1512 // set gobject values
1513 this.el.name = "editor-search-entry";
1514 this.el.hexpand = true;
1515 this.el.placeholder_text = "Press enter to search";
1516 this.el.search_delay = 3;
1517 var child_1 = new Xcls_EventControllerKey17( _this );
1519 this.el.add_controller( child_1.el );
1522 this.el.search_changed.connect( ( ) => {
1524 _this.search(_this.search_entry.el.text);
1525 _this.search_results.updateResults();
1527 GLib.Timeout.add_seconds(1,() => {
1528 _this.search_results.updateResults();
1534 // user defined functions
1535 public void forwardSearch (bool change_focus) {
1538 _this.forwardSearch(change_focus);
1542 switch(_this.windowstate.state) {
1543 case WindowState.State.CODEONLY:
1544 //case WindowState.State.CODE:
1545 // search the code being edited..
1546 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1549 case WindowState.State.PREVIEW:
1550 if (_this.windowstate.file.xtype == "Gtk") {
1551 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1553 _this.windowstate.window_rooview.forwardSearch(change_focus);
1562 public class Xcls_EventControllerKey17 : Object
1564 public Gtk.EventControllerKey el;
1565 private Editor _this;
1571 public Xcls_EventControllerKey17(Editor _owner )
1574 this.el = new Gtk.EventControllerKey();
1578 // set gobject values
1581 this.el.key_pressed.connect( (keyval, keycode, state) => {
1583 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1584 GLib.debug("SAVE: ctrl-g pressed");
1585 _this.forwardSearch(true);
1590 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1591 _this.forwardSearch(true);
1597 // print(event.key.keyval)
1603 // user defined functions
1607 public class Xcls_search_results : Object
1609 public Gtk.Label el;
1610 private Editor _this;
1616 public Xcls_search_results(Editor _owner )
1619 _this.search_results = this;
1620 this.el = new Gtk.Label( "No Results" );
1624 // set gobject values
1625 this.el.margin_end = 4;
1626 this.el.margin_start = 4;
1629 // user defined functions
1630 public void updateResults () {
1631 this.el.visible = true;
1633 var res = _this.searchcontext.get_occurrences_count();
1635 _this.search_results.el.label = "??? Matches";
1639 _this.nextBtn.el.sensitive = false;
1640 _this.backBtn.el.sensitive = false;
1643 _this.search_results.el.label = "%d Matches".printf(res);
1644 _this.nextBtn.el.sensitive = true;
1645 _this.backBtn.el.sensitive = true;
1648 _this.search_results.el.label = "No Matches";
1653 public class Xcls_nextBtn : Object
1655 public Gtk.Button el;
1656 private Editor _this;
1660 public bool always_show_image;
1663 public Xcls_nextBtn(Editor _owner )
1666 _this.nextBtn = this;
1667 this.el = new Gtk.Button();
1670 this.always_show_image = true;
1672 // set gobject values
1673 this.el.icon_name = "go-down";
1674 this.el.sensitive = false;
1677 this.el.clicked.connect( (event) => {
1679 _this.forwardSearch(true);
1685 // user defined functions
1688 public class Xcls_backBtn : Object
1690 public Gtk.Button el;
1691 private Editor _this;
1695 public bool always_show_image;
1698 public Xcls_backBtn(Editor _owner )
1701 _this.backBtn = this;
1702 this.el = new Gtk.Button();
1705 this.always_show_image = true;
1707 // set gobject values
1708 this.el.icon_name = "go-up";
1709 this.el.sensitive = false;
1712 this.el.clicked.connect( (event) => {
1714 _this.backSearch(true);
1719 // user defined functions
1722 public class Xcls_MenuButton21 : Object
1724 public Gtk.MenuButton el;
1725 private Editor _this;
1729 public bool always_show_image;
1732 public Xcls_MenuButton21(Editor _owner )
1735 this.el = new Gtk.MenuButton();
1738 this.always_show_image = true;
1740 // set gobject values
1741 this.el.icon_name = "emblem-system";
1742 this.el.always_show_arrow = true;
1743 new Xcls_search_settings( _this );
1744 this.el.popover = _this.search_settings.el;
1747 // user defined functions
1749 public class Xcls_search_settings : Object
1751 public Gtk.Popover el;
1752 private Editor _this;
1758 public Xcls_search_settings(Editor _owner )
1761 _this.search_settings = this;
1762 this.el = new Gtk.Popover();
1766 // set gobject values
1767 var child_1 = new Xcls_Box23( _this );
1769 this.el.child = child_1.el;
1772 // user defined functions
1774 public class Xcls_Box23 : Object
1777 private Editor _this;
1783 public Xcls_Box23(Editor _owner )
1786 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1790 // set gobject values
1791 new Xcls_case_sensitive( _this );
1792 this.el.append( _this.case_sensitive.el );
1793 new Xcls_regex( _this );
1794 this.el.append( _this.regex.el );
1795 new Xcls_multiline( _this );
1796 this.el.append( _this.multiline.el );
1799 // user defined functions
1801 public class Xcls_case_sensitive : Object
1803 public Gtk.CheckButton el;
1804 private Editor _this;
1810 public Xcls_case_sensitive(Editor _owner )
1813 _this.case_sensitive = this;
1814 this.el = new Gtk.CheckButton();
1818 // set gobject values
1819 this.el.label = "Case Sensitive";
1828 // user defined functions
1831 public class Xcls_regex : Object
1833 public Gtk.CheckButton el;
1834 private Editor _this;
1840 public Xcls_regex(Editor _owner )
1844 this.el = new Gtk.CheckButton();
1848 // set gobject values
1849 this.el.label = "Regex";
1858 // user defined functions
1861 public class Xcls_multiline : Object
1863 public Gtk.CheckButton el;
1864 private Editor _this;
1870 public Xcls_multiline(Editor _owner )
1873 _this.multiline = this;
1874 this.el = new Gtk.CheckButton();
1878 // set gobject values
1879 this.el.label = "Multi-line (add \\n)";
1882 // user defined functions
1890 public class Xcls_navigation_holder : Object
1893 private Editor _this;
1899 public Xcls_navigation_holder(Editor _owner )
1902 _this.navigation_holder = this;
1903 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1907 // set gobject values
1908 this.el.width_request = 120;
1909 this.el.hexpand = true;
1910 this.el.vexpand = true;
1911 this.el.visible = false;
1912 var child_1 = new Xcls_Box28( _this );
1914 this.el.append( child_1.el );
1915 new Xcls_navigationwindow( _this );
1916 this.el.append( _this.navigationwindow.el );
1919 // user defined functions
1921 public class Xcls_Box28 : Object
1924 private Editor _this;
1930 public Xcls_Box28(Editor _owner )
1933 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1937 // set gobject values
1940 // user defined functions
1943 public class Xcls_navigationwindow : Object
1945 public Gtk.ScrolledWindow el;
1946 private Editor _this;
1952 public Xcls_navigationwindow(Editor _owner )
1955 _this.navigationwindow = this;
1956 this.el = new Gtk.ScrolledWindow();
1960 // set gobject values
1961 this.el.hexpand = true;
1962 this.el.vexpand = true;
1963 this.el.visible = true;
1964 new Xcls_navigation( _this );
1965 this.el.child = _this.navigation.el;
1968 // user defined functions
1970 public class Xcls_navigation : Object
1972 public Gtk.ColumnView el;
1973 private Editor _this;
1977 public int last_selected_line;
1978 public Gtk.Widget? selected_row;
1981 public Xcls_navigation(Editor _owner )
1984 _this.navigation = this;
1985 new Xcls_navigationselmodel( _this );
1986 this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
1989 this.last_selected_line = -1;
1990 this.selected_row = null;
1992 // set gobject values
1993 this.el.name = "editor-navigation";
1994 var child_2 = new Xcls_ColumnViewColumn31( _this );
1996 this.el.append_column( child_2.el );
1997 var child_3 = new Xcls_GestureClick40( _this );
1999 this.el.add_controller( child_3.el );
2002 // user defined functions
2003 public Gtk.Widget? getRowWidgetAt (double x, double y, out string pos) {
2006 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
2007 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
2012 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
2017 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
2021 //GLib.debug("row number is %d", rn);
2022 //GLib.debug("click %d, %d", (int)x, (int)y);
2024 Graphene.Rect bounds;
2025 row.compute_bounds(this.el, out bounds);
2026 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
2027 // (int)bounds.get_x(), (int)bounds.get_y(),
2028 // (int)bounds.get_width(), (int)bounds.get_height()
2030 var ypos = y - bounds.get_y();
2031 //GLib.debug("rel ypos = %d", (int)ypos);
2032 var rpos = 100.0 * (ypos / bounds.get_height());
2033 //GLib.debug("rel pos = %d %%", (int)rpos);
2038 } else if (rpos < 20) {
2043 public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
2045 if (!_this.navigation_holder.el.visible && syms.size > 0) {
2046 _this.navigation_holder.el.show();
2047 _this.paned.el.position =
2048 _this.paned.el.get_width() - 200;
2050 //_this.navliststore.el.remove_all();
2053 var ls = new GLib.ListStore(typeof(Lsp.DocumentSymbol));
2055 foreach(var sym in syms) {
2058 // if syms updated is empty, but we already have one..
2059 if (_this.navliststore.el.get_n_items() > 0 && ls.get_n_items() < 1) {
2062 Lsp.DocumentSymbol.copyList(ls, _this.navliststore.el);
2063 //_this.navliststore.el.append(sym);
2064 this.last_selected_line = -1;
2065 GLib.Idle.add(() => {
2066 _this.navigationsort.collapseOnLoad();
2068 _this.buffer.el.get_iter_at_offset (
2069 out iter, _this.buffer.el.cursor_position);
2071 GLib.debug("idle update scroll %d, %d", iter.get_line(),
2072 iter.get_line_offset());
2073 this.updateSelectedLine(
2074 (uint)iter.get_line(),
2075 (uint)iter.get_line_offset()
2081 public int getRowAt (double x, double y, out string pos) {
2084 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
2085 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
2090 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
2095 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
2100 while (cr.get_prev_sibling() != null) {
2102 cr = cr.get_prev_sibling();
2105 //GLib.debug("row number is %d", rn);
2106 //GLib.debug("click %d, %d", (int)x, (int)y);
2108 Graphene.Rect bounds;
2109 row.compute_bounds(this.el, out bounds);
2110 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
2111 // (int)bounds.get_x(), (int)bounds.get_y(),
2112 // (int)bounds.get_width(), (int)bounds.get_height()
2114 var ypos = y - bounds.get_y();
2115 //GLib.debug("rel ypos = %d", (int)ypos);
2116 var rpos = 100.0 * (ypos / bounds.get_height());
2117 //GLib.debug("rel pos = %d %%", (int)rpos);
2122 } else if (rpos < 20) {
2127 public void updateSelectedLine (uint line, uint chr) {
2128 if (line == this.last_selected_line) {
2131 GLib.debug("select line %d", (int)line);
2132 this.last_selected_line = (int)line;
2136 var sym = _this.navliststore.symbolAtLine(line, chr);
2138 new_row = _this.navigationsort.getRowFromSymbol(sym);
2139 GLib.debug("select line %d - row found %d", (int)line, new_row);
2141 GLib.debug(" no symbol found at line %d", (int)line);
2144 if (this.selected_row != null) {
2145 GLib.debug(" remove selected row");
2146 this.selected_row.remove_css_class("selected-row");
2148 this.selected_row = null;
2150 this.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);
2151 var row = sym.get_data<Gtk.Widget>("widget");
2153 GLib.debug(" Add selected row");
2155 row.add_css_class("selected-row");
2156 this.selected_row = row;
2160 GLib.debug("could not find widget on row %d", new_row);
2168 public class Xcls_ColumnViewColumn31 : Object
2170 public Gtk.ColumnViewColumn el;
2171 private Editor _this;
2177 public Xcls_ColumnViewColumn31(Editor _owner )
2180 var child_1 = new Xcls_SignalListItemFactory32( _this );
2182 this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
2186 // set gobject values
2187 this.el.expand = true;
2190 // user defined functions
2192 public class Xcls_SignalListItemFactory32 : Object
2194 public Gtk.SignalListItemFactory el;
2195 private Editor _this;
2201 public Xcls_SignalListItemFactory32(Editor _owner )
2204 this.el = new Gtk.SignalListItemFactory();
2208 // set gobject values
2211 this.el.setup.connect( (listitem) => {
2213 var expand = new Gtk.TreeExpander();
2215 expand.set_indent_for_depth(true);
2216 expand.set_indent_for_icon(true);
2217 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
2218 var icon = new Gtk.Image();
2219 var lbl = new Gtk.Label("");
2220 lbl.use_markup = true;
2221 lbl.ellipsize = Pango.EllipsizeMode.END;
2223 icon.margin_end = 4;
2224 lbl.justify = Gtk.Justification.LEFT;
2227 // listitem.activatable = true; ??
2231 expand.set_child(hbox);
2232 ((Gtk.ListItem)listitem).set_child(expand);
2235 this.el.bind.connect( (listitem) => {
2237 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
2239 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2240 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2243 var hbox = (Gtk.Box) expand.child;
2246 var img = (Gtk.Image) hbox.get_first_child();
2247 var lbl = (Gtk.Label) img.get_next_sibling();
2249 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
2250 var sym = (Lsp.DocumentSymbol) lr.get_item();
2252 sym.set_data<Gtk.Widget>("widget", expand.get_parent());
2253 expand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>("symbol", sym);
2255 //GLib.debug("save sym on %s", expand.get_parent().get_parent().get_type().name());
2257 //GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
2259 expand.set_hide_expander( sym.children.get_n_items() < 1);
2260 expand.set_list_row(lr);
2261 //this.in_bind = true;
2262 // default is to expand
2264 //this.in_bind = false;
2266 sym.bind_property("symbol_icon",
2268 GLib.BindingFlags.SYNC_CREATE);
2270 hbox.css_classes = { sym.symbol_icon };
2272 sym.bind_property("name",
2274 GLib.BindingFlags.SYNC_CREATE);
2275 // should be better?- --line no?
2276 sym.bind_property("tooltip",
2277 lbl, "tooltip_markup",
2278 GLib.BindingFlags.SYNC_CREATE);
2284 // user defined functions
2288 public class Xcls_navigationselmodel : Object
2290 public Gtk.NoSelection el;
2291 private Editor _this;
2297 public Xcls_navigationselmodel(Editor _owner )
2300 _this.navigationselmodel = this;
2301 new Xcls_navigationsort( _this );
2302 this.el = new Gtk.NoSelection( _this.navigationsort.el );
2306 // set gobject values
2309 // user defined functions
2311 public class Xcls_navigationsort : Object
2313 public Gtk.SortListModel el;
2314 private Editor _this;
2320 public Xcls_navigationsort(Editor _owner )
2323 _this.navigationsort = this;
2324 var child_1 = new Xcls_TreeListModel35( _this );
2326 var child_2 = new Xcls_TreeListRowSorter37( _this );
2328 this.el = new Gtk.SortListModel( child_1.el, child_2.el );
2332 // set gobject values
2335 // user defined functions
2336 public void collapseOnLoad () {
2337 for (var i=0;i < this.el.get_n_items(); i++) {
2338 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2339 var sym = (Lsp.DocumentSymbol)tr.get_item();
2341 case Lsp.SymbolKind.Enum:
2342 tr.expanded = false;
2345 //tr.expanded = true;
2354 public int getRowFromSymbol (Lsp.DocumentSymbol sym) {
2356 for (var i=0;i < this.el.get_n_items(); i++) {
2357 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2359 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2365 public Lsp.DocumentSymbol? getSymbolAt (uint row) {
2367 var tr = (Gtk.TreeListRow)this.el.get_item(row);
2369 var a = tr.get_item();;
2370 GLib.debug("get_item (2) = %s", a.get_type().name());
2373 return (Lsp.DocumentSymbol)tr.get_item();
2377 public class Xcls_TreeListModel35 : Object
2379 public Gtk.TreeListModel el;
2380 private Editor _this;
2386 public Xcls_TreeListModel35(Editor _owner )
2389 new Xcls_navliststore( _this );
2390 this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
2392 return ((Lsp.DocumentSymbol)item).children;
2398 // set gobject values
2401 this.el.items_changed.connect( (position, removed, added) => {
2402 GLib.debug("tree item changed %d , %d , %d",(int) position, (int)removed, (int) added);
2406 //var sym = (Lsp.DocumentSymbol) this.el.get_item(position);
2407 var row = this.el.get_row(position);
2409 GLib.debug("got %s", row.get_item().get_type().name());
2415 // user defined functions
2417 public class Xcls_navliststore : Object
2419 public GLib.ListStore el;
2420 private Editor _this;
2426 public Xcls_navliststore(Editor _owner )
2429 _this.navliststore = this;
2430 this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
2434 // set gobject values
2437 // user defined functions
2438 public Lsp.DocumentSymbol? symbolAtLine (uint line, uint chr) {
2441 for(var i = 0; i < this.el.get_n_items();i++) {
2442 var el = (Lsp.DocumentSymbol)this.el.get_item(i);
2443 //GLib.debug("Check sym %s : %d-%d",
2444 // el.name , (int)el.range.start.line,
2445 // (int)el.range.end.line
2447 var ret = el.containsLine(line,chr);
2459 public class Xcls_TreeListRowSorter37 : Object
2461 public Gtk.TreeListRowSorter el;
2462 private Editor _this;
2468 public Xcls_TreeListRowSorter37(Editor _owner )
2471 var child_1 = new Xcls_StringSorter38( _this );
2473 this.el = new Gtk.TreeListRowSorter( child_1.el );
2477 // set gobject values
2480 // user defined functions
2482 public class Xcls_StringSorter38 : Object
2484 public Gtk.StringSorter el;
2485 private Editor _this;
2491 public Xcls_StringSorter38(Editor _owner )
2494 var child_1 = new Xcls_PropertyExpression39( _this );
2496 this.el = new Gtk.StringSorter( child_1.el );
2500 // set gobject values
2503 // user defined functions
2505 public class Xcls_PropertyExpression39 : Object
2507 public Gtk.PropertyExpression el;
2508 private Editor _this;
2514 public Xcls_PropertyExpression39(Editor _owner )
2517 this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
2521 // set gobject values
2524 // user defined functions
2531 public class Xcls_GestureClick40 : Object
2533 public Gtk.GestureClick el;
2534 private Editor _this;
2540 public Xcls_GestureClick40(Editor _owner )
2543 this.el = new Gtk.GestureClick();
2547 // set gobject values
2550 this.el.pressed.connect( (n_press, x, y) => {
2552 var row = _this.navigation.getRowWidgetAt(x,y, out pos );
2555 GLib.debug("no row selected items");
2558 GLib.debug("got click on %s", row.get_type().name());
2559 //Lsp.DocumentSymbol
2560 var sym = row.get_data<Lsp.DocumentSymbol>("symbol");
2576 GLib.debug("goto line %d", (int)sym.range.start.line);
2577 _this.scroll_to_line((int)sym.range.start.line);
2579 _this.buffer.el.get_iter_at_line_offset(out iter,
2580 (int)sym.range.start.line,
2581 (int)sym.range.start.character
2583 _this.buffer.el.place_cursor(iter);
2588 // user defined functions