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_navliststore navliststore;
35 public int pos_root_x;
36 public Xcls_MainWindow window;
38 public int pos_root_y;
40 public int last_error_counter;
41 public GtkSource.SearchContext searchcontext;
42 public int last_search_end;
43 public signal void save ();
44 public JsRender.JsRender? file;
45 public JsRender.Node node;
46 public JsRender.NodeProp? prop;
47 public string activeEditor;
53 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
59 this.last_error_counter = 0;
60 this.searchcontext = null;
61 this.last_search_end = 0;
65 this.activeEditor = "\"\"";
68 this.el.homogeneous = false;
69 this.el.hexpand = true;
70 this.el.vexpand = true;
71 var child_1 = new Xcls_Paned1( _this );
73 this.el.append( child_1.el );
76 // user defined functions
77 public bool saveContents () {
80 if (_this.file == null) {
86 var str = _this.buffer.toString();
88 _this.buffer.checkSyntax();
92 // LeftPanel.model.changed( str , false);
94 _this.save_button.el.sensitive = false;
96 // find the text for the node..
97 if (_this.file.xtype != "PlainFile") {
98 // in theory these properties have to exist!?!
100 //this.window.windowstate.left_props.reload();
102 _this.file.setSource( str );
111 public void forwardSearch (bool change_focus) {
113 if (this.searchcontext == null) {
117 Gtk.TextIter beg, st,en;
118 bool has_wrapped_around;
119 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
120 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
122 this.last_search_end = 0; // not sure if this should happen
124 if (has_wrapped_around) {
128 this.last_search_end = en.get_offset();
130 this.view.el.grab_focus();
132 this.buffer.el.place_cursor(st);
133 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
137 public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
142 if (file.xtype != "PlainFile") {
146 // find the text for the node..
147 this.view.load( prop.val );
148 this.updateErrorMarks();
152 this.close_btn.el.show();
155 this.view.load( file.toSource() );
156 this.updateErrorMarks();
157 this.close_btn.el.hide();
158 var ls = file.getLanguageServer();
159 ls.documentSymbols.begin(file, (a,o) => {
160 _this.navigation.show(ls.documentSymbols.end(o));
167 public void backSearch (bool change_focus) {
169 if (this.searchcontext == null) {
173 Gtk.TextIter beg, st,en;
174 bool has_wrapped_around;
175 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
177 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
178 this.last_search_end = 0;
180 this.last_search_end = en.get_offset();
182 this.view.el.grab_focus();
184 this.buffer.el.place_cursor(st);
185 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
189 public string tempFileContents () {
192 if (_this.file == null) {
195 var str= this.buffer.toString();
196 if (_this.file.xtype == "PlainFile") {
204 GLib.debug("calling validate");
205 // clear the buttons.
206 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
207 return this.file.toSource(); ;
210 var oldcode = _this.prop.val;
211 _this.prop.val = str;
212 var ret = _this.file.toSource();
213 _this.prop.val = oldcode;
217 public void reset () {
222 this.searchcontext = null;
225 public int search (string in_txt) {
227 var s = new GtkSource.SearchSettings();
228 s.case_sensitive = _this.case_sensitive.el.active;
229 s.regex_enabled = _this.regex.el.active;
230 s.wrap_around = false;
232 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
233 this.searchcontext.set_highlight(true);
236 if (_this.multiline.el.active) {
237 txt = in_txt.replace("\\n", "\n");
240 s.set_search_text(txt);
241 Gtk.TextIter beg, st,en;
243 this.buffer.el.get_start_iter(out beg);
244 bool has_wrapped_around;
245 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
246 this.last_search_end = 0;
248 return this.searchcontext.get_occurrences_count();
254 public void updateErrorMarks () {
258 var buf = _this.buffer.el;
261 buf.get_bounds (out start, out end);
266 //GLib.debug("highlight errors");
268 // we should highlight other types of errors..
270 if (_this.window.windowstate.state != WindowState.State.CODEONLY
272 _this.window.windowstate.state != WindowState.State.CODE
274 //GLib.debug("windowstate != CODEONLY?");
280 if (_this.file == null) {
281 GLib.debug("file is null?");
285 var ar = this.file.getErrors();
287 buf.remove_source_marks (start, end, "ERR");
288 buf.remove_source_marks (start, end, "WARN");
289 buf.remove_source_marks (start, end, "DEPR");
290 buf.remove_tag_by_name ("ERR", start, end);
291 buf.remove_tag_by_name ("WARN", start, end);
292 buf.remove_tag_by_name ("DEPR", start, end);
293 this.last_error_counter = file.error_counter ;
294 //GLib.debug("highlight %s : %s has no errors", this.file.relpath, category);
299 // basicaly check if there is no change, then we do not do any update..
300 // we can do this by just using an error counter?
301 // if that's changed then we will do an update, otherwise dont bother.
307 var tlines = buf.get_line_count () +1;
309 if (_this.prop != null) {
310 // this still seems flaky...
312 tlines = _this.prop.end_line;
313 offset = _this.prop.start_line;
314 hoffset = _this.node.node_pad.length + 2; //shift it left by 2 ? ..
319 if (this.last_error_counter == file.error_counter) {
325 buf.remove_source_marks (start, end, "ERR");
326 buf.remove_source_marks (start, end, "WARN");
327 buf.remove_source_marks (start, end, "DEPR");
328 buf.remove_tag_by_name ("ERR", start, end);
329 buf.remove_tag_by_name ("WARN", start, end);
330 buf.remove_tag_by_name ("DEPR", start, end);
332 foreach(var diag in ar) {
334 // print("get inter\n");
335 var eline = (int)diag.range.start.line - offset;
336 var eline_to = (int)diag.range.end.line - offset;
337 //var eline = diag.range.end_line - offset;
338 //GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
339 // err.line ,eline, offset);
342 if (eline > tlines || eline < 0) {
346 buf.get_iter_at_line( out iter, eline);
347 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
348 buf.create_source_mark( msg, diag.category, iter);
350 var spos = (int)diag.range.start.character - hoffset;
351 if (spos < 0) { spos =0 ; }
352 if (spos > iter.get_chars_in_line()) {
353 spos = iter.get_chars_in_line();
355 buf.get_iter_at_line( out iter, eline_to);
356 var epos = (int)diag.range.end.character - hoffset;
357 if (epos < 0) { epos =0 ; }
358 if (epos > iter.get_chars_in_line()) {
359 epos = iter.get_chars_in_line();
363 buf.get_iter_at_line_offset( out start, eline, spos);
365 buf.get_iter_at_line_offset( out end, eline_to,epos);
367 buf.apply_tag_by_name(diag.category, start, end);
369 // GLib.debug("set line %d to %s", eline, msg);
370 //this.marks.set(eline, msg);
372 this.last_error_counter = file.error_counter ;
379 public void scroll_to_line (int line) {
381 GLib.Timeout.add(500, () => {
383 var buf = this.view.el.get_buffer();
385 var sbuf = (GtkSource.Buffer) buf;
389 sbuf.get_iter_at_line(out iter, line);
390 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
394 public class Xcls_Paned1 : Object
397 private Editor _this;
403 public Xcls_Paned1(Editor _owner )
406 this.el = new Gtk.Paned( Gtk.Orientation.HORIZONTAL );
410 // set gobject values
411 var child_1 = new Xcls_Box2( _this );
413 this.el.start_child = child_1.el;
414 new Xcls_navigationwindow( _this );
415 this.el.end_child = _this.navigationwindow.el;
418 // user defined functions
420 public class Xcls_Box2 : Object
423 private Editor _this;
429 public Xcls_Box2(Editor _owner )
432 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
436 // set gobject values
437 var child_1 = new Xcls_Box3( _this );
439 this.el.append( child_1.el );
440 new Xcls_RightEditor( _this );
441 this.el.append( _this.RightEditor.el );
442 var child_3 = new Xcls_Box15( _this );
444 this.el.append ( child_3.el );
447 // user defined functions
449 public class Xcls_Box3 : Object
452 private Editor _this;
458 public Xcls_Box3(Editor _owner )
461 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
465 // set gobject values
466 this.el.homogeneous = false;
467 this.el.hexpand = true;
468 new Xcls_save_button( _this );
469 this.el.append( _this.save_button.el );
470 var child_2 = new Xcls_Label5( _this );
472 this.el.append( child_2.el );
473 var child_3 = new Xcls_Scale6( _this );
475 this.el.append( child_3.el );
476 new Xcls_close_btn( _this );
477 this.el.append( _this.close_btn.el );
480 // user defined functions
482 public class Xcls_save_button : Object
484 public Gtk.Button el;
485 private Editor _this;
491 public Xcls_save_button(Editor _owner )
494 _this.save_button = this;
495 this.el = new Gtk.Button();
499 // set gobject values
500 this.el.label = "Save";
503 this.el.clicked.connect( () => {
504 _this.saveContents();
508 // user defined functions
511 public class Xcls_Label5 : Object
514 private Editor _this;
520 public Xcls_Label5(Editor _owner )
523 this.el = new Gtk.Label( null );
527 // set gobject values
528 this.el.hexpand = true;
531 // user defined functions
534 public class Xcls_Scale6 : Object
537 private Editor _this;
543 public Xcls_Scale6(Editor _owner )
546 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
550 // set gobject values
551 this.el.width_request = 200;
552 this.el.has_origin = true;
553 this.el.draw_value = false;
555 this.el.sensitive = true;
560 //this.el.set_range(6,30);
561 this.el.set_value ( BuilderApplication.settings.editor_font_size);
562 BuilderApplication.settings.editor_font_size_updated.connect(
564 BuilderApplication.settings.editor_font_size_inchange = true;
565 // GLib.debug("update range");
566 this.el.set_value (BuilderApplication.settings.editor_font_size);
567 BuilderApplication.settings.editor_font_size_inchange = false;
575 this.el.change_value.connect( (st, val ) => {
576 if (BuilderApplication.settings.editor_font_size_inchange) {
579 BuilderApplication.settings.editor_font_size = val;
584 // user defined functions
587 public class Xcls_close_btn : Object
589 public Gtk.Button el;
590 private Editor _this;
596 public Xcls_close_btn(Editor _owner )
599 _this.close_btn = this;
600 this.el = new Gtk.Button();
604 // set gobject values
605 this.el.icon_name = "window-close";
606 var child_1 = new Xcls_Image8( _this );
608 this.el.child = child_1.el;
611 this.el.clicked.connect( () => {
612 _this.saveContents();
613 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
617 // user defined functions
619 public class Xcls_Image8 : Object
622 private Editor _this;
628 public Xcls_Image8(Editor _owner )
631 this.el = new Gtk.Image();
635 // set gobject values
636 this.el.icon_name = "window-close";
637 this.el.icon_size = Gtk.IconSize.NORMAL;
640 // user defined functions
645 public class Xcls_RightEditor : Object
647 public Gtk.ScrolledWindow el;
648 private Editor _this;
654 public Xcls_RightEditor(Editor _owner )
657 _this.RightEditor = this;
658 this.el = new Gtk.ScrolledWindow();
662 // set gobject values
663 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
664 this.el.vexpand = true;
665 this.el.overlay_scrolling = false;
666 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
667 new Xcls_view( _this );
668 this.el.child = _this.view.el;
671 // user defined functions
673 public class Xcls_view : Object
675 public GtkSource.View el;
676 private Editor _this;
680 public Gtk.CssProvider css;
683 public Xcls_view(Editor _owner )
687 this.el = new GtkSource.View();
692 // set gobject values
693 this.el.auto_indent = true;
694 this.el.indent_width = 4;
695 this.el.name = "editor-view";
696 this.el.show_line_marks = true;
697 this.el.insert_spaces_instead_of_tabs = true;
698 this.el.show_line_numbers = true;
699 this.el.hexpand = true;
700 this.el.vexpand = true;
701 this.el.has_tooltip = true;
702 this.el.css_classes = { "code-editor" };
703 this.el.tab_width = 4;
704 this.el.highlight_current_line = true;
705 new Xcls_buffer( _this );
706 this.el.buffer = _this.buffer.el;
707 new Xcls_keystate( _this );
708 this.el.add_controller( _this.keystate.el );
709 var child_3 = new Xcls_EventControllerScroll13( _this );
711 this.el.add_controller( child_3.el );
712 var child_4 = new Xcls_GestureClick14( _this );
714 this.el.add_controller( child_4.el );
718 this.el.completion.add_provider(
719 new Palete.CompletionProvider(_this)
722 // hover seems pretty useless.. - ??
723 //var hover = this.el.get_hover();
724 //hover.add_provider(new Palete.HoverProvider(_this));
726 //this.el.completion.unblock_interactive();
727 this.el.completion.select_on_show = true; // select
728 //this.el.completion.remember_info_visibility = true;
731 var attrs = new GtkSource.MarkAttributes();
733 attrs.set_icon_name ( "process-stop");
734 attrs.query_tooltip_text.connect(( mark) => {
735 GLib.debug("tooltip query? %s", mark.name);
736 return strdup( mark.name);
738 attrs.query_tooltip_markup.connect(( mark) => {
739 GLib.debug("tooltip query? %s", mark.name);
740 return strdup( mark.name);
742 this.el.set_mark_attributes ("ERR", attrs, 1);
746 var wattrs = new GtkSource.MarkAttributes();
747 wattrs.set_icon_name ( "process-stop");
748 wattrs.query_tooltip_text.connect(( mark) => {
749 GLib.debug("tooltip query? %s", mark.name);
750 return strdup(mark.name);
752 wattrs.query_tooltip_markup.connect(( mark) => {
753 GLib.debug("tooltip query? %s", mark.name);
754 return strdup(mark.name);
756 this.el.set_mark_attributes ("WARN", wattrs, 1);
760 var dattrs = new GtkSource.MarkAttributes();
762 dattrs.set_icon_name ( "process-stop");
764 dattrs.query_tooltip_text.connect(( mark) => {
765 GLib.debug("tooltip query? %s", mark.name);
766 return strdup(mark.name);
768 //dattrs.query_tooltip_markup.connect(( mark) => {
769 // GLib.debug("tooltip query? %s", mark.name);
770 // return strdup(mark.name);
772 this.el.set_mark_attributes ("DEPR", dattrs, 1);
775 this.el.get_space_drawer().set_matrix(null);
776 this.el.get_space_drawer().set_types_for_locations(
777 GtkSource.SpaceLocationFlags.ALL,
778 GtkSource.SpaceTypeFlags.ALL
780 this.el.get_space_drawer().set_enable_matrix(true);
783 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
785 //GLib.debug("query tooltip");
789 var yoff = (int) _this.RightEditor.el.vadjustment.value;
791 // I think this is problematic - if it's compliing / updating at same time as query.
793 //if (_this.window.statusbar_compile_spinner.el.spinning) {
797 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
799 var l = iter.get_line();
803 // GLib.debug("query tooltip line %d", (int) l);
809 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
810 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
811 tooltip.set_text(_this.buffer.marks.get(l).dup());
819 // this crashes?? - not sure why.
820 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
821 if (marks.is_empty()) {
822 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
824 if (marks.is_empty()) {
825 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
828 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
830 marks.@foreach((m) => {
831 //GLib.debug("got mark %s", m.name);
832 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
834 // true if there is a mark..
835 if (str.length > 0 ) {
836 tooltip.set_text( str );
838 return str.length > 0 ? true : false;
843 // user defined functions
844 public void load (string str) {
846 // show the help page for the active node..
847 //this.get('/Help').show();
849 // this.get('/BottomPane').el.set_current_page(0);
850 GLib.debug("load called - Reset undo buffer");
852 var buf = (GtkSource.Buffer)this.el.get_buffer();
853 buf.begin_irreversible_action();
854 buf.set_text(str, str.length);
855 buf.end_irreversible_action();
857 var lm = GtkSource.LanguageManager.get_default();
859 if (_this.file != null) {
860 lang = _this.file.language;
862 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
863 var lg = _this.file.content_type.length > 0 ?
864 lm.guess_language(_this.file.path, _this.file.content_type) :
865 lm.get_language(lang);
868 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
870 this.el.insert_spaces_instead_of_tabs = true;
872 print("sourcelanguage = %s\n", lg.name);
873 if (lg.name == "Vala") {
874 this.el.insert_spaces_instead_of_tabs = false;
878 this.el.grab_focus();
879 _this.save_button.el.sensitive = false;
880 _this.last_error_counter = -1;
883 public class Xcls_buffer : Object
885 public GtkSource.Buffer el;
886 private Editor _this;
890 public int error_line;
891 public Gee.HashMap<int,string>? xmarks;
892 public bool check_queued;
895 public Xcls_buffer(Editor _owner )
899 this.el = new GtkSource.Buffer( null );
902 this.error_line = -1;
904 this.check_queued = false;
906 // set gobject values
907 this.el.highlight_syntax = true;
908 this.el.highlight_matching_brackets = true;
909 this.el.enable_undo = true;
914 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
915 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
916 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
917 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
918 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
919 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
920 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
921 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
924 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
925 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
926 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
929 this.el.cursor_moved.connect( ( ) => {
930 var cp = _this.view.el.cursor_position;
932 _this.view.el.et_iter_at_offset (
933 out iter, _this.view.el.cursor_position);
934 var line =iter.get_line();
935 _this.navigation.updateSelectedLine(iter.get_line());
939 this.el.changed.connect( () => {
942 _this.save_button.el.sensitive = true;
943 print("EDITOR CHANGED");
948 // this.get('/LeftPanel.model').changed( str , false);
953 // user defined functions
954 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
957 this.el.get_bounds (out start, out end);
959 this.el.remove_source_marks (start, end, type);
960 GLib.debug("highlight errors");
962 // we should highlight other types of errors..
964 if (!obj.has_member(type)) {
965 GLib.debug("Return has no errors\n");
969 if (_this.window.windowstate.state != WindowState.State.CODEONLY
971 _this.window.windowstate.state != WindowState.State.CODE
973 GLib.debug("windowstate != CODEONLY?");
978 //this.marks = new Gee.HashMap<int,string>();
979 var err = obj.get_object_member(type);
981 if (_this.file == null) {
982 GLib.debug("file is null?");
986 var valafn = _this.file.path;
988 if (_this.file.xtype != "PlainFile") {
992 var regex = new Regex("\\.bjs$");
994 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
995 } catch (GLib.RegexError e) {
1002 if (!err.has_member(valafn)) {
1003 GLib.debug("File path has no errors");
1007 var lines = err.get_object_member(valafn);
1010 if (obj.has_member("line_offset")) { // ?? why??
1011 offset = (int)obj.get_int_member("line_offset") + 1;
1015 var tlines = this.el.get_line_count () +1;
1017 if (_this.prop != null) {
1019 tlines = _this.prop.end_line + 1;
1020 offset = _this.prop.start_line + 1;
1026 lines.foreach_member((obj, line, node) => {
1029 // print("get inter\n");
1030 var eline = int.parse(line) - offset;
1031 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
1034 if (eline > tlines || eline < 0) {
1039 this.el.get_iter_at_line( out iter, eline);
1040 //print("mark line\n");
1042 var ar = lines.get_array_member(line);
1043 for (var i = 0 ; i < ar.get_length(); i++) {
1044 if (ar.get_string_element(i) == "Success") {
1047 msg += (msg.length > 0) ? "\n" : "";
1048 msg += ar.get_string_element(i);
1053 msg = "Line: %d".printf(eline+1) + " " + msg;
1054 this.el.create_source_mark(msg, type, iter);
1055 GLib.debug("set line %d to %m", eline, msg);
1056 // this.marks.set(eline, msg);
1065 public bool checkSyntax () {
1068 var str = this.toString();
1071 if (this.error_line > 0) {
1074 this.el.get_bounds (out start, out end);
1076 this.el.remove_source_marks (start, end, null);
1078 if (str.length < 1) {
1079 print("checkSyntax - empty string?\n");
1084 if (_this.file.xtype == "PlainFile") {
1086 // assume it's gtk...
1087 var oldcode =_this.file.toSource();
1088 _this.file.setSource(str);
1089 BuilderApplication.showSpinner("appointment soon","document change pending");
1090 _this.file.getLanguageServer().document_change(_this.file);
1092 _this.file.setSource(oldcode);
1098 if (_this.file == null) {
1106 GLib.debug("calling validate");
1107 // clear the buttons.
1108 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1111 var oldcode = _this.prop.val;
1113 _this.prop.val = str;
1114 _this.node.updated_count++;
1115 _this.file.getLanguageServer().document_change(_this.file);
1116 _this.node.updated_count++;
1117 _this.prop.val = oldcode;
1120 //print("done mark line\n");
1122 return true; // at present allow saving - even if it's invalid..
1124 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1126 this.error_line = validate_res.size;
1128 if (this.error_line < 1) {
1131 var tlines = this.el.get_line_count ();
1133 var valiter = validate_res.map_iterator();
1134 while (valiter.next()) {
1136 // print("get inter\n");
1137 var eline = valiter.get_key();
1138 if (eline > tlines) {
1141 this.el.get_iter_at_line( out iter, eline);
1142 //print("mark line\n");
1143 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1147 public string toString () {
1151 this.el.get_start_iter(out s);
1152 this.el.get_end_iter(out e);
1153 var ret = this.el.get_text(s,e,true);
1154 //print("TO STRING? " + ret);
1159 public class Xcls_keystate : Object
1161 public Gtk.EventControllerKey el;
1162 private Editor _this;
1166 public bool is_control;
1169 public Xcls_keystate(Editor _owner )
1172 _this.keystate = this;
1173 this.el = new Gtk.EventControllerKey();
1176 this.is_control = false;
1178 // set gobject values
1181 this.el.key_released.connect( (keyval, keycode, state) => {
1183 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1184 this.is_control = false;
1186 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1187 GLib.debug("SAVE: ctrl-S pressed");
1188 _this.saveContents();
1192 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1193 GLib.debug("SAVE: ctrl-g pressed");
1194 _this.forwardSearch(true);
1197 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1198 GLib.debug("SAVE: ctrl-f pressed");
1199 _this.search_entry.el.grab_focus();
1200 _this.search_entry.el.select_region(0,-1);
1203 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1204 _this.view.el.show_completion();
1208 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1209 var line = iter.get_line();
1210 var offset = iter.get_line_offset();
1211 GLib.debug("line %d off %d", line ,offset);
1212 if (_this.prop != null) {
1213 line += _this.prop.start_line + 1; // i think..
1214 offset += 12; // should probably be 8 without namespaced
1215 GLib.debug("guess line %d off %d", line ,offset);
1217 //_this.view.el.show_completion();
1218 // print(event.key.keyval)
1227 this.el.key_pressed.connect( (keyval, keycode, state) => {
1229 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1230 this.is_control = true;
1236 // user defined functions
1239 public class Xcls_EventControllerScroll13 : Object
1241 public Gtk.EventControllerScroll el;
1242 private Editor _this;
1246 public double distance;
1249 public Xcls_EventControllerScroll13(Editor _owner )
1252 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1255 this.distance = 0.0f;
1257 // set gobject values
1260 this.el.scroll.connect( (dx, dy) => {
1261 if (!_this.keystate.is_control) {
1264 //GLib.debug("scroll %f", dy);
1266 this.distance += dy;
1268 //GLib.debug("scroll %f / %f", dy, this.distance);
1270 if (this.distance < -1) {
1272 BuilderApplication.settings.editor_font_size ++;
1275 if (this.distance > 1) {
1276 BuilderApplication.settings.editor_font_size --;
1284 // user defined functions
1287 public class Xcls_GestureClick14 : Object
1289 public Gtk.GestureClick el;
1290 private Editor _this;
1296 public Xcls_GestureClick14(Editor _owner )
1299 this.el = new Gtk.GestureClick();
1303 // set gobject values
1306 // user defined functions
1311 public class Xcls_Box15 : Object
1314 private Editor _this;
1320 public Xcls_Box15(Editor _owner )
1323 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1327 // set gobject values
1328 this.el.homogeneous = false;
1329 this.el.vexpand = false;
1330 new Xcls_search_entry( _this );
1331 this.el.append( _this.search_entry.el );
1332 new Xcls_search_results( _this );
1333 this.el.append( _this.search_results.el );
1334 new Xcls_nextBtn( _this );
1335 this.el.append( _this.nextBtn.el );
1336 new Xcls_backBtn( _this );
1337 this.el.append( _this.backBtn.el );
1338 var child_5 = new Xcls_MenuButton21( _this );
1340 this.el.append( child_5.el );
1343 // user defined functions
1345 public class Xcls_search_entry : Object
1347 public Gtk.SearchEntry el;
1348 private Editor _this;
1352 public Gtk.CssProvider css;
1355 public Xcls_search_entry(Editor _owner )
1358 _this.search_entry = this;
1359 this.el = new Gtk.SearchEntry();
1363 // set gobject values
1364 this.el.name = "editor-search-entry";
1365 this.el.hexpand = true;
1366 this.el.placeholder_text = "Press enter to search";
1367 this.el.search_delay = 3;
1368 var child_1 = new Xcls_EventControllerKey17( _this );
1370 this.el.add_controller( child_1.el );
1373 this.el.search_changed.connect( ( ) => {
1375 _this.search(_this.search_entry.el.text);
1376 _this.search_results.updateResults();
1378 GLib.Timeout.add_seconds(1,() => {
1379 _this.search_results.updateResults();
1385 // user defined functions
1386 public void forwardSearch (bool change_focus) {
1389 _this.forwardSearch(change_focus);
1393 switch(_this.windowstate.state) {
1394 case WindowState.State.CODEONLY:
1395 //case WindowState.State.CODE:
1396 // search the code being edited..
1397 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1400 case WindowState.State.PREVIEW:
1401 if (_this.windowstate.file.xtype == "Gtk") {
1402 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1404 _this.windowstate.window_rooview.forwardSearch(change_focus);
1413 public class Xcls_EventControllerKey17 : Object
1415 public Gtk.EventControllerKey el;
1416 private Editor _this;
1422 public Xcls_EventControllerKey17(Editor _owner )
1425 this.el = new Gtk.EventControllerKey();
1429 // set gobject values
1432 this.el.key_pressed.connect( (keyval, keycode, state) => {
1434 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1435 GLib.debug("SAVE: ctrl-g pressed");
1436 _this.forwardSearch(true);
1441 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1442 _this.forwardSearch(true);
1448 // print(event.key.keyval)
1454 // user defined functions
1458 public class Xcls_search_results : Object
1460 public Gtk.Label el;
1461 private Editor _this;
1467 public Xcls_search_results(Editor _owner )
1470 _this.search_results = this;
1471 this.el = new Gtk.Label( "No Results" );
1475 // set gobject values
1476 this.el.margin_end = 4;
1477 this.el.margin_start = 4;
1480 // user defined functions
1481 public void updateResults () {
1482 this.el.visible = true;
1484 var res = _this.searchcontext.get_occurrences_count();
1486 _this.search_results.el.label = "??? Matches";
1490 _this.nextBtn.el.sensitive = false;
1491 _this.backBtn.el.sensitive = false;
1494 _this.search_results.el.label = "%d Matches".printf(res);
1495 _this.nextBtn.el.sensitive = true;
1496 _this.backBtn.el.sensitive = true;
1499 _this.search_results.el.label = "No Matches";
1504 public class Xcls_nextBtn : Object
1506 public Gtk.Button el;
1507 private Editor _this;
1511 public bool always_show_image;
1514 public Xcls_nextBtn(Editor _owner )
1517 _this.nextBtn = this;
1518 this.el = new Gtk.Button();
1521 this.always_show_image = true;
1523 // set gobject values
1524 this.el.icon_name = "go-down";
1525 this.el.sensitive = false;
1528 this.el.clicked.connect( (event) => {
1530 _this.forwardSearch(true);
1536 // user defined functions
1539 public class Xcls_backBtn : Object
1541 public Gtk.Button el;
1542 private Editor _this;
1546 public bool always_show_image;
1549 public Xcls_backBtn(Editor _owner )
1552 _this.backBtn = this;
1553 this.el = new Gtk.Button();
1556 this.always_show_image = true;
1558 // set gobject values
1559 this.el.icon_name = "go-up";
1560 this.el.sensitive = false;
1563 this.el.clicked.connect( (event) => {
1565 _this.backSearch(true);
1570 // user defined functions
1573 public class Xcls_MenuButton21 : Object
1575 public Gtk.MenuButton el;
1576 private Editor _this;
1580 public bool always_show_image;
1583 public Xcls_MenuButton21(Editor _owner )
1586 this.el = new Gtk.MenuButton();
1589 this.always_show_image = true;
1591 // set gobject values
1592 this.el.icon_name = "emblem-system";
1593 this.el.always_show_arrow = true;
1594 new Xcls_search_settings( _this );
1595 this.el.popover = _this.search_settings.el;
1598 // user defined functions
1600 public class Xcls_search_settings : Object
1602 public Gtk.Popover el;
1603 private Editor _this;
1609 public Xcls_search_settings(Editor _owner )
1612 _this.search_settings = this;
1613 this.el = new Gtk.Popover();
1617 // set gobject values
1618 var child_1 = new Xcls_Box23( _this );
1620 this.el.child = child_1.el;
1623 // user defined functions
1625 public class Xcls_Box23 : Object
1628 private Editor _this;
1634 public Xcls_Box23(Editor _owner )
1637 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1641 // set gobject values
1642 new Xcls_case_sensitive( _this );
1643 this.el.append( _this.case_sensitive.el );
1644 new Xcls_regex( _this );
1645 this.el.append( _this.regex.el );
1646 new Xcls_multiline( _this );
1647 this.el.append( _this.multiline.el );
1650 // user defined functions
1652 public class Xcls_case_sensitive : Object
1654 public Gtk.CheckButton el;
1655 private Editor _this;
1661 public Xcls_case_sensitive(Editor _owner )
1664 _this.case_sensitive = this;
1665 this.el = new Gtk.CheckButton();
1669 // set gobject values
1670 this.el.label = "Case Sensitive";
1679 // user defined functions
1682 public class Xcls_regex : Object
1684 public Gtk.CheckButton el;
1685 private Editor _this;
1691 public Xcls_regex(Editor _owner )
1695 this.el = new Gtk.CheckButton();
1699 // set gobject values
1700 this.el.label = "Regex";
1709 // user defined functions
1712 public class Xcls_multiline : Object
1714 public Gtk.CheckButton el;
1715 private Editor _this;
1721 public Xcls_multiline(Editor _owner )
1724 _this.multiline = this;
1725 this.el = new Gtk.CheckButton();
1729 // set gobject values
1730 this.el.label = "Multi-line (add \\n)";
1733 // user defined functions
1741 public class Xcls_navigationwindow : Object
1743 public Gtk.ScrolledWindow el;
1744 private Editor _this;
1750 public Xcls_navigationwindow(Editor _owner )
1753 _this.navigationwindow = this;
1754 this.el = new Gtk.ScrolledWindow();
1758 // set gobject values
1759 this.el.visible = false;
1760 new Xcls_navigation( _this );
1761 this.el.child = _this.navigation.el;
1764 // user defined functions
1766 public class Xcls_navigation : Object
1768 public Gtk.ColumnView el;
1769 private Editor _this;
1773 public int selected_row;
1776 public Xcls_navigation(Editor _owner )
1779 _this.navigation = this;
1780 new Xcls_navigationselmodel( _this );
1781 this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
1784 this.selected_row = -1;
1786 // set gobject values
1787 this.el.name = "editor-navigation";
1788 var child_2 = new Xcls_ColumnViewColumn29( _this );
1790 this.el.append_column( child_2.el );
1791 var child_3 = new Xcls_GestureClick38( _this );
1793 this.el.add_controller( child_3.el );
1796 // user defined functions
1797 public Gtk.Widget? getWidgetAtRow (uint row) {
1800 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
1801 var colview = gesture.widget;
1802 var line_no = check_list_widget(colview, x,y);
1804 var item = colview.model.get_item(line_no);
1808 //GLib.debug("Get Widget At Row %d", (int)row);
1809 var child = this.el.get_first_child();
1811 var reading_header = true;
1813 while (child != null) {
1814 //GLib.debug("Got %s", child.get_type().name());
1816 if (reading_header) {
1819 if (child.get_type().name() != "GtkColumnListView") {
1821 child = child.get_next_sibling();
1824 // should be columnlistview
1825 child = child.get_first_child();
1829 reading_header = false;
1836 if (line_no == row) {
1837 //GLib.debug("Returning widget %s", child.get_type().name());
1838 return (Gtk.Widget)child;
1840 child = child.get_next_sibling();
1842 //GLib.debug("Rturning null");
1846 public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
1847 _this.navigationwindow.el.show();
1848 _this.navliststore.el.remove_all();
1849 foreach(var sym in syms) {
1850 _this.navliststore.el.append(sym);
1855 public int getRowAt (double x, double y, out string pos) {
1858 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
1859 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
1864 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
1869 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
1874 while (cr.get_prev_sibling() != null) {
1876 cr = cr.get_prev_sibling();
1879 //GLib.debug("row number is %d", rn);
1880 //GLib.debug("click %d, %d", (int)x, (int)y);
1882 Graphene.Rect bounds;
1883 row.compute_bounds(this.el, out bounds);
1884 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
1885 // (int)bounds.get_x(), (int)bounds.get_y(),
1886 // (int)bounds.get_width(), (int)bounds.get_height()
1888 var ypos = y - bounds.get_y();
1889 //GLib.debug("rel ypos = %d", (int)ypos);
1890 var rpos = 100.0 * (ypos / bounds.get_height());
1891 //GLib.debug("rel pos = %d %%", (int)rpos);
1896 } else if (rpos < 20) {
1901 public void updateSelectedLine (int line) {
1904 var sym = _this.navliststore.symbolAtLine(line);
1906 new_row = _this.navigationselmodel.getRowFromSymbol(sym);
1908 if (new_row == this.selected_row) {
1911 if (this.selected_row > -1) {
1912 var old = this.getWidgetAtRow(this.selected_row);
1914 old.remove_css_class("selcted-row");
1918 var row = this.getWidgetAtRow(new_row);
1920 row.add_css_class("selcted-row");
1922 this.selected_row = new_row;
1928 public class Xcls_ColumnViewColumn29 : Object
1930 public Gtk.ColumnViewColumn el;
1931 private Editor _this;
1937 public Xcls_ColumnViewColumn29(Editor _owner )
1940 var child_1 = new Xcls_SignalListItemFactory30( _this );
1942 this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
1946 // set gobject values
1947 this.el.expand = true;
1950 // user defined functions
1952 public class Xcls_SignalListItemFactory30 : Object
1954 public Gtk.SignalListItemFactory el;
1955 private Editor _this;
1961 public Xcls_SignalListItemFactory30(Editor _owner )
1964 this.el = new Gtk.SignalListItemFactory();
1968 // set gobject values
1971 this.el.setup.connect( (listitem) => {
1973 var expand = new Gtk.TreeExpander();
1975 expand.set_indent_for_depth(true);
1976 expand.set_indent_for_icon(true);
1977 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
1978 var icon = new Gtk.Image();
1979 var lbl = new Gtk.Label("");
1980 lbl.use_markup = true;
1981 lbl.ellipsize = Pango.EllipsizeMode.END;
1983 icon.margin_end = 4;
1984 lbl.justify = Gtk.Justification.LEFT;
1987 // listitem.activatable = true; ??
1991 expand.set_child(hbox);
1992 ((Gtk.ListItem)listitem).set_child(expand);
1995 this.el.bind.connect( (listitem) => {
1996 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
1998 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1999 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2002 var hbox = (Gtk.Box) expand.child;
2005 var img = (Gtk.Image) hbox.get_first_child();
2006 var lbl = (Gtk.Label) img.get_next_sibling();
2008 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
2009 var sym = (Lsp.DocumentSymbol) lr.get_item();
2011 GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
2013 expand.set_hide_expander( sym.children.get_n_items() < 1);
2014 expand.set_list_row(lr);
2016 sym.bind_property("symbol_icon",
2018 GLib.BindingFlags.SYNC_CREATE);
2020 hbox.add_css_class(sym.symbol_icon);
2022 sym.bind_property("name",
2024 GLib.BindingFlags.SYNC_CREATE);
2025 // should be better?- --line no?
2026 sym.bind_property("tooltip",
2027 lbl, "tooltip_markup",
2028 GLib.BindingFlags.SYNC_CREATE);
2034 // user defined functions
2038 public class Xcls_navigationselmodel : Object
2040 public Gtk.NoSelection el;
2041 private Editor _this;
2047 public Xcls_navigationselmodel(Editor _owner )
2050 _this.navigationselmodel = this;
2051 var child_1 = new Xcls_SortListModel32( _this );
2053 this.el = new Gtk.NoSelection( child_1.el );
2057 // set gobject values
2060 // user defined functions
2061 public Lsp.DocumentSymbol? getSymbollAt (uint row) {
2063 var tr = (Gtk.TreeListRow)this.el.get_item(row);
2065 var a = tr.get_item();;
2066 GLib.debug("get_item (2) = %s", a.get_type().name());
2069 return (Lsp.DocumentSymbol)tr.get_item();
2072 public int getRowFromSymbol (Lsp.DocumentSymbol sym) {
2074 for (var i=0;i < this.el.get_n_items(); i++) {
2077 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2079 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2086 public class Xcls_SortListModel32 : Object
2088 public Gtk.SortListModel el;
2089 private Editor _this;
2095 public Xcls_SortListModel32(Editor _owner )
2098 var child_1 = new Xcls_TreeListModel33( _this );
2100 var child_2 = new Xcls_TreeListRowSorter35( _this );
2102 this.el = new Gtk.SortListModel( child_1.el, child_2.el );
2106 // set gobject values
2109 // user defined functions
2111 public class Xcls_TreeListModel33 : Object
2113 public Gtk.TreeListModel el;
2114 private Editor _this;
2120 public Xcls_TreeListModel33(Editor _owner )
2123 new Xcls_navliststore( _this );
2124 this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
2126 return ((Lsp.DocumentSymbol)item).children;
2132 // set gobject values
2135 // user defined functions
2137 public class Xcls_navliststore : Object
2139 public GLib.ListStore el;
2140 private Editor _this;
2146 public Xcls_navliststore(Editor _owner )
2149 _this.navliststore = this;
2150 this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
2154 // set gobject values
2157 // user defined functions
2158 public Lsp.DocumentSymbol? symbolAtLine (uint line) {
2161 for(var i = 0; i < this.el.get_n_items();i++) {
2162 var el = (Lsp.DocumentSymbol)this.el.get_item(i);
2163 var ret = el.containsLine(i);
2175 public class Xcls_TreeListRowSorter35 : Object
2177 public Gtk.TreeListRowSorter el;
2178 private Editor _this;
2184 public Xcls_TreeListRowSorter35(Editor _owner )
2187 var child_1 = new Xcls_StringSorter36( _this );
2189 this.el = new Gtk.TreeListRowSorter( child_1.el );
2193 // set gobject values
2196 // user defined functions
2198 public class Xcls_StringSorter36 : Object
2200 public Gtk.StringSorter el;
2201 private Editor _this;
2207 public Xcls_StringSorter36(Editor _owner )
2210 var child_1 = new Xcls_PropertyExpression37( _this );
2212 this.el = new Gtk.StringSorter( child_1.el );
2216 // set gobject values
2219 // user defined functions
2221 public class Xcls_PropertyExpression37 : Object
2223 public Gtk.PropertyExpression el;
2224 private Editor _this;
2230 public Xcls_PropertyExpression37(Editor _owner )
2233 this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
2237 // set gobject values
2240 // user defined functions
2247 public class Xcls_GestureClick38 : Object
2249 public Gtk.GestureClick el;
2250 private Editor _this;
2256 public Xcls_GestureClick38(Editor _owner )
2259 this.el = new Gtk.GestureClick();
2263 // set gobject values
2266 this.el.pressed.connect( (n_press, x, y) => {
2268 var row = _this.navigation.getRowAt(x,y, out pos );
2270 GLib.debug("no row selected items");
2273 //Lsp.DocumentSymbol
2274 var sym = _this.navigationselmodel.getSymbollAt(row);
2290 GLib.debug("goto line %d", (int)sym.range.start.line);
2291 _this.scroll_to_line((int)sym.range.start.line);
2296 // user defined functions