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_keystate keystate;
21 public Xcls_search_entry search_entry;
22 public Xcls_search_results search_results;
23 public Xcls_nextBtn nextBtn;
24 public Xcls_backBtn backBtn;
25 public Xcls_search_settings search_settings;
26 public Xcls_case_sensitive case_sensitive;
27 public Xcls_regex regex;
28 public Xcls_multiline multiline;
31 public int pos_root_x;
32 public Xcls_MainWindow window;
34 public int pos_root_y;
36 public int last_error_counter;
37 public GtkSource.SearchContext searchcontext;
38 public int last_search_end;
39 public signal void save ();
40 public JsRender.JsRender? file;
41 public JsRender.Node node;
42 public JsRender.NodeProp? prop;
43 public string activeEditor;
49 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
55 this.last_error_counter = 0;
56 this.searchcontext = null;
57 this.last_search_end = 0;
61 this.activeEditor = "";
64 this.el.homogeneous = false;
65 this.el.hexpand = true;
66 this.el.vexpand = true;
67 var child_1 = new Xcls_Box1( _this );
69 this.el.append( child_1.el );
70 new Xcls_RightEditor( _this );
71 this.el.append( _this.RightEditor.el );
72 var child_3 = new Xcls_Box12( _this );
74 this.el.append ( child_3.el );
77 // user defined functions
78 public bool saveContents () {
81 if (_this.file == null) {
87 var str = _this.buffer.toString();
89 _this.buffer.checkSyntax();
93 // LeftPanel.model.changed( str , false);
95 _this.save_button.el.sensitive = false;
97 // find the text for the node..
98 if (_this.file.xtype != "PlainFile") {
99 // in theory these properties have to exist!?!
101 //this.window.windowstate.left_props.reload();
103 _this.file.setSource( str );
112 public void forwardSearch (bool change_focus) {
114 if (this.searchcontext == null) {
118 Gtk.TextIter beg, st,en;
119 bool has_wrapped_around;
120 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
121 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
123 this.last_search_end = 0; // not sure if this should happen
125 if (has_wrapped_around) {
129 this.last_search_end = en.get_offset();
131 this.view.el.grab_focus();
133 this.buffer.el.place_cursor(st);
134 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
138 public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
143 if (file.xtype != "PlainFile") {
147 // find the text for the node..
148 this.view.load( prop.val );
149 this.updateErrorMarks();
151 this.close_btn.el.show();
154 this.view.load( file.toSource() );
155 this.updateErrorMarks();
156 this.close_btn.el.hide();
161 public void backSearch (bool change_focus) {
163 if (this.searchcontext == null) {
167 Gtk.TextIter beg, st,en;
168 bool has_wrapped_around;
169 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
171 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
172 this.last_search_end = 0;
174 this.last_search_end = en.get_offset();
176 this.view.el.grab_focus();
178 this.buffer.el.place_cursor(st);
179 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
183 public string tempFileContents () {
186 if (_this.file == null) {
189 var str= this.buffer.toString();
190 if (_this.file.xtype == "PlainFile") {
198 GLib.debug("calling validate");
199 // clear the buttons.
200 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
201 return this.file.toSource(); ;
204 var oldcode = _this.prop.val;
205 _this.prop.val = str;
206 var ret = _this.file.toSource();
207 _this.prop.val = oldcode;
211 public void reset () {
216 this.searchcontext = null;
219 public int search (string in_txt) {
221 var s = new GtkSource.SearchSettings();
222 s.case_sensitive = _this.case_sensitive.el.active;
223 s.regex_enabled = _this.regex.el.active;
224 s.wrap_around = false;
226 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
227 this.searchcontext.set_highlight(true);
230 if (_this.multiline.el.active) {
231 txt = in_txt.replace("\\n", "\n");
234 s.set_search_text(txt);
235 Gtk.TextIter beg, st,en;
237 this.buffer.el.get_start_iter(out beg);
238 bool has_wrapped_around;
239 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
240 this.last_search_end = 0;
242 return this.searchcontext.get_occurrences_count();
248 public void updateErrorMarks () {
252 var buf = _this.buffer.el;
255 buf.get_bounds (out start, out end);
260 //GLib.debug("highlight errors");
262 // we should highlight other types of errors..
264 if (_this.window.windowstate.state != WindowState.State.CODEONLY
266 _this.window.windowstate.state != WindowState.State.CODE
268 //GLib.debug("windowstate != CODEONLY?");
274 if (_this.file == null) {
275 GLib.debug("file is null?");
279 var ar = this.file.getErrors();
281 buf.remove_source_marks (start, end, "ERR");
282 buf.remove_source_marks (start, end, "WARN");
283 buf.remove_source_marks (start, end, "DEPR");
284 buf.remove_tag_by_name ("ERR", start, end);
285 buf.remove_tag_by_name ("WARN", start, end);
286 buf.remove_tag_by_name ("DEPR", start, end);
287 this.last_error_counter = file.error_counter ;
288 //GLib.debug("highlight %s : %s has no errors", this.file.relpath, category);
293 // basicaly check if there is no change, then we do not do any update..
294 // we can do this by just using an error counter?
295 // if that's changed then we will do an update, otherwise dont bother.
301 var tlines = buf.get_line_count () +1;
303 if (_this.prop != null) {
304 // this still seems flaky...
306 tlines = _this.prop.end_line;
307 offset = _this.prop.start_line;
308 hoffset = _this.node.node_pad.length + 2; //shift it left by 2 ? ..
313 if (this.last_error_counter == file.error_counter) {
319 buf.remove_source_marks (start, end, "ERR");
320 buf.remove_source_marks (start, end, "WARN");
321 buf.remove_source_marks (start, end, "DEPR");
322 buf.remove_tag_by_name ("ERR", start, end);
323 buf.remove_tag_by_name ("WARN", start, end);
324 buf.remove_tag_by_name ("DEPR", start, end);
326 foreach(var diag in ar) {
328 // print("get inter\n");
329 var eline = (int)diag.range.start.line - offset;
330 var eline_to = (int)diag.range.end.line - offset;
331 //var eline = diag.range.end_line - offset;
332 //GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
333 // err.line ,eline, offset);
336 if (eline > tlines || eline < 0) {
340 buf.get_iter_at_line( out iter, eline);
341 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
342 buf.create_source_mark( msg, diag.category, iter);
344 var spos = (int)diag.range.start.character - hoffset;
345 if (spos < 0) { spos =0 ; }
346 if (spos > iter.get_chars_in_line()) {
347 spos = iter.get_chars_in_line();
349 buf.get_iter_at_line( out iter, eline_to);
350 var epos = (int)diag.range.end.character - hoffset;
351 if (epos < 0) { epos =0 ; }
352 if (epos > iter.get_chars_in_line()) {
353 epos = iter.get_chars_in_line();
357 buf.get_iter_at_line_offset( out start, eline, spos);
359 buf.get_iter_at_line_offset( out end, eline_to,epos);
361 buf.apply_tag_by_name(diag.category, start, end);
363 // GLib.debug("set line %d to %s", eline, msg);
364 //this.marks.set(eline, msg);
366 this.last_error_counter = file.error_counter ;
373 public void scroll_to_line (int line) {
375 GLib.Timeout.add(500, () => {
377 var buf = this.view.el.get_buffer();
379 var sbuf = (GtkSource.Buffer) buf;
383 sbuf.get_iter_at_line(out iter, line);
384 this.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
388 public class Xcls_Box1 : Object
391 private Editor _this;
397 public Xcls_Box1(Editor _owner )
400 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
404 // set gobject values
405 this.el.homogeneous = false;
406 this.el.hexpand = true;
407 new Xcls_save_button( _this );
408 this.el.append( _this.save_button.el );
409 var child_2 = new Xcls_Label3( _this );
411 this.el.append( child_2.el );
412 var child_3 = new Xcls_Scale4( _this );
414 this.el.append( child_3.el );
415 new Xcls_close_btn( _this );
416 this.el.append( _this.close_btn.el );
419 // user defined functions
421 public class Xcls_save_button : Object
423 public Gtk.Button el;
424 private Editor _this;
430 public Xcls_save_button(Editor _owner )
433 _this.save_button = this;
434 this.el = new Gtk.Button();
438 // set gobject values
439 this.el.label = "Save";
442 this.el.clicked.connect( () => {
443 _this.saveContents();
447 // user defined functions
450 public class Xcls_Label3 : Object
453 private Editor _this;
459 public Xcls_Label3(Editor _owner )
462 this.el = new Gtk.Label( null );
466 // set gobject values
467 this.el.hexpand = true;
470 // user defined functions
473 public class Xcls_Scale4 : Object
476 private Editor _this;
482 public Xcls_Scale4(Editor _owner )
485 this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
489 // set gobject values
490 this.el.width_request = 200;
491 this.el.has_origin = true;
492 this.el.draw_value = false;
494 this.el.sensitive = true;
499 //this.el.set_range(6,30);
500 this.el.set_value ( BuilderApplication.settings.editor_font_size);
501 BuilderApplication.settings.editor_font_size_updated.connect(
503 BuilderApplication.settings.editor_font_size_inchange = true;
504 // GLib.debug("update range");
505 this.el.set_value (BuilderApplication.settings.editor_font_size);
506 BuilderApplication.settings.editor_font_size_inchange = false;
514 this.el.change_value.connect( (st, val ) => {
515 if (BuilderApplication.settings.editor_font_size_inchange) {
518 BuilderApplication.settings.editor_font_size = val;
523 // user defined functions
526 public class Xcls_close_btn : Object
528 public Gtk.Button el;
529 private Editor _this;
535 public Xcls_close_btn(Editor _owner )
538 _this.close_btn = this;
539 this.el = new Gtk.Button();
543 // set gobject values
544 this.el.icon_name = "window-close";
545 var child_1 = new Xcls_Image6( _this );
547 this.el.child = child_1.el;
550 this.el.clicked.connect( () => {
551 _this.saveContents();
552 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
556 // user defined functions
558 public class Xcls_Image6 : Object
561 private Editor _this;
567 public Xcls_Image6(Editor _owner )
570 this.el = new Gtk.Image();
574 // set gobject values
575 this.el.icon_name = "window-close";
576 this.el.icon_size = Gtk.IconSize.NORMAL;
579 // user defined functions
584 public class Xcls_RightEditor : Object
586 public Gtk.ScrolledWindow el;
587 private Editor _this;
593 public Xcls_RightEditor(Editor _owner )
596 _this.RightEditor = this;
597 this.el = new Gtk.ScrolledWindow();
601 // set gobject values
602 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
603 this.el.vexpand = true;
604 this.el.overlay_scrolling = false;
605 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
606 new Xcls_view( _this );
607 this.el.child = _this.view.el;
610 // user defined functions
612 public class Xcls_view : Object
614 public GtkSource.View el;
615 private Editor _this;
619 public Gtk.CssProvider css;
622 public Xcls_view(Editor _owner )
626 this.el = new GtkSource.View();
631 // set gobject values
632 this.el.auto_indent = true;
633 this.el.indent_width = 4;
634 this.el.name = "editor-view";
635 this.el.show_line_marks = true;
636 this.el.insert_spaces_instead_of_tabs = true;
637 this.el.show_line_numbers = true;
638 this.el.hexpand = true;
639 this.el.vexpand = true;
640 this.el.has_tooltip = true;
641 this.el.css_classes = { "code-editor" };
642 this.el.tab_width = 4;
643 this.el.highlight_current_line = true;
644 new Xcls_buffer( _this );
645 this.el.buffer = _this.buffer.el;
646 new Xcls_keystate( _this );
647 this.el.add_controller( _this.keystate.el );
648 var child_3 = new Xcls_EventControllerScroll11( _this );
650 this.el.add_controller( child_3.el );
654 this.el.completion.add_provider(
655 new Palete.CompletionProvider(_this)
658 var hover = this.el.get_hover();
659 hover.add_provider(new Palete.HoverProvider());
661 //this.el.completion.unblock_interactive();
662 this.el.completion.select_on_show = true; // select
663 //this.el.completion.remember_info_visibility = true;
666 var attrs = new GtkSource.MarkAttributes();
668 attrs.set_icon_name ( "process-stop");
669 attrs.query_tooltip_text.connect(( mark) => {
670 GLib.debug("tooltip query? %s", mark.name);
671 return strdup( mark.name);
673 attrs.query_tooltip_markup.connect(( mark) => {
674 GLib.debug("tooltip query? %s", mark.name);
675 return strdup( mark.name);
677 this.el.set_mark_attributes ("ERR", attrs, 1);
681 var wattrs = new GtkSource.MarkAttributes();
682 wattrs.set_icon_name ( "process-stop");
683 wattrs.query_tooltip_text.connect(( mark) => {
684 GLib.debug("tooltip query? %s", mark.name);
685 return strdup(mark.name);
687 wattrs.query_tooltip_markup.connect(( mark) => {
688 GLib.debug("tooltip query? %s", mark.name);
689 return strdup(mark.name);
691 this.el.set_mark_attributes ("WARN", wattrs, 1);
695 var dattrs = new GtkSource.MarkAttributes();
697 dattrs.set_icon_name ( "process-stop");
699 dattrs.query_tooltip_text.connect(( mark) => {
700 GLib.debug("tooltip query? %s", mark.name);
701 return strdup(mark.name);
703 //dattrs.query_tooltip_markup.connect(( mark) => {
704 // GLib.debug("tooltip query? %s", mark.name);
705 // return strdup(mark.name);
707 this.el.set_mark_attributes ("DEPR", dattrs, 1);
710 this.el.get_space_drawer().set_matrix(null);
711 this.el.get_space_drawer().set_types_for_locations(
712 GtkSource.SpaceLocationFlags.ALL,
713 GtkSource.SpaceTypeFlags.ALL
715 this.el.get_space_drawer().set_enable_matrix(true);
718 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
720 //GLib.debug("query tooltip");
724 var yoff = (int) _this.RightEditor.el.vadjustment.value;
726 // I think this is problematic - if it's compliing / updating at same time as query.
728 //if (_this.window.statusbar_compile_spinner.el.spinning) {
732 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
734 var l = iter.get_line();
738 // GLib.debug("query tooltip line %d", (int) l);
744 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
745 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
746 tooltip.set_text(_this.buffer.marks.get(l).dup());
754 // this crashes?? - not sure why.
755 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
756 if (marks.is_empty()) {
757 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
759 if (marks.is_empty()) {
760 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
763 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
765 marks.@foreach((m) => {
766 //GLib.debug("got mark %s", m.name);
767 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
769 // true if there is a mark..
770 if (str.length > 0 ) {
771 tooltip.set_text( str );
773 return str.length > 0 ? true : false;
778 // user defined functions
779 public void load (string str) {
781 // show the help page for the active node..
782 //this.get('/Help').show();
784 // this.get('/BottomPane').el.set_current_page(0);
785 GLib.debug("load called - Reset undo buffer");
787 var buf = (GtkSource.Buffer)this.el.get_buffer();
788 buf.begin_irreversible_action();
789 buf.set_text(str, str.length);
790 buf.end_irreversible_action();
792 var lm = GtkSource.LanguageManager.get_default();
794 if (_this.file != null) {
795 lang = _this.file.language;
797 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
798 var lg = _this.file.content_type.length > 0 ?
799 lm.guess_language(_this.file.path, _this.file.content_type) :
800 lm.get_language(lang);
803 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
805 this.el.insert_spaces_instead_of_tabs = true;
807 print("sourcelanguage = %s\n", lg.name);
808 if (lg.name == "Vala") {
809 this.el.insert_spaces_instead_of_tabs = false;
813 this.el.grab_focus();
814 _this.save_button.el.sensitive = false;
815 _this.last_error_counter = -1;
818 public class Xcls_buffer : Object
820 public GtkSource.Buffer el;
821 private Editor _this;
825 public int error_line;
826 public Gee.HashMap<int,string>? xmarks;
827 public bool check_queued;
830 public Xcls_buffer(Editor _owner )
834 this.el = new GtkSource.Buffer( null );
837 this.error_line = -1;
839 this.check_queued = false;
841 // set gobject values
842 this.el.highlight_syntax = true;
843 this.el.highlight_matching_brackets = true;
844 this.el.enable_undo = true;
849 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
850 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
851 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
852 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
853 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
854 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
855 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
856 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
859 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
860 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
861 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
864 this.el.changed.connect( () => {
867 _this.save_button.el.sensitive = true;
868 print("EDITOR CHANGED");
873 // this.get('/LeftPanel.model').changed( str , false);
878 // user defined functions
879 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
882 this.el.get_bounds (out start, out end);
884 this.el.remove_source_marks (start, end, type);
885 GLib.debug("highlight errors");
887 // we should highlight other types of errors..
889 if (!obj.has_member(type)) {
890 GLib.debug("Return has no errors\n");
894 if (_this.window.windowstate.state != WindowState.State.CODEONLY
896 _this.window.windowstate.state != WindowState.State.CODE
898 GLib.debug("windowstate != CODEONLY?");
903 //this.marks = new Gee.HashMap<int,string>();
904 var err = obj.get_object_member(type);
906 if (_this.file == null) {
907 GLib.debug("file is null?");
911 var valafn = _this.file.path;
913 if (_this.file.xtype != "PlainFile") {
917 var regex = new Regex("\\.bjs$");
919 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
920 } catch (GLib.RegexError e) {
927 if (!err.has_member(valafn)) {
928 GLib.debug("File path has no errors");
932 var lines = err.get_object_member(valafn);
935 if (obj.has_member("line_offset")) { // ?? why??
936 offset = (int)obj.get_int_member("line_offset") + 1;
940 var tlines = this.el.get_line_count () +1;
942 if (_this.prop != null) {
944 tlines = _this.prop.end_line + 1;
945 offset = _this.prop.start_line + 1;
951 lines.foreach_member((obj, line, node) => {
954 // print("get inter\n");
955 var eline = int.parse(line) - offset;
956 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
959 if (eline > tlines || eline < 0) {
964 this.el.get_iter_at_line( out iter, eline);
965 //print("mark line\n");
967 var ar = lines.get_array_member(line);
968 for (var i = 0 ; i < ar.get_length(); i++) {
969 if (ar.get_string_element(i) == "Success") {
972 msg += (msg.length > 0) ? "\n" : "";
973 msg += ar.get_string_element(i);
978 msg = "Line: %d".printf(eline+1) + " " + msg;
979 this.el.create_source_mark(msg, type, iter);
980 GLib.debug("set line %d to %m", eline, msg);
981 // this.marks.set(eline, msg);
990 public bool checkSyntax () {
993 var str = this.toString();
996 if (this.error_line > 0) {
999 this.el.get_bounds (out start, out end);
1001 this.el.remove_source_marks (start, end, null);
1003 if (str.length < 1) {
1004 print("checkSyntax - empty string?\n");
1009 if (_this.file.xtype == "PlainFile") {
1011 // assume it's gtk...
1012 var oldcode =_this.file.toSource();
1013 _this.file.setSource(str);
1014 BuilderApplication.showSpinner("appointment soon","document change pending");
1015 _this.file.getLanguageServer().document_change(_this.file);
1017 _this.file.setSource(oldcode);
1023 if (_this.file == null) {
1031 GLib.debug("calling validate");
1032 // clear the buttons.
1033 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1036 var oldcode = _this.prop.val;
1038 _this.prop.val = str;
1039 _this.node.updated_count++;
1040 _this.file.getLanguageServer().document_change(_this.file);
1041 _this.node.updated_count++;
1042 _this.prop.val = oldcode;
1045 //print("done mark line\n");
1047 return true; // at present allow saving - even if it's invalid..
1049 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1051 this.error_line = validate_res.size;
1053 if (this.error_line < 1) {
1056 var tlines = this.el.get_line_count ();
1058 var valiter = validate_res.map_iterator();
1059 while (valiter.next()) {
1061 // print("get inter\n");
1062 var eline = valiter.get_key();
1063 if (eline > tlines) {
1066 this.el.get_iter_at_line( out iter, eline);
1067 //print("mark line\n");
1068 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1072 public string toString () {
1076 this.el.get_start_iter(out s);
1077 this.el.get_end_iter(out e);
1078 var ret = this.el.get_text(s,e,true);
1079 //print("TO STRING? " + ret);
1084 public class Xcls_keystate : Object
1086 public Gtk.EventControllerKey el;
1087 private Editor _this;
1091 public bool is_control;
1094 public Xcls_keystate(Editor _owner )
1097 _this.keystate = this;
1098 this.el = new Gtk.EventControllerKey();
1101 this.is_control = false;
1103 // set gobject values
1106 this.el.key_released.connect( (keyval, keycode, state) => {
1108 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1109 this.is_control = false;
1111 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1112 GLib.debug("SAVE: ctrl-S pressed");
1113 _this.saveContents();
1117 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1118 GLib.debug("SAVE: ctrl-g pressed");
1119 _this.forwardSearch(true);
1122 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1123 GLib.debug("SAVE: ctrl-f pressed");
1124 _this.search_entry.el.grab_focus();
1125 _this.search_entry.el.select_region(0,-1);
1128 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1129 _this.view.el.show_completion();
1133 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1134 var line = iter.get_line();
1135 var offset = iter.get_line_offset();
1136 GLib.debug("line %d off %d", line ,offset);
1137 if (_this.prop != null) {
1138 line += _this.prop.start_line + 1; // i think..
1139 offset += 12; // should probably be 8 without namespaced
1140 GLib.debug("guess line %d off %d", line ,offset);
1142 //_this.view.el.show_completion();
1143 // print(event.key.keyval)
1152 this.el.key_pressed.connect( (keyval, keycode, state) => {
1154 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1155 this.is_control = true;
1161 // user defined functions
1164 public class Xcls_EventControllerScroll11 : Object
1166 public Gtk.EventControllerScroll el;
1167 private Editor _this;
1171 public double distance;
1174 public Xcls_EventControllerScroll11(Editor _owner )
1177 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1180 this.distance = 0.0f;
1182 // set gobject values
1185 this.el.scroll.connect( (dx, dy) => {
1186 if (!_this.keystate.is_control) {
1189 //GLib.debug("scroll %f", dy);
1191 this.distance += dy;
1193 //GLib.debug("scroll %f / %f", dy, this.distance);
1195 if (this.distance < -1) {
1197 BuilderApplication.settings.editor_font_size ++;
1200 if (this.distance > 1) {
1201 BuilderApplication.settings.editor_font_size --;
1209 // user defined functions
1214 public class Xcls_Box12 : Object
1217 private Editor _this;
1223 public Xcls_Box12(Editor _owner )
1226 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1230 // set gobject values
1231 this.el.homogeneous = false;
1232 this.el.vexpand = false;
1233 new Xcls_search_entry( _this );
1234 this.el.append( _this.search_entry.el );
1235 new Xcls_search_results( _this );
1236 this.el.append( _this.search_results.el );
1237 new Xcls_nextBtn( _this );
1238 this.el.append( _this.nextBtn.el );
1239 new Xcls_backBtn( _this );
1240 this.el.append( _this.backBtn.el );
1241 var child_5 = new Xcls_MenuButton18( _this );
1243 this.el.append( child_5.el );
1246 // user defined functions
1248 public class Xcls_search_entry : Object
1250 public Gtk.SearchEntry el;
1251 private Editor _this;
1255 public Gtk.CssProvider css;
1258 public Xcls_search_entry(Editor _owner )
1261 _this.search_entry = this;
1262 this.el = new Gtk.SearchEntry();
1266 // set gobject values
1267 this.el.name = "editor-search-entry";
1268 this.el.hexpand = true;
1269 this.el.placeholder_text = "Press enter to search";
1270 this.el.search_delay = 3;
1271 var child_1 = new Xcls_EventControllerKey14( _this );
1273 this.el.add_controller( child_1.el );
1276 this.el.search_changed.connect( ( ) => {
1278 _this.search(_this.search_entry.el.text);
1279 _this.search_results.updateResults();
1281 GLib.Timeout.add_seconds(1,() => {
1282 _this.search_results.updateResults();
1288 // user defined functions
1289 public void forwardSearch (bool change_focus) {
1292 _this.forwardSearch(change_focus);
1296 switch(_this.windowstate.state) {
1297 case WindowState.State.CODEONLY:
1298 //case WindowState.State.CODE:
1299 // search the code being edited..
1300 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1303 case WindowState.State.PREVIEW:
1304 if (_this.windowstate.file.xtype == "Gtk") {
1305 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1307 _this.windowstate.window_rooview.forwardSearch(change_focus);
1316 public class Xcls_EventControllerKey14 : Object
1318 public Gtk.EventControllerKey el;
1319 private Editor _this;
1325 public Xcls_EventControllerKey14(Editor _owner )
1328 this.el = new Gtk.EventControllerKey();
1332 // set gobject values
1335 this.el.key_pressed.connect( (keyval, keycode, state) => {
1337 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1338 GLib.debug("SAVE: ctrl-g pressed");
1339 _this.forwardSearch(true);
1344 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1345 _this.forwardSearch(true);
1351 // print(event.key.keyval)
1357 // user defined functions
1361 public class Xcls_search_results : Object
1363 public Gtk.Label el;
1364 private Editor _this;
1370 public Xcls_search_results(Editor _owner )
1373 _this.search_results = this;
1374 this.el = new Gtk.Label( "No Results" );
1378 // set gobject values
1379 this.el.margin_end = 4;
1380 this.el.margin_start = 4;
1383 // user defined functions
1384 public void updateResults () {
1385 this.el.visible = true;
1387 var res = _this.searchcontext.get_occurrences_count();
1389 _this.search_results.el.label = "??? Matches";
1393 _this.nextBtn.el.sensitive = false;
1394 _this.backBtn.el.sensitive = false;
1397 _this.search_results.el.label = "%d Matches".printf(res);
1398 _this.nextBtn.el.sensitive = true;
1399 _this.backBtn.el.sensitive = true;
1402 _this.search_results.el.label = "No Matches";
1407 public class Xcls_nextBtn : Object
1409 public Gtk.Button el;
1410 private Editor _this;
1414 public bool always_show_image;
1417 public Xcls_nextBtn(Editor _owner )
1420 _this.nextBtn = this;
1421 this.el = new Gtk.Button();
1424 this.always_show_image = true;
1426 // set gobject values
1427 this.el.icon_name = "go-down";
1428 this.el.sensitive = false;
1431 this.el.clicked.connect( (event) => {
1433 _this.forwardSearch(true);
1439 // user defined functions
1442 public class Xcls_backBtn : Object
1444 public Gtk.Button el;
1445 private Editor _this;
1449 public bool always_show_image;
1452 public Xcls_backBtn(Editor _owner )
1455 _this.backBtn = this;
1456 this.el = new Gtk.Button();
1459 this.always_show_image = true;
1461 // set gobject values
1462 this.el.icon_name = "go-up";
1463 this.el.sensitive = false;
1466 this.el.clicked.connect( (event) => {
1468 _this.backSearch(true);
1473 // user defined functions
1476 public class Xcls_MenuButton18 : Object
1478 public Gtk.MenuButton el;
1479 private Editor _this;
1483 public bool always_show_image;
1486 public Xcls_MenuButton18(Editor _owner )
1489 this.el = new Gtk.MenuButton();
1492 this.always_show_image = true;
1494 // set gobject values
1495 this.el.icon_name = "emblem-system";
1496 this.el.always_show_arrow = true;
1497 new Xcls_search_settings( _this );
1498 this.el.popover = _this.search_settings.el;
1501 // user defined functions
1503 public class Xcls_search_settings : Object
1505 public Gtk.Popover el;
1506 private Editor _this;
1512 public Xcls_search_settings(Editor _owner )
1515 _this.search_settings = this;
1516 this.el = new Gtk.Popover();
1520 // set gobject values
1521 var child_1 = new Xcls_Box20( _this );
1523 this.el.child = child_1.el;
1526 // user defined functions
1528 public class Xcls_Box20 : Object
1531 private Editor _this;
1537 public Xcls_Box20(Editor _owner )
1540 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1544 // set gobject values
1545 new Xcls_case_sensitive( _this );
1546 this.el.append( _this.case_sensitive.el );
1547 new Xcls_regex( _this );
1548 this.el.append( _this.regex.el );
1549 new Xcls_multiline( _this );
1550 this.el.append( _this.multiline.el );
1553 // user defined functions
1555 public class Xcls_case_sensitive : Object
1557 public Gtk.CheckButton el;
1558 private Editor _this;
1564 public Xcls_case_sensitive(Editor _owner )
1567 _this.case_sensitive = this;
1568 this.el = new Gtk.CheckButton();
1572 // set gobject values
1573 this.el.label = "Case Sensitive";
1582 // user defined functions
1585 public class Xcls_regex : Object
1587 public Gtk.CheckButton el;
1588 private Editor _this;
1594 public Xcls_regex(Editor _owner )
1598 this.el = new Gtk.CheckButton();
1602 // set gobject values
1603 this.el.label = "Regex";
1612 // user defined functions
1615 public class Xcls_multiline : Object
1617 public Gtk.CheckButton el;
1618 private Editor _this;
1624 public Xcls_multiline(Editor _owner )
1627 _this.multiline = this;
1628 this.el = new Gtk.CheckButton();
1632 // set gobject values
1633 this.el.label = "Multi-line (add \\n)";
1636 // user defined functions