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 );
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, null);
281 buf.remove_tag_by_name ("ERR", start, end);
282 buf.remove_tag_by_name ("WARN", start, end);
283 buf.remove_tag_by_name ("DEPR", start, end);
284 this.last_error_counter = file.error_counter ;
285 //GLib.debug("highlight %s : %s has no errors", this.file.relpath, category);
290 // basicaly check if there is no change, then we do not do any update..
291 // we can do this by just using an error counter?
292 // if that's changed then we will do an update, otherwise dont bother.
298 var tlines = buf.get_line_count () +1;
300 if (_this.prop != null) {
301 // this still seems flaky...
303 tlines = _this.prop.end_line;
304 offset = _this.prop.start_line;
305 hoffset = _this.node.node_pad.length + 2; //shift it left by 2 ? ..
310 if (this.last_error_counter == file.error_counter) {
316 buf.remove_source_marks (start, end, null);
317 buf.remove_tag_by_name ("ERR", start, end);
318 buf.remove_tag_by_name ("WARN", start, end);
319 buf.remove_tag_by_name ("DEPR", start, end);
321 foreach(var diag in ar) {
323 // print("get inter\n");
324 var eline = (int)diag.range.start.line - offset;
325 var eline_to = (int)diag.range.end.line - offset;
326 //var eline = diag.range.end_line - offset;
327 //GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
328 // err.line ,eline, offset);
331 if (eline > tlines || eline < 0) {
336 buf.get_iter_at_line( out iter, eline);
337 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
338 buf.create_source_mark( msg, diag.category, iter);
340 buf.get_iter_at_line_offset( out start,
341 eline, (int)diag.range.start.character - hoffset);
342 buf.get_iter_at_line_offset( out end,
343 eline_to, (int)diag.range.end.character - hoffset);
345 buf.apply_tag_by_name(diag.category, start, end);
347 // GLib.debug("set line %d to %s", eline, msg);
348 //this.marks.set(eline, msg);
350 this.last_error_counter = file.error_counter ;
357 public void scroll_to_line (int line) {
359 GLib.Timeout.add(500, () => {
361 var buf = this.view.el.get_buffer();
363 var sbuf = (GtkSource.Buffer) buf;
367 sbuf.get_iter_at_line(out iter, line);
368 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
372 public class Xcls_Box2 : Object
375 private Editor _this;
381 public Xcls_Box2(Editor _owner )
384 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
388 // set gobject values
389 this.el.homogeneous = false;
390 this.el.hexpand = true;
391 new Xcls_save_button( _this );
392 this.el.append( _this.save_button.el );
393 var child_2 = new Xcls_Label4( _this );
395 this.el.append( child_2.el );
396 var child_3 = new Xcls_Scale5( _this );
398 this.el.append( child_3.el );
399 new Xcls_close_btn( _this );
400 this.el.append( _this.close_btn.el );
403 // user defined functions
405 public class Xcls_save_button : Object
407 public Gtk.Button el;
408 private Editor _this;
414 public Xcls_save_button(Editor _owner )
417 _this.save_button = this;
418 this.el = new Gtk.Button();
422 // set gobject values
423 this.el.label = "Save";
426 this.el.clicked.connect( () => {
427 _this.saveContents();
431 // user defined functions
434 public class Xcls_Label4 : Object
437 private Editor _this;
443 public Xcls_Label4(Editor _owner )
446 this.el = new Gtk.Label( null );
450 // set gobject values
451 this.el.hexpand = true;
454 // user defined functions
457 public class Xcls_Scale5 : Object
460 private Editor _this;
466 public Xcls_Scale5(Editor _owner )
469 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
473 // set gobject values
474 this.el.width_request = 200;
475 this.el.has_origin = true;
476 this.el.draw_value = false;
478 this.el.sensitive = true;
483 this.el.set_range(6,30);
484 this.el.set_value(8);
488 this.el.change_value.connect( (st, val ) => {
491 _this.view.css.load_from_string(
492 "#editor-view { font: %dpx monospace; }".printf((int)val)
499 // user defined functions
502 public class Xcls_close_btn : Object
504 public Gtk.Button el;
505 private Editor _this;
511 public Xcls_close_btn(Editor _owner )
514 _this.close_btn = this;
515 this.el = new Gtk.Button();
519 // set gobject values
520 this.el.icon_name = "window-close";
521 var child_1 = new Xcls_Image7( _this );
522 this.el.child = child_1.el;
525 this.el.clicked.connect( () => {
526 _this.saveContents();
527 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
531 // user defined functions
533 public class Xcls_Image7 : Object
536 private Editor _this;
542 public Xcls_Image7(Editor _owner )
545 this.el = new Gtk.Image();
549 // set gobject values
550 this.el.icon_name = "window-close";
551 this.el.icon_size = Gtk.IconSize.NORMAL;
554 // user defined functions
559 public class Xcls_RightEditor : Object
561 public Gtk.ScrolledWindow el;
562 private Editor _this;
568 public Xcls_RightEditor(Editor _owner )
571 _this.RightEditor = this;
572 this.el = new Gtk.ScrolledWindow();
576 // set gobject values
577 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
578 this.el.vexpand = true;
579 this.el.overlay_scrolling = false;
580 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
581 new Xcls_view( _this );
582 this.el.child = _this.view.el;
585 // user defined functions
587 public class Xcls_view : Object
589 public GtkSource.View el;
590 private Editor _this;
594 public Gtk.CssProvider css;
597 public Xcls_view(Editor _owner )
601 this.el = new GtkSource.View();
606 // set gobject values
607 this.el.auto_indent = true;
608 this.el.indent_width = 4;
609 this.el.name = "editor-view";
610 this.el.show_line_marks = true;
611 this.el.insert_spaces_instead_of_tabs = true;
612 this.el.show_line_numbers = true;
613 this.el.hexpand = true;
614 this.el.vexpand = true;
615 this.el.has_tooltip = true;
616 this.el.tab_width = 4;
617 this.el.highlight_current_line = true;
618 new Xcls_buffer( _this );
619 this.el.buffer = _this.buffer.el;
620 var child_2 = new Xcls_EventControllerKey11( _this );
622 this.el.add_controller( child_2.el );
626 this.css = new Gtk.CssProvider();
628 this.css.load_from_string(
629 "#editor-view { font: 12px monospace;}"
632 Gtk.StyleContext.add_provider_for_display(
633 this.el.get_display(),
635 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
640 this.el.completion.add_provider(
641 new Palete.CompletionProvider(_this)
644 //this.el.completion.unblock_interactive();
645 this.el.completion.select_on_show = true; // select
646 //this.el.completion.remember_info_visibility = true;
649 var attrs = new GtkSource.MarkAttributes();
651 attrs.set_icon_name ( "process-stop");
652 attrs.query_tooltip_text.connect(( mark) => {
653 GLib.debug("tooltip query? %s", mark.name);
654 return strdup( mark.name);
656 attrs.query_tooltip_markup.connect(( mark) => {
657 GLib.debug("tooltip query? %s", mark.name);
658 return strdup( mark.name);
660 this.el.set_mark_attributes ("ERR", attrs, 1);
664 var wattrs = new GtkSource.MarkAttributes();
665 wattrs.set_icon_name ( "process-stop");
666 wattrs.query_tooltip_text.connect(( mark) => {
667 GLib.debug("tooltip query? %s", mark.name);
668 return strdup(mark.name);
670 wattrs.query_tooltip_markup.connect(( mark) => {
671 GLib.debug("tooltip query? %s", mark.name);
672 return strdup(mark.name);
674 this.el.set_mark_attributes ("WARN", wattrs, 1);
678 var dattrs = new GtkSource.MarkAttributes();
680 dattrs.set_icon_name ( "process-stop");
682 dattrs.query_tooltip_text.connect(( mark) => {
683 GLib.debug("tooltip query? %s", mark.name);
684 return strdup(mark.name);
686 //dattrs.query_tooltip_markup.connect(( mark) => {
687 // GLib.debug("tooltip query? %s", mark.name);
688 // return strdup(mark.name);
690 this.el.set_mark_attributes ("DEPR", dattrs, 1);
693 this.el.get_space_drawer().set_matrix(null);
694 this.el.get_space_drawer().set_types_for_locations(
695 GtkSource.SpaceLocationFlags.ALL,
696 GtkSource.SpaceTypeFlags.ALL
698 this.el.get_space_drawer().set_enable_matrix(true);
701 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
703 //GLib.debug("query tooltip");
707 var yoff = (int) _this.RightEditor.el.vadjustment.value;
709 // I think this is problematic - if it's compliing / updating at same time as query.
711 //if (_this.window.statusbar_compile_spinner.el.spinning) {
715 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
717 var l = iter.get_line();
721 // GLib.debug("query tooltip line %d", (int) l);
727 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
728 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
729 tooltip.set_text(_this.buffer.marks.get(l).dup());
737 // this crashes?? - not sure why.
738 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
739 if (marks.is_empty()) {
740 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
742 if (marks.is_empty()) {
743 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
746 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
748 marks.@foreach((m) => {
749 //GLib.debug("got mark %s", m.name);
750 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
752 // true if there is a mark..
753 if (str.length > 0 ) {
754 tooltip.set_text( str );
756 return str.length > 0 ? true : false;
761 // user defined functions
762 public void load (string str) {
764 // show the help page for the active node..
765 //this.get('/Help').show();
767 // this.get('/BottomPane').el.set_current_page(0);
768 GLib.debug("load called - Reset undo buffer");
770 var buf = (GtkSource.Buffer)this.el.get_buffer();
771 buf.begin_irreversible_action();
772 buf.set_text(str, str.length);
773 buf.end_irreversible_action();
775 var lm = GtkSource.LanguageManager.get_default();
777 if (_this.file != null) {
778 lang = _this.file.language;
780 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
781 var lg = _this.file.content_type.length > 0 ?
782 lm.guess_language(_this.file.path, _this.file.content_type) :
783 lm.get_language(lang);
786 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
788 this.el.insert_spaces_instead_of_tabs = true;
790 print("sourcelanguage = %s\n", lg.name);
791 if (lg.name == "Vala") {
792 this.el.insert_spaces_instead_of_tabs = false;
796 this.el.grab_focus();
797 _this.save_button.el.sensitive = false;
798 _this.last_error_counter = -1;
801 public class Xcls_buffer : Object
803 public GtkSource.Buffer el;
804 private Editor _this;
808 public int error_line;
809 public Gee.HashMap<int,string>? xmarks;
810 public bool check_queued;
813 public Xcls_buffer(Editor _owner )
817 this.el = new GtkSource.Buffer( null );
820 this.error_line = -1;
822 this.check_queued = false;
824 // set gobject values
825 this.el.highlight_syntax = true;
826 this.el.highlight_matching_brackets = true;
827 this.el.enable_undo = true;
832 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
833 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
834 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
835 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
836 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
837 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
838 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
839 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
842 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
843 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
844 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
847 this.el.changed.connect( () => {
850 _this.save_button.el.sensitive = true;
851 print("EDITOR CHANGED");
856 // this.get('/LeftPanel.model').changed( str , false);
861 // user defined functions
862 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
865 this.el.get_bounds (out start, out end);
867 this.el.remove_source_marks (start, end, type);
868 GLib.debug("highlight errors");
870 // we should highlight other types of errors..
872 if (!obj.has_member(type)) {
873 GLib.debug("Return has no errors\n");
877 if (_this.window.windowstate.state != WindowState.State.CODEONLY
879 _this.window.windowstate.state != WindowState.State.CODE
881 GLib.debug("windowstate != CODEONLY?");
886 //this.marks = new Gee.HashMap<int,string>();
887 var err = obj.get_object_member(type);
889 if (_this.file == null) {
890 GLib.debug("file is null?");
894 var valafn = _this.file.path;
896 if (_this.file.xtype != "PlainFile") {
900 var regex = new Regex("\\.bjs$");
902 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
903 } catch (GLib.RegexError e) {
910 if (!err.has_member(valafn)) {
911 GLib.debug("File path has no errors");
915 var lines = err.get_object_member(valafn);
918 if (obj.has_member("line_offset")) { // ?? why??
919 offset = (int)obj.get_int_member("line_offset") + 1;
923 var tlines = this.el.get_line_count () +1;
925 if (_this.prop != null) {
927 tlines = _this.prop.end_line + 1;
928 offset = _this.prop.start_line + 1;
934 lines.foreach_member((obj, line, node) => {
937 // print("get inter\n");
938 var eline = int.parse(line) - offset;
939 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
942 if (eline > tlines || eline < 0) {
947 this.el.get_iter_at_line( out iter, eline);
948 //print("mark line\n");
950 var ar = lines.get_array_member(line);
951 for (var i = 0 ; i < ar.get_length(); i++) {
952 if (ar.get_string_element(i) == "Success") {
955 msg += (msg.length > 0) ? "\n" : "";
956 msg += ar.get_string_element(i);
961 msg = "Line: %d".printf(eline+1) + " " + msg;
962 this.el.create_source_mark(msg, type, iter);
963 GLib.debug("set line %d to %m", eline, msg);
964 // this.marks.set(eline, msg);
973 public bool checkSyntax () {
976 var str = this.toString();
979 if (this.error_line > 0) {
982 this.el.get_bounds (out start, out end);
984 this.el.remove_source_marks (start, end, null);
986 if (str.length < 1) {
987 print("checkSyntax - empty string?\n");
992 if (_this.file.xtype == "PlainFile") {
994 // assume it's gtk...
995 var oldcode =_this.file.toSource();
996 _this.file.setSource(str);
997 BuilderApplication.showSpinner("appointment soon","document change pending");
998 _this.file.getLanguageServer().document_change(_this.file);
1000 _this.file.setSource(oldcode);
1006 if (_this.file == null) {
1014 GLib.debug("calling validate");
1015 // clear the buttons.
1016 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1019 var oldcode = _this.prop.val;
1021 _this.prop.val = str;
1022 _this.node.updated_count++;
1023 _this.file.getLanguageServer().document_change(_this.file);
1024 _this.node.updated_count++;
1025 _this.prop.val = oldcode;
1028 //print("done mark line\n");
1030 return true; // at present allow saving - even if it's invalid..
1032 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1034 this.error_line = validate_res.size;
1036 if (this.error_line < 1) {
1039 var tlines = this.el.get_line_count ();
1041 var valiter = validate_res.map_iterator();
1042 while (valiter.next()) {
1044 // print("get inter\n");
1045 var eline = valiter.get_key();
1046 if (eline > tlines) {
1049 this.el.get_iter_at_line( out iter, eline);
1050 //print("mark line\n");
1051 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1055 public string toString () {
1059 this.el.get_start_iter(out s);
1060 this.el.get_end_iter(out e);
1061 var ret = this.el.get_text(s,e,true);
1062 //print("TO STRING? " + ret);
1067 public class Xcls_EventControllerKey11 : Object
1069 public Gtk.EventControllerKey el;
1070 private Editor _this;
1076 public Xcls_EventControllerKey11(Editor _owner )
1079 this.el = new Gtk.EventControllerKey();
1083 // set gobject values
1086 this.el.key_released.connect( (keyval, keycode, state) => {
1089 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1090 GLib.debug("SAVE: ctrl-S pressed");
1091 _this.saveContents();
1095 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1096 GLib.debug("SAVE: ctrl-g pressed");
1097 _this.forwardSearch(true);
1100 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1101 GLib.debug("SAVE: ctrl-f pressed");
1102 _this.search_entry.el.grab_focus();
1103 _this.search_entry.el.select_region(0,-1);
1106 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1107 _this.view.el.show_completion();
1111 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1112 var line = iter.get_line();
1113 var offset = iter.get_line_offset();
1114 GLib.debug("line %d off %d", line ,offset);
1115 if (_this.prop != null) {
1116 line += _this.prop.start_line + 1; // i think..
1117 offset += 12; // should probably be 8 without namespaced
1118 GLib.debug("guess line %d off %d", line ,offset);
1120 //_this.view.el.show_completion();
1121 // print(event.key.keyval)
1132 // user defined functions
1137 public class Xcls_Box12 : Object
1140 private Editor _this;
1146 public Xcls_Box12(Editor _owner )
1149 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1153 // set gobject values
1154 this.el.homogeneous = false;
1155 this.el.vexpand = false;
1156 new Xcls_search_entry( _this );
1157 this.el.append( _this.search_entry.el );
1158 new Xcls_search_results( _this );
1159 this.el.append( _this.search_results.el );
1160 new Xcls_nextBtn( _this );
1161 this.el.append( _this.nextBtn.el );
1162 new Xcls_backBtn( _this );
1163 this.el.append( _this.backBtn.el );
1164 var child_5 = new Xcls_MenuButton18( _this );
1166 this.el.append( child_5.el );
1169 // user defined functions
1171 public class Xcls_search_entry : Object
1173 public Gtk.SearchEntry el;
1174 private Editor _this;
1178 public Gtk.CssProvider css;
1181 public Xcls_search_entry(Editor _owner )
1184 _this.search_entry = this;
1185 this.el = new Gtk.SearchEntry();
1189 // set gobject values
1190 this.el.name = "editor-search-entry";
1191 this.el.hexpand = true;
1192 this.el.placeholder_text = "Press enter to search";
1193 this.el.search_delay = 3;
1194 var child_1 = new Xcls_EventControllerKey14( _this );
1196 this.el.add_controller( child_1.el );
1199 this.el.search_changed.connect( ( ) => {
1201 _this.search(_this.search_entry.el.text);
1202 _this.search_results.updateResults();
1204 GLib.Timeout.add_seconds(1,() => {
1205 _this.search_results.updateResults();
1211 // user defined functions
1212 public void forwardSearch (bool change_focus) {
1215 _this.forwardSearch(change_focus);
1219 switch(_this.windowstate.state) {
1220 case WindowState.State.CODEONLY:
1221 //case WindowState.State.CODE:
1222 // search the code being edited..
1223 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1226 case WindowState.State.PREVIEW:
1227 if (_this.windowstate.file.xtype == "Gtk") {
1228 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1230 _this.windowstate.window_rooview.forwardSearch(change_focus);
1239 public class Xcls_EventControllerKey14 : Object
1241 public Gtk.EventControllerKey el;
1242 private Editor _this;
1248 public Xcls_EventControllerKey14(Editor _owner )
1251 this.el = new Gtk.EventControllerKey();
1255 // set gobject values
1258 this.el.key_pressed.connect( (keyval, keycode, state) => {
1260 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1261 GLib.debug("SAVE: ctrl-g pressed");
1262 _this.forwardSearch(true);
1267 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1268 _this.forwardSearch(true);
1274 // print(event.key.keyval)
1280 // user defined functions
1284 public class Xcls_search_results : Object
1286 public Gtk.Label el;
1287 private Editor _this;
1293 public Xcls_search_results(Editor _owner )
1296 _this.search_results = this;
1297 this.el = new Gtk.Label( "No Results" );
1301 // set gobject values
1302 this.el.margin_end = 4;
1303 this.el.margin_start = 4;
1306 // user defined functions
1307 public void updateResults () {
1308 this.el.visible = true;
1310 var res = _this.searchcontext.get_occurrences_count();
1312 _this.search_results.el.label = "??? Matches";
1316 _this.nextBtn.el.sensitive = false;
1317 _this.backBtn.el.sensitive = false;
1320 _this.search_results.el.label = "%d Matches".printf(res);
1321 _this.nextBtn.el.sensitive = true;
1322 _this.backBtn.el.sensitive = true;
1325 _this.search_results.el.label = "No Matches";
1330 public class Xcls_nextBtn : Object
1332 public Gtk.Button el;
1333 private Editor _this;
1337 public bool always_show_image;
1340 public Xcls_nextBtn(Editor _owner )
1343 _this.nextBtn = this;
1344 this.el = new Gtk.Button();
1347 this.always_show_image = true;
1349 // set gobject values
1350 this.el.icon_name = "go-down";
1351 this.el.sensitive = false;
1354 this.el.clicked.connect( (event) => {
1356 _this.forwardSearch(true);
1362 // user defined functions
1365 public class Xcls_backBtn : Object
1367 public Gtk.Button el;
1368 private Editor _this;
1372 public bool always_show_image;
1375 public Xcls_backBtn(Editor _owner )
1378 _this.backBtn = this;
1379 this.el = new Gtk.Button();
1382 this.always_show_image = true;
1384 // set gobject values
1385 this.el.icon_name = "go-up";
1386 this.el.sensitive = false;
1389 this.el.clicked.connect( (event) => {
1391 _this.backSearch(true);
1396 // user defined functions
1399 public class Xcls_MenuButton18 : Object
1401 public Gtk.MenuButton el;
1402 private Editor _this;
1406 public bool always_show_image;
1409 public Xcls_MenuButton18(Editor _owner )
1412 this.el = new Gtk.MenuButton();
1415 this.always_show_image = true;
1417 // set gobject values
1418 this.el.icon_name = "emblem-system";
1419 this.el.always_show_arrow = true;
1420 new Xcls_search_settings( _this );
1421 this.el.popover = _this.search_settings.el;
1424 // user defined functions
1426 public class Xcls_search_settings : Object
1428 public Gtk.Popover el;
1429 private Editor _this;
1435 public Xcls_search_settings(Editor _owner )
1438 _this.search_settings = this;
1439 this.el = new Gtk.Popover();
1443 // set gobject values
1444 var child_1 = new Xcls_Box20( _this );
1445 this.el.child = child_1.el;
1448 // user defined functions
1450 public class Xcls_Box20 : Object
1453 private Editor _this;
1459 public Xcls_Box20(Editor _owner )
1462 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1466 // set gobject values
1467 new Xcls_case_sensitive( _this );
1468 this.el.append( _this.case_sensitive.el );
1469 new Xcls_regex( _this );
1470 this.el.append( _this.regex.el );
1471 new Xcls_multiline( _this );
1472 this.el.append( _this.multiline.el );
1475 // user defined functions
1477 public class Xcls_case_sensitive : Object
1479 public Gtk.CheckButton el;
1480 private Editor _this;
1486 public Xcls_case_sensitive(Editor _owner )
1489 _this.case_sensitive = this;
1490 this.el = new Gtk.CheckButton();
1494 // set gobject values
1495 this.el.label = "Case Sensitive";
1504 // user defined functions
1507 public class Xcls_regex : Object
1509 public Gtk.CheckButton el;
1510 private Editor _this;
1516 public Xcls_regex(Editor _owner )
1520 this.el = new Gtk.CheckButton();
1524 // set gobject values
1525 this.el.label = "Regex";
1534 // user defined functions
1537 public class Xcls_multiline : Object
1539 public Gtk.CheckButton el;
1540 private Editor _this;
1546 public Xcls_multiline(Editor _owner )
1549 _this.multiline = this;
1550 this.el = new Gtk.CheckButton();
1554 // set gobject values
1555 this.el.label = "Multi-line (add \\n)";
1558 // user defined functions