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;
552 var child_1 = new Xcls_GestureClick61( _this );
554 this.el.add_controller( child_1.el );
557 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
558 GLib.debug("using quiery tooltip?");
559 var lbl = new Gtk.Label(this.el.tooltip_markup);
560 lbl.width_request = 500;
561 tooltip.set_custom(lbl);
567 // user defined functions
568 public void setHelp (Lsp.Hover? help) {
569 if (help == null || help.contents == null
570 || help.contents.size < 1) {
571 this.el.set_text("");
574 var sig = help.contents.get(0).value.split(" ");
576 for(var i =0; i < sig.length; i++) {
595 str += ("<span underline=\"single\" color=\"blue\" >" +
596 GLib.Markup.escape_text(sig[i])
601 if (help.contents.size > 1) {
602 this.el.tooltip_markup = GLib.Markup.escape_text(help.contents.get(1).value);
604 this.el.tooltip_markup = GLib.Markup.escape_text(help.contents.get(0).value);
606 this.el.set_markup(string.joinv(" ",str));
610 public class Xcls_GestureClick61 : Object
612 public Gtk.GestureClick el;
613 private Editor _this;
619 public Xcls_GestureClick61(Editor _owner )
622 this.el = new Gtk.GestureClick();
626 // set gobject values
629 this.el.pressed.connect( (n_press, x, y) => {
631 _this.helper.el.get_layout().xy_to_index(x,y, out ix, out tr);
632 GLib.debug("label click %d", ix);
636 // user defined functions
640 public class Xcls_Scale6 : Object
643 private Editor _this;
649 public Xcls_Scale6(Editor _owner )
652 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
656 // set gobject values
657 this.el.width_request = 150;
658 this.el.has_origin = true;
659 this.el.halign = Gtk.Align.END;
660 this.el.draw_value = false;
662 this.el.sensitive = true;
667 //this.el.set_range(6,30);
668 this.el.set_value ( BuilderApplication.settings.editor_font_size);
669 BuilderApplication.settings.editor_font_size_updated.connect(
671 BuilderApplication.settings.editor_font_size_inchange = true;
672 // GLib.debug("update range");
673 this.el.set_value (BuilderApplication.settings.editor_font_size);
674 BuilderApplication.settings.editor_font_size_inchange = false;
682 this.el.change_value.connect( (st, val ) => {
683 if (BuilderApplication.settings.editor_font_size_inchange) {
686 BuilderApplication.settings.editor_font_size = val;
691 // user defined functions
694 public class Xcls_close_btn : Object
696 public Gtk.Button el;
697 private Editor _this;
703 public Xcls_close_btn(Editor _owner )
706 _this.close_btn = this;
707 this.el = new Gtk.Button();
711 // set gobject values
712 this.el.icon_name = "window-close";
713 this.el.halign = Gtk.Align.END;
714 var child_1 = new Xcls_Image8( _this );
716 this.el.child = child_1.el;
719 this.el.clicked.connect( () => {
720 _this.saveContents();
721 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
725 // user defined functions
727 public class Xcls_Image8 : Object
730 private Editor _this;
736 public Xcls_Image8(Editor _owner )
739 this.el = new Gtk.Image();
743 // set gobject values
744 this.el.icon_name = "window-close";
745 this.el.icon_size = Gtk.IconSize.NORMAL;
748 // user defined functions
753 public class Xcls_RightEditor : Object
755 public Gtk.ScrolledWindow el;
756 private Editor _this;
762 public Xcls_RightEditor(Editor _owner )
765 _this.RightEditor = this;
766 this.el = new Gtk.ScrolledWindow();
770 // set gobject values
771 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
772 this.el.vexpand = true;
773 this.el.overlay_scrolling = false;
774 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
775 new Xcls_view( _this );
776 this.el.child = _this.view.el;
779 // user defined functions
781 public class Xcls_view : Object
783 public GtkSource.View el;
784 private Editor _this;
788 public Gtk.CssProvider css;
791 public Xcls_view(Editor _owner )
795 this.el = new GtkSource.View();
800 // set gobject values
801 this.el.auto_indent = true;
802 this.el.indent_width = 4;
803 this.el.name = "editor-view";
804 this.el.show_line_marks = true;
805 this.el.insert_spaces_instead_of_tabs = true;
806 this.el.show_line_numbers = true;
807 this.el.hexpand = true;
808 this.el.vexpand = true;
809 this.el.has_tooltip = true;
810 this.el.css_classes = { "code-editor" };
811 this.el.tab_width = 4;
812 this.el.highlight_current_line = true;
813 new Xcls_buffer( _this );
814 this.el.buffer = _this.buffer.el;
815 new Xcls_keystate( _this );
816 this.el.add_controller( _this.keystate.el );
817 var child_3 = new Xcls_EventControllerScroll13( _this );
819 this.el.add_controller( child_3.el );
820 var child_4 = new Xcls_GestureClick14( _this );
822 this.el.add_controller( child_4.el );
826 this.el.completion.add_provider(
827 new Palete.CompletionProvider(_this)
830 // hover seems pretty useless.. - ??
831 //var hover = this.el.get_hover();
832 //hover.add_provider(new Palete.HoverProvider(_this));
834 //this.el.completion.unblock_interactive();
835 this.el.completion.select_on_show = true; // select
836 //this.el.completion.remember_info_visibility = true;
839 var attrs = new GtkSource.MarkAttributes();
841 attrs.set_icon_name ( "process-stop");
842 attrs.query_tooltip_text.connect(( mark) => {
843 GLib.debug("tooltip query? %s", mark.name);
844 return strdup( mark.name);
846 attrs.query_tooltip_markup.connect(( mark) => {
847 GLib.debug("tooltip query? %s", mark.name);
848 return strdup( mark.name);
850 this.el.set_mark_attributes ("ERR", attrs, 1);
854 var wattrs = new GtkSource.MarkAttributes();
855 wattrs.set_icon_name ( "process-stop");
856 wattrs.query_tooltip_text.connect(( mark) => {
857 GLib.debug("tooltip query? %s", mark.name);
858 return strdup(mark.name);
860 wattrs.query_tooltip_markup.connect(( mark) => {
861 GLib.debug("tooltip query? %s", mark.name);
862 return strdup(mark.name);
864 this.el.set_mark_attributes ("WARN", wattrs, 1);
868 var dattrs = new GtkSource.MarkAttributes();
870 dattrs.set_icon_name ( "process-stop");
872 dattrs.query_tooltip_text.connect(( mark) => {
873 GLib.debug("tooltip query? %s", mark.name);
874 return strdup(mark.name);
876 //dattrs.query_tooltip_markup.connect(( mark) => {
877 // GLib.debug("tooltip query? %s", mark.name);
878 // return strdup(mark.name);
880 this.el.set_mark_attributes ("DEPR", dattrs, 1);
883 this.el.get_space_drawer().set_matrix(null);
884 this.el.get_space_drawer().set_types_for_locations(
885 GtkSource.SpaceLocationFlags.ALL,
886 GtkSource.SpaceTypeFlags.ALL
888 this.el.get_space_drawer().set_enable_matrix(true);
891 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
893 //GLib.debug("query tooltip");
897 var yoff = (int) _this.RightEditor.el.vadjustment.value;
899 // I think this is problematic - if it's compliing / updating at same time as query.
901 //if (_this.window.statusbar_compile_spinner.el.spinning) {
905 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
907 var l = iter.get_line();
911 // GLib.debug("query tooltip line %d", (int) l);
917 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
918 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
919 tooltip.set_text(_this.buffer.marks.get(l).dup());
927 // this crashes?? - not sure why.
928 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
929 if (marks.is_empty()) {
930 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
932 if (marks.is_empty()) {
933 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
936 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
938 marks.@foreach((m) => {
939 //GLib.debug("got mark %s", m.name);
940 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
942 // true if there is a mark..
943 if (str.length > 0 ) {
944 tooltip.set_text( str );
946 return str.length > 0 ? true : false;
951 // user defined functions
952 public void load (string str) {
954 // show the help page for the active node..
955 //this.get('/Help').show();
957 // this.get('/BottomPane').el.set_current_page(0);
958 GLib.debug("load called - Reset undo buffer");
960 var buf = (GtkSource.Buffer)this.el.get_buffer();
961 buf.begin_irreversible_action();
962 buf.set_text(str, str.length);
963 buf.end_irreversible_action();
965 var lm = GtkSource.LanguageManager.get_default();
967 if (_this.file != null) {
968 lang = _this.file.language;
970 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
971 var lg = _this.file.content_type.length > 0 ?
972 lm.guess_language(_this.file.path, _this.file.content_type) :
973 lm.get_language(lang);
976 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
978 this.el.insert_spaces_instead_of_tabs = true;
980 print("sourcelanguage = %s\n", lg.name);
981 if (lg.name == "Vala") {
982 this.el.insert_spaces_instead_of_tabs = false;
986 this.el.grab_focus();
987 _this.save_button.el.sensitive = false;
988 _this.last_error_counter = -1;
991 public class Xcls_buffer : Object
993 public GtkSource.Buffer el;
994 private Editor _this;
998 public int error_line;
999 public Gee.HashMap<int,string>? xmarks;
1000 public bool check_queued;
1003 public Xcls_buffer(Editor _owner )
1006 _this.buffer = this;
1007 this.el = new GtkSource.Buffer( null );
1010 this.error_line = -1;
1012 this.check_queued = false;
1014 // set gobject values
1015 this.el.highlight_syntax = true;
1016 this.el.highlight_matching_brackets = true;
1017 this.el.enable_undo = true;
1022 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
1023 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
1024 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
1025 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
1026 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
1027 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
1028 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
1029 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
1032 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
1033 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
1034 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
1037 this.el.cursor_moved.connect( ( ) => {
1040 this.el.get_iter_at_offset (
1041 out iter, this.el.cursor_position);
1043 _this.navigation.updateSelectedLine(
1044 (uint)iter.get_line(),
1045 (uint)iter.get_line_offset()
1047 this.showHelp(iter);
1050 this.el.changed.connect( () => {
1053 _this.save_button.el.sensitive = true;
1054 print("EDITOR CHANGED");
1059 // this.get('/LeftPanel.model').changed( str , false);
1064 // user defined functions
1065 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
1068 this.el.get_bounds (out start, out end);
1070 this.el.remove_source_marks (start, end, type);
1071 GLib.debug("highlight errors");
1073 // we should highlight other types of errors..
1075 if (!obj.has_member(type)) {
1076 GLib.debug("Return has no errors\n");
1080 if (_this.window.windowstate.state != WindowState.State.CODEONLY
1082 _this.window.windowstate.state != WindowState.State.CODE
1084 GLib.debug("windowstate != CODEONLY?");
1089 //this.marks = new Gee.HashMap<int,string>();
1090 var err = obj.get_object_member(type);
1092 if (_this.file == null) {
1093 GLib.debug("file is null?");
1097 var valafn = _this.file.path;
1099 if (_this.file.xtype != "PlainFile") {
1103 var regex = new Regex("\\.bjs$");
1104 // should not happen
1105 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1106 } catch (GLib.RegexError e) {
1113 if (!err.has_member(valafn)) {
1114 GLib.debug("File path has no errors");
1118 var lines = err.get_object_member(valafn);
1121 if (obj.has_member("line_offset")) { // ?? why??
1122 offset = (int)obj.get_int_member("line_offset") + 1;
1126 var tlines = this.el.get_line_count () +1;
1128 if (_this.prop != null) {
1130 tlines = _this.prop.end_line + 1;
1131 offset = _this.prop.start_line + 1;
1137 lines.foreach_member((obj, line, node) => {
1140 // print("get inter\n");
1141 var eline = int.parse(line) - offset;
1142 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
1145 if (eline > tlines || eline < 0) {
1150 this.el.get_iter_at_line( out iter, eline);
1151 //print("mark line\n");
1153 var ar = lines.get_array_member(line);
1154 for (var i = 0 ; i < ar.get_length(); i++) {
1155 if (ar.get_string_element(i) == "Success") {
1158 msg += (msg.length > 0) ? "\n" : "";
1159 msg += ar.get_string_element(i);
1164 msg = "Line: %d".printf(eline+1) + " " + msg;
1165 this.el.create_source_mark(msg, type, iter);
1166 GLib.debug("set line %d to %m", eline, msg);
1167 // this.marks.set(eline, msg);
1176 public bool checkSyntax () {
1179 var str = this.toString();
1182 if (this.error_line > 0) {
1185 this.el.get_bounds (out start, out end);
1187 this.el.remove_source_marks (start, end, null);
1189 if (str.length < 1) {
1190 print("checkSyntax - empty string?\n");
1195 if (_this.file.xtype == "PlainFile") {
1197 // assume it's gtk...
1198 var oldcode =_this.file.toSource();
1199 _this.file.setSource(str);
1200 BuilderApplication.showSpinner("appointment soon","document change pending");
1201 _this.file.getLanguageServer().document_change(_this.file);
1202 _this.file.getLanguageServer().queueDocumentSymbols(_this.file);
1203 _this.file.setSource(oldcode);
1209 if (_this.file == null) {
1217 GLib.debug("calling validate");
1218 // clear the buttons.
1219 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1222 var oldcode = _this.prop.val;
1224 _this.prop.val = str;
1225 _this.node.updated_count++;
1226 _this.file.getLanguageServer().document_change(_this.file);
1227 _this.node.updated_count++;
1228 _this.prop.val = oldcode;
1231 //print("done mark line\n");
1233 return true; // at present allow saving - even if it's invalid..
1235 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1237 this.error_line = validate_res.size;
1239 if (this.error_line < 1) {
1242 var tlines = this.el.get_line_count ();
1244 var valiter = validate_res.map_iterator();
1245 while (valiter.next()) {
1247 // print("get inter\n");
1248 var eline = valiter.get_key();
1249 if (eline > tlines) {
1252 this.el.get_iter_at_line( out iter, eline);
1253 //print("mark line\n");
1254 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1258 public string toString () {
1262 this.el.get_start_iter(out s);
1263 this.el.get_end_iter(out e);
1264 var ret = this.el.get_text(s,e,true);
1265 //print("TO STRING? " + ret);
1268 public void showHelp (Gtk.TextIter iter) {
1269 var back = iter.copy();
1270 back.backward_char();
1272 var forward = iter.copy();
1273 forward.forward_char();
1275 // what's the character at the iter?
1276 var str = back.get_text(iter);
1277 str += iter.get_text(forward);
1278 if (str.strip().length < 1) {
1281 var offset = iter.get_line_offset();
1282 var line = iter.get_line();
1283 if (_this.prop != null) {
1285 line += _this.prop.start_line ;
1286 // this is based on Gtk using tabs (hence 1/2 chars);
1287 offset += _this.node.node_pad.length;
1288 // javascript listeners are indented 2 more spaces.
1289 if (_this.prop.ptype == JsRender.NodePropType.LISTENER) {
1294 var ls = _this.file.getLanguageServer();
1296 _this.file, line, offset,
1299 var res = ls.hover.end(o );
1301 _this.helper.setHelp(res);
1302 } catch (GLib.Error e) {
1309 public class Xcls_keystate : Object
1311 public Gtk.EventControllerKey el;
1312 private Editor _this;
1316 public bool is_control;
1319 public Xcls_keystate(Editor _owner )
1322 _this.keystate = this;
1323 this.el = new Gtk.EventControllerKey();
1326 this.is_control = false;
1328 // set gobject values
1331 this.el.key_released.connect( (keyval, keycode, state) => {
1333 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1334 this.is_control = false;
1336 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1337 GLib.debug("SAVE: ctrl-S pressed");
1338 _this.saveContents();
1342 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1343 GLib.debug("SAVE: ctrl-g pressed");
1344 _this.forwardSearch(true);
1347 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1348 GLib.debug("SAVE: ctrl-f pressed");
1349 _this.search_entry.el.grab_focus();
1350 _this.search_entry.el.select_region(0,-1);
1353 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1354 _this.view.el.show_completion();
1358 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1359 var line = iter.get_line();
1360 var offset = iter.get_line_offset();
1361 GLib.debug("line %d off %d", line ,offset);
1362 if (_this.prop != null) {
1363 line += _this.prop.start_line + 1; // i think..
1364 offset += 12; // should probably be 8 without namespaced
1365 GLib.debug("guess line %d off %d", line ,offset);
1367 //_this.view.el.show_completion();
1368 // print(event.key.keyval)
1375 this.el.key_pressed.connect( (keyval, keycode, state) => {
1377 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1378 this.is_control = true;
1384 // user defined functions
1387 public class Xcls_EventControllerScroll13 : Object
1389 public Gtk.EventControllerScroll el;
1390 private Editor _this;
1394 public double distance;
1397 public Xcls_EventControllerScroll13(Editor _owner )
1400 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1403 this.distance = 0.0f;
1405 // set gobject values
1408 this.el.scroll.connect( (dx, dy) => {
1409 if (!_this.keystate.is_control) {
1412 //GLib.debug("scroll %f", dy);
1414 this.distance += dy;
1416 //GLib.debug("scroll %f / %f", dy, this.distance);
1418 if (this.distance < -1) {
1420 BuilderApplication.settings.editor_font_size ++;
1423 if (this.distance > 1) {
1424 BuilderApplication.settings.editor_font_size --;
1432 // user defined functions
1435 public class Xcls_GestureClick14 : Object
1437 public Gtk.GestureClick el;
1438 private Editor _this;
1444 public Xcls_GestureClick14(Editor _owner )
1447 this.el = new Gtk.GestureClick();
1451 // set gobject values
1454 this.el.pressed.connect( (n_press, x, y) => {
1456 int buffer_x, buffer_y;
1457 var gut = _this.view.el.get_gutter(Gtk.TextWindowType.LEFT);
1459 _this.view.el.window_to_buffer_coords (Gtk.TextWindowType.TEXT,
1460 (int)x - gut.get_width(), (int)y,
1461 out buffer_x, out buffer_y);
1462 _this.view.el.get_iter_at_location (out iter,
1463 buffer_x, buffer_y);;
1466 if (_this.buffer.el.iter_has_context_class(iter, "comment") ||
1467 _this.buffer.el.iter_has_context_class(iter, "string")
1471 _this.buffer.showHelp(iter);
1478 // user defined functions
1483 public class Xcls_Box15 : Object
1486 private Editor _this;
1492 public Xcls_Box15(Editor _owner )
1495 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1499 // set gobject values
1500 this.el.homogeneous = false;
1501 this.el.vexpand = false;
1502 new Xcls_search_entry( _this );
1503 this.el.append( _this.search_entry.el );
1504 new Xcls_search_results( _this );
1505 this.el.append( _this.search_results.el );
1506 new Xcls_nextBtn( _this );
1507 this.el.append( _this.nextBtn.el );
1508 new Xcls_backBtn( _this );
1509 this.el.append( _this.backBtn.el );
1510 var child_5 = new Xcls_MenuButton21( _this );
1512 this.el.append( child_5.el );
1515 // user defined functions
1517 public class Xcls_search_entry : Object
1519 public Gtk.SearchEntry el;
1520 private Editor _this;
1524 public Gtk.CssProvider css;
1527 public Xcls_search_entry(Editor _owner )
1530 _this.search_entry = this;
1531 this.el = new Gtk.SearchEntry();
1535 // set gobject values
1536 this.el.name = "editor-search-entry";
1537 this.el.hexpand = true;
1538 this.el.placeholder_text = "Press enter to search";
1539 this.el.search_delay = 3;
1540 var child_1 = new Xcls_EventControllerKey17( _this );
1542 this.el.add_controller( child_1.el );
1545 this.el.search_changed.connect( ( ) => {
1547 _this.search(_this.search_entry.el.text);
1548 _this.search_results.updateResults();
1550 GLib.Timeout.add_seconds(1,() => {
1551 _this.search_results.updateResults();
1557 // user defined functions
1558 public void forwardSearch (bool change_focus) {
1561 _this.forwardSearch(change_focus);
1565 switch(_this.windowstate.state) {
1566 case WindowState.State.CODEONLY:
1567 //case WindowState.State.CODE:
1568 // search the code being edited..
1569 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1572 case WindowState.State.PREVIEW:
1573 if (_this.windowstate.file.xtype == "Gtk") {
1574 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1576 _this.windowstate.window_rooview.forwardSearch(change_focus);
1585 public class Xcls_EventControllerKey17 : Object
1587 public Gtk.EventControllerKey el;
1588 private Editor _this;
1594 public Xcls_EventControllerKey17(Editor _owner )
1597 this.el = new Gtk.EventControllerKey();
1601 // set gobject values
1604 this.el.key_pressed.connect( (keyval, keycode, state) => {
1606 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1607 GLib.debug("SAVE: ctrl-g pressed");
1608 _this.forwardSearch(true);
1613 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1614 _this.forwardSearch(true);
1620 // print(event.key.keyval)
1626 // user defined functions
1630 public class Xcls_search_results : Object
1632 public Gtk.Label el;
1633 private Editor _this;
1639 public Xcls_search_results(Editor _owner )
1642 _this.search_results = this;
1643 this.el = new Gtk.Label( "No Results" );
1647 // set gobject values
1648 this.el.margin_end = 4;
1649 this.el.margin_start = 4;
1652 // user defined functions
1653 public void updateResults () {
1654 this.el.visible = true;
1656 var res = _this.searchcontext.get_occurrences_count();
1658 _this.search_results.el.label = "??? Matches";
1662 _this.nextBtn.el.sensitive = false;
1663 _this.backBtn.el.sensitive = false;
1666 _this.search_results.el.label = "%d Matches".printf(res);
1667 _this.nextBtn.el.sensitive = true;
1668 _this.backBtn.el.sensitive = true;
1671 _this.search_results.el.label = "No Matches";
1676 public class Xcls_nextBtn : Object
1678 public Gtk.Button el;
1679 private Editor _this;
1683 public bool always_show_image;
1686 public Xcls_nextBtn(Editor _owner )
1689 _this.nextBtn = this;
1690 this.el = new Gtk.Button();
1693 this.always_show_image = true;
1695 // set gobject values
1696 this.el.icon_name = "go-down";
1697 this.el.sensitive = false;
1700 this.el.clicked.connect( (event) => {
1702 _this.forwardSearch(true);
1708 // user defined functions
1711 public class Xcls_backBtn : Object
1713 public Gtk.Button el;
1714 private Editor _this;
1718 public bool always_show_image;
1721 public Xcls_backBtn(Editor _owner )
1724 _this.backBtn = this;
1725 this.el = new Gtk.Button();
1728 this.always_show_image = true;
1730 // set gobject values
1731 this.el.icon_name = "go-up";
1732 this.el.sensitive = false;
1735 this.el.clicked.connect( (event) => {
1737 _this.backSearch(true);
1742 // user defined functions
1745 public class Xcls_MenuButton21 : Object
1747 public Gtk.MenuButton el;
1748 private Editor _this;
1752 public bool always_show_image;
1755 public Xcls_MenuButton21(Editor _owner )
1758 this.el = new Gtk.MenuButton();
1761 this.always_show_image = true;
1763 // set gobject values
1764 this.el.icon_name = "emblem-system";
1765 this.el.always_show_arrow = true;
1766 new Xcls_search_settings( _this );
1767 this.el.popover = _this.search_settings.el;
1770 // user defined functions
1772 public class Xcls_search_settings : Object
1774 public Gtk.Popover el;
1775 private Editor _this;
1781 public Xcls_search_settings(Editor _owner )
1784 _this.search_settings = this;
1785 this.el = new Gtk.Popover();
1789 // set gobject values
1790 var child_1 = new Xcls_Box23( _this );
1792 this.el.child = child_1.el;
1795 // user defined functions
1797 public class Xcls_Box23 : Object
1800 private Editor _this;
1806 public Xcls_Box23(Editor _owner )
1809 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1813 // set gobject values
1814 new Xcls_case_sensitive( _this );
1815 this.el.append( _this.case_sensitive.el );
1816 new Xcls_regex( _this );
1817 this.el.append( _this.regex.el );
1818 new Xcls_multiline( _this );
1819 this.el.append( _this.multiline.el );
1822 // user defined functions
1824 public class Xcls_case_sensitive : Object
1826 public Gtk.CheckButton el;
1827 private Editor _this;
1833 public Xcls_case_sensitive(Editor _owner )
1836 _this.case_sensitive = this;
1837 this.el = new Gtk.CheckButton();
1841 // set gobject values
1842 this.el.label = "Case Sensitive";
1851 // user defined functions
1854 public class Xcls_regex : Object
1856 public Gtk.CheckButton el;
1857 private Editor _this;
1863 public Xcls_regex(Editor _owner )
1867 this.el = new Gtk.CheckButton();
1871 // set gobject values
1872 this.el.label = "Regex";
1881 // user defined functions
1884 public class Xcls_multiline : Object
1886 public Gtk.CheckButton el;
1887 private Editor _this;
1893 public Xcls_multiline(Editor _owner )
1896 _this.multiline = this;
1897 this.el = new Gtk.CheckButton();
1901 // set gobject values
1902 this.el.label = "Multi-line (add \\n)";
1905 // user defined functions
1913 public class Xcls_navigation_holder : Object
1916 private Editor _this;
1922 public Xcls_navigation_holder(Editor _owner )
1925 _this.navigation_holder = this;
1926 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1930 // set gobject values
1931 this.el.width_request = 120;
1932 this.el.hexpand = true;
1933 this.el.vexpand = true;
1934 this.el.visible = false;
1935 var child_1 = new Xcls_Box28( _this );
1937 this.el.append( child_1.el );
1938 new Xcls_navigationwindow( _this );
1939 this.el.append( _this.navigationwindow.el );
1942 // user defined functions
1944 public class Xcls_Box28 : Object
1947 private Editor _this;
1953 public Xcls_Box28(Editor _owner )
1956 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1960 // set gobject values
1963 // user defined functions
1966 public class Xcls_navigationwindow : Object
1968 public Gtk.ScrolledWindow el;
1969 private Editor _this;
1975 public Xcls_navigationwindow(Editor _owner )
1978 _this.navigationwindow = this;
1979 this.el = new Gtk.ScrolledWindow();
1983 // set gobject values
1984 this.el.hexpand = true;
1985 this.el.vexpand = true;
1986 this.el.visible = true;
1987 new Xcls_navigation( _this );
1988 this.el.child = _this.navigation.el;
1991 // user defined functions
1993 public class Xcls_navigation : Object
1995 public Gtk.ColumnView el;
1996 private Editor _this;
2000 public int last_selected_line;
2001 public Gtk.Widget? selected_row;
2004 public Xcls_navigation(Editor _owner )
2007 _this.navigation = this;
2008 new Xcls_navigationselmodel( _this );
2009 this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
2012 this.last_selected_line = -1;
2013 this.selected_row = null;
2015 // set gobject values
2016 this.el.name = "editor-navigation";
2017 var child_2 = new Xcls_ColumnViewColumn31( _this );
2019 this.el.append_column( child_2.el );
2020 var child_3 = new Xcls_GestureClick40( _this );
2022 this.el.add_controller( child_3.el );
2025 // user defined functions
2026 public Gtk.Widget? getRowWidgetAt (double x, double y, out string pos) {
2029 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
2030 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
2035 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
2040 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
2044 //GLib.debug("row number is %d", rn);
2045 //GLib.debug("click %d, %d", (int)x, (int)y);
2047 Graphene.Rect bounds;
2048 row.compute_bounds(this.el, out bounds);
2049 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
2050 // (int)bounds.get_x(), (int)bounds.get_y(),
2051 // (int)bounds.get_width(), (int)bounds.get_height()
2053 var ypos = y - bounds.get_y();
2054 //GLib.debug("rel ypos = %d", (int)ypos);
2055 var rpos = 100.0 * (ypos / bounds.get_height());
2056 //GLib.debug("rel pos = %d %%", (int)rpos);
2061 } else if (rpos < 20) {
2066 public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
2068 if (!_this.navigation_holder.el.visible) {
2069 _this.navigation_holder.el.show();
2070 _this.paned.el.position =
2071 _this.paned.el.get_width() - 200;
2073 //_this.navliststore.el.remove_all();
2076 var ls = new GLib.ListStore(typeof(Lsp.DocumentSymbol));
2078 foreach(var sym in syms) {
2081 Lsp.DocumentSymbol.copyList(ls, _this.navliststore.el);
2082 //_this.navliststore.el.append(sym);
2083 this.last_selected_line = -1;
2084 GLib.Idle.add(() => {
2085 _this.navigationsort.collapseOnLoad();
2087 _this.buffer.el.get_iter_at_offset (
2088 out iter, _this.buffer.el.cursor_position);
2090 GLib.debug("idle update scroll %d, %d", iter.get_line(),
2091 iter.get_line_offset());
2092 this.updateSelectedLine(
2093 (uint)iter.get_line(),
2094 (uint)iter.get_line_offset()
2100 public int getRowAt (double x, double y, out string pos) {
2103 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
2104 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
2109 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
2114 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
2119 while (cr.get_prev_sibling() != null) {
2121 cr = cr.get_prev_sibling();
2124 //GLib.debug("row number is %d", rn);
2125 //GLib.debug("click %d, %d", (int)x, (int)y);
2127 Graphene.Rect bounds;
2128 row.compute_bounds(this.el, out bounds);
2129 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
2130 // (int)bounds.get_x(), (int)bounds.get_y(),
2131 // (int)bounds.get_width(), (int)bounds.get_height()
2133 var ypos = y - bounds.get_y();
2134 //GLib.debug("rel ypos = %d", (int)ypos);
2135 var rpos = 100.0 * (ypos / bounds.get_height());
2136 //GLib.debug("rel pos = %d %%", (int)rpos);
2141 } else if (rpos < 20) {
2146 public void updateSelectedLine (uint line, uint chr) {
2147 if (line == this.last_selected_line) {
2150 GLib.debug("select line %d", (int)line);
2151 this.last_selected_line = (int)line;
2155 var sym = _this.navliststore.symbolAtLine(line, chr);
2157 new_row = _this.navigationsort.getRowFromSymbol(sym);
2158 GLib.debug("select line %d - row found %d", (int)line, new_row);
2160 GLib.debug(" no symbol found at line %d", (int)line);
2163 if (this.selected_row != null) {
2164 GLib.debug(" remove selected row");
2165 this.selected_row.remove_css_class("selected-row");
2167 this.selected_row = null;
2169 this.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);
2170 var row = sym.get_data<Gtk.Widget>("widget");
2172 GLib.debug(" Add selected row");
2174 row.add_css_class("selected-row");
2175 this.selected_row = row;
2179 GLib.debug("could not find widget on row %d", new_row);
2187 public class Xcls_ColumnViewColumn31 : Object
2189 public Gtk.ColumnViewColumn el;
2190 private Editor _this;
2196 public Xcls_ColumnViewColumn31(Editor _owner )
2199 var child_1 = new Xcls_SignalListItemFactory32( _this );
2201 this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
2205 // set gobject values
2206 this.el.expand = true;
2209 // user defined functions
2211 public class Xcls_SignalListItemFactory32 : Object
2213 public Gtk.SignalListItemFactory el;
2214 private Editor _this;
2220 public Xcls_SignalListItemFactory32(Editor _owner )
2223 this.el = new Gtk.SignalListItemFactory();
2227 // set gobject values
2230 this.el.setup.connect( (listitem) => {
2232 var expand = new Gtk.TreeExpander();
2234 expand.set_indent_for_depth(true);
2235 expand.set_indent_for_icon(true);
2236 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
2237 var icon = new Gtk.Image();
2238 var lbl = new Gtk.Label("");
2239 lbl.use_markup = true;
2240 lbl.ellipsize = Pango.EllipsizeMode.END;
2242 icon.margin_end = 4;
2243 lbl.justify = Gtk.Justification.LEFT;
2246 // listitem.activatable = true; ??
2250 expand.set_child(hbox);
2251 ((Gtk.ListItem)listitem).set_child(expand);
2254 this.el.bind.connect( (listitem) => {
2256 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
2258 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2259 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2262 var hbox = (Gtk.Box) expand.child;
2265 var img = (Gtk.Image) hbox.get_first_child();
2266 var lbl = (Gtk.Label) img.get_next_sibling();
2268 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
2269 var sym = (Lsp.DocumentSymbol) lr.get_item();
2271 sym.set_data<Gtk.Widget>("widget", expand.get_parent());
2272 expand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>("symbol", sym);
2274 //GLib.debug("save sym on %s", expand.get_parent().get_parent().get_type().name());
2276 //GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
2278 expand.set_hide_expander( sym.children.get_n_items() < 1);
2279 expand.set_list_row(lr);
2280 //this.in_bind = true;
2281 // default is to expand
2283 //this.in_bind = false;
2285 sym.bind_property("symbol_icon",
2287 GLib.BindingFlags.SYNC_CREATE);
2289 hbox.css_classes = { sym.symbol_icon };
2291 sym.bind_property("name",
2293 GLib.BindingFlags.SYNC_CREATE);
2294 // should be better?- --line no?
2295 sym.bind_property("tooltip",
2296 lbl, "tooltip_markup",
2297 GLib.BindingFlags.SYNC_CREATE);
2303 // user defined functions
2307 public class Xcls_navigationselmodel : Object
2309 public Gtk.NoSelection el;
2310 private Editor _this;
2316 public Xcls_navigationselmodel(Editor _owner )
2319 _this.navigationselmodel = this;
2320 new Xcls_navigationsort( _this );
2321 this.el = new Gtk.NoSelection( _this.navigationsort.el );
2325 // set gobject values
2328 // user defined functions
2330 public class Xcls_navigationsort : Object
2332 public Gtk.SortListModel el;
2333 private Editor _this;
2339 public Xcls_navigationsort(Editor _owner )
2342 _this.navigationsort = this;
2343 var child_1 = new Xcls_TreeListModel35( _this );
2345 var child_2 = new Xcls_TreeListRowSorter37( _this );
2347 this.el = new Gtk.SortListModel( child_1.el, child_2.el );
2351 // set gobject values
2354 // user defined functions
2355 public void collapseOnLoad () {
2356 for (var i=0;i < this.el.get_n_items(); i++) {
2357 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2358 var sym = (Lsp.DocumentSymbol)tr.get_item();
2360 case Lsp.SymbolKind.Enum:
2361 tr.expanded = false;
2364 //tr.expanded = true;
2373 public int getRowFromSymbol (Lsp.DocumentSymbol sym) {
2375 for (var i=0;i < this.el.get_n_items(); i++) {
2376 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2378 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2384 public Lsp.DocumentSymbol? getSymbolAt (uint row) {
2386 var tr = (Gtk.TreeListRow)this.el.get_item(row);
2388 var a = tr.get_item();;
2389 GLib.debug("get_item (2) = %s", a.get_type().name());
2392 return (Lsp.DocumentSymbol)tr.get_item();
2396 public class Xcls_TreeListModel35 : Object
2398 public Gtk.TreeListModel el;
2399 private Editor _this;
2405 public Xcls_TreeListModel35(Editor _owner )
2408 new Xcls_navliststore( _this );
2409 this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
2411 return ((Lsp.DocumentSymbol)item).children;
2417 // set gobject values
2420 this.el.items_changed.connect( (position, removed, added) => {
2421 GLib.debug("tree item changed %d , %d , %d",(int) position, (int)removed, (int) added);
2425 //var sym = (Lsp.DocumentSymbol) this.el.get_item(position);
2426 var row = this.el.get_row(position);
2428 GLib.debug("got %s", row.get_item().get_type().name());
2434 // user defined functions
2436 public class Xcls_navliststore : Object
2438 public GLib.ListStore el;
2439 private Editor _this;
2445 public Xcls_navliststore(Editor _owner )
2448 _this.navliststore = this;
2449 this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
2453 // set gobject values
2456 // user defined functions
2457 public Lsp.DocumentSymbol? symbolAtLine (uint line, uint chr) {
2460 for(var i = 0; i < this.el.get_n_items();i++) {
2461 var el = (Lsp.DocumentSymbol)this.el.get_item(i);
2462 //GLib.debug("Check sym %s : %d-%d",
2463 // el.name , (int)el.range.start.line,
2464 // (int)el.range.end.line
2466 var ret = el.containsLine(line,chr);
2478 public class Xcls_TreeListRowSorter37 : Object
2480 public Gtk.TreeListRowSorter el;
2481 private Editor _this;
2487 public Xcls_TreeListRowSorter37(Editor _owner )
2490 var child_1 = new Xcls_StringSorter38( _this );
2492 this.el = new Gtk.TreeListRowSorter( child_1.el );
2496 // set gobject values
2499 // user defined functions
2501 public class Xcls_StringSorter38 : Object
2503 public Gtk.StringSorter el;
2504 private Editor _this;
2510 public Xcls_StringSorter38(Editor _owner )
2513 var child_1 = new Xcls_PropertyExpression39( _this );
2515 this.el = new Gtk.StringSorter( child_1.el );
2519 // set gobject values
2522 // user defined functions
2524 public class Xcls_PropertyExpression39 : Object
2526 public Gtk.PropertyExpression el;
2527 private Editor _this;
2533 public Xcls_PropertyExpression39(Editor _owner )
2536 this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
2540 // set gobject values
2543 // user defined functions
2550 public class Xcls_GestureClick40 : Object
2552 public Gtk.GestureClick el;
2553 private Editor _this;
2559 public Xcls_GestureClick40(Editor _owner )
2562 this.el = new Gtk.GestureClick();
2566 // set gobject values
2569 this.el.pressed.connect( (n_press, x, y) => {
2571 var row = _this.navigation.getRowWidgetAt(x,y, out pos );
2574 GLib.debug("no row selected items");
2577 GLib.debug("got click on %s", row.get_type().name());
2578 //Lsp.DocumentSymbol
2579 var sym = row.get_data<Lsp.DocumentSymbol>("symbol");
2595 GLib.debug("goto line %d", (int)sym.range.start.line);
2596 _this.scroll_to_line((int)sym.range.start.line);
2598 _this.buffer.el.get_iter_at_line_offset(out iter,
2599 (int)sym.range.start.line,
2600 (int)sym.range.start.character
2602 _this.buffer.el.place_cursor(iter);
2607 // user defined functions