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_search_entry search_entry;
21 public Xcls_search_results search_results;
22 public Xcls_nextBtn nextBtn;
23 public Xcls_backBtn backBtn;
24 public Xcls_search_settings search_settings;
25 public Xcls_case_sensitive case_sensitive;
26 public Xcls_regex regex;
27 public Xcls_multiline multiline;
30 public int pos_root_x;
31 public Xcls_MainWindow window;
33 public int pos_root_y;
35 public int last_error_counter;
36 public GtkSource.SearchContext searchcontext;
37 public int last_search_end;
38 public signal void save ();
39 public JsRender.JsRender? file;
40 public JsRender.Node node;
41 public JsRender.NodeProp? prop;
42 public string activeEditor;
48 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
54 this.last_error_counter = 0;
55 this.searchcontext = null;
56 this.last_search_end = 0;
60 this.activeEditor = "";
63 this.el.homogeneous = false;
64 this.el.hexpand = true;
65 this.el.vexpand = true;
66 var child_1 = new Xcls_Box1( _this );
68 this.el.append( child_1.el );
69 new Xcls_RightEditor( _this );
70 this.el.append( _this.RightEditor.el );
71 var child_3 = new Xcls_Box11( _this );
73 this.el.append ( child_3.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();
150 this.close_btn.el.show();
153 this.view.load( file.toSource() );
154 this.updateErrorMarks();
155 this.close_btn.el.hide();
160 public void backSearch (bool change_focus) {
162 if (this.searchcontext == null) {
166 Gtk.TextIter beg, st,en;
167 bool has_wrapped_around;
168 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
170 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
171 this.last_search_end = 0;
173 this.last_search_end = en.get_offset();
175 this.view.el.grab_focus();
177 this.buffer.el.place_cursor(st);
178 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
182 public string tempFileContents () {
185 if (_this.file == null) {
188 var str= this.buffer.toString();
189 if (_this.file.xtype == "PlainFile") {
197 GLib.debug("calling validate");
198 // clear the buttons.
199 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
200 return this.file.toSource(); ;
203 var oldcode = _this.prop.val;
204 _this.prop.val = str;
205 var ret = _this.file.toSource();
206 _this.prop.val = oldcode;
210 public void reset () {
215 this.searchcontext = null;
218 public int search (string in_txt) {
220 var s = new GtkSource.SearchSettings();
221 s.case_sensitive = _this.case_sensitive.el.active;
222 s.regex_enabled = _this.regex.el.active;
223 s.wrap_around = false;
225 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
226 this.searchcontext.set_highlight(true);
229 if (_this.multiline.el.active) {
230 txt = in_txt.replace("\\n", "\n");
233 s.set_search_text(txt);
234 Gtk.TextIter beg, st,en;
236 this.buffer.el.get_start_iter(out beg);
237 bool has_wrapped_around;
238 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
239 this.last_search_end = 0;
241 return this.searchcontext.get_occurrences_count();
247 public void updateErrorMarks () {
251 var buf = _this.buffer.el;
254 buf.get_bounds (out start, out end);
259 //GLib.debug("highlight errors");
261 // we should highlight other types of errors..
263 if (_this.window.windowstate.state != WindowState.State.CODEONLY
265 _this.window.windowstate.state != WindowState.State.CODE
267 //GLib.debug("windowstate != CODEONLY?");
273 if (_this.file == null) {
274 GLib.debug("file is null?");
278 var ar = this.file.getErrors();
280 buf.remove_source_marks (start, end, "ERR");
281 buf.remove_source_marks (start, end, "WARN");
282 buf.remove_source_marks (start, end, "DEPR");
283 buf.remove_tag_by_name ("ERR", start, end);
284 buf.remove_tag_by_name ("WARN", start, end);
285 buf.remove_tag_by_name ("DEPR", start, end);
286 this.last_error_counter = file.error_counter ;
287 //GLib.debug("highlight %s : %s has no errors", this.file.relpath, category);
292 // basicaly check if there is no change, then we do not do any update..
293 // we can do this by just using an error counter?
294 // if that's changed then we will do an update, otherwise dont bother.
300 var tlines = buf.get_line_count () +1;
302 if (_this.prop != null) {
303 // this still seems flaky...
305 tlines = _this.prop.end_line;
306 offset = _this.prop.start_line;
307 hoffset = _this.node.node_pad.length + 2; //shift it left by 2 ? ..
312 if (this.last_error_counter == file.error_counter) {
318 buf.remove_source_marks (start, end, "ERR");
319 buf.remove_source_marks (start, end, "WARN");
320 buf.remove_source_marks (start, end, "DEPR");
321 buf.remove_tag_by_name ("ERR", start, end);
322 buf.remove_tag_by_name ("WARN", start, end);
323 buf.remove_tag_by_name ("DEPR", start, end);
325 foreach(var diag in ar) {
327 // print("get inter\n");
328 var eline = (int)diag.range.start.line - offset;
329 var eline_to = (int)diag.range.end.line - offset;
330 //var eline = diag.range.end_line - offset;
331 //GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
332 // err.line ,eline, offset);
335 if (eline > tlines || eline < 0) {
339 buf.get_iter_at_line( out iter, eline);
340 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
341 buf.create_source_mark( msg, diag.category, iter);
343 var spos = (int)diag.range.start.character - hoffset;
344 if (spos < 0) { spos =0 ; }
345 if (spos > iter.get_chars_in_line()) {
346 spos = iter.get_chars_in_line();
348 buf.get_iter_at_line( out iter, eline_to);
349 var epos = (int)diag.range.end.character - hoffset;
350 if (epos < 0) { epos =0 ; }
351 if (epos > iter.get_chars_in_line()) {
352 epos = iter.get_chars_in_line();
356 buf.get_iter_at_line_offset( out start, eline, spos);
358 buf.get_iter_at_line_offset( out end, eline_to,epos);
360 buf.apply_tag_by_name(diag.category, start, end);
362 // GLib.debug("set line %d to %s", eline, msg);
363 //this.marks.set(eline, msg);
365 this.last_error_counter = file.error_counter ;
372 public void scroll_to_line (int line) {
374 GLib.Timeout.add(500, () => {
376 var buf = this.view.el.get_buffer();
378 var sbuf = (GtkSource.Buffer) buf;
382 sbuf.get_iter_at_line(out iter, line);
383 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
387 public class Xcls_Box1 : Object
390 private Editor _this;
396 public Xcls_Box1(Editor _owner )
399 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
403 // set gobject values
404 this.el.homogeneous = false;
405 this.el.hexpand = true;
406 new Xcls_save_button( _this );
407 this.el.append( _this.save_button.el );
408 var child_2 = new Xcls_Label3( _this );
410 this.el.append( child_2.el );
411 var child_3 = new Xcls_Scale4( _this );
413 this.el.append( child_3.el );
414 new Xcls_close_btn( _this );
415 this.el.append( _this.close_btn.el );
418 // user defined functions
420 public class Xcls_save_button : Object
422 public Gtk.Button el;
423 private Editor _this;
429 public Xcls_save_button(Editor _owner )
432 _this.save_button = this;
433 this.el = new Gtk.Button();
437 // set gobject values
438 this.el.label = "Save";
441 this.el.clicked.connect( () => {
442 _this.saveContents();
446 // user defined functions
449 public class Xcls_Label3 : Object
452 private Editor _this;
458 public Xcls_Label3(Editor _owner )
461 this.el = new Gtk.Label( null );
465 // set gobject values
466 this.el.hexpand = true;
469 // user defined functions
472 public class Xcls_Scale4 : Object
475 private Editor _this;
481 public Xcls_Scale4(Editor _owner )
484 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
488 // set gobject values
489 this.el.width_request = 200;
490 this.el.has_origin = true;
491 this.el.draw_value = false;
493 this.el.sensitive = true;
498 //this.el.set_range(6,30);
499 this.el.set_value ( BuilderApplication.settings.editor_font_size);
500 BuilderApplication.settings.editor_font_size_updated.connect(
502 BuilderApplication.settings.editor_font_size_inchange = true;
503 GLib.debug("update range");
504 this.el.set_value (BuilderApplication.settings.editor_font_size);
505 BuilderApplication.settings.editor_font_size_inchange = false;
513 this.el.change_value.connect( (st, val ) => {
514 if (BuilderApplication.settings.editor_font_size_inchange) {
517 BuilderApplication.settings.editor_font_size = val;
522 // user defined functions
525 public class Xcls_close_btn : Object
527 public Gtk.Button el;
528 private Editor _this;
534 public Xcls_close_btn(Editor _owner )
537 _this.close_btn = this;
538 this.el = new Gtk.Button();
542 // set gobject values
543 this.el.icon_name = "window-close";
544 var child_1 = new Xcls_Image6( _this );
546 this.el.child = child_1.el;
549 this.el.clicked.connect( () => {
550 _this.saveContents();
551 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
555 // user defined functions
557 public class Xcls_Image6 : Object
560 private Editor _this;
566 public Xcls_Image6(Editor _owner )
569 this.el = new Gtk.Image();
573 // set gobject values
574 this.el.icon_name = "window-close";
575 this.el.icon_size = Gtk.IconSize.NORMAL;
578 // user defined functions
583 public class Xcls_RightEditor : Object
585 public Gtk.ScrolledWindow el;
586 private Editor _this;
592 public Xcls_RightEditor(Editor _owner )
595 _this.RightEditor = this;
596 this.el = new Gtk.ScrolledWindow();
600 // set gobject values
601 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
602 this.el.vexpand = true;
603 this.el.overlay_scrolling = false;
604 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
605 new Xcls_view( _this );
606 this.el.child = _this.view.el;
609 // user defined functions
611 public class Xcls_view : Object
613 public GtkSource.View el;
614 private Editor _this;
618 public Gtk.CssProvider css;
621 public Xcls_view(Editor _owner )
625 this.el = new GtkSource.View();
630 // set gobject values
631 this.el.auto_indent = true;
632 this.el.indent_width = 4;
633 this.el.name = "editor-view";
634 this.el.show_line_marks = true;
635 this.el.insert_spaces_instead_of_tabs = true;
636 this.el.show_line_numbers = true;
637 this.el.hexpand = true;
638 this.el.vexpand = true;
639 this.el.has_tooltip = true;
640 this.el.css_classes = { "code-editor" };
641 this.el.tab_width = 4;
642 this.el.highlight_current_line = true;
643 new Xcls_buffer( _this );
644 this.el.buffer = _this.buffer.el;
645 var child_2 = new Xcls_EventControllerKey10( _this );
647 this.el.add_controller( child_2.el );
651 this.el.completion.add_provider(
652 new Palete.CompletionProvider(_this)
655 //this.el.completion.unblock_interactive();
656 this.el.completion.select_on_show = true; // select
657 //this.el.completion.remember_info_visibility = true;
660 var attrs = new GtkSource.MarkAttributes();
662 attrs.set_icon_name ( "process-stop");
663 attrs.query_tooltip_text.connect(( mark) => {
664 GLib.debug("tooltip query? %s", mark.name);
665 return strdup( mark.name);
667 attrs.query_tooltip_markup.connect(( mark) => {
668 GLib.debug("tooltip query? %s", mark.name);
669 return strdup( mark.name);
671 this.el.set_mark_attributes ("ERR", attrs, 1);
675 var wattrs = new GtkSource.MarkAttributes();
676 wattrs.set_icon_name ( "process-stop");
677 wattrs.query_tooltip_text.connect(( mark) => {
678 GLib.debug("tooltip query? %s", mark.name);
679 return strdup(mark.name);
681 wattrs.query_tooltip_markup.connect(( mark) => {
682 GLib.debug("tooltip query? %s", mark.name);
683 return strdup(mark.name);
685 this.el.set_mark_attributes ("WARN", wattrs, 1);
689 var dattrs = new GtkSource.MarkAttributes();
691 dattrs.set_icon_name ( "process-stop");
693 dattrs.query_tooltip_text.connect(( mark) => {
694 GLib.debug("tooltip query? %s", mark.name);
695 return strdup(mark.name);
697 //dattrs.query_tooltip_markup.connect(( mark) => {
698 // GLib.debug("tooltip query? %s", mark.name);
699 // return strdup(mark.name);
701 this.el.set_mark_attributes ("DEPR", dattrs, 1);
704 this.el.get_space_drawer().set_matrix(null);
705 this.el.get_space_drawer().set_types_for_locations(
706 GtkSource.SpaceLocationFlags.ALL,
707 GtkSource.SpaceTypeFlags.ALL
709 this.el.get_space_drawer().set_enable_matrix(true);
712 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
714 //GLib.debug("query tooltip");
718 var yoff = (int) _this.RightEditor.el.vadjustment.value;
720 // I think this is problematic - if it's compliing / updating at same time as query.
722 //if (_this.window.statusbar_compile_spinner.el.spinning) {
726 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
728 var l = iter.get_line();
732 // GLib.debug("query tooltip line %d", (int) l);
738 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
739 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
740 tooltip.set_text(_this.buffer.marks.get(l).dup());
748 // this crashes?? - not sure why.
749 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
750 if (marks.is_empty()) {
751 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
753 if (marks.is_empty()) {
754 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
757 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
759 marks.@foreach((m) => {
760 //GLib.debug("got mark %s", m.name);
761 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
763 // true if there is a mark..
764 if (str.length > 0 ) {
765 tooltip.set_text( str );
767 return str.length > 0 ? true : false;
772 // user defined functions
773 public void load (string str) {
775 // show the help page for the active node..
776 //this.get('/Help').show();
778 // this.get('/BottomPane').el.set_current_page(0);
779 GLib.debug("load called - Reset undo buffer");
781 var buf = (GtkSource.Buffer)this.el.get_buffer();
782 buf.begin_irreversible_action();
783 buf.set_text(str, str.length);
784 buf.end_irreversible_action();
786 var lm = GtkSource.LanguageManager.get_default();
788 if (_this.file != null) {
789 lang = _this.file.language;
791 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
792 var lg = _this.file.content_type.length > 0 ?
793 lm.guess_language(_this.file.path, _this.file.content_type) :
794 lm.get_language(lang);
797 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
799 this.el.insert_spaces_instead_of_tabs = true;
801 print("sourcelanguage = %s\n", lg.name);
802 if (lg.name == "Vala") {
803 this.el.insert_spaces_instead_of_tabs = false;
807 this.el.grab_focus();
808 _this.save_button.el.sensitive = false;
809 _this.last_error_counter = -1;
812 public class Xcls_buffer : Object
814 public GtkSource.Buffer el;
815 private Editor _this;
819 public int error_line;
820 public Gee.HashMap<int,string>? xmarks;
821 public bool check_queued;
824 public Xcls_buffer(Editor _owner )
828 this.el = new GtkSource.Buffer( null );
831 this.error_line = -1;
833 this.check_queued = false;
835 // set gobject values
836 this.el.highlight_syntax = true;
837 this.el.highlight_matching_brackets = true;
838 this.el.enable_undo = true;
843 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
844 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
845 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
846 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
847 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
848 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
849 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
850 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
853 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
854 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
855 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
858 this.el.changed.connect( () => {
861 _this.save_button.el.sensitive = true;
862 print("EDITOR CHANGED");
867 // this.get('/LeftPanel.model').changed( str , false);
872 // user defined functions
873 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
876 this.el.get_bounds (out start, out end);
878 this.el.remove_source_marks (start, end, type);
879 GLib.debug("highlight errors");
881 // we should highlight other types of errors..
883 if (!obj.has_member(type)) {
884 GLib.debug("Return has no errors\n");
888 if (_this.window.windowstate.state != WindowState.State.CODEONLY
890 _this.window.windowstate.state != WindowState.State.CODE
892 GLib.debug("windowstate != CODEONLY?");
897 //this.marks = new Gee.HashMap<int,string>();
898 var err = obj.get_object_member(type);
900 if (_this.file == null) {
901 GLib.debug("file is null?");
905 var valafn = _this.file.path;
907 if (_this.file.xtype != "PlainFile") {
911 var regex = new Regex("\\.bjs$");
913 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
914 } catch (GLib.RegexError e) {
921 if (!err.has_member(valafn)) {
922 GLib.debug("File path has no errors");
926 var lines = err.get_object_member(valafn);
929 if (obj.has_member("line_offset")) { // ?? why??
930 offset = (int)obj.get_int_member("line_offset") + 1;
934 var tlines = this.el.get_line_count () +1;
936 if (_this.prop != null) {
938 tlines = _this.prop.end_line + 1;
939 offset = _this.prop.start_line + 1;
945 lines.foreach_member((obj, line, node) => {
948 // print("get inter\n");
949 var eline = int.parse(line) - offset;
950 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
953 if (eline > tlines || eline < 0) {
958 this.el.get_iter_at_line( out iter, eline);
959 //print("mark line\n");
961 var ar = lines.get_array_member(line);
962 for (var i = 0 ; i < ar.get_length(); i++) {
963 if (ar.get_string_element(i) == "Success") {
966 msg += (msg.length > 0) ? "\n" : "";
967 msg += ar.get_string_element(i);
972 msg = "Line: %d".printf(eline+1) + " " + msg;
973 this.el.create_source_mark(msg, type, iter);
974 GLib.debug("set line %d to %m", eline, msg);
975 // this.marks.set(eline, msg);
984 public bool checkSyntax () {
987 var str = this.toString();
990 if (this.error_line > 0) {
993 this.el.get_bounds (out start, out end);
995 this.el.remove_source_marks (start, end, null);
997 if (str.length < 1) {
998 print("checkSyntax - empty string?\n");
1003 if (_this.file.xtype == "PlainFile") {
1005 // assume it's gtk...
1006 var oldcode =_this.file.toSource();
1007 _this.file.setSource(str);
1008 BuilderApplication.showSpinner("appointment soon","document change pending");
1009 _this.file.getLanguageServer().document_change(_this.file);
1011 _this.file.setSource(oldcode);
1017 if (_this.file == null) {
1025 GLib.debug("calling validate");
1026 // clear the buttons.
1027 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1030 var oldcode = _this.prop.val;
1032 _this.prop.val = str;
1033 _this.node.updated_count++;
1034 _this.file.getLanguageServer().document_change(_this.file);
1035 _this.node.updated_count++;
1036 _this.prop.val = oldcode;
1039 //print("done mark line\n");
1041 return true; // at present allow saving - even if it's invalid..
1043 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1045 this.error_line = validate_res.size;
1047 if (this.error_line < 1) {
1050 var tlines = this.el.get_line_count ();
1052 var valiter = validate_res.map_iterator();
1053 while (valiter.next()) {
1055 // print("get inter\n");
1056 var eline = valiter.get_key();
1057 if (eline > tlines) {
1060 this.el.get_iter_at_line( out iter, eline);
1061 //print("mark line\n");
1062 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1066 public string toString () {
1070 this.el.get_start_iter(out s);
1071 this.el.get_end_iter(out e);
1072 var ret = this.el.get_text(s,e,true);
1073 //print("TO STRING? " + ret);
1078 public class Xcls_EventControllerKey10 : Object
1080 public Gtk.EventControllerKey el;
1081 private Editor _this;
1087 public Xcls_EventControllerKey10(Editor _owner )
1090 this.el = new Gtk.EventControllerKey();
1094 // set gobject values
1097 this.el.key_released.connect( (keyval, keycode, state) => {
1100 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1101 GLib.debug("SAVE: ctrl-S pressed");
1102 _this.saveContents();
1106 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1107 GLib.debug("SAVE: ctrl-g pressed");
1108 _this.forwardSearch(true);
1111 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1112 GLib.debug("SAVE: ctrl-f pressed");
1113 _this.search_entry.el.grab_focus();
1114 _this.search_entry.el.select_region(0,-1);
1117 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1118 _this.view.el.show_completion();
1122 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1123 var line = iter.get_line();
1124 var offset = iter.get_line_offset();
1125 GLib.debug("line %d off %d", line ,offset);
1126 if (_this.prop != null) {
1127 line += _this.prop.start_line + 1; // i think..
1128 offset += 12; // should probably be 8 without namespaced
1129 GLib.debug("guess line %d off %d", line ,offset);
1131 //_this.view.el.show_completion();
1132 // print(event.key.keyval)
1143 // user defined functions
1148 public class Xcls_Box11 : Object
1151 private Editor _this;
1157 public Xcls_Box11(Editor _owner )
1160 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1164 // set gobject values
1165 this.el.homogeneous = false;
1166 this.el.vexpand = false;
1167 new Xcls_search_entry( _this );
1168 this.el.append( _this.search_entry.el );
1169 new Xcls_search_results( _this );
1170 this.el.append( _this.search_results.el );
1171 new Xcls_nextBtn( _this );
1172 this.el.append( _this.nextBtn.el );
1173 new Xcls_backBtn( _this );
1174 this.el.append( _this.backBtn.el );
1175 var child_5 = new Xcls_MenuButton17( _this );
1177 this.el.append( child_5.el );
1180 // user defined functions
1182 public class Xcls_search_entry : Object
1184 public Gtk.SearchEntry el;
1185 private Editor _this;
1189 public Gtk.CssProvider css;
1192 public Xcls_search_entry(Editor _owner )
1195 _this.search_entry = this;
1196 this.el = new Gtk.SearchEntry();
1200 // set gobject values
1201 this.el.name = "editor-search-entry";
1202 this.el.hexpand = true;
1203 this.el.placeholder_text = "Press enter to search";
1204 this.el.search_delay = 3;
1205 var child_1 = new Xcls_EventControllerKey13( _this );
1207 this.el.add_controller( child_1.el );
1210 this.el.search_changed.connect( ( ) => {
1212 _this.search(_this.search_entry.el.text);
1213 _this.search_results.updateResults();
1215 GLib.Timeout.add_seconds(1,() => {
1216 _this.search_results.updateResults();
1222 // user defined functions
1223 public void forwardSearch (bool change_focus) {
1226 _this.forwardSearch(change_focus);
1230 switch(_this.windowstate.state) {
1231 case WindowState.State.CODEONLY:
1232 //case WindowState.State.CODE:
1233 // search the code being edited..
1234 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1237 case WindowState.State.PREVIEW:
1238 if (_this.windowstate.file.xtype == "Gtk") {
1239 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1241 _this.windowstate.window_rooview.forwardSearch(change_focus);
1250 public class Xcls_EventControllerKey13 : Object
1252 public Gtk.EventControllerKey el;
1253 private Editor _this;
1259 public Xcls_EventControllerKey13(Editor _owner )
1262 this.el = new Gtk.EventControllerKey();
1266 // set gobject values
1269 this.el.key_pressed.connect( (keyval, keycode, state) => {
1271 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1272 GLib.debug("SAVE: ctrl-g pressed");
1273 _this.forwardSearch(true);
1278 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1279 _this.forwardSearch(true);
1285 // print(event.key.keyval)
1291 // user defined functions
1295 public class Xcls_search_results : Object
1297 public Gtk.Label el;
1298 private Editor _this;
1304 public Xcls_search_results(Editor _owner )
1307 _this.search_results = this;
1308 this.el = new Gtk.Label( "No Results" );
1312 // set gobject values
1313 this.el.margin_end = 4;
1314 this.el.margin_start = 4;
1317 // user defined functions
1318 public void updateResults () {
1319 this.el.visible = true;
1321 var res = _this.searchcontext.get_occurrences_count();
1323 _this.search_results.el.label = "??? Matches";
1327 _this.nextBtn.el.sensitive = false;
1328 _this.backBtn.el.sensitive = false;
1331 _this.search_results.el.label = "%d Matches".printf(res);
1332 _this.nextBtn.el.sensitive = true;
1333 _this.backBtn.el.sensitive = true;
1336 _this.search_results.el.label = "No Matches";
1341 public class Xcls_nextBtn : Object
1343 public Gtk.Button el;
1344 private Editor _this;
1348 public bool always_show_image;
1351 public Xcls_nextBtn(Editor _owner )
1354 _this.nextBtn = this;
1355 this.el = new Gtk.Button();
1358 this.always_show_image = true;
1360 // set gobject values
1361 this.el.icon_name = "go-down";
1362 this.el.sensitive = false;
1365 this.el.clicked.connect( (event) => {
1367 _this.forwardSearch(true);
1373 // user defined functions
1376 public class Xcls_backBtn : Object
1378 public Gtk.Button el;
1379 private Editor _this;
1383 public bool always_show_image;
1386 public Xcls_backBtn(Editor _owner )
1389 _this.backBtn = this;
1390 this.el = new Gtk.Button();
1393 this.always_show_image = true;
1395 // set gobject values
1396 this.el.icon_name = "go-up";
1397 this.el.sensitive = false;
1400 this.el.clicked.connect( (event) => {
1402 _this.backSearch(true);
1407 // user defined functions
1410 public class Xcls_MenuButton17 : Object
1412 public Gtk.MenuButton el;
1413 private Editor _this;
1417 public bool always_show_image;
1420 public Xcls_MenuButton17(Editor _owner )
1423 this.el = new Gtk.MenuButton();
1426 this.always_show_image = true;
1428 // set gobject values
1429 this.el.icon_name = "emblem-system";
1430 this.el.always_show_arrow = true;
1431 new Xcls_search_settings( _this );
1432 this.el.popover = _this.search_settings.el;
1435 // user defined functions
1437 public class Xcls_search_settings : Object
1439 public Gtk.Popover el;
1440 private Editor _this;
1446 public Xcls_search_settings(Editor _owner )
1449 _this.search_settings = this;
1450 this.el = new Gtk.Popover();
1454 // set gobject values
1455 var child_1 = new Xcls_Box19( _this );
1457 this.el.child = child_1.el;
1460 // user defined functions
1462 public class Xcls_Box19 : Object
1465 private Editor _this;
1471 public Xcls_Box19(Editor _owner )
1474 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1478 // set gobject values
1479 new Xcls_case_sensitive( _this );
1480 this.el.append( _this.case_sensitive.el );
1481 new Xcls_regex( _this );
1482 this.el.append( _this.regex.el );
1483 new Xcls_multiline( _this );
1484 this.el.append( _this.multiline.el );
1487 // user defined functions
1489 public class Xcls_case_sensitive : Object
1491 public Gtk.CheckButton el;
1492 private Editor _this;
1498 public Xcls_case_sensitive(Editor _owner )
1501 _this.case_sensitive = this;
1502 this.el = new Gtk.CheckButton();
1506 // set gobject values
1507 this.el.label = "Case Sensitive";
1516 // user defined functions
1519 public class Xcls_regex : Object
1521 public Gtk.CheckButton el;
1522 private Editor _this;
1528 public Xcls_regex(Editor _owner )
1532 this.el = new Gtk.CheckButton();
1536 // set gobject values
1537 this.el.label = "Regex";
1546 // user defined functions
1549 public class Xcls_multiline : Object
1551 public Gtk.CheckButton el;
1552 private Editor _this;
1558 public Xcls_multiline(Editor _owner )
1561 _this.multiline = this;
1562 this.el = new Gtk.CheckButton();
1566 // set gobject values
1567 this.el.label = "Multi-line (add \\n)";
1570 // user defined functions