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_Box11( _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_EventControllerScroll63( _this );
650 this.el.add_controller( child_3.el );
654 this.el.completion.add_provider(
655 new Palete.CompletionProvider(_this)
658 //this.el.completion.unblock_interactive();
659 this.el.completion.select_on_show = true; // select
660 //this.el.completion.remember_info_visibility = true;
663 var attrs = new GtkSource.MarkAttributes();
665 attrs.set_icon_name ( "process-stop");
666 attrs.query_tooltip_text.connect(( mark) => {
667 GLib.debug("tooltip query? %s", mark.name);
668 return strdup( mark.name);
670 attrs.query_tooltip_markup.connect(( mark) => {
671 GLib.debug("tooltip query? %s", mark.name);
672 return strdup( mark.name);
674 this.el.set_mark_attributes ("ERR", attrs, 1);
678 var wattrs = new GtkSource.MarkAttributes();
679 wattrs.set_icon_name ( "process-stop");
680 wattrs.query_tooltip_text.connect(( mark) => {
681 GLib.debug("tooltip query? %s", mark.name);
682 return strdup(mark.name);
684 wattrs.query_tooltip_markup.connect(( mark) => {
685 GLib.debug("tooltip query? %s", mark.name);
686 return strdup(mark.name);
688 this.el.set_mark_attributes ("WARN", wattrs, 1);
692 var dattrs = new GtkSource.MarkAttributes();
694 dattrs.set_icon_name ( "process-stop");
696 dattrs.query_tooltip_text.connect(( mark) => {
697 GLib.debug("tooltip query? %s", mark.name);
698 return strdup(mark.name);
700 //dattrs.query_tooltip_markup.connect(( mark) => {
701 // GLib.debug("tooltip query? %s", mark.name);
702 // return strdup(mark.name);
704 this.el.set_mark_attributes ("DEPR", dattrs, 1);
707 this.el.get_space_drawer().set_matrix(null);
708 this.el.get_space_drawer().set_types_for_locations(
709 GtkSource.SpaceLocationFlags.ALL,
710 GtkSource.SpaceTypeFlags.ALL
712 this.el.get_space_drawer().set_enable_matrix(true);
715 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
717 //GLib.debug("query tooltip");
721 var yoff = (int) _this.RightEditor.el.vadjustment.value;
723 // I think this is problematic - if it's compliing / updating at same time as query.
725 //if (_this.window.statusbar_compile_spinner.el.spinning) {
729 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
731 var l = iter.get_line();
735 // GLib.debug("query tooltip line %d", (int) l);
741 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
742 GLib.debug("line %d setting tip to %s", l, _this.buffer.marks.get(l));
743 tooltip.set_text(_this.buffer.marks.get(l).dup());
751 // this crashes?? - not sure why.
752 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
753 if (marks.is_empty()) {
754 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
756 if (marks.is_empty()) {
757 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
760 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
762 marks.@foreach((m) => {
763 //GLib.debug("got mark %s", m.name);
764 str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
766 // true if there is a mark..
767 if (str.length > 0 ) {
768 tooltip.set_text( str );
770 return str.length > 0 ? true : false;
775 // user defined functions
776 public void load (string str) {
778 // show the help page for the active node..
779 //this.get('/Help').show();
781 // this.get('/BottomPane').el.set_current_page(0);
782 GLib.debug("load called - Reset undo buffer");
784 var buf = (GtkSource.Buffer)this.el.get_buffer();
785 buf.begin_irreversible_action();
786 buf.set_text(str, str.length);
787 buf.end_irreversible_action();
789 var lm = GtkSource.LanguageManager.get_default();
791 if (_this.file != null) {
792 lang = _this.file.language;
794 print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
795 var lg = _this.file.content_type.length > 0 ?
796 lm.guess_language(_this.file.path, _this.file.content_type) :
797 lm.get_language(lang);
800 ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg);
802 this.el.insert_spaces_instead_of_tabs = true;
804 print("sourcelanguage = %s\n", lg.name);
805 if (lg.name == "Vala") {
806 this.el.insert_spaces_instead_of_tabs = false;
810 this.el.grab_focus();
811 _this.save_button.el.sensitive = false;
812 _this.last_error_counter = -1;
815 public class Xcls_buffer : Object
817 public GtkSource.Buffer el;
818 private Editor _this;
822 public int error_line;
823 public Gee.HashMap<int,string>? xmarks;
824 public bool check_queued;
827 public Xcls_buffer(Editor _owner )
831 this.el = new GtkSource.Buffer( null );
834 this.error_line = -1;
836 this.check_queued = false;
838 // set gobject values
839 this.el.highlight_syntax = true;
840 this.el.highlight_matching_brackets = true;
841 this.el.enable_undo = true;
846 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
847 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
848 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
849 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
850 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
851 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
852 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
853 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
856 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
857 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
858 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
861 this.el.changed.connect( () => {
864 _this.save_button.el.sensitive = true;
865 print("EDITOR CHANGED");
870 // this.get('/LeftPanel.model').changed( str , false);
875 // user defined functions
876 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
879 this.el.get_bounds (out start, out end);
881 this.el.remove_source_marks (start, end, type);
882 GLib.debug("highlight errors");
884 // we should highlight other types of errors..
886 if (!obj.has_member(type)) {
887 GLib.debug("Return has no errors\n");
891 if (_this.window.windowstate.state != WindowState.State.CODEONLY
893 _this.window.windowstate.state != WindowState.State.CODE
895 GLib.debug("windowstate != CODEONLY?");
900 //this.marks = new Gee.HashMap<int,string>();
901 var err = obj.get_object_member(type);
903 if (_this.file == null) {
904 GLib.debug("file is null?");
908 var valafn = _this.file.path;
910 if (_this.file.xtype != "PlainFile") {
914 var regex = new Regex("\\.bjs$");
916 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
917 } catch (GLib.RegexError e) {
924 if (!err.has_member(valafn)) {
925 GLib.debug("File path has no errors");
929 var lines = err.get_object_member(valafn);
932 if (obj.has_member("line_offset")) { // ?? why??
933 offset = (int)obj.get_int_member("line_offset") + 1;
937 var tlines = this.el.get_line_count () +1;
939 if (_this.prop != null) {
941 tlines = _this.prop.end_line + 1;
942 offset = _this.prop.start_line + 1;
948 lines.foreach_member((obj, line, node) => {
951 // print("get inter\n");
952 var eline = int.parse(line) - offset;
953 GLib.debug("GOT ERROR on line %s -- converted to %d (offset = %d)\n", line,eline, offset);
956 if (eline > tlines || eline < 0) {
961 this.el.get_iter_at_line( out iter, eline);
962 //print("mark line\n");
964 var ar = lines.get_array_member(line);
965 for (var i = 0 ; i < ar.get_length(); i++) {
966 if (ar.get_string_element(i) == "Success") {
969 msg += (msg.length > 0) ? "\n" : "";
970 msg += ar.get_string_element(i);
975 msg = "Line: %d".printf(eline+1) + " " + msg;
976 this.el.create_source_mark(msg, type, iter);
977 GLib.debug("set line %d to %m", eline, msg);
978 // this.marks.set(eline, msg);
987 public bool checkSyntax () {
990 var str = this.toString();
993 if (this.error_line > 0) {
996 this.el.get_bounds (out start, out end);
998 this.el.remove_source_marks (start, end, null);
1000 if (str.length < 1) {
1001 print("checkSyntax - empty string?\n");
1006 if (_this.file.xtype == "PlainFile") {
1008 // assume it's gtk...
1009 var oldcode =_this.file.toSource();
1010 _this.file.setSource(str);
1011 BuilderApplication.showSpinner("appointment soon","document change pending");
1012 _this.file.getLanguageServer().document_change(_this.file);
1014 _this.file.setSource(oldcode);
1020 if (_this.file == null) {
1028 GLib.debug("calling validate");
1029 // clear the buttons.
1030 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1033 var oldcode = _this.prop.val;
1035 _this.prop.val = str;
1036 _this.node.updated_count++;
1037 _this.file.getLanguageServer().document_change(_this.file);
1038 _this.node.updated_count++;
1039 _this.prop.val = oldcode;
1042 //print("done mark line\n");
1044 return true; // at present allow saving - even if it's invalid..
1046 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1048 this.error_line = validate_res.size;
1050 if (this.error_line < 1) {
1053 var tlines = this.el.get_line_count ();
1055 var valiter = validate_res.map_iterator();
1056 while (valiter.next()) {
1058 // print("get inter\n");
1059 var eline = valiter.get_key();
1060 if (eline > tlines) {
1063 this.el.get_iter_at_line( out iter, eline);
1064 //print("mark line\n");
1065 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1069 public string toString () {
1073 this.el.get_start_iter(out s);
1074 this.el.get_end_iter(out e);
1075 var ret = this.el.get_text(s,e,true);
1076 //print("TO STRING? " + ret);
1081 public class Xcls_keystate : Object
1083 public Gtk.EventControllerKey el;
1084 private Editor _this;
1088 public bool is_control;
1091 public Xcls_keystate(Editor _owner )
1094 _this.keystate = this;
1095 this.el = new Gtk.EventControllerKey();
1098 this.is_control = false;
1100 // set gobject values
1103 this.el.key_released.connect( (keyval, keycode, state) => {
1105 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1106 this.is_control = false;
1108 if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1109 GLib.debug("SAVE: ctrl-S pressed");
1110 _this.saveContents();
1114 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1115 GLib.debug("SAVE: ctrl-g pressed");
1116 _this.forwardSearch(true);
1119 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1120 GLib.debug("SAVE: ctrl-f pressed");
1121 _this.search_entry.el.grab_focus();
1122 _this.search_entry.el.select_region(0,-1);
1125 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1126 _this.view.el.show_completion();
1130 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);
1131 var line = iter.get_line();
1132 var offset = iter.get_line_offset();
1133 GLib.debug("line %d off %d", line ,offset);
1134 if (_this.prop != null) {
1135 line += _this.prop.start_line + 1; // i think..
1136 offset += 12; // should probably be 8 without namespaced
1137 GLib.debug("guess line %d off %d", line ,offset);
1139 //_this.view.el.show_completion();
1140 // print(event.key.keyval)
1149 this.el.key_pressed.connect( (keyval, keycode, state) => {
1151 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1152 this.is_control = true;
1158 // user defined functions
1161 public class Xcls_EventControllerScroll63 : Object
1163 public Gtk.EventControllerScroll el;
1164 private Editor _this;
1168 public double distance;
1171 public Xcls_EventControllerScroll63(Editor _owner )
1174 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1177 this.distance = 0.0f;
1179 // set gobject values
1182 this.el.scroll.connect( (dx, dy) => {
1183 if (!_this.keystate.is_control) {
1186 //GLib.debug("scroll %f", dy);
1188 this.distance += dy;
1189 if (this.distance < 1) {
1190 BuilderApplication.settings.editor_font_size ++;
1193 if (this.distance > -1) {
1194 BuilderApplication.settings.editor_font_size --;
1202 // user defined functions
1207 public class Xcls_Box11 : Object
1210 private Editor _this;
1216 public Xcls_Box11(Editor _owner )
1219 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1223 // set gobject values
1224 this.el.homogeneous = false;
1225 this.el.vexpand = false;
1226 new Xcls_search_entry( _this );
1227 this.el.append( _this.search_entry.el );
1228 new Xcls_search_results( _this );
1229 this.el.append( _this.search_results.el );
1230 new Xcls_nextBtn( _this );
1231 this.el.append( _this.nextBtn.el );
1232 new Xcls_backBtn( _this );
1233 this.el.append( _this.backBtn.el );
1234 var child_5 = new Xcls_MenuButton17( _this );
1236 this.el.append( child_5.el );
1239 // user defined functions
1241 public class Xcls_search_entry : Object
1243 public Gtk.SearchEntry el;
1244 private Editor _this;
1248 public Gtk.CssProvider css;
1251 public Xcls_search_entry(Editor _owner )
1254 _this.search_entry = this;
1255 this.el = new Gtk.SearchEntry();
1259 // set gobject values
1260 this.el.name = "editor-search-entry";
1261 this.el.hexpand = true;
1262 this.el.placeholder_text = "Press enter to search";
1263 this.el.search_delay = 3;
1264 var child_1 = new Xcls_EventControllerKey13( _this );
1266 this.el.add_controller( child_1.el );
1269 this.el.search_changed.connect( ( ) => {
1271 _this.search(_this.search_entry.el.text);
1272 _this.search_results.updateResults();
1274 GLib.Timeout.add_seconds(1,() => {
1275 _this.search_results.updateResults();
1281 // user defined functions
1282 public void forwardSearch (bool change_focus) {
1285 _this.forwardSearch(change_focus);
1289 switch(_this.windowstate.state) {
1290 case WindowState.State.CODEONLY:
1291 //case WindowState.State.CODE:
1292 // search the code being edited..
1293 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1296 case WindowState.State.PREVIEW:
1297 if (_this.windowstate.file.xtype == "Gtk") {
1298 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1300 _this.windowstate.window_rooview.forwardSearch(change_focus);
1309 public class Xcls_EventControllerKey13 : Object
1311 public Gtk.EventControllerKey el;
1312 private Editor _this;
1318 public Xcls_EventControllerKey13(Editor _owner )
1321 this.el = new Gtk.EventControllerKey();
1325 // set gobject values
1328 this.el.key_pressed.connect( (keyval, keycode, state) => {
1330 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1331 GLib.debug("SAVE: ctrl-g pressed");
1332 _this.forwardSearch(true);
1337 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1338 _this.forwardSearch(true);
1344 // print(event.key.keyval)
1350 // user defined functions
1354 public class Xcls_search_results : Object
1356 public Gtk.Label el;
1357 private Editor _this;
1363 public Xcls_search_results(Editor _owner )
1366 _this.search_results = this;
1367 this.el = new Gtk.Label( "No Results" );
1371 // set gobject values
1372 this.el.margin_end = 4;
1373 this.el.margin_start = 4;
1376 // user defined functions
1377 public void updateResults () {
1378 this.el.visible = true;
1380 var res = _this.searchcontext.get_occurrences_count();
1382 _this.search_results.el.label = "??? Matches";
1386 _this.nextBtn.el.sensitive = false;
1387 _this.backBtn.el.sensitive = false;
1390 _this.search_results.el.label = "%d Matches".printf(res);
1391 _this.nextBtn.el.sensitive = true;
1392 _this.backBtn.el.sensitive = true;
1395 _this.search_results.el.label = "No Matches";
1400 public class Xcls_nextBtn : Object
1402 public Gtk.Button el;
1403 private Editor _this;
1407 public bool always_show_image;
1410 public Xcls_nextBtn(Editor _owner )
1413 _this.nextBtn = this;
1414 this.el = new Gtk.Button();
1417 this.always_show_image = true;
1419 // set gobject values
1420 this.el.icon_name = "go-down";
1421 this.el.sensitive = false;
1424 this.el.clicked.connect( (event) => {
1426 _this.forwardSearch(true);
1432 // user defined functions
1435 public class Xcls_backBtn : Object
1437 public Gtk.Button el;
1438 private Editor _this;
1442 public bool always_show_image;
1445 public Xcls_backBtn(Editor _owner )
1448 _this.backBtn = this;
1449 this.el = new Gtk.Button();
1452 this.always_show_image = true;
1454 // set gobject values
1455 this.el.icon_name = "go-up";
1456 this.el.sensitive = false;
1459 this.el.clicked.connect( (event) => {
1461 _this.backSearch(true);
1466 // user defined functions
1469 public class Xcls_MenuButton17 : Object
1471 public Gtk.MenuButton el;
1472 private Editor _this;
1476 public bool always_show_image;
1479 public Xcls_MenuButton17(Editor _owner )
1482 this.el = new Gtk.MenuButton();
1485 this.always_show_image = true;
1487 // set gobject values
1488 this.el.icon_name = "emblem-system";
1489 this.el.always_show_arrow = true;
1490 new Xcls_search_settings( _this );
1491 this.el.popover = _this.search_settings.el;
1494 // user defined functions
1496 public class Xcls_search_settings : Object
1498 public Gtk.Popover el;
1499 private Editor _this;
1505 public Xcls_search_settings(Editor _owner )
1508 _this.search_settings = this;
1509 this.el = new Gtk.Popover();
1513 // set gobject values
1514 var child_1 = new Xcls_Box19( _this );
1516 this.el.child = child_1.el;
1519 // user defined functions
1521 public class Xcls_Box19 : Object
1524 private Editor _this;
1530 public Xcls_Box19(Editor _owner )
1533 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1537 // set gobject values
1538 new Xcls_case_sensitive( _this );
1539 this.el.append( _this.case_sensitive.el );
1540 new Xcls_regex( _this );
1541 this.el.append( _this.regex.el );
1542 new Xcls_multiline( _this );
1543 this.el.append( _this.multiline.el );
1546 // user defined functions
1548 public class Xcls_case_sensitive : Object
1550 public Gtk.CheckButton el;
1551 private Editor _this;
1557 public Xcls_case_sensitive(Editor _owner )
1560 _this.case_sensitive = this;
1561 this.el = new Gtk.CheckButton();
1565 // set gobject values
1566 this.el.label = "Case Sensitive";
1575 // user defined functions
1578 public class Xcls_regex : Object
1580 public Gtk.CheckButton el;
1581 private Editor _this;
1587 public Xcls_regex(Editor _owner )
1591 this.el = new Gtk.CheckButton();
1595 // set gobject values
1596 this.el.label = "Regex";
1605 // user defined functions
1608 public class Xcls_multiline : Object
1610 public Gtk.CheckButton el;
1611 private Editor _this;
1617 public Xcls_multiline(Editor _owner )
1620 _this.multiline = this;
1621 this.el = new Gtk.CheckButton();
1625 // set gobject values
1626 this.el.label = "Multi-line (add \\n)";
1629 // user defined functions