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_close_btn close_btn;
17 public Xcls_RightEditor RightEditor;
18 public Xcls_view view;
19 public Xcls_buffer buffer;
20 public Xcls_keystate keystate;
21 public Xcls_search_entry search_entry;
22 public Xcls_search_results search_results;
23 public Xcls_nextBtn nextBtn;
24 public Xcls_backBtn backBtn;
25 public Xcls_search_settings search_settings;
26 public Xcls_case_sensitive case_sensitive;
27 public Xcls_regex regex;
28 public Xcls_multiline multiline;
29 public Xcls_navigationwindow navigationwindow;
30 public Xcls_navigation navigation;
31 public Xcls_navigationselmodel navigationselmodel;
32 public Xcls_navigationsort navigationsort;
33 public Xcls_navliststore navliststore;
36 public int pos_root_x;
37 public Xcls_MainWindow window;
39 public int pos_root_y;
41 public int last_error_counter;
42 public GtkSource.SearchContext searchcontext;
43 public int last_search_end;
44 public signal void save ();
45 public JsRender.JsRender? file;
46 public JsRender.Node node;
47 public JsRender.NodeProp? prop;
48 public string activeEditor;
54 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
60 this.last_error_counter = 0;
61 this.searchcontext = null;
62 this.last_search_end = 0;
66 this.activeEditor = "\"\"";
69 this.el.homogeneous = false;
70 this.el.hexpand = true;
71 this.el.vexpand = true;
72 var child_1 = new Xcls_Paned1( _this );
74 this.el.append( child_1.el );
77 // user defined functions
78 public bool saveContents () {
81 if (_this.file == null) {
87 var str = _this.buffer.toString();
89 _this.buffer.checkSyntax();
93 // LeftPanel.model.changed( str , false);
95 _this.save_button.el.sensitive = false;
97 // find the text for the node..
98 if (_this.file.xtype != "PlainFile") {
99 // in theory these properties have to exist!?!
101 //this.window.windowstate.left_props.reload();
103 _this.file.setSource( str );
112 public void forwardSearch (bool change_focus) {
114 if (this.searchcontext == null) {
118 Gtk.TextIter beg, st,en;
119 bool has_wrapped_around;
120 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
121 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
123 this.last_search_end = 0; // not sure if this should happen
125 if (has_wrapped_around) {
129 this.last_search_end = en.get_offset();
131 this.view.el.grab_focus();
133 this.buffer.el.place_cursor(st);
134 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
138 public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
143 if (file.xtype != "PlainFile") {
147 // find the text for the node..
148 this.view.load( prop.val );
149 this.updateErrorMarks();
153 this.close_btn.el.show();
156 this.view.load( file.toSource() );
157 this.updateErrorMarks();
158 this.close_btn.el.hide();
159 var ls = file.getLanguageServer();
160 ls.documentSymbols.begin(file, (a,o) => {
161 _this.navigation.show(ls.documentSymbols.end(o));
168 public void backSearch (bool change_focus) {
170 if (this.searchcontext == null) {
174 Gtk.TextIter beg, st,en;
175 bool has_wrapped_around;
176 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
178 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
179 this.last_search_end = 0;
181 this.last_search_end = en.get_offset();
183 this.view.el.grab_focus();
185 this.buffer.el.place_cursor(st);
186 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
190 public string tempFileContents () {
193 if (_this.file == null) {
196 var str= this.buffer.toString();
197 if (_this.file.xtype == "PlainFile") {
205 GLib.debug("calling validate");
206 // clear the buttons.
207 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
208 return this.file.toSource(); ;
211 var oldcode = _this.prop.val;
212 _this.prop.val = str;
213 var ret = _this.file.toSource();
214 _this.prop.val = oldcode;
218 public void reset () {
223 this.searchcontext = null;
226 public int search (string in_txt) {
228 var s = new GtkSource.SearchSettings();
229 s.case_sensitive = _this.case_sensitive.el.active;
230 s.regex_enabled = _this.regex.el.active;
231 s.wrap_around = false;
233 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
234 this.searchcontext.set_highlight(true);
237 if (_this.multiline.el.active) {
238 txt = in_txt.replace("\\n", "\n");
241 s.set_search_text(txt);
242 Gtk.TextIter beg, st,en;
244 this.buffer.el.get_start_iter(out beg);
245 bool has_wrapped_around;
246 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
247 this.last_search_end = 0;
249 return this.searchcontext.get_occurrences_count();
255 public void updateErrorMarks () {
259 var buf = _this.buffer.el;
262 buf.get_bounds (out start, out end);
267 //GLib.debug("highlight errors");
269 // we should highlight other types of errors..
271 if (_this.window.windowstate.state != WindowState.State.CODEONLY
273 _this.window.windowstate.state != WindowState.State.CODE
275 //GLib.debug("windowstate != CODEONLY?");
281 if (_this.file == null) {
282 GLib.debug("file is null?");
286 var ar = this.file.getErrors();
288 buf.remove_source_marks (start, end, "ERR");
289 buf.remove_source_marks (start, end, "WARN");
290 buf.remove_source_marks (start, end, "DEPR");
291 buf.remove_tag_by_name ("ERR", start, end);
292 buf.remove_tag_by_name ("WARN", start, end);
293 buf.remove_tag_by_name ("DEPR", start, end);
294 this.last_error_counter = file.error_counter ;
295 //GLib.debug("highlight %s : %s has no errors", this.file.relpath, category);
300 // basicaly check if there is no change, then we do not do any update..
301 // we can do this by just using an error counter?
302 // if that's changed then we will do an update, otherwise dont bother.
308 var tlines = buf.get_line_count () +1;
310 if (_this.prop != null) {
311 // this still seems flaky...
313 tlines = _this.prop.end_line;
314 offset = _this.prop.start_line;
315 hoffset = _this.node.node_pad.length + 2; //shift it left by 2 ? ..
320 if (this.last_error_counter == file.error_counter) {
326 buf.remove_source_marks (start, end, "ERR");
327 buf.remove_source_marks (start, end, "WARN");
328 buf.remove_source_marks (start, end, "DEPR");
329 buf.remove_tag_by_name ("ERR", start, end);
330 buf.remove_tag_by_name ("WARN", start, end);
331 buf.remove_tag_by_name ("DEPR", start, end);
333 foreach(var diag in ar) {
335 // print("get inter\n");
336 var eline = (int)diag.range.start.line - offset;
337 var eline_to = (int)diag.range.end.line - offset;
338 //var eline = diag.range.end_line - offset;
339 //GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
340 // err.line ,eline, offset);
343 if (eline > tlines || eline < 0) {
347 buf.get_iter_at_line( out iter, eline);
348 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
349 buf.create_source_mark( msg, diag.category, iter);
351 var spos = (int)diag.range.start.character - hoffset;
352 if (spos < 0) { spos =0 ; }
353 if (spos > iter.get_chars_in_line()) {
354 spos = iter.get_chars_in_line();
356 buf.get_iter_at_line( out iter, eline_to);
357 var epos = (int)diag.range.end.character - hoffset;
358 if (epos < 0) { epos =0 ; }
359 if (epos > iter.get_chars_in_line()) {
360 epos = iter.get_chars_in_line();
364 buf.get_iter_at_line_offset( out start, eline, spos);
366 buf.get_iter_at_line_offset( out end, eline_to,epos);
368 buf.apply_tag_by_name(diag.category, start, end);
370 // GLib.debug("set line %d to %s", eline, msg);
371 //this.marks.set(eline, msg);
373 this.last_error_counter = file.error_counter ;
380 public void scroll_to_line (int line) {
382 GLib.Timeout.add(500, () => {
384 var buf = this.view.el.get_buffer();
386 var sbuf = (GtkSource.Buffer) buf;
390 sbuf.get_iter_at_line(out iter, line);
391 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
395 public class Xcls_Paned1 : Object
398 private Editor _this;
404 public Xcls_Paned1(Editor _owner )
407 this.el = new Gtk.Paned( Gtk.Orientation.HORIZONTAL );
411 // set gobject values
412 var child_1 = new Xcls_Box2( _this );
414 this.el.start_child = child_1.el;
415 new Xcls_navigationwindow( _this );
416 this.el.end_child = _this.navigationwindow.el;
419 // user defined functions
421 public class Xcls_Box2 : Object
424 private Editor _this;
430 public Xcls_Box2(Editor _owner )
433 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
437 // set gobject values
438 var child_1 = new Xcls_Box3( _this );
440 this.el.append( child_1.el );
441 new Xcls_RightEditor( _this );
442 this.el.append( _this.RightEditor.el );
443 var child_3 = new Xcls_Box15( _this );
445 this.el.append ( child_3.el );
448 // user defined functions
450 public class Xcls_Box3 : Object
453 private Editor _this;
459 public Xcls_Box3(Editor _owner )
462 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
466 // set gobject values
467 this.el.homogeneous = false;
468 this.el.hexpand = true;
469 new Xcls_save_button( _this );
470 this.el.append( _this.save_button.el );
471 var child_2 = new Xcls_Label5( _this );
473 this.el.append( child_2.el );
474 var child_3 = new Xcls_Scale6( _this );
476 this.el.append( child_3.el );
477 new Xcls_close_btn( _this );
478 this.el.append( _this.close_btn.el );
481 // user defined functions
483 public class Xcls_save_button : Object
485 public Gtk.Button el;
486 private Editor _this;
492 public Xcls_save_button(Editor _owner )
495 _this.save_button = this;
496 this.el = new Gtk.Button();
500 // set gobject values
501 this.el.label = "Save";
504 this.el.clicked.connect( () => {
505 _this.saveContents();
509 // user defined functions
512 public class Xcls_Label5 : Object
515 private Editor _this;
521 public Xcls_Label5(Editor _owner )
524 this.el = new Gtk.Label( null );
528 // set gobject values
529 this.el.hexpand = true;
532 // user defined functions
535 public class Xcls_Scale6 : Object
538 private Editor _this;
544 public Xcls_Scale6(Editor _owner )
547 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
551 // set gobject values
552 this.el.width_request = 200;
553 this.el.has_origin = true;
554 this.el.draw_value = false;
556 this.el.sensitive = true;
561 //this.el.set_range(6,30);
562 this.el.set_value ( BuilderApplication.settings.editor_font_size);
563 BuilderApplication.settings.editor_font_size_updated.connect(
565 BuilderApplication.settings.editor_font_size_inchange = true;
566 // GLib.debug("update range");
567 this.el.set_value (BuilderApplication.settings.editor_font_size);
568 BuilderApplication.settings.editor_font_size_inchange = false;
576 this.el.change_value.connect( (st, val ) => {
577 if (BuilderApplication.settings.editor_font_size_inchange) {
580 BuilderApplication.settings.editor_font_size = val;
585 // user defined functions
588 public class Xcls_close_btn : Object
590 public Gtk.Button el;
591 private Editor _this;
597 public Xcls_close_btn(Editor _owner )
600 _this.close_btn = this;
601 this.el = new Gtk.Button();
605 // set gobject values
606 this.el.icon_name = "window-close";
607 var child_1 = new Xcls_Image8( _this );
609 this.el.child = child_1.el;
612 this.el.clicked.connect( () => {
613 _this.saveContents();
614 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
618 // user defined functions
620 public class Xcls_Image8 : Object
623 private Editor _this;
629 public Xcls_Image8(Editor _owner )
632 this.el = new Gtk.Image();
636 // set gobject values
637 this.el.icon_name = "window-close";
638 this.el.icon_size = Gtk.IconSize.NORMAL;
641 // user defined functions
646 public class Xcls_RightEditor : Object
648 public Gtk.ScrolledWindow el;
649 private Editor _this;
655 public Xcls_RightEditor(Editor _owner )
658 _this.RightEditor = this;
659 this.el = new Gtk.ScrolledWindow();
663 // set gobject values
664 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
665 this.el.vexpand = true;
666 this.el.overlay_scrolling = false;
667 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
668 new Xcls_view( _this );
669 this.el.child = _this.view.el;
672 // user defined functions
674 public class Xcls_view : Object
676 public GtkSource.View el;
677 private Editor _this;
681 public Gtk.CssProvider css;
684 public Xcls_view(Editor _owner )
688 this.el = new GtkSource.View();
693 // set gobject values
694 this.el.auto_indent = true;
695 this.el.indent_width = 4;
696 this.el.name = "editor-view";
697 this.el.show_line_marks = true;
698 this.el.insert_spaces_instead_of_tabs = true;
699 this.el.show_line_numbers = true;
700 this.el.hexpand = true;
701 this.el.vexpand = true;
702 this.el.has_tooltip = true;
703 this.el.css_classes = { "code-editor" };
704 this.el.tab_width = 4;
705 this.el.highlight_current_line = true;
706 new Xcls_buffer( _this );
707 this.el.buffer = _this.buffer.el;
708 new Xcls_keystate( _this );
709 this.el.add_controller( _this.keystate.el );
710 var child_3 = new Xcls_EventControllerScroll13( _this );
712 this.el.add_controller( child_3.el );
713 var child_4 = new Xcls_GestureClick14( _this );
715 this.el.add_controller( child_4.el );
719 this.el.completion.add_provider(
720 new Palete.CompletionProvider(_this)
723 // hover seems pretty useless.. - ??
724 //var hover = this.el.get_hover();
725 //hover.add_provider(new Palete.HoverProvider(_this));
727 //this.el.completion.unblock_interactive();
728 this.el.completion.select_on_show = true; // select
729 //this.el.completion.remember_info_visibility = true;
732 var attrs = new GtkSource.MarkAttributes();
734 attrs.set_icon_name ( "process-stop");
735 attrs.query_tooltip_text.connect(( mark) => {
736 GLib.debug("tooltip query? %s", mark.name);
737 return strdup( mark.name);
739 attrs.query_tooltip_markup.connect(( mark) => {
740 GLib.debug("tooltip query? %s", mark.name);
741 return strdup( mark.name);
743 this.el.set_mark_attributes ("ERR", attrs, 1);
747 var wattrs = new GtkSource.MarkAttributes();
748 wattrs.set_icon_name ( "process-stop");
749 wattrs.query_tooltip_text.connect(( mark) => {
750 GLib.debug("tooltip query? %s", mark.name);
751 return strdup(mark.name);
753 wattrs.query_tooltip_markup.connect(( mark) => {
754 GLib.debug("tooltip query? %s", mark.name);
755 return strdup(mark.name);
757 this.el.set_mark_attributes ("WARN", wattrs, 1);
761 var dattrs = new GtkSource.MarkAttributes();
763 dattrs.set_icon_name ( "process-stop");
765 dattrs.query_tooltip_text.connect(( mark) => {
766 GLib.debug("tooltip query? %s", mark.name);
767 return strdup(mark.name);
769 //dattrs.query_tooltip_markup.connect(( mark) => {
770 // GLib.debug("tooltip query? %s", mark.name);
771 // return strdup(mark.name);
773 this.el.set_mark_attributes ("DEPR", dattrs, 1);
776 this.el.get_space_drawer().set_matrix(null);
777 this.el.get_space_drawer().set_types_for_locations(
778 GtkSource.SpaceLocationFlags.ALL,
779 GtkSource.SpaceTypeFlags.ALL
781 this.el.get_space_drawer().set_enable_matrix(true);
784 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
786 //GLib.debug("query tooltip");
790 var yoff = (int) _this.RightEditor.el.vadjustment.value;
792 // I think this is problematic - if it's compliing / updating at same time as query.
794 //if (_this.window.statusbar_compile_spinner.el.spinning) {
798 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
800 var l = iter.get_line();
804 // GLib.debug("query tooltip line %d", (int) l);
810 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
811 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
812 tooltip.set_text(_this.buffer.marks.get(l).dup());
820 // this crashes?? - not sure why.
821 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
822 if (marks.is_empty()) {
823 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
825 if (marks.is_empty()) {
826 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
829 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
831 marks.@foreach((m) => {
832 //GLib.debug("got mark %s", m.name);
833 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
835 // true if there is a mark..
836 if (str.length > 0 ) {
837 tooltip.set_text( str );
839 return str.length > 0 ? true : false;
844 // user defined functions
845 public void load (string str) {
847 // show the help page for the active node..
848 //this.get('/Help').show();
850 // this.get('/BottomPane').el.set_current_page(0);
851 GLib.debug("load called - Reset undo buffer");
853 var buf = (GtkSource.Buffer)this.el.get_buffer();
854 buf.begin_irreversible_action();
855 buf.set_text(str, str.length);
856 buf.end_irreversible_action();
858 var lm = GtkSource.LanguageManager.get_default();
860 if (_this.file != null) {
861 lang = _this.file.language;
863 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
864 var lg = _this.file.content_type.length > 0 ?
865 lm.guess_language(_this.file.path, _this.file.content_type) :
866 lm.get_language(lang);
869 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
871 this.el.insert_spaces_instead_of_tabs = true;
873 print("sourcelanguage = %s\n", lg.name);
874 if (lg.name == "Vala") {
875 this.el.insert_spaces_instead_of_tabs = false;
879 this.el.grab_focus();
880 _this.save_button.el.sensitive = false;
881 _this.last_error_counter = -1;
884 public class Xcls_buffer : Object
886 public GtkSource.Buffer el;
887 private Editor _this;
891 public int error_line;
892 public Gee.HashMap<int,string>? xmarks;
893 public bool check_queued;
896 public Xcls_buffer(Editor _owner )
900 this.el = new GtkSource.Buffer( null );
903 this.error_line = -1;
905 this.check_queued = false;
907 // set gobject values
908 this.el.highlight_syntax = true;
909 this.el.highlight_matching_brackets = true;
910 this.el.enable_undo = true;
915 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
916 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
917 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
918 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
919 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
920 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
921 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
922 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
925 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
926 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
927 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
930 this.el.cursor_moved.connect( ( ) => {
933 this.el.get_iter_at_offset (
934 out iter, this.el.cursor_position);
935 var line = iter.get_line();
936 _this.navigation.updateSelectedLine(
937 (uint)iter.get_line(),
938 (uint)iter.get_line_offset()
943 this.el.changed.connect( () => {
946 _this.save_button.el.sensitive = true;
947 print("EDITOR CHANGED");
952 // this.get('/LeftPanel.model').changed( str , false);
957 // user defined functions
958 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
961 this.el.get_bounds (out start, out end);
963 this.el.remove_source_marks (start, end, type);
964 GLib.debug("highlight errors");
966 // we should highlight other types of errors..
968 if (!obj.has_member(type)) {
969 GLib.debug("Return has no errors\n");
973 if (_this.window.windowstate.state != WindowState.State.CODEONLY
975 _this.window.windowstate.state != WindowState.State.CODE
977 GLib.debug("windowstate != CODEONLY?");
982 //this.marks = new Gee.HashMap<int,string>();
983 var err = obj.get_object_member(type);
985 if (_this.file == null) {
986 GLib.debug("file is null?");
990 var valafn = _this.file.path;
992 if (_this.file.xtype != "PlainFile") {
996 var regex = new Regex("\\.bjs$");
998 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
999 } catch (GLib.RegexError e) {
1006 if (!err.has_member(valafn)) {
1007 GLib.debug("File path has no errors");
1011 var lines = err.get_object_member(valafn);
1014 if (obj.has_member("line_offset")) { // ?? why??
1015 offset = (int)obj.get_int_member("line_offset") + 1;
1019 var tlines = this.el.get_line_count () +1;
1021 if (_this.prop != null) {
1023 tlines = _this.prop.end_line + 1;
1024 offset = _this.prop.start_line + 1;
1030 lines.foreach_member((obj, line, node) => {
1033 // print("get inter\n");
1034 var eline = int.parse(line) - offset;
1035 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
1038 if (eline > tlines || eline < 0) {
1043 this.el.get_iter_at_line( out iter, eline);
1044 //print("mark line\n");
1046 var ar = lines.get_array_member(line);
1047 for (var i = 0 ; i < ar.get_length(); i++) {
1048 if (ar.get_string_element(i) == "Success") {
1051 msg += (msg.length > 0) ? "\n" : "";
1052 msg += ar.get_string_element(i);
1057 msg = "Line: %d".printf(eline+1) + " " + msg;
1058 this.el.create_source_mark(msg, type, iter);
1059 GLib.debug("set line %d to %m", eline, msg);
1060 // this.marks.set(eline, msg);
1069 public bool checkSyntax () {
1072 var str = this.toString();
1075 if (this.error_line > 0) {
1078 this.el.get_bounds (out start, out end);
1080 this.el.remove_source_marks (start, end, null);
1082 if (str.length < 1) {
1083 print("checkSyntax - empty string?\n");
1088 if (_this.file.xtype == "PlainFile") {
1090 // assume it's gtk...
1091 var oldcode =_this.file.toSource();
1092 _this.file.setSource(str);
1093 BuilderApplication.showSpinner("appointment soon","document change pending");
1094 _this.file.getLanguageServer().document_change(_this.file);
1096 _this.file.setSource(oldcode);
1102 if (_this.file == null) {
1110 GLib.debug("calling validate");
1111 // clear the buttons.
1112 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1115 var oldcode = _this.prop.val;
1117 _this.prop.val = str;
1118 _this.node.updated_count++;
1119 _this.file.getLanguageServer().document_change(_this.file);
1120 _this.node.updated_count++;
1121 _this.prop.val = oldcode;
1124 //print("done mark line\n");
1126 return true; // at present allow saving - even if it's invalid..
1128 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1130 this.error_line = validate_res.size;
1132 if (this.error_line < 1) {
1135 var tlines = this.el.get_line_count ();
1137 var valiter = validate_res.map_iterator();
1138 while (valiter.next()) {
1140 // print("get inter\n");
1141 var eline = valiter.get_key();
1142 if (eline > tlines) {
1145 this.el.get_iter_at_line( out iter, eline);
1146 //print("mark line\n");
1147 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1151 public string toString () {
1155 this.el.get_start_iter(out s);
1156 this.el.get_end_iter(out e);
1157 var ret = this.el.get_text(s,e,true);
1158 //print("TO STRING? " + ret);
1163 public class Xcls_keystate : Object
1165 public Gtk.EventControllerKey el;
1166 private Editor _this;
1170 public bool is_control;
1173 public Xcls_keystate(Editor _owner )
1176 _this.keystate = this;
1177 this.el = new Gtk.EventControllerKey();
1180 this.is_control = false;
1182 // set gobject values
1185 this.el.key_released.connect( (keyval, keycode, state) => {
1187 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1188 this.is_control = false;
1190 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1191 GLib.debug("SAVE: ctrl-S pressed");
1192 _this.saveContents();
1196 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1197 GLib.debug("SAVE: ctrl-g pressed");
1198 _this.forwardSearch(true);
1201 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1202 GLib.debug("SAVE: ctrl-f pressed");
1203 _this.search_entry.el.grab_focus();
1204 _this.search_entry.el.select_region(0,-1);
1207 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1208 _this.view.el.show_completion();
1212 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1213 var line = iter.get_line();
1214 var offset = iter.get_line_offset();
1215 GLib.debug("line %d off %d", line ,offset);
1216 if (_this.prop != null) {
1217 line += _this.prop.start_line + 1; // i think..
1218 offset += 12; // should probably be 8 without namespaced
1219 GLib.debug("guess line %d off %d", line ,offset);
1221 //_this.view.el.show_completion();
1222 // print(event.key.keyval)
1231 this.el.key_pressed.connect( (keyval, keycode, state) => {
1233 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1234 this.is_control = true;
1240 // user defined functions
1243 public class Xcls_EventControllerScroll13 : Object
1245 public Gtk.EventControllerScroll el;
1246 private Editor _this;
1250 public double distance;
1253 public Xcls_EventControllerScroll13(Editor _owner )
1256 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1259 this.distance = 0.0f;
1261 // set gobject values
1264 this.el.scroll.connect( (dx, dy) => {
1265 if (!_this.keystate.is_control) {
1268 //GLib.debug("scroll %f", dy);
1270 this.distance += dy;
1272 //GLib.debug("scroll %f / %f", dy, this.distance);
1274 if (this.distance < -1) {
1276 BuilderApplication.settings.editor_font_size ++;
1279 if (this.distance > 1) {
1280 BuilderApplication.settings.editor_font_size --;
1288 // user defined functions
1291 public class Xcls_GestureClick14 : Object
1293 public Gtk.GestureClick el;
1294 private Editor _this;
1300 public Xcls_GestureClick14(Editor _owner )
1303 this.el = new Gtk.GestureClick();
1307 // set gobject values
1310 // user defined functions
1315 public class Xcls_Box15 : Object
1318 private Editor _this;
1324 public Xcls_Box15(Editor _owner )
1327 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1331 // set gobject values
1332 this.el.homogeneous = false;
1333 this.el.vexpand = false;
1334 new Xcls_search_entry( _this );
1335 this.el.append( _this.search_entry.el );
1336 new Xcls_search_results( _this );
1337 this.el.append( _this.search_results.el );
1338 new Xcls_nextBtn( _this );
1339 this.el.append( _this.nextBtn.el );
1340 new Xcls_backBtn( _this );
1341 this.el.append( _this.backBtn.el );
1342 var child_5 = new Xcls_MenuButton21( _this );
1344 this.el.append( child_5.el );
1347 // user defined functions
1349 public class Xcls_search_entry : Object
1351 public Gtk.SearchEntry el;
1352 private Editor _this;
1356 public Gtk.CssProvider css;
1359 public Xcls_search_entry(Editor _owner )
1362 _this.search_entry = this;
1363 this.el = new Gtk.SearchEntry();
1367 // set gobject values
1368 this.el.name = "editor-search-entry";
1369 this.el.hexpand = true;
1370 this.el.placeholder_text = "Press enter to search";
1371 this.el.search_delay = 3;
1372 var child_1 = new Xcls_EventControllerKey17( _this );
1374 this.el.add_controller( child_1.el );
1377 this.el.search_changed.connect( ( ) => {
1379 _this.search(_this.search_entry.el.text);
1380 _this.search_results.updateResults();
1382 GLib.Timeout.add_seconds(1,() => {
1383 _this.search_results.updateResults();
1389 // user defined functions
1390 public void forwardSearch (bool change_focus) {
1393 _this.forwardSearch(change_focus);
1397 switch(_this.windowstate.state) {
1398 case WindowState.State.CODEONLY:
1399 //case WindowState.State.CODE:
1400 // search the code being edited..
1401 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1404 case WindowState.State.PREVIEW:
1405 if (_this.windowstate.file.xtype == "Gtk") {
1406 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1408 _this.windowstate.window_rooview.forwardSearch(change_focus);
1417 public class Xcls_EventControllerKey17 : Object
1419 public Gtk.EventControllerKey el;
1420 private Editor _this;
1426 public Xcls_EventControllerKey17(Editor _owner )
1429 this.el = new Gtk.EventControllerKey();
1433 // set gobject values
1436 this.el.key_pressed.connect( (keyval, keycode, state) => {
1438 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1439 GLib.debug("SAVE: ctrl-g pressed");
1440 _this.forwardSearch(true);
1445 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1446 _this.forwardSearch(true);
1452 // print(event.key.keyval)
1458 // user defined functions
1462 public class Xcls_search_results : Object
1464 public Gtk.Label el;
1465 private Editor _this;
1471 public Xcls_search_results(Editor _owner )
1474 _this.search_results = this;
1475 this.el = new Gtk.Label( "No Results" );
1479 // set gobject values
1480 this.el.margin_end = 4;
1481 this.el.margin_start = 4;
1484 // user defined functions
1485 public void updateResults () {
1486 this.el.visible = true;
1488 var res = _this.searchcontext.get_occurrences_count();
1490 _this.search_results.el.label = "??? Matches";
1494 _this.nextBtn.el.sensitive = false;
1495 _this.backBtn.el.sensitive = false;
1498 _this.search_results.el.label = "%d Matches".printf(res);
1499 _this.nextBtn.el.sensitive = true;
1500 _this.backBtn.el.sensitive = true;
1503 _this.search_results.el.label = "No Matches";
1508 public class Xcls_nextBtn : Object
1510 public Gtk.Button el;
1511 private Editor _this;
1515 public bool always_show_image;
1518 public Xcls_nextBtn(Editor _owner )
1521 _this.nextBtn = this;
1522 this.el = new Gtk.Button();
1525 this.always_show_image = true;
1527 // set gobject values
1528 this.el.icon_name = "go-down";
1529 this.el.sensitive = false;
1532 this.el.clicked.connect( (event) => {
1534 _this.forwardSearch(true);
1540 // user defined functions
1543 public class Xcls_backBtn : Object
1545 public Gtk.Button el;
1546 private Editor _this;
1550 public bool always_show_image;
1553 public Xcls_backBtn(Editor _owner )
1556 _this.backBtn = this;
1557 this.el = new Gtk.Button();
1560 this.always_show_image = true;
1562 // set gobject values
1563 this.el.icon_name = "go-up";
1564 this.el.sensitive = false;
1567 this.el.clicked.connect( (event) => {
1569 _this.backSearch(true);
1574 // user defined functions
1577 public class Xcls_MenuButton21 : Object
1579 public Gtk.MenuButton el;
1580 private Editor _this;
1584 public bool always_show_image;
1587 public Xcls_MenuButton21(Editor _owner )
1590 this.el = new Gtk.MenuButton();
1593 this.always_show_image = true;
1595 // set gobject values
1596 this.el.icon_name = "emblem-system";
1597 this.el.always_show_arrow = true;
1598 new Xcls_search_settings( _this );
1599 this.el.popover = _this.search_settings.el;
1602 // user defined functions
1604 public class Xcls_search_settings : Object
1606 public Gtk.Popover el;
1607 private Editor _this;
1613 public Xcls_search_settings(Editor _owner )
1616 _this.search_settings = this;
1617 this.el = new Gtk.Popover();
1621 // set gobject values
1622 var child_1 = new Xcls_Box23( _this );
1624 this.el.child = child_1.el;
1627 // user defined functions
1629 public class Xcls_Box23 : Object
1632 private Editor _this;
1638 public Xcls_Box23(Editor _owner )
1641 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1645 // set gobject values
1646 new Xcls_case_sensitive( _this );
1647 this.el.append( _this.case_sensitive.el );
1648 new Xcls_regex( _this );
1649 this.el.append( _this.regex.el );
1650 new Xcls_multiline( _this );
1651 this.el.append( _this.multiline.el );
1654 // user defined functions
1656 public class Xcls_case_sensitive : Object
1658 public Gtk.CheckButton el;
1659 private Editor _this;
1665 public Xcls_case_sensitive(Editor _owner )
1668 _this.case_sensitive = this;
1669 this.el = new Gtk.CheckButton();
1673 // set gobject values
1674 this.el.label = "Case Sensitive";
1683 // user defined functions
1686 public class Xcls_regex : Object
1688 public Gtk.CheckButton el;
1689 private Editor _this;
1695 public Xcls_regex(Editor _owner )
1699 this.el = new Gtk.CheckButton();
1703 // set gobject values
1704 this.el.label = "Regex";
1713 // user defined functions
1716 public class Xcls_multiline : Object
1718 public Gtk.CheckButton el;
1719 private Editor _this;
1725 public Xcls_multiline(Editor _owner )
1728 _this.multiline = this;
1729 this.el = new Gtk.CheckButton();
1733 // set gobject values
1734 this.el.label = "Multi-line (add \\n)";
1737 // user defined functions
1745 public class Xcls_navigationwindow : Object
1747 public Gtk.ScrolledWindow el;
1748 private Editor _this;
1754 public Xcls_navigationwindow(Editor _owner )
1757 _this.navigationwindow = this;
1758 this.el = new Gtk.ScrolledWindow();
1762 // set gobject values
1763 this.el.visible = false;
1764 new Xcls_navigation( _this );
1765 this.el.child = _this.navigation.el;
1768 // user defined functions
1770 public class Xcls_navigation : Object
1772 public Gtk.ColumnView el;
1773 private Editor _this;
1777 public int last_selected_line;
1778 public Gtk.Widget? selected_row;
1781 public Xcls_navigation(Editor _owner )
1784 _this.navigation = this;
1785 new Xcls_navigationselmodel( _this );
1786 this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
1789 this.last_selected_line = -1;
1790 this.selected_row = null;
1792 // set gobject values
1793 this.el.name = "editor-navigation";
1794 var child_2 = new Xcls_ColumnViewColumn29( _this );
1796 this.el.append_column( child_2.el );
1797 var child_3 = new Xcls_GestureClick38( _this );
1799 this.el.add_controller( child_3.el );
1802 // user defined functions
1803 public Gtk.Widget? getWidgetAtRow (uint row) {
1806 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
1807 var colview = gesture.widget;
1808 var line_no = check_list_widget(colview, x,y);
1810 var item = colview.model.get_item(line_no);
1814 //GLib.debug("Get Widget At Row %d", (int)row);
1815 var child = this.el.get_first_child();
1817 var reading_header = true;
1819 while (child != null) {
1820 //GLib.debug("Got %s", child.get_type().name());
1822 if (reading_header) {
1825 if (child.get_type().name() != "GtkColumnListView") {
1827 child = child.get_next_sibling();
1830 // should be columnlistview
1831 child = child.get_first_child();
1835 reading_header = false;
1842 if (line_no == row) {
1843 //GLib.debug("Returning widget %s", child.get_type().name());
1844 return (Gtk.Widget)child;
1846 child = child.get_next_sibling();
1848 GLib.debug("Failed to find row (max = %d)", line_no);
1852 public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
1853 _this.navigationwindow.el.show();
1854 _this.navliststore.el.remove_all();
1855 foreach(var sym in syms) {
1856 _this.navliststore.el.append(sym);
1861 public int getRowAt (double x, double y, out string pos) {
1864 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
1865 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
1870 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
1875 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
1880 while (cr.get_prev_sibling() != null) {
1882 cr = cr.get_prev_sibling();
1885 //GLib.debug("row number is %d", rn);
1886 //GLib.debug("click %d, %d", (int)x, (int)y);
1888 Graphene.Rect bounds;
1889 row.compute_bounds(this.el, out bounds);
1890 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
1891 // (int)bounds.get_x(), (int)bounds.get_y(),
1892 // (int)bounds.get_width(), (int)bounds.get_height()
1894 var ypos = y - bounds.get_y();
1895 //GLib.debug("rel ypos = %d", (int)ypos);
1896 var rpos = 100.0 * (ypos / bounds.get_height());
1897 //GLib.debug("rel pos = %d %%", (int)rpos);
1902 } else if (rpos < 20) {
1907 public void updateSelectedLine (uint line, uint chr) {
1908 if (line == this.last_selected_line) {
1911 GLib.debug("select line %d", (int)line);
1912 this.last_selected_line = (int)line;
1916 var sym = _this.navliststore.symbolAtLine(line, chr);
1918 new_row = _this.navigationsort.getRowFromSymbol(sym);
1919 GLib.debug("select line %d - row found %d", (int)line, new_row);
1921 GLib.debug(" no symbol found at line %d", (int)line);
1924 if (this.selected_row != null) {
1925 GLib.debug(" remove selected row");
1926 this.selected_row.remove_css_class("selected-row");
1928 this.selected_row = null;
1930 this.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);
1931 var row = this.getWidgetAtRow(new_row);
1933 GLib.debug(" Add selected row");
1935 row.add_css_class("selected-row");
1936 this.selected_row = row;
1940 GLib.debug("could not find widget on row %d", new_row);
1948 public class Xcls_ColumnViewColumn29 : Object
1950 public Gtk.ColumnViewColumn el;
1951 private Editor _this;
1957 public Xcls_ColumnViewColumn29(Editor _owner )
1960 var child_1 = new Xcls_SignalListItemFactory30( _this );
1962 this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
1966 // set gobject values
1967 this.el.expand = true;
1970 // user defined functions
1972 public class Xcls_SignalListItemFactory30 : Object
1974 public Gtk.SignalListItemFactory el;
1975 private Editor _this;
1981 public Xcls_SignalListItemFactory30(Editor _owner )
1984 this.el = new Gtk.SignalListItemFactory();
1988 // set gobject values
1991 this.el.setup.connect( (listitem) => {
1993 var expand = new Gtk.TreeExpander();
1995 expand.set_indent_for_depth(true);
1996 expand.set_indent_for_icon(true);
1997 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
1998 var icon = new Gtk.Image();
1999 var lbl = new Gtk.Label("");
2000 lbl.use_markup = true;
2001 lbl.ellipsize = Pango.EllipsizeMode.END;
2003 icon.margin_end = 4;
2004 lbl.justify = Gtk.Justification.LEFT;
2007 // listitem.activatable = true; ??
2011 expand.set_child(hbox);
2012 ((Gtk.ListItem)listitem).set_child(expand);
2015 this.el.bind.connect( (listitem) => {
2016 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
2018 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2019 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2022 var hbox = (Gtk.Box) expand.child;
2025 var img = (Gtk.Image) hbox.get_first_child();
2026 var lbl = (Gtk.Label) img.get_next_sibling();
2028 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
2029 var sym = (Lsp.DocumentSymbol) lr.get_item();
2031 GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
2033 expand.set_hide_expander( sym.children.get_n_items() < 1);
2034 expand.set_list_row(lr);
2036 sym.bind_property("symbol_icon",
2038 GLib.BindingFlags.SYNC_CREATE);
2040 hbox.add_css_class(sym.symbol_icon);
2042 sym.bind_property("name",
2044 GLib.BindingFlags.SYNC_CREATE);
2045 // should be better?- --line no?
2046 sym.bind_property("tooltip",
2047 lbl, "tooltip_markup",
2048 GLib.BindingFlags.SYNC_CREATE);
2054 // user defined functions
2058 public class Xcls_navigationselmodel : Object
2060 public Gtk.NoSelection el;
2061 private Editor _this;
2067 public Xcls_navigationselmodel(Editor _owner )
2070 _this.navigationselmodel = this;
2071 new Xcls_navigationsort( _this );
2072 this.el = new Gtk.NoSelection( _this.navigationsort.el );
2076 // set gobject values
2079 // user defined functions
2080 public int getRowFromSymbolx (Lsp.DocumentSymbol sym) {
2082 for (var i=0;i < this.el.get_n_items(); i++) {
2083 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2085 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2091 public Lsp.DocumentSymbol? getSymbollAtOLD (uint row) {
2093 var tr = (Gtk.TreeListRow)this.el.get_item(row);
2095 var a = tr.get_item();;
2096 GLib.debug("get_item (2) = %s", a.get_type().name());
2099 return (Lsp.DocumentSymbol)tr.get_item();
2103 public class Xcls_navigationsort : Object
2105 public Gtk.SortListModel el;
2106 private Editor _this;
2112 public Xcls_navigationsort(Editor _owner )
2115 _this.navigationsort = this;
2116 var child_1 = new Xcls_TreeListModel33( _this );
2118 var child_2 = new Xcls_TreeListRowSorter35( _this );
2120 this.el = new Gtk.SortListModel( child_1.el, child_2.el );
2124 // set gobject values
2127 // user defined functions
2128 public int getRowFromSymbol (Lsp.DocumentSymbol sym) {
2130 for (var i=0;i < this.el.get_n_items(); i++) {
2131 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2133 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2139 public Lsp.DocumentSymbol? getSymbolAt (uint row) {
2141 var tr = (Gtk.TreeListRow)this.el.get_item(row);
2143 var a = tr.get_item();;
2144 GLib.debug("get_item (2) = %s", a.get_type().name());
2147 return (Lsp.DocumentSymbol)tr.get_item();
2151 public class Xcls_TreeListModel33 : Object
2153 public Gtk.TreeListModel el;
2154 private Editor _this;
2160 public Xcls_TreeListModel33(Editor _owner )
2163 new Xcls_navliststore( _this );
2164 this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
2166 return ((Lsp.DocumentSymbol)item).children;
2172 // set gobject values
2175 // user defined functions
2177 public class Xcls_navliststore : Object
2179 public GLib.ListStore el;
2180 private Editor _this;
2186 public Xcls_navliststore(Editor _owner )
2189 _this.navliststore = this;
2190 this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
2194 // set gobject values
2197 // user defined functions
2198 public Lsp.DocumentSymbol? symbolAtLine (uint line, uint chr) {
2201 for(var i = 0; i < this.el.get_n_items();i++) {
2202 var el = (Lsp.DocumentSymbol)this.el.get_item(i);
2203 //GLib.debug("Check sym %s : %d-%d",
2204 // el.name , (int)el.range.start.line,
2205 // (int)el.range.end.line
2207 var ret = el.containsLine(line,chr);
2219 public class Xcls_TreeListRowSorter35 : Object
2221 public Gtk.TreeListRowSorter el;
2222 private Editor _this;
2228 public Xcls_TreeListRowSorter35(Editor _owner )
2231 var child_1 = new Xcls_StringSorter36( _this );
2233 this.el = new Gtk.TreeListRowSorter( child_1.el );
2237 // set gobject values
2240 // user defined functions
2242 public class Xcls_StringSorter36 : Object
2244 public Gtk.StringSorter el;
2245 private Editor _this;
2251 public Xcls_StringSorter36(Editor _owner )
2254 var child_1 = new Xcls_PropertyExpression37( _this );
2256 this.el = new Gtk.StringSorter( child_1.el );
2260 // set gobject values
2263 // user defined functions
2265 public class Xcls_PropertyExpression37 : Object
2267 public Gtk.PropertyExpression el;
2268 private Editor _this;
2274 public Xcls_PropertyExpression37(Editor _owner )
2277 this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
2281 // set gobject values
2284 // user defined functions
2291 public class Xcls_GestureClick38 : Object
2293 public Gtk.GestureClick el;
2294 private Editor _this;
2300 public Xcls_GestureClick38(Editor _owner )
2303 this.el = new Gtk.GestureClick();
2307 // set gobject values
2310 this.el.pressed.connect( (n_press, x, y) => {
2312 var row = _this.navigation.getRowAt(x,y, out pos );
2314 GLib.debug("no row selected items");
2317 //Lsp.DocumentSymbol
2318 var sym = _this.navigationsort.getSymbolAt(row);
2334 GLib.debug("goto line %d", (int)sym.range.start.line);
2335 _this.scroll_to_line((int)sym.range.start.line);
2340 // user defined functions