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.changed.connect( () => {
932 _this.save_button.el.sensitive = true;
933 print("EDITOR CHANGED");
938 // this.get('/LeftPanel.model').changed( str , false);
943 // user defined functions
944 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
947 this.el.get_bounds (out start, out end);
949 this.el.remove_source_marks (start, end, type);
950 GLib.debug("highlight errors");
952 // we should highlight other types of errors..
954 if (!obj.has_member(type)) {
955 GLib.debug("Return has no errors\n");
959 if (_this.window.windowstate.state != WindowState.State.CODEONLY
961 _this.window.windowstate.state != WindowState.State.CODE
963 GLib.debug("windowstate != CODEONLY?");
968 //this.marks = new Gee.HashMap<int,string>();
969 var err = obj.get_object_member(type);
971 if (_this.file == null) {
972 GLib.debug("file is null?");
976 var valafn = _this.file.path;
978 if (_this.file.xtype != "PlainFile") {
982 var regex = new Regex("\\.bjs$");
984 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
985 } catch (GLib.RegexError e) {
992 if (!err.has_member(valafn)) {
993 GLib.debug("File path has no errors");
997 var lines = err.get_object_member(valafn);
1000 if (obj.has_member("line_offset")) { // ?? why??
1001 offset = (int)obj.get_int_member("line_offset") + 1;
1005 var tlines = this.el.get_line_count () +1;
1007 if (_this.prop != null) {
1009 tlines = _this.prop.end_line + 1;
1010 offset = _this.prop.start_line + 1;
1016 lines.foreach_member((obj, line, node) => {
1019 // print("get inter\n");
1020 var eline = int.parse(line) - offset;
1021 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
1024 if (eline > tlines || eline < 0) {
1029 this.el.get_iter_at_line( out iter, eline);
1030 //print("mark line\n");
1032 var ar = lines.get_array_member(line);
1033 for (var i = 0 ; i < ar.get_length(); i++) {
1034 if (ar.get_string_element(i) == "Success") {
1037 msg += (msg.length > 0) ? "\n" : "";
1038 msg += ar.get_string_element(i);
1043 msg = "Line: %d".printf(eline+1) + " " + msg;
1044 this.el.create_source_mark(msg, type, iter);
1045 GLib.debug("set line %d to %m", eline, msg);
1046 // this.marks.set(eline, msg);
1055 public bool checkSyntax () {
1058 var str = this.toString();
1061 if (this.error_line > 0) {
1064 this.el.get_bounds (out start, out end);
1066 this.el.remove_source_marks (start, end, null);
1068 if (str.length < 1) {
1069 print("checkSyntax - empty string?\n");
1074 if (_this.file.xtype == "PlainFile") {
1076 // assume it's gtk...
1077 var oldcode =_this.file.toSource();
1078 _this.file.setSource(str);
1079 BuilderApplication.showSpinner("appointment soon","document change pending");
1080 _this.file.getLanguageServer().document_change(_this.file);
1082 _this.file.setSource(oldcode);
1088 if (_this.file == null) {
1096 GLib.debug("calling validate");
1097 // clear the buttons.
1098 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1101 var oldcode = _this.prop.val;
1103 _this.prop.val = str;
1104 _this.node.updated_count++;
1105 _this.file.getLanguageServer().document_change(_this.file);
1106 _this.node.updated_count++;
1107 _this.prop.val = oldcode;
1110 //print("done mark line\n");
1112 return true; // at present allow saving - even if it's invalid..
1114 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1116 this.error_line = validate_res.size;
1118 if (this.error_line < 1) {
1121 var tlines = this.el.get_line_count ();
1123 var valiter = validate_res.map_iterator();
1124 while (valiter.next()) {
1126 // print("get inter\n");
1127 var eline = valiter.get_key();
1128 if (eline > tlines) {
1131 this.el.get_iter_at_line( out iter, eline);
1132 //print("mark line\n");
1133 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1137 public string toString () {
1141 this.el.get_start_iter(out s);
1142 this.el.get_end_iter(out e);
1143 var ret = this.el.get_text(s,e,true);
1144 //print("TO STRING? " + ret);
1149 public class Xcls_keystate : Object
1151 public Gtk.EventControllerKey el;
1152 private Editor _this;
1156 public bool is_control;
1159 public Xcls_keystate(Editor _owner )
1162 _this.keystate = this;
1163 this.el = new Gtk.EventControllerKey();
1166 this.is_control = false;
1168 // set gobject values
1171 this.el.key_released.connect( (keyval, keycode, state) => {
1173 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1174 this.is_control = false;
1176 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1177 GLib.debug("SAVE: ctrl-S pressed");
1178 _this.saveContents();
1182 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1183 GLib.debug("SAVE: ctrl-g pressed");
1184 _this.forwardSearch(true);
1187 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1188 GLib.debug("SAVE: ctrl-f pressed");
1189 _this.search_entry.el.grab_focus();
1190 _this.search_entry.el.select_region(0,-1);
1193 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1194 _this.view.el.show_completion();
1198 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1199 var line = iter.get_line();
1200 var offset = iter.get_line_offset();
1201 GLib.debug("line %d off %d", line ,offset);
1202 if (_this.prop != null) {
1203 line += _this.prop.start_line + 1; // i think..
1204 offset += 12; // should probably be 8 without namespaced
1205 GLib.debug("guess line %d off %d", line ,offset);
1207 //_this.view.el.show_completion();
1208 // print(event.key.keyval)
1217 this.el.key_pressed.connect( (keyval, keycode, state) => {
1219 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1220 this.is_control = true;
1226 // user defined functions
1229 public class Xcls_EventControllerScroll13 : Object
1231 public Gtk.EventControllerScroll el;
1232 private Editor _this;
1236 public double distance;
1239 public Xcls_EventControllerScroll13(Editor _owner )
1242 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1245 this.distance = 0.0f;
1247 // set gobject values
1250 this.el.scroll.connect( (dx, dy) => {
1251 if (!_this.keystate.is_control) {
1254 //GLib.debug("scroll %f", dy);
1256 this.distance += dy;
1258 //GLib.debug("scroll %f / %f", dy, this.distance);
1260 if (this.distance < -1) {
1262 BuilderApplication.settings.editor_font_size ++;
1265 if (this.distance > 1) {
1266 BuilderApplication.settings.editor_font_size --;
1274 // user defined functions
1277 public class Xcls_GestureClick14 : Object
1279 public Gtk.GestureClick el;
1280 private Editor _this;
1286 public Xcls_GestureClick14(Editor _owner )
1289 this.el = new Gtk.GestureClick();
1293 // set gobject values
1296 // user defined functions
1301 public class Xcls_Box15 : Object
1304 private Editor _this;
1310 public Xcls_Box15(Editor _owner )
1313 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1317 // set gobject values
1318 this.el.homogeneous = false;
1319 this.el.vexpand = false;
1320 new Xcls_search_entry( _this );
1321 this.el.append( _this.search_entry.el );
1322 new Xcls_search_results( _this );
1323 this.el.append( _this.search_results.el );
1324 new Xcls_nextBtn( _this );
1325 this.el.append( _this.nextBtn.el );
1326 new Xcls_backBtn( _this );
1327 this.el.append( _this.backBtn.el );
1328 var child_5 = new Xcls_MenuButton21( _this );
1330 this.el.append( child_5.el );
1333 // user defined functions
1335 public class Xcls_search_entry : Object
1337 public Gtk.SearchEntry el;
1338 private Editor _this;
1342 public Gtk.CssProvider css;
1345 public Xcls_search_entry(Editor _owner )
1348 _this.search_entry = this;
1349 this.el = new Gtk.SearchEntry();
1353 // set gobject values
1354 this.el.name = "editor-search-entry";
1355 this.el.hexpand = true;
1356 this.el.placeholder_text = "Press enter to search";
1357 this.el.search_delay = 3;
1358 var child_1 = new Xcls_EventControllerKey17( _this );
1360 this.el.add_controller( child_1.el );
1363 this.el.search_changed.connect( ( ) => {
1365 _this.search(_this.search_entry.el.text);
1366 _this.search_results.updateResults();
1368 GLib.Timeout.add_seconds(1,() => {
1369 _this.search_results.updateResults();
1375 // user defined functions
1376 public void forwardSearch (bool change_focus) {
1379 _this.forwardSearch(change_focus);
1383 switch(_this.windowstate.state) {
1384 case WindowState.State.CODEONLY:
1385 //case WindowState.State.CODE:
1386 // search the code being edited..
1387 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1390 case WindowState.State.PREVIEW:
1391 if (_this.windowstate.file.xtype == "Gtk") {
1392 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1394 _this.windowstate.window_rooview.forwardSearch(change_focus);
1403 public class Xcls_EventControllerKey17 : Object
1405 public Gtk.EventControllerKey el;
1406 private Editor _this;
1412 public Xcls_EventControllerKey17(Editor _owner )
1415 this.el = new Gtk.EventControllerKey();
1419 // set gobject values
1422 this.el.key_pressed.connect( (keyval, keycode, state) => {
1424 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1425 GLib.debug("SAVE: ctrl-g pressed");
1426 _this.forwardSearch(true);
1431 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1432 _this.forwardSearch(true);
1438 // print(event.key.keyval)
1444 // user defined functions
1448 public class Xcls_search_results : Object
1450 public Gtk.Label el;
1451 private Editor _this;
1457 public Xcls_search_results(Editor _owner )
1460 _this.search_results = this;
1461 this.el = new Gtk.Label( "No Results" );
1465 // set gobject values
1466 this.el.margin_end = 4;
1467 this.el.margin_start = 4;
1470 // user defined functions
1471 public void updateResults () {
1472 this.el.visible = true;
1474 var res = _this.searchcontext.get_occurrences_count();
1476 _this.search_results.el.label = "??? Matches";
1480 _this.nextBtn.el.sensitive = false;
1481 _this.backBtn.el.sensitive = false;
1484 _this.search_results.el.label = "%d Matches".printf(res);
1485 _this.nextBtn.el.sensitive = true;
1486 _this.backBtn.el.sensitive = true;
1489 _this.search_results.el.label = "No Matches";
1494 public class Xcls_nextBtn : Object
1496 public Gtk.Button el;
1497 private Editor _this;
1501 public bool always_show_image;
1504 public Xcls_nextBtn(Editor _owner )
1507 _this.nextBtn = this;
1508 this.el = new Gtk.Button();
1511 this.always_show_image = true;
1513 // set gobject values
1514 this.el.icon_name = "go-down";
1515 this.el.sensitive = false;
1518 this.el.clicked.connect( (event) => {
1520 _this.forwardSearch(true);
1526 // user defined functions
1529 public class Xcls_backBtn : Object
1531 public Gtk.Button el;
1532 private Editor _this;
1536 public bool always_show_image;
1539 public Xcls_backBtn(Editor _owner )
1542 _this.backBtn = this;
1543 this.el = new Gtk.Button();
1546 this.always_show_image = true;
1548 // set gobject values
1549 this.el.icon_name = "go-up";
1550 this.el.sensitive = false;
1553 this.el.clicked.connect( (event) => {
1555 _this.backSearch(true);
1560 // user defined functions
1563 public class Xcls_MenuButton21 : Object
1565 public Gtk.MenuButton el;
1566 private Editor _this;
1570 public bool always_show_image;
1573 public Xcls_MenuButton21(Editor _owner )
1576 this.el = new Gtk.MenuButton();
1579 this.always_show_image = true;
1581 // set gobject values
1582 this.el.icon_name = "emblem-system";
1583 this.el.always_show_arrow = true;
1584 new Xcls_search_settings( _this );
1585 this.el.popover = _this.search_settings.el;
1588 // user defined functions
1590 public class Xcls_search_settings : Object
1592 public Gtk.Popover el;
1593 private Editor _this;
1599 public Xcls_search_settings(Editor _owner )
1602 _this.search_settings = this;
1603 this.el = new Gtk.Popover();
1607 // set gobject values
1608 var child_1 = new Xcls_Box23( _this );
1610 this.el.child = child_1.el;
1613 // user defined functions
1615 public class Xcls_Box23 : Object
1618 private Editor _this;
1624 public Xcls_Box23(Editor _owner )
1627 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1631 // set gobject values
1632 new Xcls_case_sensitive( _this );
1633 this.el.append( _this.case_sensitive.el );
1634 new Xcls_regex( _this );
1635 this.el.append( _this.regex.el );
1636 new Xcls_multiline( _this );
1637 this.el.append( _this.multiline.el );
1640 // user defined functions
1642 public class Xcls_case_sensitive : Object
1644 public Gtk.CheckButton el;
1645 private Editor _this;
1651 public Xcls_case_sensitive(Editor _owner )
1654 _this.case_sensitive = this;
1655 this.el = new Gtk.CheckButton();
1659 // set gobject values
1660 this.el.label = "Case Sensitive";
1669 // user defined functions
1672 public class Xcls_regex : Object
1674 public Gtk.CheckButton el;
1675 private Editor _this;
1681 public Xcls_regex(Editor _owner )
1685 this.el = new Gtk.CheckButton();
1689 // set gobject values
1690 this.el.label = "Regex";
1699 // user defined functions
1702 public class Xcls_multiline : Object
1704 public Gtk.CheckButton el;
1705 private Editor _this;
1711 public Xcls_multiline(Editor _owner )
1714 _this.multiline = this;
1715 this.el = new Gtk.CheckButton();
1719 // set gobject values
1720 this.el.label = "Multi-line (add \\n)";
1723 // user defined functions
1731 public class Xcls_navigationwindow : Object
1733 public Gtk.ScrolledWindow el;
1734 private Editor _this;
1740 public Xcls_navigationwindow(Editor _owner )
1743 _this.navigationwindow = this;
1744 this.el = new Gtk.ScrolledWindow();
1748 // set gobject values
1749 this.el.visible = false;
1750 new Xcls_navigation( _this );
1751 this.el.child = _this.navigation.el;
1754 // user defined functions
1756 public class Xcls_navigation : Object
1758 public Gtk.ColumnView el;
1759 private Editor _this;
1765 public Xcls_navigation(Editor _owner )
1768 _this.navigation = this;
1769 new Xcls_navigationselmodel( _this );
1770 this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
1774 // set gobject values
1775 this.el.name = "editor-navigation";
1776 var child_2 = new Xcls_ColumnViewColumn29( _this );
1778 this.el.append_column( child_2.el );
1779 var child_3 = new Xcls_GestureClick34( _this );
1781 this.el.add_controller( child_3.el );
1784 // user defined functions
1785 public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
1786 _this.navigationwindow.el.show();
1787 _this.navliststore.el.remove_all();
1788 foreach(var sym in syms) {
1789 _this.navliststore.el.append(sym);
1794 public int getRowAt (double x, double y, out string pos) {
1797 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
1798 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
1803 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
1808 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
1813 while (cr.get_prev_sibling() != null) {
1815 cr = cr.get_prev_sibling();
1818 //GLib.debug("row number is %d", rn);
1819 //GLib.debug("click %d, %d", (int)x, (int)y);
1821 Graphene.Rect bounds;
1822 row.compute_bounds(this.el, out bounds);
1823 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
1824 // (int)bounds.get_x(), (int)bounds.get_y(),
1825 // (int)bounds.get_width(), (int)bounds.get_height()
1827 var ypos = y - bounds.get_y();
1828 //GLib.debug("rel ypos = %d", (int)ypos);
1829 var rpos = 100.0 * (ypos / bounds.get_height());
1830 //GLib.debug("rel pos = %d %%", (int)rpos);
1835 } else if (rpos < 20) {
1841 public class Xcls_ColumnViewColumn29 : Object
1843 public Gtk.ColumnViewColumn el;
1844 private Editor _this;
1850 public Xcls_ColumnViewColumn29(Editor _owner )
1853 var child_1 = new Xcls_SignalListItemFactory30( _this );
1855 this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
1859 // set gobject values
1860 this.el.expand = true;
1863 // user defined functions
1865 public class Xcls_SignalListItemFactory30 : Object
1867 public Gtk.SignalListItemFactory el;
1868 private Editor _this;
1874 public Xcls_SignalListItemFactory30(Editor _owner )
1877 this.el = new Gtk.SignalListItemFactory();
1881 // set gobject values
1884 this.el.setup.connect( (listitem) => {
1886 var expand = new Gtk.TreeExpander();
1888 expand.set_indent_for_depth(true);
1889 expand.set_indent_for_icon(true);
1890 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
1891 var icon = new Gtk.Image();
1892 var lbl = new Gtk.Label("");
1893 lbl.use_markup = true;
1894 lbl.ellipsize = Pango.EllipsizeMode.END;
1896 icon.margin_end = 4;
1897 lbl.justify = Gtk.Justification.LEFT;
1900 // listitem.activatable = true; ??
1904 expand.set_child(hbox);
1905 ((Gtk.ListItem)listitem).set_child(expand);
1908 this.el.bind.connect( (listitem) => {
1909 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
1911 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1912 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1915 var hbox = (Gtk.Box) expand.child;
1918 var img = (Gtk.Image) hbox.get_first_child();
1919 var lbl = (Gtk.Label) img.get_next_sibling();
1921 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
1922 var sym = (Lsp.DocumentSymbol) lr.get_item();
1924 GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
1926 expand.set_hide_expander( sym.children.get_n_items() < 1);
1927 expand.set_list_row(lr);
1929 sym.bind_property("symbol_icon",
1931 GLib.BindingFlags.SYNC_CREATE);
1933 hbox.add_css_class(sym.symbol_icon);
1935 sym.bind_property("name",
1937 GLib.BindingFlags.SYNC_CREATE);
1938 // should be better?- --line no?
1939 sym.bind_property("tooltip",
1940 lbl, "tooltip_markup",
1941 GLib.BindingFlags.SYNC_CREATE);
1947 // user defined functions
1951 public class Xcls_navigationselmodel : Object
1953 public Gtk.NoSelection el;
1954 private Editor _this;
1960 public Xcls_navigationselmodel(Editor _owner )
1963 _this.navigationselmodel = this;
1964 var child_1 = new Xcls_SortListModel60( _this );
1966 this.el = new Gtk.NoSelection( child_1.el );
1970 // set gobject values
1973 // user defined functions
1974 public Lsp.DocumentSymbol? getSymoblAt (uint row) {
1976 var tr = (Gtk.TreeListRow)this.el.get_item(row);
1978 var a = tr.get_item();;
1979 GLib.debug("get_item (2) = %s", a.get_type().name());
1982 return (Lsp.DocumentSymbol)tr.get_item();
1986 public class Xcls_SortListModel60 : Object
1988 public Gtk.SortListModel el;
1989 private Editor _this;
1995 public Xcls_SortListModel60(Editor _owner )
1998 var child_1 = new Xcls_TreeListModel171( _this );
2000 var child_2 = new Xcls_TreeListRowSorter209( _this );
2002 this.el = new Gtk.SortListModel( child_1.el, child_2.el );
2006 // set gobject values
2009 // user defined functions
2011 public class Xcls_TreeListModel171 : Object
2013 public Gtk.TreeListModel el;
2014 private Editor _this;
2020 public Xcls_TreeListModel171(Editor _owner )
2023 new Xcls_navliststore( _this );
2024 this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
2026 return ((Lsp.DocumentSymbol)item).children;
2032 // set gobject values
2035 // user defined functions
2037 public class Xcls_navliststore : Object
2039 public GLib.ListStore el;
2040 private Editor _this;
2046 public Xcls_navliststore(Editor _owner )
2049 _this.navliststore = this;
2050 this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
2054 // set gobject values
2057 // user defined functions
2061 public class Xcls_TreeListRowSorter209 : Object
2063 public Gtk.TreeListRowSorter el;
2064 private Editor _this;
2070 public Xcls_TreeListRowSorter209(Editor _owner )
2073 var child_1 = new Xcls_StringSorter217( _this );
2075 this.el = new Gtk.TreeListRowSorter( child_1.el );
2079 // set gobject values
2082 // user defined functions
2084 public class Xcls_StringSorter217 : Object
2086 public Gtk.StringSorter el;
2087 private Editor _this;
2093 public Xcls_StringSorter217(Editor _owner )
2096 var child_1 = new Xcls_PropertyExpression224( _this );
2098 this.el = new Gtk.StringSorter( child_1.el );
2102 // set gobject values
2105 // user defined functions
2107 public class Xcls_PropertyExpression224 : Object
2109 public Gtk.PropertyExpression el;
2110 private Editor _this;
2116 public Xcls_PropertyExpression224(Editor _owner )
2119 this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
2123 // set gobject values
2126 // user defined functions
2133 public class Xcls_GestureClick34 : Object
2135 public Gtk.GestureClick el;
2136 private Editor _this;
2142 public Xcls_GestureClick34(Editor _owner )
2145 this.el = new Gtk.GestureClick();
2149 // set gobject values
2152 this.el.pressed.connect( (n_press, x, y) => {
2154 var row = _this.navigation.getRowAt(x,y, out pos );
2156 GLib.debug("no row selected items");
2159 //Lsp.DocumentSymbol
2160 var sym = _this.navigationselmodel.getSymoblAt(row);
2176 _this.scroll_to_line((int)sym.range.start.line);
2181 // user defined functions