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, "ERR");
278 buf.remove_source_marks (start, end, "WARN");
279 buf.remove_source_marks (start, end, "DEPR");
280 this.last_error_counter = file.error_counter ;
281 GLib.debug("higjlight has no errors");
284 if (this.last_error_counter == file.error_counter) {
288 var tlines = buf.get_line_count () +1;
292 buf.remove_source_marks (start, end, "ERR");
293 buf.remove_source_marks (start, end, "WARN");
294 buf.remove_source_marks (start, end, "DEPR");
295 buf.remove_tag_by_name ("ERR", start, end);
296 buf.remove_tag_by_name ("WARN", start, end);
297 buf.remove_tag_by_name ("DEPR", start, end);
298 foreach(var diag in ar) {
302 // print("get inter\n");
303 var eline = (int)diag.range.start.line ;
304 var eline_to = (int)diag.range.end.line;
305 if (eline > tlines || eline < 0) {
310 buf.get_iter_at_line( out iter, eline);
312 buf.get_iter_at_line_offset( out start,
313 eline, (int)diag.range.start.character);
314 buf.get_iter_at_line_offset( out end,
315 eline_to, (int)diag.range.end.character);
317 buf.apply_tag_by_name(diag.category, start, end);
320 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
321 buf.create_source_mark( msg, diag.category, iter);
322 GLib.debug("set line %d to %s", eline, msg);
323 //this.marks.set(eline, msg);
325 this.last_error_counter = file.error_counter ;
332 public void scroll_to_line (int line) {
335 GLib.Timeout.add(100, () => {
337 this.notebook.el.set_current_page( 1 );
340 var buf = this.sourceview.el.get_buffer();
342 var sbuf = (GtkSource.Buffer) buf;
346 sbuf.get_iter_at_line(out iter, line);
347 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
353 public class Xcls_notebook : Object
355 public Gtk.Notebook el;
356 private Xcls_WindowRooView _this;
362 public Xcls_notebook(Xcls_WindowRooView _owner )
365 _this.notebook = this;
366 this.el = new Gtk.Notebook();
370 // set gobject values
371 this.el.vexpand = true;
372 new Xcls_label_preview( _this );
373 new Xcls_label_code( _this );
374 new Xcls_paned( _this );
375 this.el.append_page ( _this.paned.el , _this.label_preview.el );
376 var child_4 = new Xcls_Box12( _this );
378 this.el.append_page ( child_4.el , _this.label_code.el );
381 // user defined functions
383 public class Xcls_label_preview : Object
386 private Xcls_WindowRooView _this;
392 public Xcls_label_preview(Xcls_WindowRooView _owner )
395 _this.label_preview = this;
396 this.el = new Gtk.Label( "Preview" );
400 // set gobject values
403 // user defined functions
406 public class Xcls_label_code : Object
409 private Xcls_WindowRooView _this;
415 public Xcls_label_code(Xcls_WindowRooView _owner )
418 _this.label_code = this;
419 this.el = new Gtk.Label( "Preview Generated Code" );
423 // set gobject values
426 // user defined functions
429 public class Xcls_paned : Object
432 private Xcls_WindowRooView _this;
438 public Xcls_paned(Xcls_WindowRooView _owner )
442 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
446 // set gobject values
447 this.el.vexpand = true;
448 new Xcls_viewbox( _this );
449 this.el.set_start_child ( _this.viewbox.el );
450 new Xcls_inspectorcontainer( _this );
451 this.el.set_end_child ( _this.inspectorcontainer.el );
454 // user defined functions
456 public class Xcls_viewbox : Object
459 private Xcls_WindowRooView _this;
465 public Xcls_viewbox(Xcls_WindowRooView _owner )
468 _this.viewbox = this;
469 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
473 // set gobject values
474 this.el.homogeneous = false;
475 this.el.vexpand = true;
476 var child_1 = new Xcls_Box6( _this );
478 this.el.append( child_1.el );
479 new Xcls_view( _this );
480 this.el.append( _this.view.el );
483 // user defined functions
485 public class Xcls_Box6 : Object
488 private Xcls_WindowRooView _this;
494 public Xcls_Box6(Xcls_WindowRooView _owner )
497 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
501 // set gobject values
502 this.el.homogeneous = true;
503 this.el.height_request = 20;
504 this.el.vexpand = false;
505 var child_1 = new Xcls_Button7( _this );
507 this.el.append( child_1.el );
508 new Xcls_AutoRedraw( _this );
509 this.el.append( _this.AutoRedraw.el );
510 var child_3 = new Xcls_Button9( _this );
512 this.el.append( child_3.el );
515 // user defined functions
517 public class Xcls_Button7 : Object
519 public Gtk.Button el;
520 private Xcls_WindowRooView _this;
526 public Xcls_Button7(Xcls_WindowRooView _owner )
529 this.el = new Gtk.Button();
533 // set gobject values
534 this.el.label = "Redraw";
537 this.el.clicked.connect( ( ) => {
538 _this.view.renderJS( true);
542 // user defined functions
545 public class Xcls_AutoRedraw : Object
547 public Gtk.CheckButton el;
548 private Xcls_WindowRooView _this;
554 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
557 _this.AutoRedraw = this;
558 this.el = new Gtk.CheckButton();
562 // set gobject values
563 this.el.active = true;
564 this.el.label = "Auto Redraw On";
567 this.el.toggled.connect( (state) => {
568 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
572 // user defined functions
575 public class Xcls_Button9 : Object
577 public Gtk.Button el;
578 private Xcls_WindowRooView _this;
584 public Xcls_Button9(Xcls_WindowRooView _owner )
587 this.el = new Gtk.Button();
591 // set gobject values
592 this.el.label = "Full Redraw";
595 this.el.clicked.connect( () => {
596 _this.view.redraws = 99;
597 // _this.view.el.web_context.clear_cache();
598 //_this.view.renderJS(true);
599 FakeServerCache.clear();
605 // user defined functions
609 public class Xcls_view : Object
611 public WebKit.WebView el;
612 private Xcls_WindowRooView _this;
616 public WebKit.WebInspector inspector;
617 public bool pendingRedraw;
619 public bool refreshRequired;
621 public string runhtml;
622 public string renderedData;
623 public GLib.DateTime lastRedraw;
626 public Xcls_view(Xcls_WindowRooView _owner )
630 this.el = new WebKit.WebView();
633 this.pendingRedraw = false;
635 this.refreshRequired = false;
638 this.renderedData = "";
639 this.lastRedraw = null;
641 // set gobject values
642 this.el.vexpand = true;
647 // this may not work!?
648 var settings = this.el.get_settings();
649 settings.enable_developer_extras = true;
652 var fs= new FakeServer(this.el);
654 // this was an attempt to change the url perms.. did not work..
655 // settings.enable_file_access_from_file_uris = true;
656 // settings.enable_offline_web_application_cache - true;
657 // settings.enable_universal_access_from_file_uris = true;
664 // FIXME - base url of script..
665 // we need it so some of the database features work.
666 this.el.load_html( "Render not ready" ,
667 //fixme - should be a config option!
668 // or should we catch stuff and fix it up..
669 "http://localhost/app.Builder/"
673 //this.el.open('file:///' + __script_path__ + '/../builder.html');
678 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
679 null, // list of targets
680 Gdk.DragAction.COPY // what to do with data after dropped
683 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
684 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
686 GLib.Timeout.add_seconds(1, () =>{
687 //print("run refresh?");
688 if (this.el == null) {
699 this.el.script_dialog.connect( (dialog) => {
701 if (this.el == null) {
705 var msg = dialog.get_message();
706 if (msg.length < 4) {
710 //GLib.debug("script dialog got %s", msg);
712 if (msg.substring(0,4) != "IPC:") {
715 var ar = msg.split(":", 3);
723 // GLib.debug("GOT saveHTML %d", ar[2].length);
724 _this.file.saveHTML(ar[2]);
733 this.el.ready_to_show.connect( ( ) => {
734 this.initInspector();
737 this.el.load_changed.connect( (le) => {
738 if (le != WebKit.LoadEvent.FINISHED) {
741 if (this.runjs.length < 1) {
744 // this.el.run_javascript(this.runjs, null);
745 FakeServerCache.remove( this.runjs);
750 // user defined functions
751 public void initInspector () {
755 // this.inspector.open_window.connect(() => {
756 this.inspector = this.el.get_inspector();
758 this.inspector.open_window.connect(() => {
759 print("inspector attach\n");
760 var wv = this.inspector.get_web_view();
762 print("got inspector web view\n");
764 var cn = _this.inspectorcontainer.el.get_first_child();
766 _this.inspectorcontainer.el.remove(cn);
769 _this.inspectorcontainer.el.append(wv);
772 print("got inspector web view FAILED\n");
773 //this.inspector.close();
775 //this.inspector = null;
782 this.inspector.show();
787 public void renderJS (bool force) {
789 // this is the public redraw call..
790 // we refresh in a loop privately..
791 var autodraw = _this.AutoRedraw.el.active;
792 if (!autodraw && !force) {
793 print("Skipping redraw - no force, and autodraw off");
797 this.refreshRequired = true;
800 public void reInit () {
802 // if this happens destroy the webkit..
804 this.el.stop_loading();
806 if (_this.viewbox.el.get_parent() == null) {
811 _this.viewbox.el.remove(_this.viewcontainer.el);
812 //_this.paned.el.remove(_this.inspectorcontainer.el);
814 // destory seems to cause problems.
816 //_this.viewcontainer.el.destroy();
817 //_this.inspectorcontainer.el.destroy();
818 var inv =new Xcls_inspectorcontainer(_this);
820 _this.paned.el.set_end_child(inv.el);
821 _this.inspectorcontainer = inv;
824 var nv =new Xcls_viewcontainer(_this);
826 _this.viewbox.el.append(nv.el);
828 _this.viewcontainer = nv;
831 //while(Gtk.events_pending ()) Gtk.main_iteration ();
832 //_this.view.renderJS(true);
833 _this.view.refreshRequired = true;
837 public void runRefresh ()
839 // this is run every 2 seconds from the init..
842 if (!this.refreshRequired) {
843 // print("no refresh required");
847 if (this.lastRedraw != null) {
848 // do not redraw if last redraw was less that 5 seconds ago.
849 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
854 if (_this.file == null) {
859 this.refreshRequired = false;
860 // print("HTML RENDERING");
863 //this.get('/BottomPane').el.show();
864 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
865 _this.file.webkit_page_id = this.el.get_page_id();
867 var js = _this.file.toSourcePreview();
876 var project = (Project.Roo) _this.file.project;
878 //print (project.fn);
879 // set it to non-empty.
881 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
884 // this.runhtml = this.runhtml || '';
887 // then we need to reload the browser using
888 // load_html_string..
890 // then trigger a redraw once it's loaded..
891 this.pendingRedraw = true;
893 var runhtml = "<script type=\"text/javascript\">\n" ;
897 GLib. File.new_for_uri("resource:///html/roo.builder.js").load_contents(null, out builderhtml, null);
902 runhtml += (string) builderhtml + "\n";
903 runhtml += "</script>\n" ;
905 // fix to make sure they are the same..
906 this.runhtml = project.runhtml;
907 // need to modify paths
910 var base_template = project.base_template;
911 var f = GLib. File.new_for_uri("resource:///html/" + base_template);
913 if (base_template.length > 0 && !f.query_exists(null)) {
915 GLib.debug("invalid base_template name - using default: %s", base_template);
916 f = GLib. File.new_for_uri("resource:///html/roo.builder.html");
920 f.load_contents(null, out inhtml, null);
926 this.renderedData = js;
929 string js_src = js + "
930 Roo.onReady(function() {
931 if (" + _this.file.name +".show) {
932 " + _this.file.name +".show({});
934 Builder.saveHTML.defer(100, Builder);
937 Roo.XComponent.build();
940 // print("render js: " + js);
942 // console.log('not loaded yet');
944 this.lastRedraw = new DateTime.now_local();
947 //this.runjs = js_src;
948 var fc = FakeServerCache.factory_with_data(js_src);
949 this.runjs = fc.fname;
950 var html = (string) inhtml;
951 html = html.replace("</head>", runhtml + this.runhtml +
952 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
953 // "<script type=\"text/javascript\">\n" +
958 //print("LOAD HTML " + html);
960 var rootURL = project.rootURL;
964 this.el.load_html( html ,
965 //fixme - should be a config option!
966 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
968 this.initInspector();
969 // force the inspector...
970 // this.initInspector();
972 // - no need for this, the builder javascript will call it when build is complete
973 //GLib.Timeout.add_seconds(1, () => {
974 // this.el.run_javascript("Builder.saveHTML()",null);
977 // print( "before render" + this.lastRedraw);
978 // print( "after render" + (new Date()));
984 public class Xcls_inspectorcontainer : Object
987 private Xcls_WindowRooView _this;
993 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
996 _this.inspectorcontainer = this;
997 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1001 // set gobject values
1002 this.el.vexpand = true;
1005 // user defined functions
1009 public class Xcls_Box12 : Object
1012 private Xcls_WindowRooView _this;
1018 public Xcls_Box12(Xcls_WindowRooView _owner )
1021 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1025 // set gobject values
1026 this.el.vexpand = true;
1027 new Xcls_sourceviewscroll( _this );
1028 this.el.append( _this.sourceviewscroll.el );
1029 var child_2 = new Xcls_Box17( _this );
1031 this.el.append( child_2.el );
1034 // user defined functions
1036 public class Xcls_sourceviewscroll : Object
1038 public Gtk.ScrolledWindow el;
1039 private Xcls_WindowRooView _this;
1045 public Xcls_sourceviewscroll(Xcls_WindowRooView _owner )
1048 _this.sourceviewscroll = this;
1049 this.el = new Gtk.ScrolledWindow();
1053 // set gobject values
1054 this.el.vexpand = true;
1055 new Xcls_sourceview( _this );
1056 this.el.set_child ( _this.sourceview.el );
1059 // user defined functions
1061 public class Xcls_sourceview : Object
1063 public GtkSource.View el;
1064 private Xcls_WindowRooView _this;
1068 public int editable_start_pos;
1069 public bool loading;
1070 public bool button_is_pressed;
1071 public string prop_selected;
1072 public Gtk.CssProvider? css;
1073 public bool key_is_pressed;
1074 public JsRender.Node? node_selected;
1077 public Xcls_sourceview(Xcls_WindowRooView _owner )
1080 _this.sourceview = this;
1081 this.el = new GtkSource.View();
1084 this.editable_start_pos = -1;
1085 this.loading = true;
1086 this.button_is_pressed = false;
1087 this.prop_selected = "";
1089 this.key_is_pressed = false;
1090 this.node_selected = null;
1092 // set gobject values
1093 this.el.name = "roo-view";
1094 this.el.editable = false;
1095 this.el.show_line_marks = true;
1096 this.el.show_line_numbers = true;
1097 this.el.css_classes = { "code-editor" };
1098 new Xcls_buffer( _this );
1099 this.el.set_buffer ( _this.buffer.el );
1100 var child_2 = new Xcls_EventControllerKey16( _this );
1102 this.el.add_controller ( child_2.el );
1110 this.loading = true;
1111 //var buf = this.el.get_buffer();
1112 //buf.notify.connect(this.onCursorChanged);
1115 var attrs = new GtkSource.MarkAttributes();
1116 attrs.set_icon_name ( "process-stop");
1117 attrs.query_tooltip_text.connect(( mark) => {
1118 //print("tooltip query? %s\n", mark.name);
1122 this.el.set_mark_attributes ("ERR", attrs, 1);
1124 var wattrs = new GtkSource.MarkAttributes();
1125 wattrs.set_icon_name ( "process-stop");
1126 wattrs.query_tooltip_text.connect(( mark) => {
1127 //print("tooltip query? %s\n", mark.name);
1131 this.el.set_mark_attributes ("WARN", wattrs, 1);
1135 var dattrs = new GtkSource.MarkAttributes();
1136 dattrs.set_icon_name ( "process-stop");
1137 dattrs.query_tooltip_text.connect(( mark) => {
1138 //print("tooltip query? %s\n", mark.name);
1142 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1145 var gattrs = new GtkSource.MarkAttributes();
1146 var grey = Gdk.RGBA();
1147 grey.parse ( "#ccc");
1148 gattrs.set_background ( grey);
1151 this.el.set_mark_attributes ("grey", gattrs, 1);
1160 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
1162 //GLib.debug("query tooltip");
1166 var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
1168 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
1170 var l = iter.get_line();
1171 //GLib.debug("query tooltip line %d", (int) l);
1172 var marks = _this.buffer.el.get_source_marks_at_line(l, null);
1173 //GLib.debug("query tooltip line marks %d", (int) marks.length());
1175 marks.@foreach((m) => {
1176 //GLib.debug("got mark %s", m.name);
1177 str += (str.length > 0 ? "\n" : "") + m.name;
1179 // true if there is a mark..
1180 if (str.length > 0 ) {
1181 tooltip.set_text( str);
1183 return str.length > 0 ? true : false;
1188 // user defined functions
1189 public void loadFile ( ) {
1190 this.loading = true;
1193 // get the cursor and scroll position....
1194 var buf = this.el.get_buffer();
1195 var cpos = buf.cursor_position;
1197 print("BEFORE LOAD cursor = %d\n", cpos);
1199 var vadj_pos = this.el.get_vadjustment().get_value();
1208 if (_this.file == null || _this.file.xtype != "Roo") {
1209 print("xtype != Roo");
1210 this.loading = false;
1214 // get the string from the rendered tree...
1216 var str = _this.file.toSource();
1218 // print("setting str %d\n", str.length);
1219 buf.set_text(str, str.length);
1220 var lm = GtkSource.LanguageManager.get_default();
1222 //?? is javascript going to work as js?
1224 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
1227 _this.main_window.windowstate.updateErrorMarksAll();
1229 // restore the cursor position?
1230 // after reloading the contents.
1231 GLib.Timeout.add(500, () => {
1232 _this.buffer.in_cursor_change = true;
1233 print("RESORTING cursor to = %d\n", cpos);
1234 Gtk.TextIter cpos_iter;
1235 buf.get_iter_at_offset(out cpos_iter, cpos);
1236 buf.place_cursor(cpos_iter);
1238 this.el.get_vadjustment().set_value(vadj_pos);;
1239 _this.buffer.in_cursor_change = false;
1243 //_this.buffer.checkSyntax();
1247 this.loading = false;
1248 _this.buffer.dirty = false;
1250 public void nodeSelected (JsRender.Node? sel, bool scroll) {
1256 // this is connected in widnowstate
1257 print("Roo-view - node selected\n");
1258 var buf = this.el.get_buffer();
1260 var sbuf = (GtkSource.Buffer) buf;
1265 // clear all the marks..
1269 sbuf.get_bounds (out start, out end);
1270 sbuf.remove_source_marks (start, end, "grey");
1272 this.node_selected = sel;
1274 // no highlighting..
1278 sbuf.get_iter_at_line(out iter, sel.line_start);
1281 Gtk.TextIter cur_iter;
1282 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1284 //var cur_line = cur_iter.get_line();
1285 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1288 if (! _this.buffer.in_cursor_change) {
1289 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1294 for (var i = 0; i < buf.get_line_count();i++) {
1295 if (i < sel.line_start || i > sel.line_end) {
1297 sbuf.get_iter_at_line(out iter, i);
1298 sbuf.create_source_mark(null, "grey", iter);
1306 public void updateGreySelection (bool scroll) {
1307 var sel = this.node_selected;
1308 print("node selected\n");
1309 var buf = this.el.get_buffer();
1310 var sbuf = (GtkSource.Buffer) buf;
1313 this.clearGreySelection();
1318 print("no selected node\n");
1319 // no highlighting..
1323 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1325 sbuf.get_iter_at_line(out iter, sel.line_start);
1328 Gtk.TextIter cur_iter;
1329 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1331 var cursor_at_line = cur_iter.get_line();
1334 //var cur_line = cur_iter.get_line();
1335 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1339 print("scrolling to node -- should occur on node picking.\n");
1340 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1343 var start_line = sel.line_start;
1344 var end_line = sel.line_end;
1347 this.el.editable = false;
1349 //var colon_pos = 0;
1351 this.editable_start_pos = -1;
1353 // now if we have selected a property...
1354 if (this.prop_selected.length> 0 ) {
1357 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1358 start_line = nstart;
1360 // this.el.editable = true; << cant do this!!?
1361 print("start line = %d, end line = %d\n", start_line, end_line);
1363 // see if we are 'right of ':'
1364 // get an iter for the start of the line.
1365 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1366 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1367 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1372 if (end_first_line_iter.forward_to_line_end()) {
1373 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1375 print("first line = %s\n", first_line);
1376 if (first_line.contains(":")) {
1377 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1378 print("colon_pos = %d\n", this.editable_start_pos);
1382 //Gtk.TextIter colon_iter;
1383 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1384 //sbuf.create_source_mark(null, "active_text", colon_iter);
1389 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1390 //if (start_line - 1 == cursor_at_line) {
1391 // should be ok - current_posssion can not be less than '-1'...
1392 if (sbuf.cursor_position < this.editable_start_pos) {
1394 print("cursor is before start pos.. - turn off editable...\n");
1395 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1396 //print("before cursor string = %s\n", before_cursor_string);
1397 //if (!before_cursor_string.contains(":")) {
1398 this.el.editable = false;
1407 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1412 print("checking selection\n");
1415 // check selection - if it's out of 'bounds'
1416 if (this.el.editable && sbuf.get_has_selection()) {
1417 Gtk.TextIter sel_start_iter, sel_end_iter;
1418 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1420 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1421 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1423 this.el.editable = false;
1425 if (this.editable_start_pos > 0 &&
1426 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1429 this.el.editable = false;
1439 for (var i = 0; i < buf.get_line_count();i++) {
1440 if (i < (start_line -1) || i > (end_line -1)) {
1442 sbuf.get_iter_at_line(out iter, i);
1443 sbuf.create_source_mark(null, "grey", iter);
1448 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1449 Gtk.TextIter cpos_iter;
1450 buf.get_iter_at_line(out cpos_iter, start_line);
1452 buf.place_cursor(cpos_iter);
1457 public void clearGreySelection () {
1458 // clear all the marks..
1459 var sbuf = (GtkSource.Buffer)this.el.buffer;
1464 sbuf.get_bounds (out start, out end);
1465 sbuf.remove_source_marks (start, end, "grey");
1469 public string toString () {
1472 this.el.get_buffer().get_start_iter(out s);
1473 this.el.get_buffer().get_end_iter(out e);
1474 var ret = this.el.get_buffer().get_text(s,e,true);
1475 //print("TO STRING? " + ret);
1479 public class Xcls_buffer : Object
1481 public GtkSource.Buffer el;
1482 private Xcls_WindowRooView _this;
1486 public int error_line;
1487 public bool in_cursor_change;
1489 public int last_line;
1492 public Xcls_buffer(Xcls_WindowRooView _owner )
1495 _this.buffer = this;
1496 this.el = new GtkSource.Buffer( null );
1499 this.error_line = -1;
1500 this.in_cursor_change = false;
1502 this.last_line = -1;
1504 // set gobject values
1510 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
1511 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
1512 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
1513 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
1514 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
1515 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
1516 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
1517 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
1520 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
1521 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
1522 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
1526 this.el.cursor_moved.connect( ( ) => {
1527 GLib.debug("cursor moved called");
1530 if (this.in_cursor_change ) {
1531 GLib.debug("cursor changed : %d [ignoring nested call)", this.el.cursor_position);
1535 GLib.debug("cursor changed : %d", this.el.cursor_position);
1537 this.el.get_iter_at_offset(out cpos, this.el.cursor_position);
1539 var ln = cpos.get_line();
1540 if (this.last_line == ln ){
1543 this.last_line = ln;
1544 var node = _this.file.lineToNode(ln);
1547 print("can not find node\n");
1550 this.in_cursor_change = true;
1551 var ltree = _this.main_window.windowstate.left_tree;
1552 ltree.model.selectNode(node);
1553 this.in_cursor_change = false;
1555 this.el.changed.connect( () => {
1559 // _this.save_button.el.sensitive = true;
1560 ///?? has changed occured during loading?
1562 // only trigger this if
1567 if (_this.sourceview.loading) {
1573 print("- PREVIEW EDITOR CHANGED--");
1576 // this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1580 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1581 print("button or key not pressed to generate change?!\n");
1586 // what are we editing??
1587 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1591 // find the colon on the first line...
1593 if (_this.sourceview.editable_start_pos > -1) {
1595 var buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();
1597 //print("cursor changed : %d\n", buf.cursor_position);
1598 Gtk.TextIter spos,epos;
1599 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1600 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1603 var line = spos.get_line();
1604 var endline = buf.get_line_count();
1605 while (line < endline) {
1607 buf.get_iter_at_line(out epos, line);
1608 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1609 buf.get_iter_at_line(out epos, line);
1616 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1618 // in theory the last char will be '}' or '},' .. or ','
1619 // we should chop the ',' of the end...
1620 var str = buf.get_text(spos, epos, false);
1621 print("got string\n%s\n", str);
1629 // user defined functions
1630 public string toString () {
1634 this.el.get_start_iter(out s);
1635 this.el.get_end_iter(out e);
1636 var ret = this.el.get_text(s,e,true);
1637 //print("TO STRING? " + ret);
1642 public class Xcls_EventControllerKey16 : Object
1644 public Gtk.EventControllerKey el;
1645 private Xcls_WindowRooView _this;
1651 public Xcls_EventControllerKey16(Xcls_WindowRooView _owner )
1654 this.el = new Gtk.EventControllerKey();
1658 // set gobject values
1661 this.el.key_pressed.connect( (keyval, keycode, state) => {
1665 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1666 GLib.debug("SAVE: ctrl-g pressed");
1667 _this.forwardSearch(true);
1670 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1671 GLib.debug("SAVE: ctrl-f pressed");
1672 _this.search_entry.el.grab_focus();
1676 //this.button_is_pressed = true;
1678 // print(event.key.keyval)
1686 // user defined functions
1691 public class Xcls_Box17 : Object
1694 private Xcls_WindowRooView _this;
1700 public Xcls_Box17(Xcls_WindowRooView _owner )
1703 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1707 // set gobject values
1708 this.el.homogeneous = false;
1709 this.el.vexpand = false;
1710 new Xcls_search_entry( _this );
1711 this.el.append( _this.search_entry.el );
1712 new Xcls_search_results( _this );
1713 this.el.append( _this.search_results.el );
1714 new Xcls_nextBtn( _this );
1715 this.el.append( _this.nextBtn.el );
1716 new Xcls_backBtn( _this );
1717 this.el.append( _this.backBtn.el );
1718 var child_5 = new Xcls_MenuButton23( _this );
1720 this.el.append( child_5.el );
1723 // user defined functions
1725 public class Xcls_search_entry : Object
1727 public Gtk.SearchEntry el;
1728 private Xcls_WindowRooView _this;
1734 public Xcls_search_entry(Xcls_WindowRooView _owner )
1737 _this.search_entry = this;
1738 this.el = new Gtk.SearchEntry();
1742 // set gobject values
1743 this.el.name = "roo-search-entry";
1744 this.el.hexpand = true;
1745 this.el.placeholder_text = "Press enter to search";
1746 var child_1 = new Xcls_EventControllerKey19( _this );
1748 this.el.add_controller( child_1.el );
1751 this.el.search_changed.connect( ( ) => {
1753 _this.search(_this.search_entry.el.text);
1754 _this.search_results.updateResults();
1756 GLib.Timeout.add_seconds(1,() => {
1757 _this.search_results.updateResults();
1763 // user defined functions
1764 public void forwardSearch (bool change_focus) {
1767 _this.forwardSearch(change_focus);
1771 switch(_this.windowstate.state) {
1772 case WindowState.State.CODEONLY:
1773 //case WindowState.State.CODE:
1774 // search the code being edited..
1775 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1778 case WindowState.State.PREVIEW:
1779 if (_this.windowstate.file.xtype == "Gtk") {
1780 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1782 _this.windowstate.window_rooview.forwardSearch(change_focus);
1791 public class Xcls_EventControllerKey19 : Object
1793 public Gtk.EventControllerKey el;
1794 private Xcls_WindowRooView _this;
1800 public Xcls_EventControllerKey19(Xcls_WindowRooView _owner )
1803 this.el = new Gtk.EventControllerKey();
1807 // set gobject values
1810 this.el.key_pressed.connect( (keyval, keycode, state) => {
1812 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1813 GLib.debug("SAVE: ctrl-g pressed");
1814 _this.forwardSearch(true);
1819 if (keyval == Gdk.Key.Return) {
1820 _this.forwardSearch(true);
1826 // print(event.key.keyval)
1832 // user defined functions
1836 public class Xcls_search_results : Object
1838 public Gtk.Label el;
1839 private Xcls_WindowRooView _this;
1845 public Xcls_search_results(Xcls_WindowRooView _owner )
1848 _this.search_results = this;
1849 this.el = new Gtk.Label( "No Results" );
1853 // set gobject values
1854 this.el.margin_end = 4;
1855 this.el.margin_start = 4;
1858 // user defined functions
1859 public void updateResults () {
1860 this.el.visible = true;
1862 var res = _this.searchcontext.get_occurrences_count();
1864 _this.search_results.el.label = "??? Matches";
1868 _this.nextBtn.el.sensitive = false;
1869 _this.backBtn.el.sensitive = false;
1872 _this.search_results.el.label = "%d Matches".printf(res);
1873 _this.nextBtn.el.sensitive = true;
1874 _this.backBtn.el.sensitive = true;
1877 _this.search_results.el.label = "No Matches";
1882 public class Xcls_nextBtn : Object
1884 public Gtk.Button el;
1885 private Xcls_WindowRooView _this;
1889 public bool always_show_image;
1892 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1895 _this.nextBtn = this;
1896 this.el = new Gtk.Button();
1899 this.always_show_image = true;
1901 // set gobject values
1902 this.el.icon_name = "go-down";
1903 this.el.sensitive = false;
1906 this.el.clicked.connect( (event) => {
1908 _this.forwardSearch(true);
1913 // user defined functions
1916 public class Xcls_backBtn : Object
1918 public Gtk.Button el;
1919 private Xcls_WindowRooView _this;
1923 public bool always_show_image;
1926 public Xcls_backBtn(Xcls_WindowRooView _owner )
1929 _this.backBtn = this;
1930 this.el = new Gtk.Button();
1933 this.always_show_image = true;
1935 // set gobject values
1936 this.el.icon_name = "go-up";
1937 this.el.sensitive = false;
1940 this.el.clicked.connect( (event) => {
1942 _this.backSearch(true);
1948 // user defined functions
1951 public class Xcls_MenuButton23 : Object
1953 public Gtk.MenuButton el;
1954 private Xcls_WindowRooView _this;
1958 public bool always_show_image;
1961 public Xcls_MenuButton23(Xcls_WindowRooView _owner )
1964 this.el = new Gtk.MenuButton();
1967 this.always_show_image = true;
1969 // set gobject values
1970 this.el.icon_name = "emblem-system";
1971 new Xcls_search_settings( _this );
1972 this.el.popover = _this.search_settings.el;
1975 // user defined functions
1977 public class Xcls_search_settings : Object
1979 public Gtk.Popover el;
1980 private Xcls_WindowRooView _this;
1986 public Xcls_search_settings(Xcls_WindowRooView _owner )
1989 _this.search_settings = this;
1990 this.el = new Gtk.Popover();
1994 // set gobject values
1995 var child_1 = new Xcls_Box25( _this );
1997 this.el.child = child_1.el;
2000 // user defined functions
2002 public class Xcls_Box25 : Object
2005 private Xcls_WindowRooView _this;
2011 public Xcls_Box25(Xcls_WindowRooView _owner )
2014 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
2018 // set gobject values
2019 new Xcls_case_sensitive( _this );
2020 this.el.append( _this.case_sensitive.el );
2021 new Xcls_regex( _this );
2022 this.el.append( _this.regex.el );
2023 new Xcls_multiline( _this );
2024 this.el.append( _this.multiline.el );
2027 // user defined functions
2029 public class Xcls_case_sensitive : Object
2031 public Gtk.CheckButton el;
2032 private Xcls_WindowRooView _this;
2038 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2041 _this.case_sensitive = this;
2042 this.el = new Gtk.CheckButton();
2046 // set gobject values
2047 this.el.label = "Case Sensitive";
2056 // user defined functions
2059 public class Xcls_regex : Object
2061 public Gtk.CheckButton el;
2062 private Xcls_WindowRooView _this;
2068 public Xcls_regex(Xcls_WindowRooView _owner )
2072 this.el = new Gtk.CheckButton();
2076 // set gobject values
2077 this.el.label = "Regex";
2086 // user defined functions
2089 public class Xcls_multiline : Object
2091 public Gtk.CheckButton el;
2092 private Xcls_WindowRooView _this;
2098 public Xcls_multiline(Xcls_WindowRooView _owner )
2101 _this.multiline = this;
2102 this.el = new Gtk.CheckButton();
2106 // set gobject values
2107 this.el.label = "Multi-line (add \\n)";
2116 // user defined functions