1 static Xcls_WindowRooView _WindowRooView;
3 public class Xcls_WindowRooView : Object
6 private Xcls_WindowRooView _this;
8 public static Xcls_WindowRooView singleton()
10 if (_WindowRooView == null) {
11 _WindowRooView= new Xcls_WindowRooView();
13 return _WindowRooView;
15 public Xcls_notebook notebook;
16 public Xcls_label_preview label_preview;
17 public Xcls_label_code label_code;
18 public Xcls_paned paned;
19 public Xcls_viewbox viewbox;
20 public Xcls_AutoRedraw AutoRedraw;
21 public Xcls_view view;
22 public Xcls_inspectorcontainer inspectorcontainer;
23 public Xcls_sourceviewscroll sourceviewscroll;
24 public Xcls_sourceview sourceview;
25 public Xcls_buffer buffer;
26 public Xcls_search_entry search_entry;
27 public Xcls_search_results search_results;
28 public Xcls_nextBtn nextBtn;
29 public Xcls_backBtn backBtn;
30 public Xcls_search_settings search_settings;
31 public Xcls_case_sensitive case_sensitive;
32 public Xcls_regex regex;
33 public Xcls_multiline multiline;
36 public Gtk.Widget lastObj;
37 public Xcls_MainWindow main_window;
38 public int last_error_counter;
39 public int last_search_end;
40 public GtkSource.SearchContext searchcontext;
41 public JsRender.JsRender file;
44 public Xcls_WindowRooView()
47 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
51 this.last_error_counter = 0;
52 this.last_search_end = 0;
56 this.el.hexpand = true;
57 this.el.vexpand = true;
58 new Xcls_notebook( _this );
59 this.el.append( _this.notebook.el );
62 // user defined functions
63 public void loadFile (JsRender.JsRender file)
66 this.view.renderJS(true);
67 this.notebook.el.page = 0;// gtk preview
68 this.sourceview.loadFile();
69 this.last_error_counter = -1;
70 this.updateErrorMarks();
72 public void highlightNodeAtLine (int ln) {
79 var node = _this.file.lineToNode(ln+1);
82 //print("can not find node\n");
85 var prop = node.lineToProp(ln+1);
86 print("prop : %s", prop == null ? "???" : prop.name);
89 // ---------- this selects the tree's node...
91 var ltree = _this.main_window.windowstate.left_tree;
92 ltree.model.selectNode(node);
94 //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
97 //print("changing cursor on tree..\n");
101 // let's try allowing editing on the methods.
102 // a little klunky at present..
103 _this.sourceview.prop_selected = "";
106 //see if we can find it..
107 var kv = prop.split(":");
110 //var k = prop.get_key(kv[1]);
111 // fixme -- need to determine if it's an editable property...
112 _this.sourceview.prop_selected = prop;
114 } else if (kv[0] == "l") {
115 _this.sourceview.prop_selected = prop;
120 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
121 _this.sourceview.nodeSelected(node,false);
123 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
124 // GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
125 // this.allow_node_scroll = true;
141 public void requestRedraw () {
142 this.view.renderJS(false);
143 this.sourceview.loadFile();
145 public void forwardSearch (bool change_focus) {
147 if (this.searchcontext == null) {
150 this.notebook.el.page = 1;
151 Gtk.TextIter beg, st,en;
152 bool has_wrapped_around;
153 var buf = this.sourceview.el.get_buffer();
154 buf.get_iter_at_offset(out beg, this.last_search_end);
155 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
156 this.last_search_end = 0;
159 this.last_search_end = en.get_offset();
161 this.sourceview.el.grab_focus();
163 buf.place_cursor(st);
167 this.sourceview.el.scroll_to_iter(st, 0.0f, true, 0.0f, 0.5f);
170 var ln = st.get_line();
172 this.highlightNodeAtLine(ln);
174 public void backSearch (bool change_focus) {
176 if (this.searchcontext == null) {
180 Gtk.TextIter beg, st,en;
181 bool has_wrapped_around;
182 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
184 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
186 this.last_search_end = 0;
189 this.last_search_end = en.get_offset();
191 this.sourceview.el.grab_focus();
193 this.buffer.el.place_cursor(st);
194 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
195 var ln = st.get_line();
196 this.highlightNodeAtLine(ln);
200 public int search (string in_txt) {
201 this.notebook.el.page = 1;
205 var s = new GtkSource.SearchSettings();
206 s.case_sensitive = _this.case_sensitive.el.active;
207 s.regex_enabled = _this.regex.el.active;
208 s.wrap_around = false;
210 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
211 this.searchcontext.set_highlight(true);
214 if (_this.multiline.el.active) {
215 txt = in_txt.replace("\\n", "\n");
218 s.set_search_text(txt);
219 Gtk.TextIter beg, st,en;
220 bool has_wrapped_around;
221 this.buffer.el.get_start_iter(out beg);
222 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
223 this.last_search_end = 0;
225 return this.searchcontext.get_occurrences_count();
231 public void createThumb () {
234 if (this.file == null) {
238 if (this.notebook.el.page > 0 ) {
242 this.file.widgetToIcon(this.view.el);
249 public void updateErrorMarks () {
253 var buf = _this.buffer.el;
256 buf.get_bounds (out start, out end);
260 GLib.debug("highlight errors");
262 // we should highlight other types of errors..
267 if (_this.file == null) {
268 GLib.debug("file is null?");
272 var ar = this.file.getErrors();
274 buf.remove_tag_by_name ("ERR", start, end);
275 buf.remove_tag_by_name ("WARN", start, end);
276 buf.remove_tag_by_name ("DEPR", start, end);
277 buf.remove_source_marks (start, end, null);
278 this.last_error_counter = file.error_counter ;
279 GLib.debug("higjlight has no errors");
282 if (this.last_error_counter == file.error_counter) {
286 var tlines = buf.get_line_count () +1;
290 buf.remove_source_marks (start, end, null);
291 buf.remove_tag_by_name ("ERR", start, end);
292 buf.remove_tag_by_name ("WARN", start, end);
293 buf.remove_tag_by_name ("DEPR", start, end);
294 foreach(var diag in ar) {
298 // print("get inter\n");
299 var eline = (int)diag.range.start.line ;
300 var eline_to = (int)diag.range.end.line;
301 if (eline > tlines || eline < 0) {
306 buf.get_iter_at_line( out iter, eline);
308 buf.get_iter_at_line_offset( out start,
309 eline, (int)diag.range.start.character);
310 buf.get_iter_at_line_offset( out end,
311 eline_to, (int)diag.range.end.character);
313 buf.apply_tag_by_name(diag.category, start, end);
316 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
317 buf.create_source_mark( msg, diag.category, iter);
318 GLib.debug("set line %d to %s", eline, msg);
319 //this.marks.set(eline, msg);
321 this.last_error_counter = file.error_counter ;
328 public void scroll_to_line (int line) {
331 GLib.Timeout.add(100, () => {
333 this.notebook.el.set_current_page( 1 );
336 var buf = this.sourceview.el.get_buffer();
338 var sbuf = (GtkSource.Buffer) buf;
342 sbuf.get_iter_at_line(out iter, line);
343 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
349 public class Xcls_notebook : Object
351 public Gtk.Notebook el;
352 private Xcls_WindowRooView _this;
358 public Xcls_notebook(Xcls_WindowRooView _owner )
361 _this.notebook = this;
362 this.el = new Gtk.Notebook();
366 // set gobject values
367 this.el.vexpand = true;
368 new Xcls_label_preview( _this );
369 new Xcls_label_code( _this );
370 new Xcls_paned( _this );
371 this.el.append_page ( _this.paned.el , _this.label_preview.el );
372 var child_4 = new Xcls_Box13( _this );
374 this.el.append_page ( child_4.el , _this.label_code.el );
377 // user defined functions
379 public class Xcls_label_preview : Object
382 private Xcls_WindowRooView _this;
388 public Xcls_label_preview(Xcls_WindowRooView _owner )
391 _this.label_preview = this;
392 this.el = new Gtk.Label( "Preview" );
396 // set gobject values
399 // user defined functions
402 public class Xcls_label_code : Object
405 private Xcls_WindowRooView _this;
411 public Xcls_label_code(Xcls_WindowRooView _owner )
414 _this.label_code = this;
415 this.el = new Gtk.Label( "Preview Generated Code" );
419 // set gobject values
422 // user defined functions
425 public class Xcls_paned : Object
428 private Xcls_WindowRooView _this;
434 public Xcls_paned(Xcls_WindowRooView _owner )
438 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
442 // set gobject values
443 this.el.vexpand = true;
444 new Xcls_viewbox( _this );
445 this.el.set_start_child ( _this.viewbox.el );
446 new Xcls_inspectorcontainer( _this );
447 this.el.set_end_child ( _this.inspectorcontainer.el );
450 // user defined functions
452 public class Xcls_viewbox : Object
455 private Xcls_WindowRooView _this;
461 public Xcls_viewbox(Xcls_WindowRooView _owner )
464 _this.viewbox = this;
465 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
469 // set gobject values
470 this.el.homogeneous = false;
471 this.el.vexpand = true;
472 var child_1 = new Xcls_Box7( _this );
474 this.el.append( child_1.el );
475 new Xcls_view( _this );
476 this.el.append( _this.view.el );
479 // user defined functions
481 public class Xcls_Box7 : Object
484 private Xcls_WindowRooView _this;
490 public Xcls_Box7(Xcls_WindowRooView _owner )
493 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
497 // set gobject values
498 this.el.homogeneous = true;
499 this.el.height_request = 20;
500 this.el.vexpand = false;
501 var child_1 = new Xcls_Button8( _this );
503 this.el.append( child_1.el );
504 new Xcls_AutoRedraw( _this );
505 this.el.append( _this.AutoRedraw.el );
506 var child_3 = new Xcls_Button10( _this );
508 this.el.append( child_3.el );
511 // user defined functions
513 public class Xcls_Button8 : Object
515 public Gtk.Button el;
516 private Xcls_WindowRooView _this;
522 public Xcls_Button8(Xcls_WindowRooView _owner )
525 this.el = new Gtk.Button();
529 // set gobject values
530 this.el.label = "Redraw";
533 this.el.clicked.connect( ( ) => {
534 _this.view.renderJS( true);
538 // user defined functions
541 public class Xcls_AutoRedraw : Object
543 public Gtk.CheckButton el;
544 private Xcls_WindowRooView _this;
550 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
553 _this.AutoRedraw = this;
554 this.el = new Gtk.CheckButton();
558 // set gobject values
559 this.el.active = true;
560 this.el.label = "Auto Redraw On";
563 this.el.toggled.connect( (state) => {
564 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
568 // user defined functions
571 public class Xcls_Button10 : Object
573 public Gtk.Button el;
574 private Xcls_WindowRooView _this;
580 public Xcls_Button10(Xcls_WindowRooView _owner )
583 this.el = new Gtk.Button();
587 // set gobject values
588 this.el.label = "Full Redraw";
591 this.el.clicked.connect( () => {
592 _this.view.redraws = 99;
593 // _this.view.el.web_context.clear_cache();
594 //_this.view.renderJS(true);
595 FakeServerCache.clear();
601 // user defined functions
605 public class Xcls_view : Object
607 public WebKit.WebView el;
608 private Xcls_WindowRooView _this;
612 public WebKit.WebInspector inspector;
613 public bool pendingRedraw;
615 public bool refreshRequired;
617 public string runhtml;
618 public string renderedData;
619 public GLib.DateTime lastRedraw;
622 public Xcls_view(Xcls_WindowRooView _owner )
626 this.el = new WebKit.WebView();
629 this.pendingRedraw = false;
631 this.refreshRequired = false;
634 this.renderedData = "";
635 this.lastRedraw = null;
637 // set gobject values
638 this.el.vexpand = true;
643 // this may not work!?
644 var settings = this.el.get_settings();
645 settings.enable_developer_extras = true;
648 var fs= new FakeServer(this.el);
650 // this was an attempt to change the url perms.. did not work..
651 // settings.enable_file_access_from_file_uris = true;
652 // settings.enable_offline_web_application_cache - true;
653 // settings.enable_universal_access_from_file_uris = true;
660 // FIXME - base url of script..
661 // we need it so some of the database features work.
662 this.el.load_html( "Render not ready" ,
663 //fixme - should be a config option!
664 // or should we catch stuff and fix it up..
665 "http://localhost/app.Builder/"
669 //this.el.open('file:///' + __script_path__ + '/../builder.html');
674 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
675 null, // list of targets
676 Gdk.DragAction.COPY // what to do with data after dropped
679 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
680 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
682 GLib.Timeout.add_seconds(1, () =>{
683 //print("run refresh?");
684 if (this.el == null) {
695 this.el.script_dialog.connect( (dialog) => {
698 if (this.el == null) {
702 var msg = dialog.get_message();
703 if (msg.length < 4) {
707 GLib.debug("script dialog got %s", msg);
709 if (msg.substring(0,4) != "IPC:") {
712 var ar = msg.split(":", 3);
719 GLib.debug("GOT saveHTML %d", ar[2].length);
720 _this.file.saveHTML(ar[2]);
728 this.el.ready_to_show.connect( ( ) => {
729 this.initInspector();
732 this.el.load_changed.connect( (le) => {
733 if (le != WebKit.LoadEvent.FINISHED) {
736 if (this.runjs.length < 1) {
739 // this.el.run_javascript(this.runjs, null);
740 FakeServerCache.remove( this.runjs);
745 // user defined functions
746 public void initInspector () {
750 // this.inspector.open_window.connect(() => {
751 this.inspector = this.el.get_inspector();
753 this.inspector.open_window.connect(() => {
754 print("inspector attach\n");
755 var wv = this.inspector.get_web_view();
757 print("got inspector web view\n");
759 var cn = _this.inspectorcontainer.el.get_first_child();
761 _this.inspectorcontainer.el.remove(cn);
764 _this.inspectorcontainer.el.append(wv);
767 print("got inspector web view FAILED\n");
768 //this.inspector.close();
770 //this.inspector = null;
777 this.inspector.show();
782 public void renderJS (bool force) {
784 // this is the public redraw call..
785 // we refresh in a loop privately..
786 var autodraw = _this.AutoRedraw.el.active;
787 if (!autodraw && !force) {
788 print("Skipping redraw - no force, and autodraw off");
792 this.refreshRequired = true;
794 public void reInit () {
796 // if this happens destroy the webkit..
798 this.el.stop_loading();
800 if (_this.viewbox.el.get_parent() == null) {
805 _this.viewbox.el.remove(_this.viewcontainer.el);
806 //_this.paned.el.remove(_this.inspectorcontainer.el);
808 // destory seems to cause problems.
810 //_this.viewcontainer.el.destroy();
811 //_this.inspectorcontainer.el.destroy();
812 var inv =new Xcls_inspectorcontainer(_this);
814 _this.paned.el.set_end_child(inv.el);
815 _this.inspectorcontainer = inv;
818 var nv =new Xcls_viewcontainer(_this);
820 _this.viewbox.el.append(nv.el);
822 _this.viewcontainer = nv;
825 //while(Gtk.events_pending ()) Gtk.main_iteration ();
826 //_this.view.renderJS(true);
827 _this.view.refreshRequired = true;
831 public void runRefresh ()
833 // this is run every 2 seconds from the init..
837 if (!this.refreshRequired) {
838 // print("no refresh required");
842 if (this.lastRedraw != null) {
843 // do not redraw if last redraw was less that 5 seconds ago.
844 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
849 if (_this.file == null) {
854 this.refreshRequired = false;
855 // print("HTML RENDERING");
858 //this.get('/BottomPane').el.show();
859 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
860 _this.file.webkit_page_id = this.el.get_page_id();
862 var js = _this.file.toSourcePreview();
871 var project = (Project.Roo) _this.file.project;
873 //print (project.fn);
874 // set it to non-empty.
876 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
879 // this.runhtml = this.runhtml || '';
882 // then we need to reload the browser using
883 // load_html_string..
885 // then trigger a redraw once it's loaded..
886 this.pendingRedraw = true;
888 var runhtml = "<script type=\"text/javascript\">\n" ;
892 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
897 runhtml += builderhtml + "\n";
898 runhtml += "</script>\n" ;
900 // fix to make sure they are the same..
901 this.runhtml = project.runhtml;
902 // need to modify paths
905 var base_template = project.base_template;
907 if (base_template.length > 0 && !FileUtils.test(
908 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
910 print("invalid base_template name - using default: %s\n", base_template);
915 GLib.FileUtils.get_contents(
916 BuilderApplication.configDirectory() + "/resources/" +
917 (base_template.length > 0 ? base_template : "roo.builder.html")
923 this.renderedData = js;
926 string js_src = js + "
927 Roo.onReady(function() {
928 if (" + _this.file.name +".show) {
929 " + _this.file.name +".show({});
931 Builder.saveHTML.defer(100, Builder);
934 Roo.XComponent.build();
937 // print("render js: " + js);
939 // console.log('not loaded yet');
941 this.lastRedraw = new DateTime.now_local();
944 //this.runjs = js_src;
945 var fc = FakeServerCache.factory_with_data(js_src);
946 this.runjs = fc.fname;
948 var html = inhtml.replace("</head>", runhtml + this.runhtml +
949 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
950 // "<script type=\"text/javascript\">\n" +
955 //print("LOAD HTML " + html);
957 var rootURL = project.rootURL;
961 this.el.load_html( html ,
962 //fixme - should be a config option!
963 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
965 this.initInspector();
966 // force the inspector...
967 // this.initInspector();
969 // - no need for this, the builder javascript will call it when build is complete
970 //GLib.Timeout.add_seconds(1, () => {
971 // this.el.run_javascript("Builder.saveHTML()",null);
974 // print( "before render" + this.lastRedraw);
975 // print( "after render" + (new Date()));
981 public class Xcls_inspectorcontainer : Object
984 private Xcls_WindowRooView _this;
990 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
993 _this.inspectorcontainer = this;
994 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
998 // set gobject values
999 this.el.vexpand = true;
1002 // user defined functions
1006 public class Xcls_Box13 : Object
1009 private Xcls_WindowRooView _this;
1015 public Xcls_Box13(Xcls_WindowRooView _owner )
1018 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1022 // set gobject values
1023 this.el.vexpand = true;
1024 new Xcls_sourceviewscroll( _this );
1025 this.el.append( _this.sourceviewscroll.el );
1026 var child_2 = new Xcls_Box18( _this );
1028 this.el.append( child_2.el );
1031 // user defined functions
1033 public class Xcls_sourceviewscroll : Object
1035 public Gtk.ScrolledWindow el;
1036 private Xcls_WindowRooView _this;
1042 public Xcls_sourceviewscroll(Xcls_WindowRooView _owner )
1045 _this.sourceviewscroll = this;
1046 this.el = new Gtk.ScrolledWindow();
1050 // set gobject values
1051 this.el.vexpand = true;
1052 new Xcls_sourceview( _this );
1053 this.el.set_child ( _this.sourceview.el );
1056 // user defined functions
1058 public class Xcls_sourceview : Object
1060 public GtkSource.View el;
1061 private Xcls_WindowRooView _this;
1065 public int editable_start_pos;
1066 public bool loading;
1067 public bool button_is_pressed;
1068 public string prop_selected;
1069 public bool key_is_pressed;
1070 public Gtk.CssProvider css;
1071 public JsRender.Node? node_selected;
1074 public Xcls_sourceview(Xcls_WindowRooView _owner )
1077 _this.sourceview = this;
1078 this.el = new GtkSource.View();
1081 this.editable_start_pos = -1;
1082 this.loading = true;
1083 this.button_is_pressed = false;
1084 this.prop_selected = "";
1085 this.key_is_pressed = false;
1086 this.node_selected = null;
1088 // set gobject values
1089 this.el.name = "roo-view";
1090 this.el.editable = false;
1091 this.el.show_line_marks = true;
1092 this.el.show_line_numbers = true;
1093 new Xcls_buffer( _this );
1094 this.el.set_buffer ( _this.buffer.el );
1095 var child_2 = new Xcls_EventControllerKey17( _this );
1097 this.el.add_controller ( child_2.el );
1103 this.css = new Gtk.CssProvider();
1105 this.css.load_from_string(
1106 "#roo-view { font: 10px monospace; }"
1109 Gtk.StyleContext.add_provider_for_display(
1110 this.el.get_display(),
1112 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1117 this.loading = true;
1118 //var buf = this.el.get_buffer();
1119 //buf.notify.connect(this.onCursorChanged);
1122 var attrs = new GtkSource.MarkAttributes();
1123 attrs.set_icon_name ( "process-stop");
1124 attrs.query_tooltip_text.connect(( mark) => {
1125 //print("tooltip query? %s\n", mark.name);
1129 this.el.set_mark_attributes ("ERR", attrs, 1);
1131 var wattrs = new GtkSource.MarkAttributes();
1132 wattrs.set_icon_name ( "process-stop");
1133 wattrs.query_tooltip_text.connect(( mark) => {
1134 //print("tooltip query? %s\n", mark.name);
1138 this.el.set_mark_attributes ("WARN", wattrs, 1);
1142 var dattrs = new GtkSource.MarkAttributes();
1143 dattrs.set_icon_name ( "process-stop");
1144 dattrs.query_tooltip_text.connect(( mark) => {
1145 //print("tooltip query? %s\n", mark.name);
1149 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1152 var gattrs = new GtkSource.MarkAttributes();
1153 var grey = Gdk.RGBA();
1154 grey.parse ( "#ccc");
1155 gattrs.set_background ( grey);
1158 this.el.set_mark_attributes ("grey", gattrs, 1);
1167 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
1169 //GLib.debug("query tooltip");
1173 var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
1175 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
1177 var l = iter.get_line();
1178 //GLib.debug("query tooltip line %d", (int) l);
1179 var marks = _this.buffer.el.get_source_marks_at_line(l, null);
1180 //GLib.debug("query tooltip line marks %d", (int) marks.length());
1182 marks.@foreach((m) => {
1183 //GLib.debug("got mark %s", m.name);
1184 str += (str.length > 0 ? "\n" : "") + m.name;
1186 // true if there is a mark..
1187 if (str.length > 0 ) {
1188 tooltip.set_text( str);
1190 return str.length > 0 ? true : false;
1195 // user defined functions
1196 public void loadFile ( ) {
1197 this.loading = true;
1200 // get the cursor and scroll position....
1201 var buf = this.el.get_buffer();
1202 var cpos = buf.cursor_position;
1204 print("BEFORE LOAD cursor = %d\n", cpos);
1206 var vadj_pos = this.el.get_vadjustment().get_value();
1211 var sbuf = (GtkSource.Buffer) buf;
1215 if (_this.file == null || _this.file.xtype != "Roo") {
1216 print("xtype != Roo");
1217 this.loading = false;
1221 // get the string from the rendered tree...
1223 var str = _this.file.toSource();
1225 // print("setting str %d\n", str.length);
1226 buf.set_text(str, str.length);
1227 var lm = GtkSource.LanguageManager.get_default();
1229 //?? is javascript going to work as js?
1231 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
1234 _this.main_window.windowstate.updateErrorMarksAll();
1236 // restore the cursor position?
1237 // after reloading the contents.
1238 GLib.Timeout.add(500, () => {
1239 _this.buffer.in_cursor_change = true;
1240 print("RESORTING cursor to = %d\n", cpos);
1241 Gtk.TextIter cpos_iter;
1242 buf.get_iter_at_offset(out cpos_iter, cpos);
1243 buf.place_cursor(cpos_iter);
1245 this.el.get_vadjustment().set_value(vadj_pos);;
1246 _this.buffer.in_cursor_change = false;
1250 //_this.buffer.checkSyntax();
1254 this.loading = false;
1255 _this.buffer.dirty = false;
1257 public void nodeSelected (JsRender.Node? sel, bool scroll) {
1263 // this is connected in widnowstate
1264 print("Roo-view - node selected\n");
1265 var buf = this.el.get_buffer();
1267 var sbuf = (GtkSource.Buffer) buf;
1272 // clear all the marks..
1276 sbuf.get_bounds (out start, out end);
1277 sbuf.remove_source_marks (start, end, "grey");
1279 this.node_selected = sel;
1281 // no highlighting..
1285 sbuf.get_iter_at_line(out iter, sel.line_start);
1288 Gtk.TextIter cur_iter;
1289 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1291 //var cur_line = cur_iter.get_line();
1292 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1295 if (! _this.buffer.in_cursor_change) {
1296 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1301 for (var i = 0; i < buf.get_line_count();i++) {
1302 if (i < sel.line_start || i > sel.line_end) {
1304 sbuf.get_iter_at_line(out iter, i);
1305 sbuf.create_source_mark(null, "grey", iter);
1313 public void updateGreySelection (bool scroll) {
1314 var sel = this.node_selected;
1315 print("node selected\n");
1316 var buf = this.el.get_buffer();
1317 var sbuf = (GtkSource.Buffer) buf;
1320 this.clearGreySelection();
1325 print("no selected node\n");
1326 // no highlighting..
1330 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1332 sbuf.get_iter_at_line(out iter, sel.line_start);
1335 Gtk.TextIter cur_iter;
1336 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1338 var cursor_at_line = cur_iter.get_line();
1341 //var cur_line = cur_iter.get_line();
1342 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1346 print("scrolling to node -- should occur on node picking.\n");
1347 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1350 var start_line = sel.line_start;
1351 var end_line = sel.line_end;
1354 this.el.editable = false;
1356 //var colon_pos = 0;
1358 this.editable_start_pos = -1;
1360 // now if we have selected a property...
1361 if (this.prop_selected.length> 0 ) {
1364 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1365 start_line = nstart;
1367 // this.el.editable = true; << cant do this!!?
1368 print("start line = %d, end line = %d\n", start_line, end_line);
1370 // see if we are 'right of ':'
1371 // get an iter for the start of the line.
1372 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1373 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1374 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1379 if (end_first_line_iter.forward_to_line_end()) {
1380 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1382 print("first line = %s\n", first_line);
1383 if (first_line.contains(":")) {
1384 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1385 print("colon_pos = %d\n", this.editable_start_pos);
1389 //Gtk.TextIter colon_iter;
1390 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1391 //sbuf.create_source_mark(null, "active_text", colon_iter);
1396 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1397 //if (start_line - 1 == cursor_at_line) {
1398 // should be ok - current_posssion can not be less than '-1'...
1399 if (sbuf.cursor_position < this.editable_start_pos) {
1401 print("cursor is before start pos.. - turn off editable...\n");
1402 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1403 //print("before cursor string = %s\n", before_cursor_string);
1404 //if (!before_cursor_string.contains(":")) {
1405 this.el.editable = false;
1414 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1419 print("checking selection\n");
1422 // check selection - if it's out of 'bounds'
1423 if (this.el.editable && sbuf.get_has_selection()) {
1424 Gtk.TextIter sel_start_iter, sel_end_iter;
1425 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1427 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1428 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1430 this.el.editable = false;
1432 if (this.editable_start_pos > 0 &&
1433 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1436 this.el.editable = false;
1446 for (var i = 0; i < buf.get_line_count();i++) {
1447 if (i < (start_line -1) || i > (end_line -1)) {
1449 sbuf.get_iter_at_line(out iter, i);
1450 sbuf.create_source_mark(null, "grey", iter);
1455 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1456 Gtk.TextIter cpos_iter;
1457 buf.get_iter_at_line(out cpos_iter, start_line);
1459 buf.place_cursor(cpos_iter);
1464 public void clearGreySelection () {
1465 // clear all the marks..
1466 var sbuf = (GtkSource.Buffer)this.el.buffer;
1471 sbuf.get_bounds (out start, out end);
1472 sbuf.remove_source_marks (start, end, "grey");
1476 public string toString () {
1479 this.el.get_buffer().get_start_iter(out s);
1480 this.el.get_buffer().get_end_iter(out e);
1481 var ret = this.el.get_buffer().get_text(s,e,true);
1482 //print("TO STRING? " + ret);
1486 public class Xcls_buffer : Object
1488 public GtkSource.Buffer el;
1489 private Xcls_WindowRooView _this;
1493 public int error_line;
1494 public bool in_cursor_change;
1496 public int last_line;
1499 public Xcls_buffer(Xcls_WindowRooView _owner )
1502 _this.buffer = this;
1503 this.el = new GtkSource.Buffer( null );
1506 this.error_line = -1;
1507 this.in_cursor_change = false;
1509 this.last_line = -1;
1511 // set gobject values
1517 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
1518 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
1519 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
1520 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
1521 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
1522 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
1523 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
1524 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
1527 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
1528 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
1529 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
1533 this.el.cursor_moved.connect( ( ) => {
1534 GLib.debug("cursor moved called");
1537 if (this.in_cursor_change ) {
1538 GLib.debug("cursor changed : %d [ignoring nested call)", this.el.cursor_position);
1542 GLib.debug("cursor changed : %d", this.el.cursor_position);
1544 this.el.get_iter_at_offset(out cpos, this.el.cursor_position);
1546 var ln = cpos.get_line();
1547 if (this.last_line == ln ){
1550 this.last_line = ln;
1551 var node = _this.file.lineToNode(ln);
1554 print("can not find node\n");
1557 this.in_cursor_change = true;
1558 var ltree = _this.main_window.windowstate.left_tree;
1559 ltree.model.selectNode(node);
1560 this.in_cursor_change = false;
1562 this.el.changed.connect( () => {
1566 // _this.save_button.el.sensitive = true;
1567 ///?? has changed occured during loading?
1569 // only trigger this if
1574 if (_this.sourceview.loading) {
1580 print("- PREVIEW EDITOR CHANGED--");
1583 // this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1587 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1588 print("button or key not pressed to generate change?!\n");
1593 // what are we editing??
1594 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1598 // find the colon on the first line...
1600 if (_this.sourceview.editable_start_pos > -1) {
1602 var buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();
1604 //print("cursor changed : %d\n", buf.cursor_position);
1605 Gtk.TextIter spos,epos;
1606 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1607 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1610 var line = spos.get_line();
1611 var endline = buf.get_line_count();
1612 while (line < endline) {
1614 buf.get_iter_at_line(out epos, line);
1615 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1616 buf.get_iter_at_line(out epos, line);
1623 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1625 // in theory the last char will be '}' or '},' .. or ','
1626 // we should chop the ',' of the end...
1627 var str = buf.get_text(spos, epos, false);
1628 print("got string\n%s\n", str);
1636 // user defined functions
1637 public string toString () {
1641 this.el.get_start_iter(out s);
1642 this.el.get_end_iter(out e);
1643 var ret = this.el.get_text(s,e,true);
1644 //print("TO STRING? " + ret);
1649 public class Xcls_EventControllerKey17 : Object
1651 public Gtk.EventControllerKey el;
1652 private Xcls_WindowRooView _this;
1658 public Xcls_EventControllerKey17(Xcls_WindowRooView _owner )
1661 this.el = new Gtk.EventControllerKey();
1665 // set gobject values
1668 this.el.key_pressed.connect( (keyval, keycode, state) => {
1672 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1673 GLib.debug("SAVE: ctrl-g pressed");
1674 _this.forwardSearch(true);
1677 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1678 GLib.debug("SAVE: ctrl-f pressed");
1679 _this.search_entry.el.grab_focus();
1683 //this.button_is_pressed = true;
1685 // print(event.key.keyval)
1693 // user defined functions
1698 public class Xcls_Box18 : Object
1701 private Xcls_WindowRooView _this;
1707 public Xcls_Box18(Xcls_WindowRooView _owner )
1710 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1714 // set gobject values
1715 this.el.homogeneous = false;
1716 this.el.vexpand = false;
1717 new Xcls_search_entry( _this );
1718 this.el.append( _this.search_entry.el );
1719 new Xcls_search_results( _this );
1720 this.el.append( _this.search_results.el );
1721 new Xcls_nextBtn( _this );
1722 this.el.append( _this.nextBtn.el );
1723 new Xcls_backBtn( _this );
1724 this.el.append( _this.backBtn.el );
1725 var child_5 = new Xcls_MenuButton24( _this );
1727 this.el.append( child_5.el );
1730 // user defined functions
1732 public class Xcls_search_entry : Object
1734 public Gtk.SearchEntry el;
1735 private Xcls_WindowRooView _this;
1739 public Gtk.CssProvider css;
1742 public Xcls_search_entry(Xcls_WindowRooView _owner )
1745 _this.search_entry = this;
1746 this.el = new Gtk.SearchEntry();
1750 // set gobject values
1751 this.el.name = "roo-search-entry";
1752 this.el.hexpand = true;
1753 this.el.placeholder_text = "Press enter to search";
1754 var child_1 = new Xcls_EventControllerKey20( _this );
1756 this.el.add_controller( child_1.el );
1760 this.css = new Gtk.CssProvider();
1762 this.css.load_from_string(
1763 "#roo-search-entry { background-color: #ccc; }"
1766 Gtk.StyleContext.add_provider_for_display(
1767 this.el.get_display(),
1769 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1773 this.el.search_changed.connect( ( ) => {
1775 _this.search(_this.search_entry.el.text);
1776 _this.search_results.updateResults();
1778 GLib.Timeout.add_seconds(1,() => {
1779 _this.search_results.updateResults();
1785 // user defined functions
1786 public void forwardSearch (bool change_focus) {
1789 _this.forwardSearch(change_focus);
1793 switch(_this.windowstate.state) {
1794 case WindowState.State.CODEONLY:
1795 //case WindowState.State.CODE:
1796 // search the code being edited..
1797 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1800 case WindowState.State.PREVIEW:
1801 if (_this.windowstate.file.xtype == "Gtk") {
1802 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1804 _this.windowstate.window_rooview.forwardSearch(change_focus);
1813 public class Xcls_EventControllerKey20 : Object
1815 public Gtk.EventControllerKey el;
1816 private Xcls_WindowRooView _this;
1822 public Xcls_EventControllerKey20(Xcls_WindowRooView _owner )
1825 this.el = new Gtk.EventControllerKey();
1829 // set gobject values
1832 this.el.key_pressed.connect( (keyval, keycode, state) => {
1834 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1835 GLib.debug("SAVE: ctrl-g pressed");
1836 _this.forwardSearch(true);
1841 if (keyval == Gdk.Key.Return) {
1842 _this.forwardSearch(true);
1848 // print(event.key.keyval)
1854 // user defined functions
1858 public class Xcls_search_results : Object
1860 public Gtk.Label el;
1861 private Xcls_WindowRooView _this;
1867 public Xcls_search_results(Xcls_WindowRooView _owner )
1870 _this.search_results = this;
1871 this.el = new Gtk.Label( "No Results" );
1875 // set gobject values
1876 this.el.margin_end = 4;
1877 this.el.margin_start = 4;
1880 // user defined functions
1881 public void updateResults () {
1882 this.el.visible = true;
1884 var res = _this.searchcontext.get_occurrences_count();
1886 _this.search_results.el.label = "??? Matches";
1890 _this.nextBtn.el.sensitive = false;
1891 _this.backBtn.el.sensitive = false;
1894 _this.search_results.el.label = "%d Matches".printf(res);
1895 _this.nextBtn.el.sensitive = true;
1896 _this.backBtn.el.sensitive = true;
1899 _this.search_results.el.label = "No Matches";
1904 public class Xcls_nextBtn : Object
1906 public Gtk.Button el;
1907 private Xcls_WindowRooView _this;
1911 public bool always_show_image;
1914 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1917 _this.nextBtn = this;
1918 this.el = new Gtk.Button();
1921 this.always_show_image = true;
1923 // set gobject values
1924 this.el.icon_name = "go-down";
1925 this.el.sensitive = false;
1928 this.el.clicked.connect( (event) => {
1930 _this.forwardSearch(true);
1935 // user defined functions
1938 public class Xcls_backBtn : Object
1940 public Gtk.Button el;
1941 private Xcls_WindowRooView _this;
1945 public bool always_show_image;
1948 public Xcls_backBtn(Xcls_WindowRooView _owner )
1951 _this.backBtn = this;
1952 this.el = new Gtk.Button();
1955 this.always_show_image = true;
1957 // set gobject values
1958 this.el.icon_name = "go-up";
1959 this.el.sensitive = false;
1962 this.el.clicked.connect( (event) => {
1964 _this.backSearch(true);
1970 // user defined functions
1973 public class Xcls_MenuButton24 : Object
1975 public Gtk.MenuButton el;
1976 private Xcls_WindowRooView _this;
1980 public bool always_show_image;
1983 public Xcls_MenuButton24(Xcls_WindowRooView _owner )
1986 this.el = new Gtk.MenuButton();
1989 this.always_show_image = true;
1991 // set gobject values
1992 this.el.icon_name = "emblem-system";
1993 new Xcls_search_settings( _this );
1994 this.el.popover = _this.search_settings.el;
1997 // user defined functions
1999 public class Xcls_search_settings : Object
2001 public Gtk.Popover el;
2002 private Xcls_WindowRooView _this;
2008 public Xcls_search_settings(Xcls_WindowRooView _owner )
2011 _this.search_settings = this;
2012 this.el = new Gtk.Popover();
2016 // set gobject values
2017 var child_1 = new Xcls_Box26( _this );
2018 this.el.child = child_1.el;
2021 // user defined functions
2023 public class Xcls_Box26 : Object
2026 private Xcls_WindowRooView _this;
2032 public Xcls_Box26(Xcls_WindowRooView _owner )
2035 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
2039 // set gobject values
2040 new Xcls_case_sensitive( _this );
2041 this.el.append( _this.case_sensitive.el );
2042 new Xcls_regex( _this );
2043 this.el.append( _this.regex.el );
2044 new Xcls_multiline( _this );
2045 this.el.append( _this.multiline.el );
2048 // user defined functions
2050 public class Xcls_case_sensitive : Object
2052 public Gtk.CheckButton el;
2053 private Xcls_WindowRooView _this;
2059 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2062 _this.case_sensitive = this;
2063 this.el = new Gtk.CheckButton();
2067 // set gobject values
2068 this.el.label = "Case Sensitive";
2077 // user defined functions
2080 public class Xcls_regex : Object
2082 public Gtk.CheckButton el;
2083 private Xcls_WindowRooView _this;
2089 public Xcls_regex(Xcls_WindowRooView _owner )
2093 this.el = new Gtk.CheckButton();
2097 // set gobject values
2098 this.el.label = "Regex";
2107 // user defined functions
2110 public class Xcls_multiline : Object
2112 public Gtk.CheckButton el;
2113 private Xcls_WindowRooView _this;
2119 public Xcls_multiline(Xcls_WindowRooView _owner )
2122 _this.multiline = this;
2123 this.el = new Gtk.CheckButton();
2127 // set gobject values
2128 this.el.label = "Multi-line (add \\n)";
2137 // user defined functions