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_Box2( _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_Box12( _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 );
150 this.close_btn.el.show();
153 this.view.load( file.toSource() );
154 this.close_btn.el.hide();
158 public void backSearch (bool change_focus) {
160 if (this.searchcontext == null) {
164 Gtk.TextIter beg, st,en;
165 bool has_wrapped_around;
166 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
168 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
169 this.last_search_end = 0;
171 this.last_search_end = en.get_offset();
173 this.view.el.grab_focus();
175 this.buffer.el.place_cursor(st);
176 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
180 public string tempFileContents () {
183 if (_this.file == null) {
186 var str= this.buffer.toString();
187 if (_this.file.xtype == "PlainFile") {
195 GLib.debug("calling validate");
196 // clear the buttons.
197 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
198 return this.file.toSource(); ;
201 var oldcode = _this.prop.val;
202 _this.prop.val = str;
203 var ret = _this.file.toSource();
204 _this.prop.val = oldcode;
208 public void reset () {
213 this.searchcontext = null;
216 public int search (string in_txt) {
218 var s = new GtkSource.SearchSettings();
219 s.case_sensitive = _this.case_sensitive.el.active;
220 s.regex_enabled = _this.regex.el.active;
221 s.wrap_around = false;
223 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
224 this.searchcontext.set_highlight(true);
227 if (_this.multiline.el.active) {
228 txt = in_txt.replace("\\n", "\n");
231 s.set_search_text(txt);
232 Gtk.TextIter beg, st,en;
234 this.buffer.el.get_start_iter(out beg);
235 bool has_wrapped_around;
236 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
237 this.last_search_end = 0;
239 return this.searchcontext.get_occurrences_count();
245 public void updateErrorMarks () {
249 var buf = _this.buffer.el;
252 buf.get_bounds (out start, out end);
257 //GLib.debug("highlight errors");
259 // we should highlight other types of errors..
261 if (_this.window.windowstate.state != WindowState.State.CODEONLY
263 _this.window.windowstate.state != WindowState.State.CODE
265 //GLib.debug("windowstate != CODEONLY?");
271 if (_this.file == null) {
272 GLib.debug("file is null?");
276 var ar = this.file.getErrors();
278 buf.remove_source_marks (start, end, null);
279 this.last_error_counter = file.error_counter ;
280 //GLib.debug("highlight %s : %s has no errors", this.file.relpath, category);
285 // basicaly check if there is no change, then we do not do any update..
286 // we can do this by just using an error counter?
287 // if that's changed then we will do an update, otherwise dont bother.
293 var tlines = buf.get_line_count () +1;
295 if (_this.prop != null) {
296 // this still seems flaky...
298 tlines = _this.prop.end_line;
299 offset = _this.prop.start_line;
300 hoffset = _this.node.node_pad.length;
305 if (this.last_error_counter == file.error_counter) {
311 buf.remove_source_marks (start, end, null);
312 foreach(var diag in ar) {
314 // print("get inter\n");
315 var eline = (int)diag.range.start.line - offset;
316 //var eline = diag.range.end_line - offset;
317 //GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
318 // err.line ,eline, offset);
321 if (eline > tlines || eline < 0) {
327 buf.get_iter_at_line_offset( out iter, eline, (int)diag.range.start.character - hoffset);
330 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
331 buf.create_source_mark( msg, diag.category, iter);
332 // GLib.debug("set line %d to %s", eline, msg);
333 //this.marks.set(eline, msg);
335 this.last_error_counter = file.error_counter ;
342 public void scroll_to_line (int line) {
344 GLib.Timeout.add(500, () => {
346 var buf = this.view.el.get_buffer();
348 var sbuf = (GtkSource.Buffer) buf;
352 sbuf.get_iter_at_line(out iter, line);
353 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
357 public class Xcls_Box2 : Object
360 private Editor _this;
366 public Xcls_Box2(Editor _owner )
369 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
373 // set gobject values
374 this.el.homogeneous = false;
375 this.el.hexpand = true;
376 new Xcls_save_button( _this );
377 this.el.append( _this.save_button.el );
378 var child_2 = new Xcls_Label4( _this );
380 this.el.append( child_2.el );
381 var child_3 = new Xcls_Scale5( _this );
383 this.el.append( child_3.el );
384 new Xcls_close_btn( _this );
385 this.el.append( _this.close_btn.el );
388 // user defined functions
390 public class Xcls_save_button : Object
392 public Gtk.Button el;
393 private Editor _this;
399 public Xcls_save_button(Editor _owner )
402 _this.save_button = this;
403 this.el = new Gtk.Button();
407 // set gobject values
408 this.el.label = "Save";
411 this.el.clicked.connect( () => {
412 _this.saveContents();
416 // user defined functions
419 public class Xcls_Label4 : Object
422 private Editor _this;
428 public Xcls_Label4(Editor _owner )
431 this.el = new Gtk.Label( null );
435 // set gobject values
436 this.el.hexpand = true;
439 // user defined functions
442 public class Xcls_Scale5 : Object
445 private Editor _this;
451 public Xcls_Scale5(Editor _owner )
454 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
458 // set gobject values
459 this.el.width_request = 200;
460 this.el.has_origin = true;
461 this.el.draw_value = false;
463 this.el.sensitive = true;
468 this.el.set_range(6,30);
469 this.el.set_value(8);
473 this.el.change_value.connect( (st, val ) => {
476 _this.view.css.load_from_string(
477 "#editor-view { font: %dpx monospace; }".printf((int)val)
484 // user defined functions
487 public class Xcls_close_btn : Object
489 public Gtk.Button el;
490 private Editor _this;
496 public Xcls_close_btn(Editor _owner )
499 _this.close_btn = this;
500 this.el = new Gtk.Button();
504 // set gobject values
505 this.el.icon_name = "window-close";
506 var child_1 = new Xcls_Image7( _this );
507 this.el.child = child_1.el;
510 this.el.clicked.connect( () => {
511 _this.saveContents();
512 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
516 // user defined functions
518 public class Xcls_Image7 : Object
521 private Editor _this;
527 public Xcls_Image7(Editor _owner )
530 this.el = new Gtk.Image();
534 // set gobject values
535 this.el.icon_name = "window-close";
536 this.el.icon_size = Gtk.IconSize.NORMAL;
539 // user defined functions
544 public class Xcls_RightEditor : Object
546 public Gtk.ScrolledWindow el;
547 private Editor _this;
553 public Xcls_RightEditor(Editor _owner )
556 _this.RightEditor = this;
557 this.el = new Gtk.ScrolledWindow();
561 // set gobject values
562 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
563 this.el.vexpand = true;
564 this.el.overlay_scrolling = false;
565 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
566 new Xcls_view( _this );
567 this.el.child = _this.view.el;
570 // user defined functions
572 public class Xcls_view : Object
574 public GtkSource.View el;
575 private Editor _this;
579 public Gtk.CssProvider css;
582 public Xcls_view(Editor _owner )
586 this.el = new GtkSource.View();
591 // set gobject values
592 this.el.auto_indent = true;
593 this.el.indent_width = 4;
594 this.el.name = "editor-view";
595 this.el.show_line_marks = true;
596 this.el.insert_spaces_instead_of_tabs = true;
597 this.el.show_line_numbers = true;
598 this.el.hexpand = true;
599 this.el.vexpand = true;
600 this.el.has_tooltip = true;
601 this.el.tab_width = 4;
602 this.el.highlight_current_line = true;
603 new Xcls_buffer( _this );
604 this.el.buffer = _this.buffer.el;
605 var child_2 = new Xcls_EventControllerKey11( _this );
607 this.el.add_controller( child_2.el );
611 this.css = new Gtk.CssProvider();
613 this.css.load_from_string(
614 "#editor-view { font: 12px monospace;}"
617 Gtk.StyleContext.add_provider_for_display(
618 this.el.get_display(),
620 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
626 this is pretty flakey - triggers Gtk with < 0 d
627 var cp = new GtkSource.CompletionWords("test");
628 cp.minimum_word_size = 3;
629 //cp.priority = 100; //?? does this do anything
630 cp.proposals_batch_size = 10;
631 cp.scan_batch_size = 1000;
633 cp.register(_this.buffer.el);
634 this.el.completion.add_provider(cp);
636 this.el.completion.add_provider(new Palete.CompletionProvider(_this));
638 //this.el.completion.unblock_interactive();
639 this.el.completion.select_on_show = true; // select
640 //this.el.completion.remember_info_visibility = true;
643 var attrs = new GtkSource.MarkAttributes();
644 var pink = Gdk.RGBA();
645 pink.parse ( "pink");
646 attrs.set_background ( pink);
647 attrs.set_icon_name ( "process-stop");
648 attrs.query_tooltip_text.connect(( mark) => {
649 GLib.debug("tooltip query? %s", mark.name);
650 return strdup( mark.name);
652 attrs.query_tooltip_markup.connect(( mark) => {
653 GLib.debug("tooltip query? %s", mark.name);
654 return strdup( mark.name);
656 this.el.set_mark_attributes ("ERR", attrs, 1);
658 var wattrs = new GtkSource.MarkAttributes();
659 var blue = Gdk.RGBA();
660 blue.parse ( "#ABF4EB");
661 wattrs.set_background ( blue);
662 wattrs.set_icon_name ( "process-stop");
663 wattrs.query_tooltip_text.connect(( mark) => {
664 GLib.debug("tooltip query? %s", mark.name);
665 return strdup(mark.name);
667 wattrs.query_tooltip_markup.connect(( mark) => {
668 GLib.debug("tooltip query? %s", mark.name);
669 return strdup(mark.name);
671 this.el.set_mark_attributes ("WARN", wattrs, 1);
675 var dattrs = new GtkSource.MarkAttributes();
676 var purple = Gdk.RGBA();
677 purple.parse ( "#EEA9FF");
678 dattrs.set_background ( purple);
679 dattrs.set_icon_name ( "process-stop");
680 dattrs.query_tooltip_text.connect(( mark) => {
681 GLib.debug("tooltip query? %s", mark.name);
682 return strdup(mark.name);
684 dattrs.query_tooltip_markup.connect(( mark) => {
685 GLib.debug("tooltip query? %s", mark.name);
686 return strdup(mark.name);
688 this.el.set_mark_attributes ("DEPR", dattrs, 1);
691 this.el.get_space_drawer().set_matrix(null);
692 this.el.get_space_drawer().set_types_for_locations(
693 GtkSource.SpaceLocationFlags.ALL,
694 GtkSource.SpaceTypeFlags.ALL
696 this.el.get_space_drawer().set_enable_matrix(true);
699 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
701 //GLib.debug("query tooltip");
705 var yoff = (int) _this.RightEditor.el.vadjustment.value;
707 // I think this is problematic - if it's compliing / updating at same time as query.
709 //if (_this.window.statusbar_compile_spinner.el.spinning) {
713 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
715 var l = iter.get_line();
719 // GLib.debug("query tooltip line %d", (int) l);
725 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
726 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
727 tooltip.set_text(_this.buffer.marks.get(l).dup());
735 // this crashes?? - not sure why.
736 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
737 if (marks.is_empty()) {
738 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
740 if (marks.is_empty()) {
741 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
744 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
746 marks.@foreach((m) => {
747 //GLib.debug("got mark %s", m.name);
748 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
750 // true if there is a mark..
751 if (str.length > 0 ) {
752 tooltip.set_text( str );
754 return str.length > 0 ? true : false;
759 // user defined functions
760 public void load (string str) {
762 // show the help page for the active node..
763 //this.get('/Help').show();
765 // this.get('/BottomPane').el.set_current_page(0);
766 GLib.debug("load called - Reset undo buffer");
768 var buf = (GtkSource.Buffer)this.el.get_buffer();
769 buf.begin_irreversible_action();
770 buf.set_text(str, str.length);
771 buf.end_irreversible_action();
773 var lm = GtkSource.LanguageManager.get_default();
775 if (_this.file != null) {
776 lang = _this.file.language;
778 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
779 var lg = _this.file.content_type.length > 0 ?
780 lm.guess_language(_this.file.path, _this.file.content_type) :
781 lm.get_language(lang);
784 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
786 this.el.insert_spaces_instead_of_tabs = true;
788 print("sourcelanguage = %s\n", lg.name);
789 if (lg.name == "Vala") {
790 this.el.insert_spaces_instead_of_tabs = false;
794 this.el.grab_focus();
795 _this.save_button.el.sensitive = false;
796 _this.last_error_counter = -1;
799 public class Xcls_buffer : Object
801 public GtkSource.Buffer el;
802 private Editor _this;
806 public int error_line;
807 public Gee.HashMap<int,string>? xmarks;
808 public bool check_queued;
811 public Xcls_buffer(Editor _owner )
815 this.el = new GtkSource.Buffer( null );
818 this.error_line = -1;
820 this.check_queued = false;
822 // set gobject values
823 this.el.highlight_syntax = true;
824 this.el.highlight_matching_brackets = true;
825 this.el.enable_undo = true;
831 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
832 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
833 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
834 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
835 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
836 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
837 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
838 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
843 this.el.changed.connect( () => {
846 _this.save_button.el.sensitive = true;
847 print("EDITOR CHANGED");
852 // this.get('/LeftPanel.model').changed( str , false);
857 // user defined functions
858 public bool checkSyntax () {
861 var str = this.toString();
864 if (this.error_line > 0) {
867 this.el.get_bounds (out start, out end);
869 this.el.remove_source_marks (start, end, null);
871 if (str.length < 1) {
872 print("checkSyntax - empty string?\n");
877 if (_this.file.xtype == "PlainFile") {
879 // assume it's gtk...
880 var oldcode =_this.file.toSource();
881 _this.file.setSource(str);
882 BuilderApplication.showSpinner("appointment soon","document change pending");
883 _this.file.getLanguageServer().document_change(_this.file);
885 _this.file.setSource(oldcode);
891 if (_this.file == null) {
899 GLib.debug("calling validate");
900 // clear the buttons.
901 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
904 var oldcode = _this.prop.val;
906 _this.prop.val = str;
907 _this.node.updated_count++;
908 _this.file.getLanguageServer().document_change(_this.file);
909 _this.node.updated_count++;
910 _this.prop.val = oldcode;
913 //print("done mark line\n");
915 return true; // at present allow saving - even if it's invalid..
917 public bool highlightErrorsJson (string type, Json.Object obj) {
920 this.el.get_bounds (out start, out end);
922 this.el.remove_source_marks (start, end, type);
923 GLib.debug("highlight errors");
925 // we should highlight other types of errors..
927 if (!obj.has_member(type)) {
928 GLib.debug("Return has no errors\n");
932 if (_this.window.windowstate.state != WindowState.State.CODEONLY
934 _this.window.windowstate.state != WindowState.State.CODE
936 GLib.debug("windowstate != CODEONLY?");
941 //this.marks = new Gee.HashMap<int,string>();
942 var err = obj.get_object_member(type);
944 if (_this.file == null) {
945 GLib.debug("file is null?");
949 var valafn = _this.file.path;
951 if (_this.file.xtype != "PlainFile") {
955 var regex = new Regex("\\.bjs$");
957 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
958 } catch (GLib.RegexError e) {
965 if (!err.has_member(valafn)) {
966 GLib.debug("File path has no errors");
970 var lines = err.get_object_member(valafn);
973 if (obj.has_member("line_offset")) { // ?? why??
974 offset = (int)obj.get_int_member("line_offset") + 1;
978 var tlines = this.el.get_line_count () +1;
980 if (_this.prop != null) {
982 tlines = _this.prop.end_line + 1;
983 offset = _this.prop.start_line + 1;
989 lines.foreach_member((obj, line, node) => {
992 // print("get inter\n");
993 var eline = int.parse(line) - offset;
994 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
997 if (eline > tlines || eline < 0) {
1002 this.el.get_iter_at_line( out iter, eline);
1003 //print("mark line\n");
1005 var ar = lines.get_array_member(line);
1006 for (var i = 0 ; i < ar.get_length(); i++) {
1007 if (ar.get_string_element(i) == "Success") {
1010 msg += (msg.length > 0) ? "\n" : "";
1011 msg += ar.get_string_element(i);
1016 msg = "Line: %d".printf(eline+1) + " " + msg;
1017 this.el.create_source_mark(msg, type, iter);
1018 GLib.debug("set line %d to %m", eline, msg);
1019 // this.marks.set(eline, msg);
1028 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1030 this.error_line = validate_res.size;
1032 if (this.error_line < 1) {
1035 var tlines = this.el.get_line_count ();
1037 var valiter = validate_res.map_iterator();
1038 while (valiter.next()) {
1040 // print("get inter\n");
1041 var eline = valiter.get_key();
1042 if (eline > tlines) {
1045 this.el.get_iter_at_line( out iter, eline);
1046 //print("mark line\n");
1047 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1051 public string toString () {
1055 this.el.get_start_iter(out s);
1056 this.el.get_end_iter(out e);
1057 var ret = this.el.get_text(s,e,true);
1058 //print("TO STRING? " + ret);
1063 public class Xcls_EventControllerKey11 : Object
1065 public Gtk.EventControllerKey el;
1066 private Editor _this;
1072 public Xcls_EventControllerKey11(Editor _owner )
1075 this.el = new Gtk.EventControllerKey();
1079 // set gobject values
1082 this.el.key_released.connect( (keyval, keycode, state) => {
1085 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1086 GLib.debug("SAVE: ctrl-S pressed");
1087 _this.saveContents();
1091 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1092 GLib.debug("SAVE: ctrl-g pressed");
1093 _this.forwardSearch(true);
1096 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1097 GLib.debug("SAVE: ctrl-f pressed");
1098 _this.search_entry.el.grab_focus();
1099 _this.search_entry.el.select_region(0,-1);
1102 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1103 _this.view.el.show_completion();
1107 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1108 var line = iter.get_line();
1109 var offset = iter.get_line_offset();
1110 GLib.debug("line %d off %d", line ,offset);
1111 if (_this.prop != null) {
1112 line += _this.prop.start_line + 1; // i think..
1113 offset += 12; // should probably be 8 without namespaced
1114 GLib.debug("guess line %d off %d", line ,offset);
1116 //_this.view.el.show_completion();
1117 // print(event.key.keyval)
1128 // user defined functions
1133 public class Xcls_Box12 : Object
1136 private Editor _this;
1142 public Xcls_Box12(Editor _owner )
1145 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1149 // set gobject values
1150 this.el.homogeneous = false;
1151 this.el.vexpand = false;
1152 new Xcls_search_entry( _this );
1153 this.el.append( _this.search_entry.el );
1154 new Xcls_search_results( _this );
1155 this.el.append( _this.search_results.el );
1156 new Xcls_nextBtn( _this );
1157 this.el.append( _this.nextBtn.el );
1158 new Xcls_backBtn( _this );
1159 this.el.append( _this.backBtn.el );
1160 var child_5 = new Xcls_MenuButton18( _this );
1162 this.el.append( child_5.el );
1165 // user defined functions
1167 public class Xcls_search_entry : Object
1169 public Gtk.SearchEntry el;
1170 private Editor _this;
1174 public Gtk.CssProvider css;
1177 public Xcls_search_entry(Editor _owner )
1180 _this.search_entry = this;
1181 this.el = new Gtk.SearchEntry();
1185 // set gobject values
1186 this.el.name = "editor-search-entry";
1187 this.el.hexpand = true;
1188 this.el.placeholder_text = "Press enter to search";
1189 this.el.search_delay = 3;
1190 var child_1 = new Xcls_EventControllerKey14( _this );
1192 this.el.add_controller( child_1.el );
1195 this.el.search_changed.connect( ( ) => {
1197 _this.search(_this.search_entry.el.text);
1198 _this.search_results.updateResults();
1200 GLib.Timeout.add_seconds(1,() => {
1201 _this.search_results.updateResults();
1207 // user defined functions
1208 public void forwardSearch (bool change_focus) {
1211 _this.forwardSearch(change_focus);
1215 switch(_this.windowstate.state) {
1216 case WindowState.State.CODEONLY:
1217 //case WindowState.State.CODE:
1218 // search the code being edited..
1219 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1222 case WindowState.State.PREVIEW:
1223 if (_this.windowstate.file.xtype == "Gtk") {
1224 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1226 _this.windowstate.window_rooview.forwardSearch(change_focus);
1235 public class Xcls_EventControllerKey14 : Object
1237 public Gtk.EventControllerKey el;
1238 private Editor _this;
1244 public Xcls_EventControllerKey14(Editor _owner )
1247 this.el = new Gtk.EventControllerKey();
1251 // set gobject values
1254 this.el.key_pressed.connect( (keyval, keycode, state) => {
1256 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1257 GLib.debug("SAVE: ctrl-g pressed");
1258 _this.forwardSearch(true);
1263 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1264 _this.forwardSearch(true);
1270 // print(event.key.keyval)
1276 // user defined functions
1280 public class Xcls_search_results : Object
1282 public Gtk.Label el;
1283 private Editor _this;
1289 public Xcls_search_results(Editor _owner )
1292 _this.search_results = this;
1293 this.el = new Gtk.Label( "No Results" );
1297 // set gobject values
1298 this.el.margin_end = 4;
1299 this.el.margin_start = 4;
1302 // user defined functions
1303 public void updateResults () {
1304 this.el.visible = true;
1306 var res = _this.searchcontext.get_occurrences_count();
1308 _this.search_results.el.label = "??? Matches";
1312 _this.nextBtn.el.sensitive = false;
1313 _this.backBtn.el.sensitive = false;
1316 _this.search_results.el.label = "%d Matches".printf(res);
1317 _this.nextBtn.el.sensitive = true;
1318 _this.backBtn.el.sensitive = true;
1321 _this.search_results.el.label = "No Matches";
1326 public class Xcls_nextBtn : Object
1328 public Gtk.Button el;
1329 private Editor _this;
1333 public bool always_show_image;
1336 public Xcls_nextBtn(Editor _owner )
1339 _this.nextBtn = this;
1340 this.el = new Gtk.Button();
1343 this.always_show_image = true;
1345 // set gobject values
1346 this.el.icon_name = "go-down";
1347 this.el.sensitive = false;
1350 this.el.clicked.connect( (event) => {
1352 _this.forwardSearch(true);
1358 // user defined functions
1361 public class Xcls_backBtn : Object
1363 public Gtk.Button el;
1364 private Editor _this;
1368 public bool always_show_image;
1371 public Xcls_backBtn(Editor _owner )
1374 _this.backBtn = this;
1375 this.el = new Gtk.Button();
1378 this.always_show_image = true;
1380 // set gobject values
1381 this.el.icon_name = "go-up";
1382 this.el.sensitive = false;
1385 this.el.clicked.connect( (event) => {
1387 _this.backSearch(true);
1392 // user defined functions
1395 public class Xcls_MenuButton18 : Object
1397 public Gtk.MenuButton el;
1398 private Editor _this;
1402 public bool always_show_image;
1405 public Xcls_MenuButton18(Editor _owner )
1408 this.el = new Gtk.MenuButton();
1411 this.always_show_image = true;
1413 // set gobject values
1414 this.el.icon_name = "emblem-system";
1415 this.el.always_show_arrow = true;
1416 new Xcls_search_settings( _this );
1417 this.el.popover = _this.search_settings.el;
1420 // user defined functions
1422 public class Xcls_search_settings : Object
1424 public Gtk.Popover el;
1425 private Editor _this;
1431 public Xcls_search_settings(Editor _owner )
1434 _this.search_settings = this;
1435 this.el = new Gtk.Popover();
1439 // set gobject values
1440 var child_1 = new Xcls_Box20( _this );
1441 this.el.child = child_1.el;
1444 // user defined functions
1446 public class Xcls_Box20 : Object
1449 private Editor _this;
1455 public Xcls_Box20(Editor _owner )
1458 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1462 // set gobject values
1463 new Xcls_case_sensitive( _this );
1464 this.el.append( _this.case_sensitive.el );
1465 new Xcls_regex( _this );
1466 this.el.append( _this.regex.el );
1467 new Xcls_multiline( _this );
1468 this.el.append( _this.multiline.el );
1471 // user defined functions
1473 public class Xcls_case_sensitive : Object
1475 public Gtk.CheckButton el;
1476 private Editor _this;
1482 public Xcls_case_sensitive(Editor _owner )
1485 _this.case_sensitive = this;
1486 this.el = new Gtk.CheckButton();
1490 // set gobject values
1491 this.el.label = "Case Sensitive";
1500 // user defined functions
1503 public class Xcls_regex : Object
1505 public Gtk.CheckButton el;
1506 private Editor _this;
1512 public Xcls_regex(Editor _owner )
1516 this.el = new Gtk.CheckButton();
1520 // set gobject values
1521 this.el.label = "Regex";
1530 // user defined functions
1533 public class Xcls_multiline : Object
1535 public Gtk.CheckButton el;
1536 private Editor _this;
1542 public Xcls_multiline(Editor _owner )
1545 _this.multiline = this;
1546 this.el = new Gtk.CheckButton();
1550 // set gobject values
1551 this.el.label = "Multi-line (add \\n)";
1554 // user defined functions