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) {
335 buf.get_iter_at_line( out iter, eline);
336 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
337 buf.create_source_mark( msg, diag.category, iter);
339 var spos = (int)diag.range.start.character - hoffset;
340 if (spos < 0) { spos =0 ; }
341 if (spos > iter.get_chars_in_line()) {
342 spos = iter.get_chars_in_line();
344 buf.get_iter_at_line( out iter, eline_to);
345 var epos = (int)diag.range.end.character - hoffset;
346 if (epos < 0) { epos =0 ; }
347 if (epos > iter.get_chars_in_line()) {
348 epos = iter.get_chars_in_line();
352 buf.get_iter_at_line_offset( out start, eline, spos);
354 buf.get_iter_at_line_offset( out end, eline_to,epos);
356 buf.apply_tag_by_name(diag.category, start, end);
358 // GLib.debug("set line %d to %s", eline, msg);
359 //this.marks.set(eline, msg);
361 this.last_error_counter = file.error_counter ;
368 public void scroll_to_line (int line) {
370 GLib.Timeout.add(500, () => {
372 var buf = this.view.el.get_buffer();
374 var sbuf = (GtkSource.Buffer) buf;
378 sbuf.get_iter_at_line(out iter, line);
379 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
383 public class Xcls_Box2 : Object
386 private Editor _this;
392 public Xcls_Box2(Editor _owner )
395 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
399 // set gobject values
400 this.el.homogeneous = false;
401 this.el.hexpand = true;
402 new Xcls_save_button( _this );
403 this.el.append( _this.save_button.el );
404 var child_2 = new Xcls_Label4( _this );
406 this.el.append( child_2.el );
407 var child_3 = new Xcls_Scale5( _this );
409 this.el.append( child_3.el );
410 new Xcls_close_btn( _this );
411 this.el.append( _this.close_btn.el );
414 // user defined functions
416 public class Xcls_save_button : Object
418 public Gtk.Button el;
419 private Editor _this;
425 public Xcls_save_button(Editor _owner )
428 _this.save_button = this;
429 this.el = new Gtk.Button();
433 // set gobject values
434 this.el.label = "Save";
437 this.el.clicked.connect( () => {
438 _this.saveContents();
442 // user defined functions
445 public class Xcls_Label4 : Object
448 private Editor _this;
454 public Xcls_Label4(Editor _owner )
457 this.el = new Gtk.Label( null );
461 // set gobject values
462 this.el.hexpand = true;
465 // user defined functions
468 public class Xcls_Scale5 : Object
471 private Editor _this;
477 public Xcls_Scale5(Editor _owner )
480 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
484 // set gobject values
485 this.el.width_request = 200;
486 this.el.has_origin = true;
487 this.el.draw_value = false;
489 this.el.sensitive = true;
494 this.el.set_range(6,30);
495 this.el.set_value(8);
499 this.el.change_value.connect( (st, val ) => {
502 _this.view.css.load_from_string(
503 "#editor-view { font: %dpx monospace; }".printf((int)val)
510 // user defined functions
513 public class Xcls_close_btn : Object
515 public Gtk.Button el;
516 private Editor _this;
522 public Xcls_close_btn(Editor _owner )
525 _this.close_btn = this;
526 this.el = new Gtk.Button();
530 // set gobject values
531 this.el.icon_name = "window-close";
532 var child_1 = new Xcls_Image7( _this );
533 this.el.child = child_1.el;
536 this.el.clicked.connect( () => {
537 _this.saveContents();
538 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
542 // user defined functions
544 public class Xcls_Image7 : Object
547 private Editor _this;
553 public Xcls_Image7(Editor _owner )
556 this.el = new Gtk.Image();
560 // set gobject values
561 this.el.icon_name = "window-close";
562 this.el.icon_size = Gtk.IconSize.NORMAL;
565 // user defined functions
570 public class Xcls_RightEditor : Object
572 public Gtk.ScrolledWindow el;
573 private Editor _this;
579 public Xcls_RightEditor(Editor _owner )
582 _this.RightEditor = this;
583 this.el = new Gtk.ScrolledWindow();
587 // set gobject values
588 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
589 this.el.vexpand = true;
590 this.el.overlay_scrolling = false;
591 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
592 new Xcls_view( _this );
593 this.el.child = _this.view.el;
596 // user defined functions
598 public class Xcls_view : Object
600 public GtkSource.View el;
601 private Editor _this;
605 public Gtk.CssProvider css;
608 public Xcls_view(Editor _owner )
612 this.el = new GtkSource.View();
617 // set gobject values
618 this.el.auto_indent = true;
619 this.el.indent_width = 4;
620 this.el.name = "editor-view";
621 this.el.show_line_marks = true;
622 this.el.insert_spaces_instead_of_tabs = true;
623 this.el.show_line_numbers = true;
624 this.el.hexpand = true;
625 this.el.vexpand = true;
626 this.el.has_tooltip = true;
627 this.el.tab_width = 4;
628 this.el.highlight_current_line = true;
629 new Xcls_buffer( _this );
630 this.el.buffer = _this.buffer.el;
631 var child_2 = new Xcls_EventControllerKey11( _this );
633 this.el.add_controller( child_2.el );
637 this.css = new Gtk.CssProvider();
639 this.css.load_from_string(
640 "#editor-view { font: 12px monospace;}"
643 Gtk.StyleContext.add_provider_for_display(
644 this.el.get_display(),
646 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
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_EventControllerKey11 : Object
1080 public Gtk.EventControllerKey el;
1081 private Editor _this;
1087 public Xcls_EventControllerKey11(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_Box12 : Object
1151 private Editor _this;
1157 public Xcls_Box12(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_MenuButton18( _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_EventControllerKey14( _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_EventControllerKey14 : Object
1252 public Gtk.EventControllerKey el;
1253 private Editor _this;
1259 public Xcls_EventControllerKey14(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_MenuButton18 : Object
1412 public Gtk.MenuButton el;
1413 private Editor _this;
1417 public bool always_show_image;
1420 public Xcls_MenuButton18(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_Box20( _this );
1456 this.el.child = child_1.el;
1459 // user defined functions
1461 public class Xcls_Box20 : Object
1464 private Editor _this;
1470 public Xcls_Box20(Editor _owner )
1473 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1477 // set gobject values
1478 new Xcls_case_sensitive( _this );
1479 this.el.append( _this.case_sensitive.el );
1480 new Xcls_regex( _this );
1481 this.el.append( _this.regex.el );
1482 new Xcls_multiline( _this );
1483 this.el.append( _this.multiline.el );
1486 // user defined functions
1488 public class Xcls_case_sensitive : Object
1490 public Gtk.CheckButton el;
1491 private Editor _this;
1497 public Xcls_case_sensitive(Editor _owner )
1500 _this.case_sensitive = this;
1501 this.el = new Gtk.CheckButton();
1505 // set gobject values
1506 this.el.label = "Case Sensitive";
1515 // user defined functions
1518 public class Xcls_regex : Object
1520 public Gtk.CheckButton el;
1521 private Editor _this;
1527 public Xcls_regex(Editor _owner )
1531 this.el = new Gtk.CheckButton();
1535 // set gobject values
1536 this.el.label = "Regex";
1545 // user defined functions
1548 public class Xcls_multiline : Object
1550 public Gtk.CheckButton el;
1551 private Editor _this;
1557 public Xcls_multiline(Editor _owner )
1560 _this.multiline = this;
1561 this.el = new Gtk.CheckButton();
1565 // set gobject values
1566 this.el.label = "Multi-line (add \\n)";
1569 // user defined functions