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 );
545 this.el.child = child_1.el;
548 this.el.clicked.connect( () => {
549 _this.saveContents();
550 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
554 // user defined functions
556 public class Xcls_Image6 : Object
559 private Editor _this;
565 public Xcls_Image6(Editor _owner )
568 this.el = new Gtk.Image();
572 // set gobject values
573 this.el.icon_name = "window-close";
574 this.el.icon_size = Gtk.IconSize.NORMAL;
577 // user defined functions
582 public class Xcls_RightEditor : Object
584 public Gtk.ScrolledWindow el;
585 private Editor _this;
591 public Xcls_RightEditor(Editor _owner )
594 _this.RightEditor = this;
595 this.el = new Gtk.ScrolledWindow();
599 // set gobject values
600 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
601 this.el.vexpand = true;
602 this.el.overlay_scrolling = false;
603 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
604 new Xcls_view( _this );
605 this.el.child = _this.view.el;
608 // user defined functions
610 public class Xcls_view : Object
612 public GtkSource.View el;
613 private Editor _this;
617 public Gtk.CssProvider css;
620 public Xcls_view(Editor _owner )
624 this.el = new GtkSource.View();
629 // set gobject values
630 this.el.auto_indent = true;
631 this.el.indent_width = 4;
632 this.el.name = "editor-view";
633 this.el.show_line_marks = true;
634 this.el.insert_spaces_instead_of_tabs = true;
635 this.el.show_line_numbers = true;
636 this.el.hexpand = true;
637 this.el.vexpand = true;
638 this.el.has_tooltip = true;
639 this.el.css_classes = { "code-editor" };
640 this.el.tab_width = 4;
641 this.el.highlight_current_line = true;
642 new Xcls_buffer( _this );
643 this.el.buffer = _this.buffer.el;
644 var child_2 = new Xcls_EventControllerKey10( _this );
646 this.el.add_controller( child_2.el );
650 this.el.completion.add_provider(
651 new Palete.CompletionProvider(_this)
654 //this.el.completion.unblock_interactive();
655 this.el.completion.select_on_show = true; // select
656 //this.el.completion.remember_info_visibility = true;
659 var attrs = new GtkSource.MarkAttributes();
661 attrs.set_icon_name ( "process-stop");
662 attrs.query_tooltip_text.connect(( mark) => {
663 GLib.debug("tooltip query? %s", mark.name);
664 return strdup( mark.name);
666 attrs.query_tooltip_markup.connect(( mark) => {
667 GLib.debug("tooltip query? %s", mark.name);
668 return strdup( mark.name);
670 this.el.set_mark_attributes ("ERR", attrs, 1);
674 var wattrs = new GtkSource.MarkAttributes();
675 wattrs.set_icon_name ( "process-stop");
676 wattrs.query_tooltip_text.connect(( mark) => {
677 GLib.debug("tooltip query? %s", mark.name);
678 return strdup(mark.name);
680 wattrs.query_tooltip_markup.connect(( mark) => {
681 GLib.debug("tooltip query? %s", mark.name);
682 return strdup(mark.name);
684 this.el.set_mark_attributes ("WARN", wattrs, 1);
688 var dattrs = new GtkSource.MarkAttributes();
690 dattrs.set_icon_name ( "process-stop");
692 dattrs.query_tooltip_text.connect(( mark) => {
693 GLib.debug("tooltip query? %s", mark.name);
694 return strdup(mark.name);
696 //dattrs.query_tooltip_markup.connect(( mark) => {
697 // GLib.debug("tooltip query? %s", mark.name);
698 // return strdup(mark.name);
700 this.el.set_mark_attributes ("DEPR", dattrs, 1);
703 this.el.get_space_drawer().set_matrix(null);
704 this.el.get_space_drawer().set_types_for_locations(
705 GtkSource.SpaceLocationFlags.ALL,
706 GtkSource.SpaceTypeFlags.ALL
708 this.el.get_space_drawer().set_enable_matrix(true);
711 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
713 //GLib.debug("query tooltip");
717 var yoff = (int) _this.RightEditor.el.vadjustment.value;
719 // I think this is problematic - if it's compliing / updating at same time as query.
721 //if (_this.window.statusbar_compile_spinner.el.spinning) {
725 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
727 var l = iter.get_line();
731 // GLib.debug("query tooltip line %d", (int) l);
737 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
738 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
739 tooltip.set_text(_this.buffer.marks.get(l).dup());
747 // this crashes?? - not sure why.
748 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
749 if (marks.is_empty()) {
750 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
752 if (marks.is_empty()) {
753 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
756 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
758 marks.@foreach((m) => {
759 //GLib.debug("got mark %s", m.name);
760 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
762 // true if there is a mark..
763 if (str.length > 0 ) {
764 tooltip.set_text( str );
766 return str.length > 0 ? true : false;
771 // user defined functions
772 public void load (string str) {
774 // show the help page for the active node..
775 //this.get('/Help').show();
777 // this.get('/BottomPane').el.set_current_page(0);
778 GLib.debug("load called - Reset undo buffer");
780 var buf = (GtkSource.Buffer)this.el.get_buffer();
781 buf.begin_irreversible_action();
782 buf.set_text(str, str.length);
783 buf.end_irreversible_action();
785 var lm = GtkSource.LanguageManager.get_default();
787 if (_this.file != null) {
788 lang = _this.file.language;
790 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
791 var lg = _this.file.content_type.length > 0 ?
792 lm.guess_language(_this.file.path, _this.file.content_type) :
793 lm.get_language(lang);
796 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
798 this.el.insert_spaces_instead_of_tabs = true;
800 print("sourcelanguage = %s\n", lg.name);
801 if (lg.name == "Vala") {
802 this.el.insert_spaces_instead_of_tabs = false;
806 this.el.grab_focus();
807 _this.save_button.el.sensitive = false;
808 _this.last_error_counter = -1;
811 public class Xcls_buffer : Object
813 public GtkSource.Buffer el;
814 private Editor _this;
818 public int error_line;
819 public Gee.HashMap<int,string>? xmarks;
820 public bool check_queued;
823 public Xcls_buffer(Editor _owner )
827 this.el = new GtkSource.Buffer( null );
830 this.error_line = -1;
832 this.check_queued = false;
834 // set gobject values
835 this.el.highlight_syntax = true;
836 this.el.highlight_matching_brackets = true;
837 this.el.enable_undo = true;
842 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
843 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
844 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
845 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
846 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
847 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
848 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
849 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
852 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
853 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
854 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
857 this.el.changed.connect( () => {
860 _this.save_button.el.sensitive = true;
861 print("EDITOR CHANGED");
866 // this.get('/LeftPanel.model').changed( str , false);
871 // user defined functions
872 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
875 this.el.get_bounds (out start, out end);
877 this.el.remove_source_marks (start, end, type);
878 GLib.debug("highlight errors");
880 // we should highlight other types of errors..
882 if (!obj.has_member(type)) {
883 GLib.debug("Return has no errors\n");
887 if (_this.window.windowstate.state != WindowState.State.CODEONLY
889 _this.window.windowstate.state != WindowState.State.CODE
891 GLib.debug("windowstate != CODEONLY?");
896 //this.marks = new Gee.HashMap<int,string>();
897 var err = obj.get_object_member(type);
899 if (_this.file == null) {
900 GLib.debug("file is null?");
904 var valafn = _this.file.path;
906 if (_this.file.xtype != "PlainFile") {
910 var regex = new Regex("\\.bjs$");
912 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
913 } catch (GLib.RegexError e) {
920 if (!err.has_member(valafn)) {
921 GLib.debug("File path has no errors");
925 var lines = err.get_object_member(valafn);
928 if (obj.has_member("line_offset")) { // ?? why??
929 offset = (int)obj.get_int_member("line_offset") + 1;
933 var tlines = this.el.get_line_count () +1;
935 if (_this.prop != null) {
937 tlines = _this.prop.end_line + 1;
938 offset = _this.prop.start_line + 1;
944 lines.foreach_member((obj, line, node) => {
947 // print("get inter\n");
948 var eline = int.parse(line) - offset;
949 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
952 if (eline > tlines || eline < 0) {
957 this.el.get_iter_at_line( out iter, eline);
958 //print("mark line\n");
960 var ar = lines.get_array_member(line);
961 for (var i = 0 ; i < ar.get_length(); i++) {
962 if (ar.get_string_element(i) == "Success") {
965 msg += (msg.length > 0) ? "\n" : "";
966 msg += ar.get_string_element(i);
971 msg = "Line: %d".printf(eline+1) + " " + msg;
972 this.el.create_source_mark(msg, type, iter);
973 GLib.debug("set line %d to %m", eline, msg);
974 // this.marks.set(eline, msg);
983 public bool checkSyntax () {
986 var str = this.toString();
989 if (this.error_line > 0) {
992 this.el.get_bounds (out start, out end);
994 this.el.remove_source_marks (start, end, null);
996 if (str.length < 1) {
997 print("checkSyntax - empty string?\n");
1002 if (_this.file.xtype == "PlainFile") {
1004 // assume it's gtk...
1005 var oldcode =_this.file.toSource();
1006 _this.file.setSource(str);
1007 BuilderApplication.showSpinner("appointment soon","document change pending");
1008 _this.file.getLanguageServer().document_change(_this.file);
1010 _this.file.setSource(oldcode);
1016 if (_this.file == null) {
1024 GLib.debug("calling validate");
1025 // clear the buttons.
1026 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1029 var oldcode = _this.prop.val;
1031 _this.prop.val = str;
1032 _this.node.updated_count++;
1033 _this.file.getLanguageServer().document_change(_this.file);
1034 _this.node.updated_count++;
1035 _this.prop.val = oldcode;
1038 //print("done mark line\n");
1040 return true; // at present allow saving - even if it's invalid..
1042 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1044 this.error_line = validate_res.size;
1046 if (this.error_line < 1) {
1049 var tlines = this.el.get_line_count ();
1051 var valiter = validate_res.map_iterator();
1052 while (valiter.next()) {
1054 // print("get inter\n");
1055 var eline = valiter.get_key();
1056 if (eline > tlines) {
1059 this.el.get_iter_at_line( out iter, eline);
1060 //print("mark line\n");
1061 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1065 public string toString () {
1069 this.el.get_start_iter(out s);
1070 this.el.get_end_iter(out e);
1071 var ret = this.el.get_text(s,e,true);
1072 //print("TO STRING? " + ret);
1077 public class Xcls_EventControllerKey10 : Object
1079 public Gtk.EventControllerKey el;
1080 private Editor _this;
1086 public Xcls_EventControllerKey10(Editor _owner )
1089 this.el = new Gtk.EventControllerKey();
1093 // set gobject values
1096 this.el.key_released.connect( (keyval, keycode, state) => {
1099 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1100 GLib.debug("SAVE: ctrl-S pressed");
1101 _this.saveContents();
1105 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1106 GLib.debug("SAVE: ctrl-g pressed");
1107 _this.forwardSearch(true);
1110 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1111 GLib.debug("SAVE: ctrl-f pressed");
1112 _this.search_entry.el.grab_focus();
1113 _this.search_entry.el.select_region(0,-1);
1116 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1117 _this.view.el.show_completion();
1121 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1122 var line = iter.get_line();
1123 var offset = iter.get_line_offset();
1124 GLib.debug("line %d off %d", line ,offset);
1125 if (_this.prop != null) {
1126 line += _this.prop.start_line + 1; // i think..
1127 offset += 12; // should probably be 8 without namespaced
1128 GLib.debug("guess line %d off %d", line ,offset);
1130 //_this.view.el.show_completion();
1131 // print(event.key.keyval)
1142 // user defined functions
1147 public class Xcls_Box11 : Object
1150 private Editor _this;
1156 public Xcls_Box11(Editor _owner )
1159 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1163 // set gobject values
1164 this.el.homogeneous = false;
1165 this.el.vexpand = false;
1166 new Xcls_search_entry( _this );
1167 this.el.append( _this.search_entry.el );
1168 new Xcls_search_results( _this );
1169 this.el.append( _this.search_results.el );
1170 new Xcls_nextBtn( _this );
1171 this.el.append( _this.nextBtn.el );
1172 new Xcls_backBtn( _this );
1173 this.el.append( _this.backBtn.el );
1174 var child_5 = new Xcls_MenuButton17( _this );
1176 this.el.append( child_5.el );
1179 // user defined functions
1181 public class Xcls_search_entry : Object
1183 public Gtk.SearchEntry el;
1184 private Editor _this;
1188 public Gtk.CssProvider css;
1191 public Xcls_search_entry(Editor _owner )
1194 _this.search_entry = this;
1195 this.el = new Gtk.SearchEntry();
1199 // set gobject values
1200 this.el.name = "editor-search-entry";
1201 this.el.hexpand = true;
1202 this.el.placeholder_text = "Press enter to search";
1203 this.el.search_delay = 3;
1204 var child_1 = new Xcls_EventControllerKey13( _this );
1206 this.el.add_controller( child_1.el );
1209 this.el.search_changed.connect( ( ) => {
1211 _this.search(_this.search_entry.el.text);
1212 _this.search_results.updateResults();
1214 GLib.Timeout.add_seconds(1,() => {
1215 _this.search_results.updateResults();
1221 // user defined functions
1222 public void forwardSearch (bool change_focus) {
1225 _this.forwardSearch(change_focus);
1229 switch(_this.windowstate.state) {
1230 case WindowState.State.CODEONLY:
1231 //case WindowState.State.CODE:
1232 // search the code being edited..
1233 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1236 case WindowState.State.PREVIEW:
1237 if (_this.windowstate.file.xtype == "Gtk") {
1238 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1240 _this.windowstate.window_rooview.forwardSearch(change_focus);
1249 public class Xcls_EventControllerKey13 : Object
1251 public Gtk.EventControllerKey el;
1252 private Editor _this;
1258 public Xcls_EventControllerKey13(Editor _owner )
1261 this.el = new Gtk.EventControllerKey();
1265 // set gobject values
1268 this.el.key_pressed.connect( (keyval, keycode, state) => {
1270 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1271 GLib.debug("SAVE: ctrl-g pressed");
1272 _this.forwardSearch(true);
1277 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1278 _this.forwardSearch(true);
1284 // print(event.key.keyval)
1290 // user defined functions
1294 public class Xcls_search_results : Object
1296 public Gtk.Label el;
1297 private Editor _this;
1303 public Xcls_search_results(Editor _owner )
1306 _this.search_results = this;
1307 this.el = new Gtk.Label( "No Results" );
1311 // set gobject values
1312 this.el.margin_end = 4;
1313 this.el.margin_start = 4;
1316 // user defined functions
1317 public void updateResults () {
1318 this.el.visible = true;
1320 var res = _this.searchcontext.get_occurrences_count();
1322 _this.search_results.el.label = "??? Matches";
1326 _this.nextBtn.el.sensitive = false;
1327 _this.backBtn.el.sensitive = false;
1330 _this.search_results.el.label = "%d Matches".printf(res);
1331 _this.nextBtn.el.sensitive = true;
1332 _this.backBtn.el.sensitive = true;
1335 _this.search_results.el.label = "No Matches";
1340 public class Xcls_nextBtn : Object
1342 public Gtk.Button el;
1343 private Editor _this;
1347 public bool always_show_image;
1350 public Xcls_nextBtn(Editor _owner )
1353 _this.nextBtn = this;
1354 this.el = new Gtk.Button();
1357 this.always_show_image = true;
1359 // set gobject values
1360 this.el.icon_name = "go-down";
1361 this.el.sensitive = false;
1364 this.el.clicked.connect( (event) => {
1366 _this.forwardSearch(true);
1372 // user defined functions
1375 public class Xcls_backBtn : Object
1377 public Gtk.Button el;
1378 private Editor _this;
1382 public bool always_show_image;
1385 public Xcls_backBtn(Editor _owner )
1388 _this.backBtn = this;
1389 this.el = new Gtk.Button();
1392 this.always_show_image = true;
1394 // set gobject values
1395 this.el.icon_name = "go-up";
1396 this.el.sensitive = false;
1399 this.el.clicked.connect( (event) => {
1401 _this.backSearch(true);
1406 // user defined functions
1409 public class Xcls_MenuButton17 : Object
1411 public Gtk.MenuButton el;
1412 private Editor _this;
1416 public bool always_show_image;
1419 public Xcls_MenuButton17(Editor _owner )
1422 this.el = new Gtk.MenuButton();
1425 this.always_show_image = true;
1427 // set gobject values
1428 this.el.icon_name = "emblem-system";
1429 this.el.always_show_arrow = true;
1430 new Xcls_search_settings( _this );
1431 this.el.popover = _this.search_settings.el;
1434 // user defined functions
1436 public class Xcls_search_settings : Object
1438 public Gtk.Popover el;
1439 private Editor _this;
1445 public Xcls_search_settings(Editor _owner )
1448 _this.search_settings = this;
1449 this.el = new Gtk.Popover();
1453 // set gobject values
1454 var child_1 = new Xcls_Box19( _this );
1455 this.el.child = child_1.el;
1458 // user defined functions
1460 public class Xcls_Box19 : Object
1463 private Editor _this;
1469 public Xcls_Box19(Editor _owner )
1472 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1476 // set gobject values
1477 new Xcls_case_sensitive( _this );
1478 this.el.append( _this.case_sensitive.el );
1479 new Xcls_regex( _this );
1480 this.el.append( _this.regex.el );
1481 new Xcls_multiline( _this );
1482 this.el.append( _this.multiline.el );
1485 // user defined functions
1487 public class Xcls_case_sensitive : Object
1489 public Gtk.CheckButton el;
1490 private Editor _this;
1496 public Xcls_case_sensitive(Editor _owner )
1499 _this.case_sensitive = this;
1500 this.el = new Gtk.CheckButton();
1504 // set gobject values
1505 this.el.label = "Case Sensitive";
1514 // user defined functions
1517 public class Xcls_regex : Object
1519 public Gtk.CheckButton el;
1520 private Editor _this;
1526 public Xcls_regex(Editor _owner )
1530 this.el = new Gtk.CheckButton();
1534 // set gobject values
1535 this.el.label = "Regex";
1544 // user defined functions
1547 public class Xcls_multiline : Object
1549 public Gtk.CheckButton el;
1550 private Editor _this;
1556 public Xcls_multiline(Editor _owner )
1559 _this.multiline = this;
1560 this.el = new Gtk.CheckButton();
1564 // set gobject values
1565 this.el.label = "Multi-line (add \\n)";
1568 // user defined functions