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_navigation navigation;
32 public int pos_root_x;
33 public Xcls_MainWindow window;
35 public int pos_root_y;
37 public int last_error_counter;
38 public GtkSource.SearchContext searchcontext;
39 public int last_search_end;
40 public signal void save ();
41 public JsRender.JsRender? file;
42 public JsRender.Node node;
43 public JsRender.NodeProp? prop;
44 public string activeEditor;
50 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
56 this.last_error_counter = 0;
57 this.searchcontext = null;
58 this.last_search_end = 0;
62 this.activeEditor = "\"\"";
65 this.el.homogeneous = false;
66 this.el.hexpand = true;
67 this.el.vexpand = true;
68 var child_1 = new Xcls_Paned1( _this );
70 this.el.append( child_1.el );
73 // user defined functions
74 public bool saveContents () {
77 if (_this.file == null) {
83 var str = _this.buffer.toString();
85 _this.buffer.checkSyntax();
89 // LeftPanel.model.changed( str , false);
91 _this.save_button.el.sensitive = false;
93 // find the text for the node..
94 if (_this.file.xtype != "PlainFile") {
95 // in theory these properties have to exist!?!
97 //this.window.windowstate.left_props.reload();
99 _this.file.setSource( str );
108 public void forwardSearch (bool change_focus) {
110 if (this.searchcontext == null) {
114 Gtk.TextIter beg, st,en;
115 bool has_wrapped_around;
116 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
117 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
119 this.last_search_end = 0; // not sure if this should happen
121 if (has_wrapped_around) {
125 this.last_search_end = en.get_offset();
127 this.view.el.grab_focus();
129 this.buffer.el.place_cursor(st);
130 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
134 public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
139 if (file.xtype != "PlainFile") {
143 // find the text for the node..
144 this.view.load( prop.val );
145 this.updateErrorMarks();
149 this.close_btn.el.show();
152 this.view.load( file.toSource() );
153 this.updateErrorMarks();
154 this.close_btn.el.hide();
155 var ls = file.getLanguageServer();
156 ls.documentSymbols.begin(file, (a,o) => {
157 _this.navigation.show(ls.documentSymbols.end(o));
164 public void backSearch (bool change_focus) {
166 if (this.searchcontext == null) {
170 Gtk.TextIter beg, st,en;
171 bool has_wrapped_around;
172 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
174 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
175 this.last_search_end = 0;
177 this.last_search_end = en.get_offset();
179 this.view.el.grab_focus();
181 this.buffer.el.place_cursor(st);
182 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
186 public string tempFileContents () {
189 if (_this.file == null) {
192 var str= this.buffer.toString();
193 if (_this.file.xtype == "PlainFile") {
201 GLib.debug("calling validate");
202 // clear the buttons.
203 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
204 return this.file.toSource(); ;
207 var oldcode = _this.prop.val;
208 _this.prop.val = str;
209 var ret = _this.file.toSource();
210 _this.prop.val = oldcode;
214 public void reset () {
219 this.searchcontext = null;
222 public int search (string in_txt) {
224 var s = new GtkSource.SearchSettings();
225 s.case_sensitive = _this.case_sensitive.el.active;
226 s.regex_enabled = _this.regex.el.active;
227 s.wrap_around = false;
229 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
230 this.searchcontext.set_highlight(true);
233 if (_this.multiline.el.active) {
234 txt = in_txt.replace("\\n", "\n");
237 s.set_search_text(txt);
238 Gtk.TextIter beg, st,en;
240 this.buffer.el.get_start_iter(out beg);
241 bool has_wrapped_around;
242 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
243 this.last_search_end = 0;
245 return this.searchcontext.get_occurrences_count();
251 public void updateErrorMarks () {
255 var buf = _this.buffer.el;
258 buf.get_bounds (out start, out end);
263 //GLib.debug("highlight errors");
265 // we should highlight other types of errors..
267 if (_this.window.windowstate.state != WindowState.State.CODEONLY
269 _this.window.windowstate.state != WindowState.State.CODE
271 //GLib.debug("windowstate != CODEONLY?");
277 if (_this.file == null) {
278 GLib.debug("file is null?");
282 var ar = this.file.getErrors();
284 buf.remove_source_marks (start, end, "ERR");
285 buf.remove_source_marks (start, end, "WARN");
286 buf.remove_source_marks (start, end, "DEPR");
287 buf.remove_tag_by_name ("ERR", start, end);
288 buf.remove_tag_by_name ("WARN", start, end);
289 buf.remove_tag_by_name ("DEPR", start, end);
290 this.last_error_counter = file.error_counter ;
291 //GLib.debug("highlight %s : %s has no errors", this.file.relpath, category);
296 // basicaly check if there is no change, then we do not do any update..
297 // we can do this by just using an error counter?
298 // if that's changed then we will do an update, otherwise dont bother.
304 var tlines = buf.get_line_count () +1;
306 if (_this.prop != null) {
307 // this still seems flaky...
309 tlines = _this.prop.end_line;
310 offset = _this.prop.start_line;
311 hoffset = _this.node.node_pad.length + 2; //shift it left by 2 ? ..
316 if (this.last_error_counter == file.error_counter) {
322 buf.remove_source_marks (start, end, "ERR");
323 buf.remove_source_marks (start, end, "WARN");
324 buf.remove_source_marks (start, end, "DEPR");
325 buf.remove_tag_by_name ("ERR", start, end);
326 buf.remove_tag_by_name ("WARN", start, end);
327 buf.remove_tag_by_name ("DEPR", start, end);
329 foreach(var diag in ar) {
331 // print("get inter\n");
332 var eline = (int)diag.range.start.line - offset;
333 var eline_to = (int)diag.range.end.line - offset;
334 //var eline = diag.range.end_line - offset;
335 //GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
336 // err.line ,eline, offset);
339 if (eline > tlines || eline < 0) {
343 buf.get_iter_at_line( out iter, eline);
344 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
345 buf.create_source_mark( msg, diag.category, iter);
347 var spos = (int)diag.range.start.character - hoffset;
348 if (spos < 0) { spos =0 ; }
349 if (spos > iter.get_chars_in_line()) {
350 spos = iter.get_chars_in_line();
352 buf.get_iter_at_line( out iter, eline_to);
353 var epos = (int)diag.range.end.character - hoffset;
354 if (epos < 0) { epos =0 ; }
355 if (epos > iter.get_chars_in_line()) {
356 epos = iter.get_chars_in_line();
360 buf.get_iter_at_line_offset( out start, eline, spos);
362 buf.get_iter_at_line_offset( out end, eline_to,epos);
364 buf.apply_tag_by_name(diag.category, start, end);
366 // GLib.debug("set line %d to %s", eline, msg);
367 //this.marks.set(eline, msg);
369 this.last_error_counter = file.error_counter ;
376 public void scroll_to_line (int line) {
378 GLib.Timeout.add(500, () => {
380 var buf = this.view.el.get_buffer();
382 var sbuf = (GtkSource.Buffer) buf;
386 sbuf.get_iter_at_line(out iter, line);
387 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
391 public class Xcls_Paned1 : Object
394 private Editor _this;
400 public Xcls_Paned1(Editor _owner )
403 this.el = new Gtk.Paned( Gtk.Orientation.HORIZONTAL );
407 // set gobject values
408 var child_1 = new Xcls_Box2( _this );
410 this.el.start_child = child_1.el;
411 var child_2 = new Xcls_ScrolledWindow27( _this );
413 this.el.end_child = child_2.el;
416 // user defined functions
418 public class Xcls_Box2 : Object
421 private Editor _this;
427 public Xcls_Box2(Editor _owner )
430 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
434 // set gobject values
435 var child_1 = new Xcls_Box3( _this );
437 this.el.append( child_1.el );
438 new Xcls_RightEditor( _this );
439 this.el.append( _this.RightEditor.el );
440 var child_3 = new Xcls_Box15( _this );
442 this.el.append ( child_3.el );
445 // user defined functions
447 public class Xcls_Box3 : Object
450 private Editor _this;
456 public Xcls_Box3(Editor _owner )
459 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
463 // set gobject values
464 this.el.homogeneous = false;
465 this.el.hexpand = true;
466 new Xcls_save_button( _this );
467 this.el.append( _this.save_button.el );
468 var child_2 = new Xcls_Label5( _this );
470 this.el.append( child_2.el );
471 var child_3 = new Xcls_Scale6( _this );
473 this.el.append( child_3.el );
474 new Xcls_close_btn( _this );
475 this.el.append( _this.close_btn.el );
478 // user defined functions
480 public class Xcls_save_button : Object
482 public Gtk.Button el;
483 private Editor _this;
489 public Xcls_save_button(Editor _owner )
492 _this.save_button = this;
493 this.el = new Gtk.Button();
497 // set gobject values
498 this.el.label = "Save";
501 this.el.clicked.connect( () => {
502 _this.saveContents();
506 // user defined functions
509 public class Xcls_Label5 : Object
512 private Editor _this;
518 public Xcls_Label5(Editor _owner )
521 this.el = new Gtk.Label( null );
525 // set gobject values
526 this.el.hexpand = true;
529 // user defined functions
532 public class Xcls_Scale6 : Object
535 private Editor _this;
541 public Xcls_Scale6(Editor _owner )
544 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
548 // set gobject values
549 this.el.width_request = 200;
550 this.el.has_origin = true;
551 this.el.draw_value = false;
553 this.el.sensitive = true;
558 //this.el.set_range(6,30);
559 this.el.set_value ( BuilderApplication.settings.editor_font_size);
560 BuilderApplication.settings.editor_font_size_updated.connect(
562 BuilderApplication.settings.editor_font_size_inchange = true;
563 // GLib.debug("update range");
564 this.el.set_value (BuilderApplication.settings.editor_font_size);
565 BuilderApplication.settings.editor_font_size_inchange = false;
573 this.el.change_value.connect( (st, val ) => {
574 if (BuilderApplication.settings.editor_font_size_inchange) {
577 BuilderApplication.settings.editor_font_size = val;
582 // user defined functions
585 public class Xcls_close_btn : Object
587 public Gtk.Button el;
588 private Editor _this;
594 public Xcls_close_btn(Editor _owner )
597 _this.close_btn = this;
598 this.el = new Gtk.Button();
602 // set gobject values
603 this.el.icon_name = "window-close";
604 var child_1 = new Xcls_Image8( _this );
606 this.el.child = child_1.el;
609 this.el.clicked.connect( () => {
610 _this.saveContents();
611 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
615 // user defined functions
617 public class Xcls_Image8 : Object
620 private Editor _this;
626 public Xcls_Image8(Editor _owner )
629 this.el = new Gtk.Image();
633 // set gobject values
634 this.el.icon_name = "window-close";
635 this.el.icon_size = Gtk.IconSize.NORMAL;
638 // user defined functions
643 public class Xcls_RightEditor : Object
645 public Gtk.ScrolledWindow el;
646 private Editor _this;
652 public Xcls_RightEditor(Editor _owner )
655 _this.RightEditor = this;
656 this.el = new Gtk.ScrolledWindow();
660 // set gobject values
661 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
662 this.el.vexpand = true;
663 this.el.overlay_scrolling = false;
664 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
665 new Xcls_view( _this );
666 this.el.child = _this.view.el;
669 // user defined functions
671 public class Xcls_view : Object
673 public GtkSource.View el;
674 private Editor _this;
678 public Gtk.CssProvider css;
681 public Xcls_view(Editor _owner )
685 this.el = new GtkSource.View();
690 // set gobject values
691 this.el.auto_indent = true;
692 this.el.indent_width = 4;
693 this.el.name = "editor-view";
694 this.el.show_line_marks = true;
695 this.el.insert_spaces_instead_of_tabs = true;
696 this.el.show_line_numbers = true;
697 this.el.hexpand = true;
698 this.el.vexpand = true;
699 this.el.has_tooltip = true;
700 this.el.css_classes = { "code-editor" };
701 this.el.tab_width = 4;
702 this.el.highlight_current_line = true;
703 new Xcls_buffer( _this );
704 this.el.buffer = _this.buffer.el;
705 new Xcls_keystate( _this );
706 this.el.add_controller( _this.keystate.el );
707 var child_3 = new Xcls_EventControllerScroll13( _this );
709 this.el.add_controller( child_3.el );
710 var child_4 = new Xcls_GestureClick14( _this );
712 this.el.add_controller( child_4.el );
716 this.el.completion.add_provider(
717 new Palete.CompletionProvider(_this)
720 // hover seems pretty useless.. - ??
721 //var hover = this.el.get_hover();
722 //hover.add_provider(new Palete.HoverProvider(_this));
724 //this.el.completion.unblock_interactive();
725 this.el.completion.select_on_show = true; // select
726 //this.el.completion.remember_info_visibility = true;
729 var attrs = new GtkSource.MarkAttributes();
731 attrs.set_icon_name ( "process-stop");
732 attrs.query_tooltip_text.connect(( mark) => {
733 GLib.debug("tooltip query? %s", mark.name);
734 return strdup( mark.name);
736 attrs.query_tooltip_markup.connect(( mark) => {
737 GLib.debug("tooltip query? %s", mark.name);
738 return strdup( mark.name);
740 this.el.set_mark_attributes ("ERR", attrs, 1);
744 var wattrs = new GtkSource.MarkAttributes();
745 wattrs.set_icon_name ( "process-stop");
746 wattrs.query_tooltip_text.connect(( mark) => {
747 GLib.debug("tooltip query? %s", mark.name);
748 return strdup(mark.name);
750 wattrs.query_tooltip_markup.connect(( mark) => {
751 GLib.debug("tooltip query? %s", mark.name);
752 return strdup(mark.name);
754 this.el.set_mark_attributes ("WARN", wattrs, 1);
758 var dattrs = new GtkSource.MarkAttributes();
760 dattrs.set_icon_name ( "process-stop");
762 dattrs.query_tooltip_text.connect(( mark) => {
763 GLib.debug("tooltip query? %s", mark.name);
764 return strdup(mark.name);
766 //dattrs.query_tooltip_markup.connect(( mark) => {
767 // GLib.debug("tooltip query? %s", mark.name);
768 // return strdup(mark.name);
770 this.el.set_mark_attributes ("DEPR", dattrs, 1);
773 this.el.get_space_drawer().set_matrix(null);
774 this.el.get_space_drawer().set_types_for_locations(
775 GtkSource.SpaceLocationFlags.ALL,
776 GtkSource.SpaceTypeFlags.ALL
778 this.el.get_space_drawer().set_enable_matrix(true);
781 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
783 //GLib.debug("query tooltip");
787 var yoff = (int) _this.RightEditor.el.vadjustment.value;
789 // I think this is problematic - if it's compliing / updating at same time as query.
791 //if (_this.window.statusbar_compile_spinner.el.spinning) {
795 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
797 var l = iter.get_line();
801 // GLib.debug("query tooltip line %d", (int) l);
807 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
808 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
809 tooltip.set_text(_this.buffer.marks.get(l).dup());
817 // this crashes?? - not sure why.
818 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
819 if (marks.is_empty()) {
820 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
822 if (marks.is_empty()) {
823 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
826 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
828 marks.@foreach((m) => {
829 //GLib.debug("got mark %s", m.name);
830 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
832 // true if there is a mark..
833 if (str.length > 0 ) {
834 tooltip.set_text( str );
836 return str.length > 0 ? true : false;
841 // user defined functions
842 public void load (string str) {
844 // show the help page for the active node..
845 //this.get('/Help').show();
847 // this.get('/BottomPane').el.set_current_page(0);
848 GLib.debug("load called - Reset undo buffer");
850 var buf = (GtkSource.Buffer)this.el.get_buffer();
851 buf.begin_irreversible_action();
852 buf.set_text(str, str.length);
853 buf.end_irreversible_action();
855 var lm = GtkSource.LanguageManager.get_default();
857 if (_this.file != null) {
858 lang = _this.file.language;
860 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
861 var lg = _this.file.content_type.length > 0 ?
862 lm.guess_language(_this.file.path, _this.file.content_type) :
863 lm.get_language(lang);
866 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
868 this.el.insert_spaces_instead_of_tabs = true;
870 print("sourcelanguage = %s\n", lg.name);
871 if (lg.name == "Vala") {
872 this.el.insert_spaces_instead_of_tabs = false;
876 this.el.grab_focus();
877 _this.save_button.el.sensitive = false;
878 _this.last_error_counter = -1;
881 public class Xcls_buffer : Object
883 public GtkSource.Buffer el;
884 private Editor _this;
888 public int error_line;
889 public Gee.HashMap<int,string>? xmarks;
890 public bool check_queued;
893 public Xcls_buffer(Editor _owner )
897 this.el = new GtkSource.Buffer( null );
900 this.error_line = -1;
902 this.check_queued = false;
904 // set gobject values
905 this.el.highlight_syntax = true;
906 this.el.highlight_matching_brackets = true;
907 this.el.enable_undo = true;
912 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
913 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
914 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
915 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
916 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
917 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
918 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
919 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
922 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
923 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
924 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
927 this.el.changed.connect( () => {
930 _this.save_button.el.sensitive = true;
931 print("EDITOR CHANGED");
936 // this.get('/LeftPanel.model').changed( str , false);
941 // user defined functions
942 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
945 this.el.get_bounds (out start, out end);
947 this.el.remove_source_marks (start, end, type);
948 GLib.debug("highlight errors");
950 // we should highlight other types of errors..
952 if (!obj.has_member(type)) {
953 GLib.debug("Return has no errors\n");
957 if (_this.window.windowstate.state != WindowState.State.CODEONLY
959 _this.window.windowstate.state != WindowState.State.CODE
961 GLib.debug("windowstate != CODEONLY?");
966 //this.marks = new Gee.HashMap<int,string>();
967 var err = obj.get_object_member(type);
969 if (_this.file == null) {
970 GLib.debug("file is null?");
974 var valafn = _this.file.path;
976 if (_this.file.xtype != "PlainFile") {
980 var regex = new Regex("\\.bjs$");
982 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
983 } catch (GLib.RegexError e) {
990 if (!err.has_member(valafn)) {
991 GLib.debug("File path has no errors");
995 var lines = err.get_object_member(valafn);
998 if (obj.has_member("line_offset")) { // ?? why??
999 offset = (int)obj.get_int_member("line_offset") + 1;
1003 var tlines = this.el.get_line_count () +1;
1005 if (_this.prop != null) {
1007 tlines = _this.prop.end_line + 1;
1008 offset = _this.prop.start_line + 1;
1014 lines.foreach_member((obj, line, node) => {
1017 // print("get inter\n");
1018 var eline = int.parse(line) - offset;
1019 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
1022 if (eline > tlines || eline < 0) {
1027 this.el.get_iter_at_line( out iter, eline);
1028 //print("mark line\n");
1030 var ar = lines.get_array_member(line);
1031 for (var i = 0 ; i < ar.get_length(); i++) {
1032 if (ar.get_string_element(i) == "Success") {
1035 msg += (msg.length > 0) ? "\n" : "";
1036 msg += ar.get_string_element(i);
1041 msg = "Line: %d".printf(eline+1) + " " + msg;
1042 this.el.create_source_mark(msg, type, iter);
1043 GLib.debug("set line %d to %m", eline, msg);
1044 // this.marks.set(eline, msg);
1053 public bool checkSyntax () {
1056 var str = this.toString();
1059 if (this.error_line > 0) {
1062 this.el.get_bounds (out start, out end);
1064 this.el.remove_source_marks (start, end, null);
1066 if (str.length < 1) {
1067 print("checkSyntax - empty string?\n");
1072 if (_this.file.xtype == "PlainFile") {
1074 // assume it's gtk...
1075 var oldcode =_this.file.toSource();
1076 _this.file.setSource(str);
1077 BuilderApplication.showSpinner("appointment soon","document change pending");
1078 _this.file.getLanguageServer().document_change(_this.file);
1080 _this.file.setSource(oldcode);
1086 if (_this.file == null) {
1094 GLib.debug("calling validate");
1095 // clear the buttons.
1096 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1099 var oldcode = _this.prop.val;
1101 _this.prop.val = str;
1102 _this.node.updated_count++;
1103 _this.file.getLanguageServer().document_change(_this.file);
1104 _this.node.updated_count++;
1105 _this.prop.val = oldcode;
1108 //print("done mark line\n");
1110 return true; // at present allow saving - even if it's invalid..
1112 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1114 this.error_line = validate_res.size;
1116 if (this.error_line < 1) {
1119 var tlines = this.el.get_line_count ();
1121 var valiter = validate_res.map_iterator();
1122 while (valiter.next()) {
1124 // print("get inter\n");
1125 var eline = valiter.get_key();
1126 if (eline > tlines) {
1129 this.el.get_iter_at_line( out iter, eline);
1130 //print("mark line\n");
1131 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1135 public string toString () {
1139 this.el.get_start_iter(out s);
1140 this.el.get_end_iter(out e);
1141 var ret = this.el.get_text(s,e,true);
1142 //print("TO STRING? " + ret);
1147 public class Xcls_keystate : Object
1149 public Gtk.EventControllerKey el;
1150 private Editor _this;
1154 public bool is_control;
1157 public Xcls_keystate(Editor _owner )
1160 _this.keystate = this;
1161 this.el = new Gtk.EventControllerKey();
1164 this.is_control = false;
1166 // set gobject values
1169 this.el.key_released.connect( (keyval, keycode, state) => {
1171 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1172 this.is_control = false;
1174 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1175 GLib.debug("SAVE: ctrl-S pressed");
1176 _this.saveContents();
1180 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1181 GLib.debug("SAVE: ctrl-g pressed");
1182 _this.forwardSearch(true);
1185 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1186 GLib.debug("SAVE: ctrl-f pressed");
1187 _this.search_entry.el.grab_focus();
1188 _this.search_entry.el.select_region(0,-1);
1191 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1192 _this.view.el.show_completion();
1196 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1197 var line = iter.get_line();
1198 var offset = iter.get_line_offset();
1199 GLib.debug("line %d off %d", line ,offset);
1200 if (_this.prop != null) {
1201 line += _this.prop.start_line + 1; // i think..
1202 offset += 12; // should probably be 8 without namespaced
1203 GLib.debug("guess line %d off %d", line ,offset);
1205 //_this.view.el.show_completion();
1206 // print(event.key.keyval)
1215 this.el.key_pressed.connect( (keyval, keycode, state) => {
1217 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1218 this.is_control = true;
1224 // user defined functions
1227 public class Xcls_EventControllerScroll13 : Object
1229 public Gtk.EventControllerScroll el;
1230 private Editor _this;
1234 public double distance;
1237 public Xcls_EventControllerScroll13(Editor _owner )
1240 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1243 this.distance = 0.0f;
1245 // set gobject values
1248 this.el.scroll.connect( (dx, dy) => {
1249 if (!_this.keystate.is_control) {
1252 //GLib.debug("scroll %f", dy);
1254 this.distance += dy;
1256 //GLib.debug("scroll %f / %f", dy, this.distance);
1258 if (this.distance < -1) {
1260 BuilderApplication.settings.editor_font_size ++;
1263 if (this.distance > 1) {
1264 BuilderApplication.settings.editor_font_size --;
1272 // user defined functions
1275 public class Xcls_GestureClick14 : Object
1277 public Gtk.GestureClick el;
1278 private Editor _this;
1284 public Xcls_GestureClick14(Editor _owner )
1287 this.el = new Gtk.GestureClick();
1291 // set gobject values
1294 // user defined functions
1299 public class Xcls_Box15 : Object
1302 private Editor _this;
1308 public Xcls_Box15(Editor _owner )
1311 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1315 // set gobject values
1316 this.el.homogeneous = false;
1317 this.el.vexpand = false;
1318 new Xcls_search_entry( _this );
1319 this.el.append( _this.search_entry.el );
1320 new Xcls_search_results( _this );
1321 this.el.append( _this.search_results.el );
1322 new Xcls_nextBtn( _this );
1323 this.el.append( _this.nextBtn.el );
1324 new Xcls_backBtn( _this );
1325 this.el.append( _this.backBtn.el );
1326 var child_5 = new Xcls_MenuButton21( _this );
1328 this.el.append( child_5.el );
1331 // user defined functions
1333 public class Xcls_search_entry : Object
1335 public Gtk.SearchEntry el;
1336 private Editor _this;
1340 public Gtk.CssProvider css;
1343 public Xcls_search_entry(Editor _owner )
1346 _this.search_entry = this;
1347 this.el = new Gtk.SearchEntry();
1351 // set gobject values
1352 this.el.name = "editor-search-entry";
1353 this.el.hexpand = true;
1354 this.el.placeholder_text = "Press enter to search";
1355 this.el.search_delay = 3;
1356 var child_1 = new Xcls_EventControllerKey17( _this );
1358 this.el.add_controller( child_1.el );
1361 this.el.search_changed.connect( ( ) => {
1363 _this.search(_this.search_entry.el.text);
1364 _this.search_results.updateResults();
1366 GLib.Timeout.add_seconds(1,() => {
1367 _this.search_results.updateResults();
1373 // user defined functions
1374 public void forwardSearch (bool change_focus) {
1377 _this.forwardSearch(change_focus);
1381 switch(_this.windowstate.state) {
1382 case WindowState.State.CODEONLY:
1383 //case WindowState.State.CODE:
1384 // search the code being edited..
1385 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1388 case WindowState.State.PREVIEW:
1389 if (_this.windowstate.file.xtype == "Gtk") {
1390 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1392 _this.windowstate.window_rooview.forwardSearch(change_focus);
1401 public class Xcls_EventControllerKey17 : Object
1403 public Gtk.EventControllerKey el;
1404 private Editor _this;
1410 public Xcls_EventControllerKey17(Editor _owner )
1413 this.el = new Gtk.EventControllerKey();
1417 // set gobject values
1420 this.el.key_pressed.connect( (keyval, keycode, state) => {
1422 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1423 GLib.debug("SAVE: ctrl-g pressed");
1424 _this.forwardSearch(true);
1429 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1430 _this.forwardSearch(true);
1436 // print(event.key.keyval)
1442 // user defined functions
1446 public class Xcls_search_results : Object
1448 public Gtk.Label el;
1449 private Editor _this;
1455 public Xcls_search_results(Editor _owner )
1458 _this.search_results = this;
1459 this.el = new Gtk.Label( "No Results" );
1463 // set gobject values
1464 this.el.margin_end = 4;
1465 this.el.margin_start = 4;
1468 // user defined functions
1469 public void updateResults () {
1470 this.el.visible = true;
1472 var res = _this.searchcontext.get_occurrences_count();
1474 _this.search_results.el.label = "??? Matches";
1478 _this.nextBtn.el.sensitive = false;
1479 _this.backBtn.el.sensitive = false;
1482 _this.search_results.el.label = "%d Matches".printf(res);
1483 _this.nextBtn.el.sensitive = true;
1484 _this.backBtn.el.sensitive = true;
1487 _this.search_results.el.label = "No Matches";
1492 public class Xcls_nextBtn : Object
1494 public Gtk.Button el;
1495 private Editor _this;
1499 public bool always_show_image;
1502 public Xcls_nextBtn(Editor _owner )
1505 _this.nextBtn = this;
1506 this.el = new Gtk.Button();
1509 this.always_show_image = true;
1511 // set gobject values
1512 this.el.icon_name = "go-down";
1513 this.el.sensitive = false;
1516 this.el.clicked.connect( (event) => {
1518 _this.forwardSearch(true);
1524 // user defined functions
1527 public class Xcls_backBtn : Object
1529 public Gtk.Button el;
1530 private Editor _this;
1534 public bool always_show_image;
1537 public Xcls_backBtn(Editor _owner )
1540 _this.backBtn = this;
1541 this.el = new Gtk.Button();
1544 this.always_show_image = true;
1546 // set gobject values
1547 this.el.icon_name = "go-up";
1548 this.el.sensitive = false;
1551 this.el.clicked.connect( (event) => {
1553 _this.backSearch(true);
1558 // user defined functions
1561 public class Xcls_MenuButton21 : Object
1563 public Gtk.MenuButton el;
1564 private Editor _this;
1568 public bool always_show_image;
1571 public Xcls_MenuButton21(Editor _owner )
1574 this.el = new Gtk.MenuButton();
1577 this.always_show_image = true;
1579 // set gobject values
1580 this.el.icon_name = "emblem-system";
1581 this.el.always_show_arrow = true;
1582 new Xcls_search_settings( _this );
1583 this.el.popover = _this.search_settings.el;
1586 // user defined functions
1588 public class Xcls_search_settings : Object
1590 public Gtk.Popover el;
1591 private Editor _this;
1597 public Xcls_search_settings(Editor _owner )
1600 _this.search_settings = this;
1601 this.el = new Gtk.Popover();
1605 // set gobject values
1606 var child_1 = new Xcls_Box23( _this );
1608 this.el.child = child_1.el;
1611 // user defined functions
1613 public class Xcls_Box23 : Object
1616 private Editor _this;
1622 public Xcls_Box23(Editor _owner )
1625 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1629 // set gobject values
1630 new Xcls_case_sensitive( _this );
1631 this.el.append( _this.case_sensitive.el );
1632 new Xcls_regex( _this );
1633 this.el.append( _this.regex.el );
1634 new Xcls_multiline( _this );
1635 this.el.append( _this.multiline.el );
1638 // user defined functions
1640 public class Xcls_case_sensitive : Object
1642 public Gtk.CheckButton el;
1643 private Editor _this;
1649 public Xcls_case_sensitive(Editor _owner )
1652 _this.case_sensitive = this;
1653 this.el = new Gtk.CheckButton();
1657 // set gobject values
1658 this.el.label = "Case Sensitive";
1667 // user defined functions
1670 public class Xcls_regex : Object
1672 public Gtk.CheckButton el;
1673 private Editor _this;
1679 public Xcls_regex(Editor _owner )
1683 this.el = new Gtk.CheckButton();
1687 // set gobject values
1688 this.el.label = "Regex";
1697 // user defined functions
1700 public class Xcls_multiline : Object
1702 public Gtk.CheckButton el;
1703 private Editor _this;
1709 public Xcls_multiline(Editor _owner )
1712 _this.multiline = this;
1713 this.el = new Gtk.CheckButton();
1717 // set gobject values
1718 this.el.label = "Multi-line (add \\n)";
1721 // user defined functions
1729 public class Xcls_ScrolledWindow27 : Object
1731 public Gtk.ScrolledWindow el;
1732 private Editor _this;
1738 public Xcls_ScrolledWindow27(Editor _owner )
1741 this.el = new Gtk.ScrolledWindow();
1745 // set gobject values
1746 this.el.visible = false;
1747 new Xcls_navigation( _this );
1748 this.el.child = _this.navigation.el;
1751 // user defined functions
1753 public class Xcls_navigation : Object
1755 public Gtk.ColumnView el;
1756 private Editor _this;
1762 public Xcls_navigation(Editor _owner )
1765 _this.navigation = this;
1766 var child_1 = new Xcls_SingleSelection31( _this );
1768 this.el = new Gtk.ColumnView( child_1.el );
1772 // set gobject values
1773 var child_2 = new Xcls_ColumnViewColumn29( _this );
1775 this.el.append_column( child_2.el );
1778 // user defined functions
1780 public class Xcls_ColumnViewColumn29 : Object
1782 public Gtk.ColumnViewColumn el;
1783 private Editor _this;
1789 public Xcls_ColumnViewColumn29(Editor _owner )
1792 var child_1 = new Xcls_SignalListItemFactory30( _this );
1794 this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
1798 // set gobject values
1799 this.el.expand = true;
1802 // user defined functions
1804 public class Xcls_SignalListItemFactory30 : Object
1806 public Gtk.SignalListItemFactory el;
1807 private Editor _this;
1813 public Xcls_SignalListItemFactory30(Editor _owner )
1816 this.el = new Gtk.SignalListItemFactory();
1820 // set gobject values
1823 this.el.setup.connect( (listitem) => {
1825 var expand = new Gtk.TreeExpander();
1827 expand.set_indent_for_depth(true);
1828 expand.set_indent_for_icon(true);
1829 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
1830 var icon = new Gtk.Image();
1831 var lbl = new Gtk.Label("");
1832 lbl.use_markup = true;
1833 lbl.ellipsize = Pango.EllipsizeMode.END;
1835 icon.margin_end = 4;
1836 lbl.justify = Gtk.Justification.LEFT;
1839 // listitem.activatable = true; ??
1843 expand.set_child(hbox);
1844 ((Gtk.ListItem)listitem).set_child(expand);
1847 this.el.bind.connect( (listitem) => {
1848 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
1850 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1851 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1854 var hbox = (Gtk.Box) expand.child;
1857 var img = (Gtk.Image) hbox.get_first_child();
1858 var lbl = (Gtk.Label) img.get_next_sibling();
1860 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
1861 var node = (JsRender.Node) lr.get_item();
1862 if (node == null || node.fqn() == "") {
1866 expand.set_hide_expander( !node.hasChildren() );
1867 expand.set_list_row(lr);
1869 node.bind_property("iconResourceName",
1871 GLib.BindingFlags.SYNC_CREATE);
1873 node.bind_property("nodeTitleProp",
1875 GLib.BindingFlags.SYNC_CREATE);
1876 node.bind_property("nodeTipProp",
1877 lbl, "tooltip_markup",
1878 GLib.BindingFlags.SYNC_CREATE);
1884 // user defined functions
1888 public class Xcls_SingleSelection31 : Object
1890 public Gtk.SingleSelection el;
1891 private Editor _this;
1897 public Xcls_SingleSelection31(Editor _owner )
1900 var child_1 = new Xcls_TreeListModel32( _this );
1902 this.el = new Gtk.SingleSelection( child_1.el );
1906 // set gobject values
1909 // user defined functions
1911 public class Xcls_TreeListModel32 : Object
1913 public Gtk.TreeListModel el;
1914 private Editor _this;
1920 public Xcls_TreeListModel32(Editor _owner )
1923 var child_1 = new Xcls_ListStore33( _this );
1925 this.el = new Gtk.TreeListModel( child_1.el, false, true, (item) => {
1927 return ((JsRender.Node)item).childstore;
1933 // set gobject values
1936 // user defined functions
1938 public class Xcls_ListStore33 : Object
1940 public GLib.ListStore el;
1941 private Editor _this;
1947 public Xcls_ListStore33(Editor _owner )
1950 this.el = new GLib.ListStore( typeof(JsRender.Node) );
1954 // set gobject values
1957 // user defined functions