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, "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_Box2 : Object
390 private Editor _this;
396 public Xcls_Box2(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_Label4( _this );
410 this.el.append( child_2.el );
411 var child_3 = new Xcls_Scale5( _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_Label4 : Object
452 private Editor _this;
458 public Xcls_Label4(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_Scale5 : Object
475 private Editor _this;
481 public Xcls_Scale5(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(8);
503 this.el.change_value.connect( (st, val ) => {
506 _this.view.css.load_from_string(
507 "#editor-view { font: %dpx monospace; }".printf((int)val)
514 // user defined functions
517 public class Xcls_close_btn : Object
519 public Gtk.Button el;
520 private Editor _this;
526 public Xcls_close_btn(Editor _owner )
529 _this.close_btn = this;
530 this.el = new Gtk.Button();
534 // set gobject values
535 this.el.icon_name = "window-close";
536 var child_1 = new Xcls_Image7( _this );
537 this.el.child = child_1.el;
540 this.el.clicked.connect( () => {
541 _this.saveContents();
542 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
546 // user defined functions
548 public class Xcls_Image7 : Object
551 private Editor _this;
557 public Xcls_Image7(Editor _owner )
560 this.el = new Gtk.Image();
564 // set gobject values
565 this.el.icon_name = "window-close";
566 this.el.icon_size = Gtk.IconSize.NORMAL;
569 // user defined functions
574 public class Xcls_RightEditor : Object
576 public Gtk.ScrolledWindow el;
577 private Editor _this;
583 public Xcls_RightEditor(Editor _owner )
586 _this.RightEditor = this;
587 this.el = new Gtk.ScrolledWindow();
591 // set gobject values
592 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
593 this.el.vexpand = true;
594 this.el.overlay_scrolling = false;
595 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
596 new Xcls_view( _this );
597 this.el.child = _this.view.el;
600 // user defined functions
602 public class Xcls_view : Object
604 public GtkSource.View el;
605 private Editor _this;
609 public Gtk.CssProvider css;
612 public Xcls_view(Editor _owner )
616 this.el = new GtkSource.View();
621 // set gobject values
622 this.el.auto_indent = true;
623 this.el.indent_width = 4;
624 this.el.name = "editor-view";
625 this.el.show_line_marks = true;
626 this.el.insert_spaces_instead_of_tabs = true;
627 this.el.show_line_numbers = true;
628 this.el.hexpand = true;
629 this.el.vexpand = true;
630 this.el.has_tooltip = true;
631 this.el.tab_width = 4;
632 this.el.highlight_current_line = true;
633 new Xcls_buffer( _this );
634 this.el.buffer = _this.buffer.el;
635 var child_2 = new Xcls_EventControllerKey11( _this );
637 this.el.add_controller( child_2.el );
641 this.css = new Gtk.CssProvider();
643 this.css.load_from_string(
644 "#editor-view { font: 12px monospace;}"
647 Gtk.StyleContext.add_provider_for_display(
648 this.el.get_display(),
650 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
655 this.el.completion.add_provider(
656 new Palete.CompletionProvider(_this)
659 //this.el.completion.unblock_interactive();
660 this.el.completion.select_on_show = true; // select
661 //this.el.completion.remember_info_visibility = true;
664 var attrs = new GtkSource.MarkAttributes();
666 attrs.set_icon_name ( "process-stop");
667 attrs.query_tooltip_text.connect(( mark) => {
668 GLib.debug("tooltip query? %s", mark.name);
669 return strdup( mark.name);
671 attrs.query_tooltip_markup.connect(( mark) => {
672 GLib.debug("tooltip query? %s", mark.name);
673 return strdup( mark.name);
675 this.el.set_mark_attributes ("ERR", attrs, 1);
679 var wattrs = new GtkSource.MarkAttributes();
680 wattrs.set_icon_name ( "process-stop");
681 wattrs.query_tooltip_text.connect(( mark) => {
682 GLib.debug("tooltip query? %s", mark.name);
683 return strdup(mark.name);
685 wattrs.query_tooltip_markup.connect(( mark) => {
686 GLib.debug("tooltip query? %s", mark.name);
687 return strdup(mark.name);
689 this.el.set_mark_attributes ("WARN", wattrs, 1);
693 var dattrs = new GtkSource.MarkAttributes();
695 dattrs.set_icon_name ( "process-stop");
697 dattrs.query_tooltip_text.connect(( mark) => {
698 GLib.debug("tooltip query? %s", mark.name);
699 return strdup(mark.name);
701 //dattrs.query_tooltip_markup.connect(( mark) => {
702 // GLib.debug("tooltip query? %s", mark.name);
703 // return strdup(mark.name);
705 this.el.set_mark_attributes ("DEPR", dattrs, 1);
708 this.el.get_space_drawer().set_matrix(null);
709 this.el.get_space_drawer().set_types_for_locations(
710 GtkSource.SpaceLocationFlags.ALL,
711 GtkSource.SpaceTypeFlags.ALL
713 this.el.get_space_drawer().set_enable_matrix(true);
716 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
718 //GLib.debug("query tooltip");
722 var yoff = (int) _this.RightEditor.el.vadjustment.value;
724 // I think this is problematic - if it's compliing / updating at same time as query.
726 //if (_this.window.statusbar_compile_spinner.el.spinning) {
730 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
732 var l = iter.get_line();
736 // GLib.debug("query tooltip line %d", (int) l);
742 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
743 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
744 tooltip.set_text(_this.buffer.marks.get(l).dup());
752 // this crashes?? - not sure why.
753 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
754 if (marks.is_empty()) {
755 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
757 if (marks.is_empty()) {
758 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
761 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
763 marks.@foreach((m) => {
764 //GLib.debug("got mark %s", m.name);
765 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
767 // true if there is a mark..
768 if (str.length > 0 ) {
769 tooltip.set_text( str );
771 return str.length > 0 ? true : false;
776 // user defined functions
777 public void load (string str) {
779 // show the help page for the active node..
780 //this.get('/Help').show();
782 // this.get('/BottomPane').el.set_current_page(0);
783 GLib.debug("load called - Reset undo buffer");
785 var buf = (GtkSource.Buffer)this.el.get_buffer();
786 buf.begin_irreversible_action();
787 buf.set_text(str, str.length);
788 buf.end_irreversible_action();
790 var lm = GtkSource.LanguageManager.get_default();
792 if (_this.file != null) {
793 lang = _this.file.language;
795 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
796 var lg = _this.file.content_type.length > 0 ?
797 lm.guess_language(_this.file.path, _this.file.content_type) :
798 lm.get_language(lang);
801 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
803 this.el.insert_spaces_instead_of_tabs = true;
805 print("sourcelanguage = %s\n", lg.name);
806 if (lg.name == "Vala") {
807 this.el.insert_spaces_instead_of_tabs = false;
811 this.el.grab_focus();
812 _this.save_button.el.sensitive = false;
813 _this.last_error_counter = -1;
816 public class Xcls_buffer : Object
818 public GtkSource.Buffer el;
819 private Editor _this;
823 public int error_line;
824 public Gee.HashMap<int,string>? xmarks;
825 public bool check_queued;
828 public Xcls_buffer(Editor _owner )
832 this.el = new GtkSource.Buffer( null );
835 this.error_line = -1;
837 this.check_queued = false;
839 // set gobject values
840 this.el.highlight_syntax = true;
841 this.el.highlight_matching_brackets = true;
842 this.el.enable_undo = true;
847 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
848 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
849 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
850 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
851 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
852 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
853 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
854 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
857 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
858 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
859 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
862 this.el.changed.connect( () => {
865 _this.save_button.el.sensitive = true;
866 print("EDITOR CHANGED");
871 // this.get('/LeftPanel.model').changed( str , false);
876 // user defined functions
877 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
880 this.el.get_bounds (out start, out end);
882 this.el.remove_source_marks (start, end, type);
883 GLib.debug("highlight errors");
885 // we should highlight other types of errors..
887 if (!obj.has_member(type)) {
888 GLib.debug("Return has no errors\n");
892 if (_this.window.windowstate.state != WindowState.State.CODEONLY
894 _this.window.windowstate.state != WindowState.State.CODE
896 GLib.debug("windowstate != CODEONLY?");
901 //this.marks = new Gee.HashMap<int,string>();
902 var err = obj.get_object_member(type);
904 if (_this.file == null) {
905 GLib.debug("file is null?");
909 var valafn = _this.file.path;
911 if (_this.file.xtype != "PlainFile") {
915 var regex = new Regex("\\.bjs$");
917 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
918 } catch (GLib.RegexError e) {
925 if (!err.has_member(valafn)) {
926 GLib.debug("File path has no errors");
930 var lines = err.get_object_member(valafn);
933 if (obj.has_member("line_offset")) { // ?? why??
934 offset = (int)obj.get_int_member("line_offset") + 1;
938 var tlines = this.el.get_line_count () +1;
940 if (_this.prop != null) {
942 tlines = _this.prop.end_line + 1;
943 offset = _this.prop.start_line + 1;
949 lines.foreach_member((obj, line, node) => {
952 // print("get inter\n");
953 var eline = int.parse(line) - offset;
954 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
957 if (eline > tlines || eline < 0) {
962 this.el.get_iter_at_line( out iter, eline);
963 //print("mark line\n");
965 var ar = lines.get_array_member(line);
966 for (var i = 0 ; i < ar.get_length(); i++) {
967 if (ar.get_string_element(i) == "Success") {
970 msg += (msg.length > 0) ? "\n" : "";
971 msg += ar.get_string_element(i);
976 msg = "Line: %d".printf(eline+1) + " " + msg;
977 this.el.create_source_mark(msg, type, iter);
978 GLib.debug("set line %d to %m", eline, msg);
979 // this.marks.set(eline, msg);
988 public bool checkSyntax () {
991 var str = this.toString();
994 if (this.error_line > 0) {
997 this.el.get_bounds (out start, out end);
999 this.el.remove_source_marks (start, end, null);
1001 if (str.length < 1) {
1002 print("checkSyntax - empty string?\n");
1007 if (_this.file.xtype == "PlainFile") {
1009 // assume it's gtk...
1010 var oldcode =_this.file.toSource();
1011 _this.file.setSource(str);
1012 BuilderApplication.showSpinner("appointment soon","document change pending");
1013 _this.file.getLanguageServer().document_change(_this.file);
1015 _this.file.setSource(oldcode);
1021 if (_this.file == null) {
1029 GLib.debug("calling validate");
1030 // clear the buttons.
1031 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1034 var oldcode = _this.prop.val;
1036 _this.prop.val = str;
1037 _this.node.updated_count++;
1038 _this.file.getLanguageServer().document_change(_this.file);
1039 _this.node.updated_count++;
1040 _this.prop.val = oldcode;
1043 //print("done mark line\n");
1045 return true; // at present allow saving - even if it's invalid..
1047 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1049 this.error_line = validate_res.size;
1051 if (this.error_line < 1) {
1054 var tlines = this.el.get_line_count ();
1056 var valiter = validate_res.map_iterator();
1057 while (valiter.next()) {
1059 // print("get inter\n");
1060 var eline = valiter.get_key();
1061 if (eline > tlines) {
1064 this.el.get_iter_at_line( out iter, eline);
1065 //print("mark line\n");
1066 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1070 public string toString () {
1074 this.el.get_start_iter(out s);
1075 this.el.get_end_iter(out e);
1076 var ret = this.el.get_text(s,e,true);
1077 //print("TO STRING? " + ret);
1082 public class Xcls_EventControllerKey11 : Object
1084 public Gtk.EventControllerKey el;
1085 private Editor _this;
1091 public Xcls_EventControllerKey11(Editor _owner )
1094 this.el = new Gtk.EventControllerKey();
1098 // set gobject values
1101 this.el.key_released.connect( (keyval, keycode, state) => {
1104 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1105 GLib.debug("SAVE: ctrl-S pressed");
1106 _this.saveContents();
1110 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1111 GLib.debug("SAVE: ctrl-g pressed");
1112 _this.forwardSearch(true);
1115 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1116 GLib.debug("SAVE: ctrl-f pressed");
1117 _this.search_entry.el.grab_focus();
1118 _this.search_entry.el.select_region(0,-1);
1121 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1122 _this.view.el.show_completion();
1126 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1127 var line = iter.get_line();
1128 var offset = iter.get_line_offset();
1129 GLib.debug("line %d off %d", line ,offset);
1130 if (_this.prop != null) {
1131 line += _this.prop.start_line + 1; // i think..
1132 offset += 12; // should probably be 8 without namespaced
1133 GLib.debug("guess line %d off %d", line ,offset);
1135 //_this.view.el.show_completion();
1136 // print(event.key.keyval)
1147 // user defined functions
1152 public class Xcls_Box12 : Object
1155 private Editor _this;
1161 public Xcls_Box12(Editor _owner )
1164 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1168 // set gobject values
1169 this.el.homogeneous = false;
1170 this.el.vexpand = false;
1171 new Xcls_search_entry( _this );
1172 this.el.append( _this.search_entry.el );
1173 new Xcls_search_results( _this );
1174 this.el.append( _this.search_results.el );
1175 new Xcls_nextBtn( _this );
1176 this.el.append( _this.nextBtn.el );
1177 new Xcls_backBtn( _this );
1178 this.el.append( _this.backBtn.el );
1179 var child_5 = new Xcls_MenuButton18( _this );
1181 this.el.append( child_5.el );
1184 // user defined functions
1186 public class Xcls_search_entry : Object
1188 public Gtk.SearchEntry el;
1189 private Editor _this;
1193 public Gtk.CssProvider css;
1196 public Xcls_search_entry(Editor _owner )
1199 _this.search_entry = this;
1200 this.el = new Gtk.SearchEntry();
1204 // set gobject values
1205 this.el.name = "editor-search-entry";
1206 this.el.hexpand = true;
1207 this.el.placeholder_text = "Press enter to search";
1208 this.el.search_delay = 3;
1209 var child_1 = new Xcls_EventControllerKey14( _this );
1211 this.el.add_controller( child_1.el );
1214 this.el.search_changed.connect( ( ) => {
1216 _this.search(_this.search_entry.el.text);
1217 _this.search_results.updateResults();
1219 GLib.Timeout.add_seconds(1,() => {
1220 _this.search_results.updateResults();
1226 // user defined functions
1227 public void forwardSearch (bool change_focus) {
1230 _this.forwardSearch(change_focus);
1234 switch(_this.windowstate.state) {
1235 case WindowState.State.CODEONLY:
1236 //case WindowState.State.CODE:
1237 // search the code being edited..
1238 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1241 case WindowState.State.PREVIEW:
1242 if (_this.windowstate.file.xtype == "Gtk") {
1243 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1245 _this.windowstate.window_rooview.forwardSearch(change_focus);
1254 public class Xcls_EventControllerKey14 : Object
1256 public Gtk.EventControllerKey el;
1257 private Editor _this;
1263 public Xcls_EventControllerKey14(Editor _owner )
1266 this.el = new Gtk.EventControllerKey();
1270 // set gobject values
1273 this.el.key_pressed.connect( (keyval, keycode, state) => {
1275 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1276 GLib.debug("SAVE: ctrl-g pressed");
1277 _this.forwardSearch(true);
1282 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1283 _this.forwardSearch(true);
1289 // print(event.key.keyval)
1295 // user defined functions
1299 public class Xcls_search_results : Object
1301 public Gtk.Label el;
1302 private Editor _this;
1308 public Xcls_search_results(Editor _owner )
1311 _this.search_results = this;
1312 this.el = new Gtk.Label( "No Results" );
1316 // set gobject values
1317 this.el.margin_end = 4;
1318 this.el.margin_start = 4;
1321 // user defined functions
1322 public void updateResults () {
1323 this.el.visible = true;
1325 var res = _this.searchcontext.get_occurrences_count();
1327 _this.search_results.el.label = "??? Matches";
1331 _this.nextBtn.el.sensitive = false;
1332 _this.backBtn.el.sensitive = false;
1335 _this.search_results.el.label = "%d Matches".printf(res);
1336 _this.nextBtn.el.sensitive = true;
1337 _this.backBtn.el.sensitive = true;
1340 _this.search_results.el.label = "No Matches";
1345 public class Xcls_nextBtn : Object
1347 public Gtk.Button el;
1348 private Editor _this;
1352 public bool always_show_image;
1355 public Xcls_nextBtn(Editor _owner )
1358 _this.nextBtn = this;
1359 this.el = new Gtk.Button();
1362 this.always_show_image = true;
1364 // set gobject values
1365 this.el.icon_name = "go-down";
1366 this.el.sensitive = false;
1369 this.el.clicked.connect( (event) => {
1371 _this.forwardSearch(true);
1377 // user defined functions
1380 public class Xcls_backBtn : Object
1382 public Gtk.Button el;
1383 private Editor _this;
1387 public bool always_show_image;
1390 public Xcls_backBtn(Editor _owner )
1393 _this.backBtn = this;
1394 this.el = new Gtk.Button();
1397 this.always_show_image = true;
1399 // set gobject values
1400 this.el.icon_name = "go-up";
1401 this.el.sensitive = false;
1404 this.el.clicked.connect( (event) => {
1406 _this.backSearch(true);
1411 // user defined functions
1414 public class Xcls_MenuButton18 : Object
1416 public Gtk.MenuButton el;
1417 private Editor _this;
1421 public bool always_show_image;
1424 public Xcls_MenuButton18(Editor _owner )
1427 this.el = new Gtk.MenuButton();
1430 this.always_show_image = true;
1432 // set gobject values
1433 this.el.icon_name = "emblem-system";
1434 this.el.always_show_arrow = true;
1435 new Xcls_search_settings( _this );
1436 this.el.popover = _this.search_settings.el;
1439 // user defined functions
1441 public class Xcls_search_settings : Object
1443 public Gtk.Popover el;
1444 private Editor _this;
1450 public Xcls_search_settings(Editor _owner )
1453 _this.search_settings = this;
1454 this.el = new Gtk.Popover();
1458 // set gobject values
1459 var child_1 = new Xcls_Box20( _this );
1460 this.el.child = child_1.el;
1463 // user defined functions
1465 public class Xcls_Box20 : Object
1468 private Editor _this;
1474 public Xcls_Box20(Editor _owner )
1477 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1481 // set gobject values
1482 new Xcls_case_sensitive( _this );
1483 this.el.append( _this.case_sensitive.el );
1484 new Xcls_regex( _this );
1485 this.el.append( _this.regex.el );
1486 new Xcls_multiline( _this );
1487 this.el.append( _this.multiline.el );
1490 // user defined functions
1492 public class Xcls_case_sensitive : Object
1494 public Gtk.CheckButton el;
1495 private Editor _this;
1501 public Xcls_case_sensitive(Editor _owner )
1504 _this.case_sensitive = this;
1505 this.el = new Gtk.CheckButton();
1509 // set gobject values
1510 this.el.label = "Case Sensitive";
1519 // user defined functions
1522 public class Xcls_regex : Object
1524 public Gtk.CheckButton el;
1525 private Editor _this;
1531 public Xcls_regex(Editor _owner )
1535 this.el = new Gtk.CheckButton();
1539 // set gobject values
1540 this.el.label = "Regex";
1549 // user defined functions
1552 public class Xcls_multiline : Object
1554 public Gtk.CheckButton el;
1555 private Editor _this;
1561 public Xcls_multiline(Editor _owner )
1564 _this.multiline = this;
1565 this.el = new Gtk.CheckButton();
1569 // set gobject values
1570 this.el.label = "Multi-line (add \\n)";
1573 // user defined functions