3 public class Editor : Object
8 public static Editor singleton()
10 if (_Editor == null) {
11 _Editor= new Editor();
15 public Xcls_save_button save_button;
16 public Xcls_helper helper;
17 public Xcls_close_btn close_btn;
18 public Xcls_RightEditor RightEditor;
19 public Xcls_view view;
20 public Xcls_buffer buffer;
21 public Xcls_keystate keystate;
22 public Xcls_search_entry search_entry;
23 public Xcls_search_results search_results;
24 public Xcls_nextBtn nextBtn;
25 public Xcls_backBtn backBtn;
26 public Xcls_search_settings search_settings;
27 public Xcls_case_sensitive case_sensitive;
28 public Xcls_regex regex;
29 public Xcls_multiline multiline;
30 public Xcls_navigation_holder navigation_holder;
31 public Xcls_navigationwindow navigationwindow;
32 public Xcls_navigation navigation;
33 public Xcls_navigationselmodel navigationselmodel;
34 public Xcls_navigationsort navigationsort;
35 public Xcls_navliststore navliststore;
38 public int pos_root_x;
39 public Xcls_MainWindow window;
41 public int pos_root_y;
43 public int last_error_counter;
44 public GtkSource.SearchContext searchcontext;
45 public int last_search_end;
46 public signal void save ();
47 public JsRender.JsRender? file;
48 public JsRender.Node node;
49 public JsRender.NodeProp? prop;
50 public string activeEditor;
56 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
62 this.last_error_counter = 0;
63 this.searchcontext = null;
64 this.last_search_end = 0;
68 this.activeEditor = "\"\"";
71 this.el.homogeneous = false;
72 this.el.hexpand = true;
73 this.el.vexpand = true;
74 var child_1 = new Xcls_Paned1( _this );
76 this.el.append( child_1.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_Paned1 : Object
408 private Editor _this;
414 public Xcls_Paned1(Editor _owner )
417 this.el = new Gtk.Paned( Gtk.Orientation.HORIZONTAL );
421 // set gobject values
422 this.el.width_request = 200;
423 this.el.shrink_end_child = false;
424 var child_1 = new Xcls_Box2( _this );
426 this.el.start_child = child_1.el;
427 new Xcls_navigation_holder( _this );
428 this.el.end_child = _this.navigation_holder.el;
431 // user defined functions
433 public class Xcls_Box2 : Object
436 private Editor _this;
442 public Xcls_Box2(Editor _owner )
445 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
449 // set gobject values
450 var child_1 = new Xcls_Box3( _this );
452 this.el.append( child_1.el );
453 new Xcls_RightEditor( _this );
454 this.el.append( _this.RightEditor.el );
455 var child_3 = new Xcls_Box15( _this );
457 this.el.append ( child_3.el );
460 // user defined functions
462 public class Xcls_Box3 : Object
465 private Editor _this;
471 public Xcls_Box3(Editor _owner )
474 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
478 // set gobject values
479 this.el.homogeneous = false;
480 this.el.hexpand = false;
481 this.el.vexpand = false;
482 new Xcls_save_button( _this );
483 this.el.append( _this.save_button.el );
484 new Xcls_helper( _this );
485 this.el.append( _this.helper.el );
486 var child_3 = new Xcls_Scale6( _this );
488 this.el.append( child_3.el );
489 new Xcls_close_btn( _this );
490 this.el.append( _this.close_btn.el );
493 // user defined functions
495 public class Xcls_save_button : Object
497 public Gtk.Button el;
498 private Editor _this;
504 public Xcls_save_button(Editor _owner )
507 _this.save_button = this;
508 this.el = new Gtk.Button();
512 // set gobject values
513 this.el.vexpand = true;
514 this.el.label = "Save";
517 this.el.clicked.connect( () => {
518 _this.saveContents();
522 // user defined functions
525 public class Xcls_helper : Object
528 private Editor _this;
534 public Xcls_helper(Editor _owner )
538 this.el = new Gtk.Label( null );
542 // set gobject values
543 this.el.margin_end = 4;
544 this.el.margin_start = 4;
545 this.el.justify = Gtk.Justification.LEFT;
546 this.el.hexpand = true;
550 // user defined functions
551 public void setHelp (Lsp.Hover? help) {
552 if (help == null || help.contents == null
553 || help.contents.size < 1) {
554 this.el.set_text("");
557 var sig = help.contents.get(0).value.split(" ");
559 for(var i =0; i < sig.length; i++) {
578 str += ("<span underline=\"single\" color=\"blue\" >" +
579 GLib.Markup.escape_text(sig[i])
584 if (help.contents.size > 1) {
585 sig += ("\n\n" + help.contents[1].value);
588 this.el.set_markup(string.joinv(" ",str));
593 public class Xcls_Scale6 : Object
596 private Editor _this;
602 public Xcls_Scale6(Editor _owner )
605 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
609 // set gobject values
610 this.el.width_request = 150;
611 this.el.has_origin = true;
612 this.el.halign = Gtk.Align.END;
613 this.el.draw_value = false;
615 this.el.sensitive = true;
620 //this.el.set_range(6,30);
621 this.el.set_value ( BuilderApplication.settings.editor_font_size);
622 BuilderApplication.settings.editor_font_size_updated.connect(
624 BuilderApplication.settings.editor_font_size_inchange = true;
625 // GLib.debug("update range");
626 this.el.set_value (BuilderApplication.settings.editor_font_size);
627 BuilderApplication.settings.editor_font_size_inchange = false;
635 this.el.change_value.connect( (st, val ) => {
636 if (BuilderApplication.settings.editor_font_size_inchange) {
639 BuilderApplication.settings.editor_font_size = val;
644 // user defined functions
647 public class Xcls_close_btn : Object
649 public Gtk.Button el;
650 private Editor _this;
656 public Xcls_close_btn(Editor _owner )
659 _this.close_btn = this;
660 this.el = new Gtk.Button();
664 // set gobject values
665 this.el.icon_name = "window-close";
666 this.el.halign = Gtk.Align.END;
667 var child_1 = new Xcls_Image8( _this );
669 this.el.child = child_1.el;
672 this.el.clicked.connect( () => {
673 _this.saveContents();
674 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
678 // user defined functions
680 public class Xcls_Image8 : Object
683 private Editor _this;
689 public Xcls_Image8(Editor _owner )
692 this.el = new Gtk.Image();
696 // set gobject values
697 this.el.icon_name = "window-close";
698 this.el.icon_size = Gtk.IconSize.NORMAL;
701 // user defined functions
706 public class Xcls_RightEditor : Object
708 public Gtk.ScrolledWindow el;
709 private Editor _this;
715 public Xcls_RightEditor(Editor _owner )
718 _this.RightEditor = this;
719 this.el = new Gtk.ScrolledWindow();
723 // set gobject values
724 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
725 this.el.vexpand = true;
726 this.el.overlay_scrolling = false;
727 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
728 new Xcls_view( _this );
729 this.el.child = _this.view.el;
732 // user defined functions
734 public class Xcls_view : Object
736 public GtkSource.View el;
737 private Editor _this;
741 public Gtk.CssProvider css;
744 public Xcls_view(Editor _owner )
748 this.el = new GtkSource.View();
753 // set gobject values
754 this.el.auto_indent = true;
755 this.el.indent_width = 4;
756 this.el.name = "editor-view";
757 this.el.show_line_marks = true;
758 this.el.insert_spaces_instead_of_tabs = true;
759 this.el.show_line_numbers = true;
760 this.el.hexpand = true;
761 this.el.vexpand = true;
762 this.el.has_tooltip = true;
763 this.el.css_classes = { "code-editor" };
764 this.el.tab_width = 4;
765 this.el.highlight_current_line = true;
766 new Xcls_buffer( _this );
767 this.el.buffer = _this.buffer.el;
768 new Xcls_keystate( _this );
769 this.el.add_controller( _this.keystate.el );
770 var child_3 = new Xcls_EventControllerScroll13( _this );
772 this.el.add_controller( child_3.el );
773 var child_4 = new Xcls_GestureClick14( _this );
775 this.el.add_controller( child_4.el );
779 this.el.completion.add_provider(
780 new Palete.CompletionProvider(_this)
783 // hover seems pretty useless.. - ??
784 //var hover = this.el.get_hover();
785 //hover.add_provider(new Palete.HoverProvider(_this));
787 //this.el.completion.unblock_interactive();
788 this.el.completion.select_on_show = true; // select
789 //this.el.completion.remember_info_visibility = true;
792 var attrs = new GtkSource.MarkAttributes();
794 attrs.set_icon_name ( "process-stop");
795 attrs.query_tooltip_text.connect(( mark) => {
796 GLib.debug("tooltip query? %s", mark.name);
797 return strdup( mark.name);
799 attrs.query_tooltip_markup.connect(( mark) => {
800 GLib.debug("tooltip query? %s", mark.name);
801 return strdup( mark.name);
803 this.el.set_mark_attributes ("ERR", attrs, 1);
807 var wattrs = new GtkSource.MarkAttributes();
808 wattrs.set_icon_name ( "process-stop");
809 wattrs.query_tooltip_text.connect(( mark) => {
810 GLib.debug("tooltip query? %s", mark.name);
811 return strdup(mark.name);
813 wattrs.query_tooltip_markup.connect(( mark) => {
814 GLib.debug("tooltip query? %s", mark.name);
815 return strdup(mark.name);
817 this.el.set_mark_attributes ("WARN", wattrs, 1);
821 var dattrs = new GtkSource.MarkAttributes();
823 dattrs.set_icon_name ( "process-stop");
825 dattrs.query_tooltip_text.connect(( mark) => {
826 GLib.debug("tooltip query? %s", mark.name);
827 return strdup(mark.name);
829 //dattrs.query_tooltip_markup.connect(( mark) => {
830 // GLib.debug("tooltip query? %s", mark.name);
831 // return strdup(mark.name);
833 this.el.set_mark_attributes ("DEPR", dattrs, 1);
836 this.el.get_space_drawer().set_matrix(null);
837 this.el.get_space_drawer().set_types_for_locations(
838 GtkSource.SpaceLocationFlags.ALL,
839 GtkSource.SpaceTypeFlags.ALL
841 this.el.get_space_drawer().set_enable_matrix(true);
844 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
846 //GLib.debug("query tooltip");
850 var yoff = (int) _this.RightEditor.el.vadjustment.value;
852 // I think this is problematic - if it's compliing / updating at same time as query.
854 //if (_this.window.statusbar_compile_spinner.el.spinning) {
858 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
860 var l = iter.get_line();
864 // GLib.debug("query tooltip line %d", (int) l);
870 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
871 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
872 tooltip.set_text(_this.buffer.marks.get(l).dup());
880 // this crashes?? - not sure why.
881 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
882 if (marks.is_empty()) {
883 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
885 if (marks.is_empty()) {
886 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
889 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
891 marks.@foreach((m) => {
892 //GLib.debug("got mark %s", m.name);
893 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
895 // true if there is a mark..
896 if (str.length > 0 ) {
897 tooltip.set_text( str );
899 return str.length > 0 ? true : false;
904 // user defined functions
905 public void load (string str) {
907 // show the help page for the active node..
908 //this.get('/Help').show();
910 // this.get('/BottomPane').el.set_current_page(0);
911 GLib.debug("load called - Reset undo buffer");
913 var buf = (GtkSource.Buffer)this.el.get_buffer();
914 buf.begin_irreversible_action();
915 buf.set_text(str, str.length);
916 buf.end_irreversible_action();
918 var lm = GtkSource.LanguageManager.get_default();
920 if (_this.file != null) {
921 lang = _this.file.language;
923 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
924 var lg = _this.file.content_type.length > 0 ?
925 lm.guess_language(_this.file.path, _this.file.content_type) :
926 lm.get_language(lang);
929 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
931 this.el.insert_spaces_instead_of_tabs = true;
933 print("sourcelanguage = %s\n", lg.name);
934 if (lg.name == "Vala") {
935 this.el.insert_spaces_instead_of_tabs = false;
939 this.el.grab_focus();
940 _this.save_button.el.sensitive = false;
941 _this.last_error_counter = -1;
944 public class Xcls_buffer : Object
946 public GtkSource.Buffer el;
947 private Editor _this;
951 public int error_line;
952 public Gee.HashMap<int,string>? xmarks;
953 public bool check_queued;
956 public Xcls_buffer(Editor _owner )
960 this.el = new GtkSource.Buffer( null );
963 this.error_line = -1;
965 this.check_queued = false;
967 // set gobject values
968 this.el.highlight_syntax = true;
969 this.el.highlight_matching_brackets = true;
970 this.el.enable_undo = true;
975 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
976 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
977 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
978 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
979 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
980 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
981 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
982 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
985 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
986 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
987 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
990 this.el.cursor_moved.connect( ( ) => {
993 this.el.get_iter_at_offset (
994 out iter, this.el.cursor_position);
996 _this.navigation.updateSelectedLine(
997 (uint)iter.get_line(),
998 (uint)iter.get_line_offset()
1000 this.showHelp(iter);
1003 this.el.changed.connect( () => {
1006 _this.save_button.el.sensitive = true;
1007 print("EDITOR CHANGED");
1012 // this.get('/LeftPanel.model').changed( str , false);
1017 // user defined functions
1018 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
1021 this.el.get_bounds (out start, out end);
1023 this.el.remove_source_marks (start, end, type);
1024 GLib.debug("highlight errors");
1026 // we should highlight other types of errors..
1028 if (!obj.has_member(type)) {
1029 GLib.debug("Return has no errors\n");
1033 if (_this.window.windowstate.state != WindowState.State.CODEONLY
1035 _this.window.windowstate.state != WindowState.State.CODE
1037 GLib.debug("windowstate != CODEONLY?");
1042 //this.marks = new Gee.HashMap<int,string>();
1043 var err = obj.get_object_member(type);
1045 if (_this.file == null) {
1046 GLib.debug("file is null?");
1050 var valafn = _this.file.path;
1052 if (_this.file.xtype != "PlainFile") {
1056 var regex = new Regex("\\.bjs$");
1057 // should not happen
1058 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1059 } catch (GLib.RegexError e) {
1066 if (!err.has_member(valafn)) {
1067 GLib.debug("File path has no errors");
1071 var lines = err.get_object_member(valafn);
1074 if (obj.has_member("line_offset")) { // ?? why??
1075 offset = (int)obj.get_int_member("line_offset") + 1;
1079 var tlines = this.el.get_line_count () +1;
1081 if (_this.prop != null) {
1083 tlines = _this.prop.end_line + 1;
1084 offset = _this.prop.start_line + 1;
1090 lines.foreach_member((obj, line, node) => {
1093 // print("get inter\n");
1094 var eline = int.parse(line) - offset;
1095 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
1098 if (eline > tlines || eline < 0) {
1103 this.el.get_iter_at_line( out iter, eline);
1104 //print("mark line\n");
1106 var ar = lines.get_array_member(line);
1107 for (var i = 0 ; i < ar.get_length(); i++) {
1108 if (ar.get_string_element(i) == "Success") {
1111 msg += (msg.length > 0) ? "\n" : "";
1112 msg += ar.get_string_element(i);
1117 msg = "Line: %d".printf(eline+1) + " " + msg;
1118 this.el.create_source_mark(msg, type, iter);
1119 GLib.debug("set line %d to %m", eline, msg);
1120 // this.marks.set(eline, msg);
1129 public bool checkSyntax () {
1132 var str = this.toString();
1135 if (this.error_line > 0) {
1138 this.el.get_bounds (out start, out end);
1140 this.el.remove_source_marks (start, end, null);
1142 if (str.length < 1) {
1143 print("checkSyntax - empty string?\n");
1148 if (_this.file.xtype == "PlainFile") {
1150 // assume it's gtk...
1151 var oldcode =_this.file.toSource();
1152 _this.file.setSource(str);
1153 BuilderApplication.showSpinner("appointment soon","document change pending");
1154 _this.file.getLanguageServer().document_change(_this.file);
1155 _this.file.getLanguageServer().queueDocumentSymbols(_this.file);
1156 _this.file.setSource(oldcode);
1162 if (_this.file == null) {
1170 GLib.debug("calling validate");
1171 // clear the buttons.
1172 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1175 var oldcode = _this.prop.val;
1177 _this.prop.val = str;
1178 _this.node.updated_count++;
1179 _this.file.getLanguageServer().document_change(_this.file);
1180 _this.node.updated_count++;
1181 _this.prop.val = oldcode;
1184 //print("done mark line\n");
1186 return true; // at present allow saving - even if it's invalid..
1188 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1190 this.error_line = validate_res.size;
1192 if (this.error_line < 1) {
1195 var tlines = this.el.get_line_count ();
1197 var valiter = validate_res.map_iterator();
1198 while (valiter.next()) {
1200 // print("get inter\n");
1201 var eline = valiter.get_key();
1202 if (eline > tlines) {
1205 this.el.get_iter_at_line( out iter, eline);
1206 //print("mark line\n");
1207 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1211 public string toString () {
1215 this.el.get_start_iter(out s);
1216 this.el.get_end_iter(out e);
1217 var ret = this.el.get_text(s,e,true);
1218 //print("TO STRING? " + ret);
1221 public void showHelp (Gtk.TextIter iter) {
1222 var back = iter.copy();
1223 back.backward_char();
1225 var forward = iter.copy();
1226 forward.forward_char();
1228 // what's the character at the iter?
1229 var str = back.get_text(iter);
1230 str += iter.get_text(forward);
1231 if (str.strip().length < 1) {
1234 var offset = iter.get_line_offset();
1235 var line = iter.get_line();
1236 if (_this.prop != null) {
1238 line += _this.prop.start_line ;
1239 // this is based on Gtk using tabs (hence 1/2 chars);
1240 offset += _this.node.node_pad.length;
1241 // javascript listeners are indented 2 more spaces.
1242 if (_this.prop.ptype == JsRender.NodePropType.LISTENER) {
1247 var ls = _this.file.getLanguageServer();
1249 _this.file, line, offset,
1252 var res = ls.hover.end(o );
1254 _this.helper.setHelp(res);
1255 } catch (GLib.Error e) {
1262 public class Xcls_keystate : Object
1264 public Gtk.EventControllerKey el;
1265 private Editor _this;
1269 public bool is_control;
1272 public Xcls_keystate(Editor _owner )
1275 _this.keystate = this;
1276 this.el = new Gtk.EventControllerKey();
1279 this.is_control = false;
1281 // set gobject values
1284 this.el.key_released.connect( (keyval, keycode, state) => {
1286 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1287 this.is_control = false;
1289 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1290 GLib.debug("SAVE: ctrl-S pressed");
1291 _this.saveContents();
1295 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1296 GLib.debug("SAVE: ctrl-g pressed");
1297 _this.forwardSearch(true);
1300 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1301 GLib.debug("SAVE: ctrl-f pressed");
1302 _this.search_entry.el.grab_focus();
1303 _this.search_entry.el.select_region(0,-1);
1306 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1307 _this.view.el.show_completion();
1311 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1312 var line = iter.get_line();
1313 var offset = iter.get_line_offset();
1314 GLib.debug("line %d off %d", line ,offset);
1315 if (_this.prop != null) {
1316 line += _this.prop.start_line + 1; // i think..
1317 offset += 12; // should probably be 8 without namespaced
1318 GLib.debug("guess line %d off %d", line ,offset);
1320 //_this.view.el.show_completion();
1321 // print(event.key.keyval)
1328 this.el.key_pressed.connect( (keyval, keycode, state) => {
1330 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1331 this.is_control = true;
1337 // user defined functions
1340 public class Xcls_EventControllerScroll13 : Object
1342 public Gtk.EventControllerScroll el;
1343 private Editor _this;
1347 public double distance;
1350 public Xcls_EventControllerScroll13(Editor _owner )
1353 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1356 this.distance = 0.0f;
1358 // set gobject values
1361 this.el.scroll.connect( (dx, dy) => {
1362 if (!_this.keystate.is_control) {
1365 //GLib.debug("scroll %f", dy);
1367 this.distance += dy;
1369 //GLib.debug("scroll %f / %f", dy, this.distance);
1371 if (this.distance < -1) {
1373 BuilderApplication.settings.editor_font_size ++;
1376 if (this.distance > 1) {
1377 BuilderApplication.settings.editor_font_size --;
1385 // user defined functions
1388 public class Xcls_GestureClick14 : Object
1390 public Gtk.GestureClick el;
1391 private Editor _this;
1397 public Xcls_GestureClick14(Editor _owner )
1400 this.el = new Gtk.GestureClick();
1404 // set gobject values
1407 this.el.pressed.connect( (n_press, x, y) => {
1409 int buffer_x, buffer_y;
1410 var gut = _this.view.el.get_gutter(Gtk.TextWindowType.LEFT);
1412 _this.view.el.window_to_buffer_coords (Gtk.TextWindowType.TEXT,
1413 (int)x - gut.get_width(), (int)y,
1414 out buffer_x, out buffer_y);
1415 _this.view.el.get_iter_at_location (out iter,
1416 buffer_x, buffer_y);;
1419 if (_this.buffer.el.iter_has_context_class(iter, "comment") ||
1420 _this.buffer.el.iter_has_context_class(iter, "string")
1424 _this.buffer.showHelp(iter);
1431 // user defined functions
1436 public class Xcls_Box15 : Object
1439 private Editor _this;
1445 public Xcls_Box15(Editor _owner )
1448 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1452 // set gobject values
1453 this.el.homogeneous = false;
1454 this.el.vexpand = false;
1455 new Xcls_search_entry( _this );
1456 this.el.append( _this.search_entry.el );
1457 new Xcls_search_results( _this );
1458 this.el.append( _this.search_results.el );
1459 new Xcls_nextBtn( _this );
1460 this.el.append( _this.nextBtn.el );
1461 new Xcls_backBtn( _this );
1462 this.el.append( _this.backBtn.el );
1463 var child_5 = new Xcls_MenuButton21( _this );
1465 this.el.append( child_5.el );
1468 // user defined functions
1470 public class Xcls_search_entry : Object
1472 public Gtk.SearchEntry el;
1473 private Editor _this;
1477 public Gtk.CssProvider css;
1480 public Xcls_search_entry(Editor _owner )
1483 _this.search_entry = this;
1484 this.el = new Gtk.SearchEntry();
1488 // set gobject values
1489 this.el.name = "editor-search-entry";
1490 this.el.hexpand = true;
1491 this.el.placeholder_text = "Press enter to search";
1492 this.el.search_delay = 3;
1493 var child_1 = new Xcls_EventControllerKey17( _this );
1495 this.el.add_controller( child_1.el );
1498 this.el.search_changed.connect( ( ) => {
1500 _this.search(_this.search_entry.el.text);
1501 _this.search_results.updateResults();
1503 GLib.Timeout.add_seconds(1,() => {
1504 _this.search_results.updateResults();
1510 // user defined functions
1511 public void forwardSearch (bool change_focus) {
1514 _this.forwardSearch(change_focus);
1518 switch(_this.windowstate.state) {
1519 case WindowState.State.CODEONLY:
1520 //case WindowState.State.CODE:
1521 // search the code being edited..
1522 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1525 case WindowState.State.PREVIEW:
1526 if (_this.windowstate.file.xtype == "Gtk") {
1527 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1529 _this.windowstate.window_rooview.forwardSearch(change_focus);
1538 public class Xcls_EventControllerKey17 : Object
1540 public Gtk.EventControllerKey el;
1541 private Editor _this;
1547 public Xcls_EventControllerKey17(Editor _owner )
1550 this.el = new Gtk.EventControllerKey();
1554 // set gobject values
1557 this.el.key_pressed.connect( (keyval, keycode, state) => {
1559 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1560 GLib.debug("SAVE: ctrl-g pressed");
1561 _this.forwardSearch(true);
1566 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1567 _this.forwardSearch(true);
1573 // print(event.key.keyval)
1579 // user defined functions
1583 public class Xcls_search_results : Object
1585 public Gtk.Label el;
1586 private Editor _this;
1592 public Xcls_search_results(Editor _owner )
1595 _this.search_results = this;
1596 this.el = new Gtk.Label( "No Results" );
1600 // set gobject values
1601 this.el.margin_end = 4;
1602 this.el.margin_start = 4;
1605 // user defined functions
1606 public void updateResults () {
1607 this.el.visible = true;
1609 var res = _this.searchcontext.get_occurrences_count();
1611 _this.search_results.el.label = "??? Matches";
1615 _this.nextBtn.el.sensitive = false;
1616 _this.backBtn.el.sensitive = false;
1619 _this.search_results.el.label = "%d Matches".printf(res);
1620 _this.nextBtn.el.sensitive = true;
1621 _this.backBtn.el.sensitive = true;
1624 _this.search_results.el.label = "No Matches";
1629 public class Xcls_nextBtn : Object
1631 public Gtk.Button el;
1632 private Editor _this;
1636 public bool always_show_image;
1639 public Xcls_nextBtn(Editor _owner )
1642 _this.nextBtn = this;
1643 this.el = new Gtk.Button();
1646 this.always_show_image = true;
1648 // set gobject values
1649 this.el.icon_name = "go-down";
1650 this.el.sensitive = false;
1653 this.el.clicked.connect( (event) => {
1655 _this.forwardSearch(true);
1661 // user defined functions
1664 public class Xcls_backBtn : Object
1666 public Gtk.Button el;
1667 private Editor _this;
1671 public bool always_show_image;
1674 public Xcls_backBtn(Editor _owner )
1677 _this.backBtn = this;
1678 this.el = new Gtk.Button();
1681 this.always_show_image = true;
1683 // set gobject values
1684 this.el.icon_name = "go-up";
1685 this.el.sensitive = false;
1688 this.el.clicked.connect( (event) => {
1690 _this.backSearch(true);
1695 // user defined functions
1698 public class Xcls_MenuButton21 : Object
1700 public Gtk.MenuButton el;
1701 private Editor _this;
1705 public bool always_show_image;
1708 public Xcls_MenuButton21(Editor _owner )
1711 this.el = new Gtk.MenuButton();
1714 this.always_show_image = true;
1716 // set gobject values
1717 this.el.icon_name = "emblem-system";
1718 this.el.always_show_arrow = true;
1719 new Xcls_search_settings( _this );
1720 this.el.popover = _this.search_settings.el;
1723 // user defined functions
1725 public class Xcls_search_settings : Object
1727 public Gtk.Popover el;
1728 private Editor _this;
1734 public Xcls_search_settings(Editor _owner )
1737 _this.search_settings = this;
1738 this.el = new Gtk.Popover();
1742 // set gobject values
1743 var child_1 = new Xcls_Box23( _this );
1745 this.el.child = child_1.el;
1748 // user defined functions
1750 public class Xcls_Box23 : Object
1753 private Editor _this;
1759 public Xcls_Box23(Editor _owner )
1762 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1766 // set gobject values
1767 new Xcls_case_sensitive( _this );
1768 this.el.append( _this.case_sensitive.el );
1769 new Xcls_regex( _this );
1770 this.el.append( _this.regex.el );
1771 new Xcls_multiline( _this );
1772 this.el.append( _this.multiline.el );
1775 // user defined functions
1777 public class Xcls_case_sensitive : Object
1779 public Gtk.CheckButton el;
1780 private Editor _this;
1786 public Xcls_case_sensitive(Editor _owner )
1789 _this.case_sensitive = this;
1790 this.el = new Gtk.CheckButton();
1794 // set gobject values
1795 this.el.label = "Case Sensitive";
1804 // user defined functions
1807 public class Xcls_regex : Object
1809 public Gtk.CheckButton el;
1810 private Editor _this;
1816 public Xcls_regex(Editor _owner )
1820 this.el = new Gtk.CheckButton();
1824 // set gobject values
1825 this.el.label = "Regex";
1834 // user defined functions
1837 public class Xcls_multiline : Object
1839 public Gtk.CheckButton el;
1840 private Editor _this;
1846 public Xcls_multiline(Editor _owner )
1849 _this.multiline = this;
1850 this.el = new Gtk.CheckButton();
1854 // set gobject values
1855 this.el.label = "Multi-line (add \\n)";
1858 // user defined functions
1866 public class Xcls_navigation_holder : Object
1869 private Editor _this;
1875 public Xcls_navigation_holder(Editor _owner )
1878 _this.navigation_holder = this;
1879 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1883 // set gobject values
1884 this.el.width_request = 120;
1885 this.el.hexpand = true;
1886 this.el.vexpand = true;
1887 this.el.visible = false;
1888 var child_1 = new Xcls_Box28( _this );
1890 this.el.append( child_1.el );
1891 new Xcls_navigationwindow( _this );
1892 this.el.append( _this.navigationwindow.el );
1895 // user defined functions
1897 public class Xcls_Box28 : Object
1900 private Editor _this;
1906 public Xcls_Box28(Editor _owner )
1909 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1913 // set gobject values
1916 // user defined functions
1919 public class Xcls_navigationwindow : Object
1921 public Gtk.ScrolledWindow el;
1922 private Editor _this;
1928 public Xcls_navigationwindow(Editor _owner )
1931 _this.navigationwindow = this;
1932 this.el = new Gtk.ScrolledWindow();
1936 // set gobject values
1937 this.el.hexpand = true;
1938 this.el.vexpand = true;
1939 this.el.visible = true;
1940 new Xcls_navigation( _this );
1941 this.el.child = _this.navigation.el;
1944 // user defined functions
1946 public class Xcls_navigation : Object
1948 public Gtk.ColumnView el;
1949 private Editor _this;
1953 public int last_selected_line;
1954 public Gtk.Widget? selected_row;
1957 public Xcls_navigation(Editor _owner )
1960 _this.navigation = this;
1961 new Xcls_navigationselmodel( _this );
1962 this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
1965 this.last_selected_line = -1;
1966 this.selected_row = null;
1968 // set gobject values
1969 this.el.width_request = 200;
1970 this.el.name = "editor-navigation";
1971 var child_2 = new Xcls_ColumnViewColumn31( _this );
1973 this.el.append_column( child_2.el );
1974 var child_3 = new Xcls_GestureClick40( _this );
1976 this.el.add_controller( child_3.el );
1979 // user defined functions
1980 public Gtk.Widget? getRowWidgetAt (double x, double y, out string pos) {
1983 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
1984 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
1989 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
1994 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
1998 //GLib.debug("row number is %d", rn);
1999 //GLib.debug("click %d, %d", (int)x, (int)y);
2001 Graphene.Rect bounds;
2002 row.compute_bounds(this.el, out bounds);
2003 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
2004 // (int)bounds.get_x(), (int)bounds.get_y(),
2005 // (int)bounds.get_width(), (int)bounds.get_height()
2007 var ypos = y - bounds.get_y();
2008 //GLib.debug("rel ypos = %d", (int)ypos);
2009 var rpos = 100.0 * (ypos / bounds.get_height());
2010 //GLib.debug("rel pos = %d %%", (int)rpos);
2015 } else if (rpos < 20) {
2020 public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
2021 _this.navigationwindow.el.show();
2023 //_this.navliststore.el.remove_all();
2026 var ls = new GLib.ListStore(typeof(Lsp.DocumentSymbol));
2028 foreach(var sym in syms) {
2031 Lsp.DocumentSymbol.copyList(ls, _this.navliststore.el);
2032 //_this.navliststore.el.append(sym);
2033 this.last_selected_line = -1;
2034 GLib.Idle.add(() => {
2035 _this.navigationsort.collapseOnLoad();
2037 _this.buffer.el.get_iter_at_offset (
2038 out iter, _this.buffer.el.cursor_position);
2040 GLib.debug("idle update scroll %d, %d", iter.get_line(),
2041 iter.get_line_offset());
2042 this.updateSelectedLine(
2043 (uint)iter.get_line(),
2044 (uint)iter.get_line_offset()
2050 public int getRowAt (double x, double y, out string pos) {
2053 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
2054 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
2059 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
2064 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
2069 while (cr.get_prev_sibling() != null) {
2071 cr = cr.get_prev_sibling();
2074 //GLib.debug("row number is %d", rn);
2075 //GLib.debug("click %d, %d", (int)x, (int)y);
2077 Graphene.Rect bounds;
2078 row.compute_bounds(this.el, out bounds);
2079 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
2080 // (int)bounds.get_x(), (int)bounds.get_y(),
2081 // (int)bounds.get_width(), (int)bounds.get_height()
2083 var ypos = y - bounds.get_y();
2084 //GLib.debug("rel ypos = %d", (int)ypos);
2085 var rpos = 100.0 * (ypos / bounds.get_height());
2086 //GLib.debug("rel pos = %d %%", (int)rpos);
2091 } else if (rpos < 20) {
2096 public void updateSelectedLine (uint line, uint chr) {
2097 if (line == this.last_selected_line) {
2100 GLib.debug("select line %d", (int)line);
2101 this.last_selected_line = (int)line;
2105 var sym = _this.navliststore.symbolAtLine(line, chr);
2107 new_row = _this.navigationsort.getRowFromSymbol(sym);
2108 GLib.debug("select line %d - row found %d", (int)line, new_row);
2110 GLib.debug(" no symbol found at line %d", (int)line);
2113 if (this.selected_row != null) {
2114 GLib.debug(" remove selected row");
2115 this.selected_row.remove_css_class("selected-row");
2117 this.selected_row = null;
2119 this.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);
2120 var row = sym.get_data<Gtk.Widget>("widget");
2122 GLib.debug(" Add selected row");
2124 row.add_css_class("selected-row");
2125 this.selected_row = row;
2129 GLib.debug("could not find widget on row %d", new_row);
2137 public class Xcls_ColumnViewColumn31 : Object
2139 public Gtk.ColumnViewColumn el;
2140 private Editor _this;
2146 public Xcls_ColumnViewColumn31(Editor _owner )
2149 var child_1 = new Xcls_SignalListItemFactory32( _this );
2151 this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
2155 // set gobject values
2156 this.el.expand = true;
2159 // user defined functions
2161 public class Xcls_SignalListItemFactory32 : Object
2163 public Gtk.SignalListItemFactory el;
2164 private Editor _this;
2170 public Xcls_SignalListItemFactory32(Editor _owner )
2173 this.el = new Gtk.SignalListItemFactory();
2177 // set gobject values
2180 this.el.setup.connect( (listitem) => {
2182 var expand = new Gtk.TreeExpander();
2184 expand.set_indent_for_depth(true);
2185 expand.set_indent_for_icon(true);
2186 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
2187 var icon = new Gtk.Image();
2188 var lbl = new Gtk.Label("");
2189 lbl.use_markup = true;
2190 lbl.ellipsize = Pango.EllipsizeMode.END;
2192 icon.margin_end = 4;
2193 lbl.justify = Gtk.Justification.LEFT;
2196 // listitem.activatable = true; ??
2200 expand.set_child(hbox);
2201 ((Gtk.ListItem)listitem).set_child(expand);
2204 this.el.bind.connect( (listitem) => {
2206 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
2208 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2209 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2212 var hbox = (Gtk.Box) expand.child;
2215 var img = (Gtk.Image) hbox.get_first_child();
2216 var lbl = (Gtk.Label) img.get_next_sibling();
2218 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
2219 var sym = (Lsp.DocumentSymbol) lr.get_item();
2221 sym.set_data<Gtk.Widget>("widget", expand.get_parent());
2222 expand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>("symbol", sym);
2224 //GLib.debug("save sym on %s", expand.get_parent().get_parent().get_type().name());
2226 //GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
2228 expand.set_hide_expander( sym.children.get_n_items() < 1);
2229 expand.set_list_row(lr);
2230 //this.in_bind = true;
2231 // default is to expand
2233 //this.in_bind = false;
2235 sym.bind_property("symbol_icon",
2237 GLib.BindingFlags.SYNC_CREATE);
2239 hbox.css_classes = { sym.symbol_icon };
2241 sym.bind_property("name",
2243 GLib.BindingFlags.SYNC_CREATE);
2244 // should be better?- --line no?
2245 sym.bind_property("tooltip",
2246 lbl, "tooltip_markup",
2247 GLib.BindingFlags.SYNC_CREATE);
2253 // user defined functions
2257 public class Xcls_navigationselmodel : Object
2259 public Gtk.NoSelection el;
2260 private Editor _this;
2266 public Xcls_navigationselmodel(Editor _owner )
2269 _this.navigationselmodel = this;
2270 new Xcls_navigationsort( _this );
2271 this.el = new Gtk.NoSelection( _this.navigationsort.el );
2275 // set gobject values
2278 // user defined functions
2280 public class Xcls_navigationsort : Object
2282 public Gtk.SortListModel el;
2283 private Editor _this;
2289 public Xcls_navigationsort(Editor _owner )
2292 _this.navigationsort = this;
2293 var child_1 = new Xcls_TreeListModel35( _this );
2295 var child_2 = new Xcls_TreeListRowSorter37( _this );
2297 this.el = new Gtk.SortListModel( child_1.el, child_2.el );
2301 // set gobject values
2304 // user defined functions
2305 public void collapseOnLoad () {
2306 for (var i=0;i < this.el.get_n_items(); i++) {
2307 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2308 var sym = (Lsp.DocumentSymbol)tr.get_item();
2310 case Lsp.SymbolKind.Enum:
2311 tr.expanded = false;
2314 //tr.expanded = true;
2323 public int getRowFromSymbol (Lsp.DocumentSymbol sym) {
2325 for (var i=0;i < this.el.get_n_items(); i++) {
2326 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2328 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2334 public Lsp.DocumentSymbol? getSymbolAt (uint row) {
2336 var tr = (Gtk.TreeListRow)this.el.get_item(row);
2338 var a = tr.get_item();;
2339 GLib.debug("get_item (2) = %s", a.get_type().name());
2342 return (Lsp.DocumentSymbol)tr.get_item();
2346 public class Xcls_TreeListModel35 : Object
2348 public Gtk.TreeListModel el;
2349 private Editor _this;
2355 public Xcls_TreeListModel35(Editor _owner )
2358 new Xcls_navliststore( _this );
2359 this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
2361 return ((Lsp.DocumentSymbol)item).children;
2367 // set gobject values
2370 this.el.items_changed.connect( (position, removed, added) => {
2371 GLib.debug("tree item changed %d , %d , %d",(int) position, (int)removed, (int) added);
2375 //var sym = (Lsp.DocumentSymbol) this.el.get_item(position);
2376 var row = this.el.get_row(position);
2378 GLib.debug("got %s", row.get_item().get_type().name());
2384 // user defined functions
2386 public class Xcls_navliststore : Object
2388 public GLib.ListStore el;
2389 private Editor _this;
2395 public Xcls_navliststore(Editor _owner )
2398 _this.navliststore = this;
2399 this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
2403 // set gobject values
2406 // user defined functions
2407 public Lsp.DocumentSymbol? symbolAtLine (uint line, uint chr) {
2410 for(var i = 0; i < this.el.get_n_items();i++) {
2411 var el = (Lsp.DocumentSymbol)this.el.get_item(i);
2412 //GLib.debug("Check sym %s : %d-%d",
2413 // el.name , (int)el.range.start.line,
2414 // (int)el.range.end.line
2416 var ret = el.containsLine(line,chr);
2428 public class Xcls_TreeListRowSorter37 : Object
2430 public Gtk.TreeListRowSorter el;
2431 private Editor _this;
2437 public Xcls_TreeListRowSorter37(Editor _owner )
2440 var child_1 = new Xcls_StringSorter38( _this );
2442 this.el = new Gtk.TreeListRowSorter( child_1.el );
2446 // set gobject values
2449 // user defined functions
2451 public class Xcls_StringSorter38 : Object
2453 public Gtk.StringSorter el;
2454 private Editor _this;
2460 public Xcls_StringSorter38(Editor _owner )
2463 var child_1 = new Xcls_PropertyExpression39( _this );
2465 this.el = new Gtk.StringSorter( child_1.el );
2469 // set gobject values
2472 // user defined functions
2474 public class Xcls_PropertyExpression39 : Object
2476 public Gtk.PropertyExpression el;
2477 private Editor _this;
2483 public Xcls_PropertyExpression39(Editor _owner )
2486 this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
2490 // set gobject values
2493 // user defined functions
2500 public class Xcls_GestureClick40 : Object
2502 public Gtk.GestureClick el;
2503 private Editor _this;
2509 public Xcls_GestureClick40(Editor _owner )
2512 this.el = new Gtk.GestureClick();
2516 // set gobject values
2519 this.el.pressed.connect( (n_press, x, y) => {
2521 var row = _this.navigation.getRowWidgetAt(x,y, out pos );
2524 GLib.debug("no row selected items");
2527 GLib.debug("got click on %s", row.get_type().name());
2528 //Lsp.DocumentSymbol
2529 var sym = row.get_data<Lsp.DocumentSymbol>("symbol");
2545 GLib.debug("goto line %d", (int)sym.range.start.line);
2546 _this.scroll_to_line((int)sym.range.start.line);
2548 _this.buffer.el.get_iter_at_line_offset(out iter,
2549 (int)sym.range.start.line,
2550 (int)sym.range.start.character
2552 _this.buffer.el.place_cursor(iter);
2557 // user defined functions