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_search_end;
39 public GtkSource.SearchContext searchcontext;
40 public JsRender.JsRender file;
43 public Xcls_WindowRooView()
46 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
50 this.last_search_end = 0;
54 this.el.hexpand = true;
55 this.el.vexpand = true;
56 new Xcls_notebook( _this );
57 this.el.append( _this.notebook.el );
60 // user defined functions
61 public void loadFile (JsRender.JsRender file)
64 this.view.renderJS(true);
65 this.notebook.el.page = 0;// gtk preview
66 this.sourceview.loadFile();
68 public void highlightNodeAtLine (int ln) {
75 var node = _this.file.lineToNode(ln+1);
78 //print("can not find node\n");
81 var prop = node.lineToProp(ln+1);
82 print("prop : %s", prop == null ? "???" : prop.name);
85 // ---------- this selects the tree's node...
87 var ltree = _this.main_window.windowstate.left_tree;
88 ltree.model.selectNode(node);
90 //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
93 //print("changing cursor on tree..\n");
97 // let's try allowing editing on the methods.
98 // a little klunky at present..
99 _this.sourceview.prop_selected = "";
102 //see if we can find it..
103 var kv = prop.split(":");
106 //var k = prop.get_key(kv[1]);
107 // fixme -- need to determine if it's an editable property...
108 _this.sourceview.prop_selected = prop;
110 } else if (kv[0] == "l") {
111 _this.sourceview.prop_selected = prop;
116 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
117 _this.sourceview.nodeSelected(node,false);
119 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
120 // GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
121 // this.allow_node_scroll = true;
137 public void requestRedraw () {
138 this.view.renderJS(false);
139 this.sourceview.loadFile();
141 public void forwardSearch (bool change_focus) {
143 if (this.searchcontext == null) {
146 this.notebook.el.page = 1;
147 Gtk.TextIter beg, st,en;
148 bool has_wrapped_around;
149 var buf = this.sourceview.el.get_buffer();
150 buf.get_iter_at_offset(out beg, this.last_search_end);
151 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
152 this.last_search_end = 0;
155 this.last_search_end = en.get_offset();
157 this.sourceview.el.grab_focus();
159 buf.place_cursor(st);
163 this.sourceview.el.scroll_to_iter(st, 0.0f, true, 0.0f, 0.5f);
166 var ln = st.get_line();
168 this.highlightNodeAtLine(ln);
170 public void backSearch (bool change_focus) {
172 if (this.searchcontext == null) {
176 Gtk.TextIter beg, st,en;
177 bool has_wrapped_around;
178 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
180 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
182 this.last_search_end = 0;
185 this.last_search_end = en.get_offset();
187 this.sourceview.el.grab_focus();
189 this.buffer.el.place_cursor(st);
190 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
191 var ln = st.get_line();
192 this.highlightNodeAtLine(ln);
196 public int search (string in_txt) {
197 this.notebook.el.page = 1;
201 var s = new GtkSource.SearchSettings();
202 s.case_sensitive = _this.case_sensitive.el.active;
203 s.regex_enabled = _this.regex.el.active;
204 s.wrap_around = false;
206 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
207 this.searchcontext.set_highlight(true);
210 if (_this.multiline.el.active) {
211 txt = in_txt.replace("\\n", "\n");
214 s.set_search_text(txt);
215 Gtk.TextIter beg, st,en;
216 bool has_wrapped_around;
217 this.buffer.el.get_start_iter(out beg);
218 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
219 this.last_search_end = 0;
221 return this.searchcontext.get_occurrences_count();
227 public void createThumb () {
230 if (this.file == null) {
234 if (this.notebook.el.page > 0 ) {
238 this.file.widgetToIcon(this.view.el);
245 public void updateErrorMarks (string category) {
249 var buf = _this.buffer.el;
252 buf.get_bounds (out start, out end);
254 buf.remove_source_marks (start, end, category);
256 GLib.debug("highlight errors");
258 // we should highlight other types of errors..
263 if (_this.file == null) {
264 GLib.debug("file is null?");
268 var ar = this.file.getErrors(category);
269 if (ar == null || ar.get_n_items() < 1) {
270 GLib.debug("higjlight %s has no errors", category);
280 var tlines = buf.get_line_count () +1;
284 for (var i = 0; i < ar.get_n_items();i++) {
285 var err = (Palete.CompileError) ar.get_item(i);
288 // print("get inter\n");
289 var eline = err.line - offset;
290 GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
291 err.line ,eline, offset);
294 if (eline > tlines || eline < 0) {
299 buf.get_iter_at_line( out iter, eline);
302 var msg = "Line: %d %s : %s".printf(eline+1, err.category, err.msg);
303 buf.create_source_mark( msg, err.category, iter);
304 GLib.debug("set line %d to %s", eline, msg);
305 //this.marks.set(eline, msg);
314 public void scroll_to_line (int line) {
317 GLib.Timeout.add(100, () => {
319 this.notebook.el.set_current_page( 1 );
322 var buf = this.sourceview.el.get_buffer();
324 var sbuf = (GtkSource.Buffer) buf;
328 sbuf.get_iter_at_line(out iter, line);
329 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
335 public class Xcls_notebook : Object
337 public Gtk.Notebook el;
338 private Xcls_WindowRooView _this;
344 public Xcls_notebook(Xcls_WindowRooView _owner )
347 _this.notebook = this;
348 this.el = new Gtk.Notebook();
352 // set gobject values
353 this.el.vexpand = true;
354 new Xcls_label_preview( _this );
355 new Xcls_label_code( _this );
356 new Xcls_paned( _this );
357 this.el.append_page ( _this.paned.el , _this.label_preview.el );
358 var child_4 = new Xcls_Box13( _this );
360 this.el.append_page ( child_4.el , _this.label_code.el );
363 // user defined functions
365 public class Xcls_label_preview : Object
368 private Xcls_WindowRooView _this;
374 public Xcls_label_preview(Xcls_WindowRooView _owner )
377 _this.label_preview = this;
378 this.el = new Gtk.Label( "Preview" );
382 // set gobject values
385 // user defined functions
388 public class Xcls_label_code : Object
391 private Xcls_WindowRooView _this;
397 public Xcls_label_code(Xcls_WindowRooView _owner )
400 _this.label_code = this;
401 this.el = new Gtk.Label( "Preview Generated Code" );
405 // set gobject values
408 // user defined functions
411 public class Xcls_paned : Object
414 private Xcls_WindowRooView _this;
420 public Xcls_paned(Xcls_WindowRooView _owner )
424 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
428 // set gobject values
429 this.el.vexpand = true;
430 new Xcls_viewbox( _this );
431 this.el.set_start_child ( _this.viewbox.el );
432 new Xcls_inspectorcontainer( _this );
433 this.el.set_end_child ( _this.inspectorcontainer.el );
436 // user defined functions
438 public class Xcls_viewbox : Object
441 private Xcls_WindowRooView _this;
447 public Xcls_viewbox(Xcls_WindowRooView _owner )
450 _this.viewbox = this;
451 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
455 // set gobject values
456 this.el.homogeneous = false;
457 this.el.vexpand = true;
458 var child_1 = new Xcls_Box7( _this );
460 this.el.append( child_1.el );
461 new Xcls_view( _this );
462 this.el.append( _this.view.el );
465 // user defined functions
467 public class Xcls_Box7 : Object
470 private Xcls_WindowRooView _this;
476 public Xcls_Box7(Xcls_WindowRooView _owner )
479 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
483 // set gobject values
484 this.el.homogeneous = true;
485 this.el.height_request = 20;
486 this.el.vexpand = false;
487 var child_1 = new Xcls_Button8( _this );
489 this.el.append( child_1.el );
490 new Xcls_AutoRedraw( _this );
491 this.el.append( _this.AutoRedraw.el );
492 var child_3 = new Xcls_Button10( _this );
494 this.el.append( child_3.el );
497 // user defined functions
499 public class Xcls_Button8 : Object
501 public Gtk.Button el;
502 private Xcls_WindowRooView _this;
508 public Xcls_Button8(Xcls_WindowRooView _owner )
511 this.el = new Gtk.Button();
515 // set gobject values
516 this.el.label = "Redraw";
519 this.el.clicked.connect( ( ) => {
520 _this.view.renderJS( true);
524 // user defined functions
527 public class Xcls_AutoRedraw : Object
529 public Gtk.CheckButton el;
530 private Xcls_WindowRooView _this;
536 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
539 _this.AutoRedraw = this;
540 this.el = new Gtk.CheckButton();
544 // set gobject values
545 this.el.active = true;
546 this.el.label = "Auto Redraw On";
549 this.el.toggled.connect( (state) => {
550 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
554 // user defined functions
557 public class Xcls_Button10 : Object
559 public Gtk.Button el;
560 private Xcls_WindowRooView _this;
566 public Xcls_Button10(Xcls_WindowRooView _owner )
569 this.el = new Gtk.Button();
573 // set gobject values
574 this.el.label = "Full Redraw";
577 this.el.clicked.connect( () => {
578 _this.view.redraws = 99;
579 // _this.view.el.web_context.clear_cache();
580 //_this.view.renderJS(true);
581 FakeServerCache.clear();
587 // user defined functions
591 public class Xcls_view : Object
593 public WebKit.WebView el;
594 private Xcls_WindowRooView _this;
598 public WebKit.WebInspector inspector;
599 public bool pendingRedraw;
601 public bool refreshRequired;
603 public string runhtml;
604 public string renderedData;
605 public GLib.DateTime lastRedraw;
608 public Xcls_view(Xcls_WindowRooView _owner )
612 this.el = new WebKit.WebView();
615 this.pendingRedraw = false;
617 this.refreshRequired = false;
620 this.renderedData = "";
621 this.lastRedraw = null;
623 // set gobject values
624 this.el.vexpand = true;
629 // this may not work!?
630 var settings = this.el.get_settings();
631 settings.enable_developer_extras = true;
634 var fs= new FakeServer(this.el);
636 // this was an attempt to change the url perms.. did not work..
637 // settings.enable_file_access_from_file_uris = true;
638 // settings.enable_offline_web_application_cache - true;
639 // settings.enable_universal_access_from_file_uris = true;
646 // FIXME - base url of script..
647 // we need it so some of the database features work.
648 this.el.load_html( "Render not ready" ,
649 //fixme - should be a config option!
650 // or should we catch stuff and fix it up..
651 "http://localhost/app.Builder/"
655 //this.el.open('file:///' + __script_path__ + '/../builder.html');
660 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
661 null, // list of targets
662 Gdk.DragAction.COPY // what to do with data after dropped
665 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
666 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
668 GLib.Timeout.add_seconds(1, () =>{
669 //print("run refresh?");
670 if (this.el == null) {
681 this.el.script_dialog.connect( (dialog) => {
684 if (this.el == null) {
688 var msg = dialog.get_message();
689 if (msg.length < 4) {
693 GLib.debug("script dialog got %s", msg);
695 if (msg.substring(0,4) != "IPC:") {
698 var ar = msg.split(":", 3);
705 GLib.debug("GOT saveHTML %d", ar[2].length);
706 _this.file.saveHTML(ar[2]);
714 this.el.ready_to_show.connect( ( ) => {
715 this.initInspector();
718 this.el.load_changed.connect( (le) => {
719 if (le != WebKit.LoadEvent.FINISHED) {
722 if (this.runjs.length < 1) {
725 // this.el.run_javascript(this.runjs, null);
726 FakeServerCache.remove( this.runjs);
731 // user defined functions
732 public void initInspector () {
736 // this.inspector.open_window.connect(() => {
737 this.inspector = this.el.get_inspector();
739 this.inspector.open_window.connect(() => {
740 print("inspector attach\n");
741 var wv = this.inspector.get_web_view();
743 print("got inspector web view\n");
745 var cn = _this.inspectorcontainer.el.get_first_child();
747 _this.inspectorcontainer.el.remove(cn);
750 _this.inspectorcontainer.el.append(wv);
753 print("got inspector web view FAILED\n");
754 //this.inspector.close();
756 //this.inspector = null;
763 this.inspector.show();
768 public void renderJS (bool force) {
770 // this is the public redraw call..
771 // we refresh in a loop privately..
772 var autodraw = _this.AutoRedraw.el.active;
773 if (!autodraw && !force) {
774 print("Skipping redraw - no force, and autodraw off");
778 this.refreshRequired = true;
780 public void reInit () {
782 // if this happens destroy the webkit..
784 this.el.stop_loading();
786 if (_this.viewbox.el.get_parent() == null) {
791 _this.viewbox.el.remove(_this.viewcontainer.el);
792 //_this.paned.el.remove(_this.inspectorcontainer.el);
794 // destory seems to cause problems.
796 //_this.viewcontainer.el.destroy();
797 //_this.inspectorcontainer.el.destroy();
798 var inv =new Xcls_inspectorcontainer(_this);
800 _this.paned.el.set_end_child(inv.el);
801 _this.inspectorcontainer = inv;
804 var nv =new Xcls_viewcontainer(_this);
806 _this.viewbox.el.append(nv.el);
808 _this.viewcontainer = nv;
811 //while(Gtk.events_pending ()) Gtk.main_iteration ();
812 //_this.view.renderJS(true);
813 _this.view.refreshRequired = true;
817 public void runRefresh ()
819 // this is run every 2 seconds from the init..
823 if (!this.refreshRequired) {
824 // print("no refresh required");
828 if (this.lastRedraw != null) {
829 // do not redraw if last redraw was less that 5 seconds ago.
830 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
835 if (_this.file == null) {
840 this.refreshRequired = false;
841 // print("HTML RENDERING");
844 //this.get('/BottomPane').el.show();
845 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
846 _this.file.webkit_page_id = this.el.get_page_id();
848 var js = _this.file.toSourcePreview();
857 var project = (Project.Roo) _this.file.project;
859 //print (project.fn);
860 // set it to non-empty.
862 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
865 // this.runhtml = this.runhtml || '';
868 // then we need to reload the browser using
869 // load_html_string..
871 // then trigger a redraw once it's loaded..
872 this.pendingRedraw = true;
874 var runhtml = "<script type=\"text/javascript\">\n" ;
878 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
883 runhtml += builderhtml + "\n";
884 runhtml += "</script>\n" ;
886 // fix to make sure they are the same..
887 this.runhtml = project.runhtml;
888 // need to modify paths
891 var base_template = project.base_template;
893 if (base_template.length > 0 && !FileUtils.test(
894 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
896 print("invalid base_template name - using default: %s\n", base_template);
901 GLib.FileUtils.get_contents(
902 BuilderApplication.configDirectory() + "/resources/" +
903 (base_template.length > 0 ? base_template : "roo.builder.html")
909 this.renderedData = js;
912 string js_src = js + "
913 Roo.onReady(function() {
914 if (" + _this.file.name +".show) {
915 " + _this.file.name +".show({});
917 Builder.saveHTML.defer(100, Builder);
920 Roo.XComponent.build();
923 // print("render js: " + js);
925 // console.log('not loaded yet');
927 this.lastRedraw = new DateTime.now_local();
930 //this.runjs = js_src;
931 var fc = FakeServerCache.factory_with_data(js_src);
932 this.runjs = fc.fname;
934 var html = inhtml.replace("</head>", runhtml + this.runhtml +
935 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
936 // "<script type=\"text/javascript\">\n" +
941 //print("LOAD HTML " + html);
943 var rootURL = project.rootURL;
947 this.el.load_html( html ,
948 //fixme - should be a config option!
949 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
951 this.initInspector();
952 // force the inspector...
953 // this.initInspector();
955 // - no need for this, the builder javascript will call it when build is complete
956 //GLib.Timeout.add_seconds(1, () => {
957 // this.el.run_javascript("Builder.saveHTML()",null);
960 // print( "before render" + this.lastRedraw);
961 // print( "after render" + (new Date()));
967 public class Xcls_inspectorcontainer : Object
970 private Xcls_WindowRooView _this;
976 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
979 _this.inspectorcontainer = this;
980 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
984 // set gobject values
985 this.el.vexpand = true;
988 // user defined functions
992 public class Xcls_Box13 : Object
995 private Xcls_WindowRooView _this;
1001 public Xcls_Box13(Xcls_WindowRooView _owner )
1004 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1008 // set gobject values
1009 this.el.vexpand = true;
1010 new Xcls_sourceviewscroll( _this );
1011 this.el.append( _this.sourceviewscroll.el );
1012 var child_2 = new Xcls_Box18( _this );
1014 this.el.append( child_2.el );
1017 // user defined functions
1019 public class Xcls_sourceviewscroll : Object
1021 public Gtk.ScrolledWindow el;
1022 private Xcls_WindowRooView _this;
1028 public Xcls_sourceviewscroll(Xcls_WindowRooView _owner )
1031 _this.sourceviewscroll = this;
1032 this.el = new Gtk.ScrolledWindow();
1036 // set gobject values
1037 this.el.vexpand = true;
1038 new Xcls_sourceview( _this );
1039 this.el.set_child ( _this.sourceview.el );
1042 // user defined functions
1044 public class Xcls_sourceview : Object
1046 public GtkSource.View el;
1047 private Xcls_WindowRooView _this;
1051 public int editable_start_pos;
1052 public bool loading;
1053 public bool button_is_pressed;
1054 public string prop_selected;
1055 public bool key_is_pressed;
1056 public Gtk.CssProvider css;
1057 public JsRender.Node? node_selected;
1060 public Xcls_sourceview(Xcls_WindowRooView _owner )
1063 _this.sourceview = this;
1064 this.el = new GtkSource.View();
1067 this.editable_start_pos = -1;
1068 this.loading = true;
1069 this.button_is_pressed = false;
1070 this.prop_selected = "";
1071 this.key_is_pressed = false;
1072 this.node_selected = null;
1074 // set gobject values
1075 this.el.name = "roo-view";
1076 this.el.editable = false;
1077 this.el.show_line_marks = true;
1078 this.el.show_line_numbers = true;
1079 new Xcls_buffer( _this );
1080 this.el.set_buffer ( _this.buffer.el );
1081 var child_2 = new Xcls_EventControllerKey17( _this );
1083 this.el.add_controller ( child_2.el );
1089 this.css = new Gtk.CssProvider();
1091 this.css.load_from_string(
1092 "#roo-view { font: 10px monospace; }"
1095 Gtk.StyleContext.add_provider_for_display(
1096 this.el.get_display(),
1098 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1103 this.loading = true;
1104 //var buf = this.el.get_buffer();
1105 //buf.notify.connect(this.onCursorChanged);
1108 var attrs = new GtkSource.MarkAttributes();
1109 var pink = Gdk.RGBA();
1110 pink.parse ( "pink");
1111 attrs.set_background ( pink);
1112 attrs.set_icon_name ( "process-stop");
1113 attrs.query_tooltip_text.connect(( mark) => {
1114 //print("tooltip query? %s\n", mark.name);
1118 this.el.set_mark_attributes ("ERR", attrs, 1);
1120 var wattrs = new GtkSource.MarkAttributes();
1121 var blue = Gdk.RGBA();
1122 blue.parse ( "#ABF4EB");
1123 wattrs.set_background ( blue);
1124 wattrs.set_icon_name ( "process-stop");
1125 wattrs.query_tooltip_text.connect(( mark) => {
1126 //print("tooltip query? %s\n", mark.name);
1130 this.el.set_mark_attributes ("WARN", wattrs, 1);
1134 var dattrs = new GtkSource.MarkAttributes();
1135 var purple = Gdk.RGBA();
1136 purple.parse ( "#EEA9FF");
1137 dattrs.set_background ( purple);
1138 dattrs.set_icon_name ( "process-stop");
1139 dattrs.query_tooltip_text.connect(( mark) => {
1140 //print("tooltip query? %s\n", mark.name);
1144 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1147 var gattrs = new GtkSource.MarkAttributes();
1148 var grey = Gdk.RGBA();
1149 grey.parse ( "#ccc");
1150 gattrs.set_background ( grey);
1153 this.el.set_mark_attributes ("grey", gattrs, 1);
1163 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
1165 //GLib.debug("query tooltip");
1169 var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
1171 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
1173 var l = iter.get_line();
1174 //GLib.debug("query tooltip line %d", (int) l);
1175 var marks = _this.buffer.el.get_source_marks_at_line(l, null);
1176 //GLib.debug("query tooltip line marks %d", (int) marks.length());
1178 marks.@foreach((m) => {
1179 //GLib.debug("got mark %s", m.name);
1180 str += (str.length > 0 ? "\n" : "") + m.name;
1182 // true if there is a mark..
1183 if (str.length > 0 ) {
1184 tooltip.set_text( str);
1186 return str.length > 0 ? true : false;
1191 // user defined functions
1192 public void loadFile ( ) {
1193 this.loading = true;
1196 // get the cursor and scroll position....
1197 var buf = this.el.get_buffer();
1198 var cpos = buf.cursor_position;
1200 print("BEFORE LOAD cursor = %d\n", cpos);
1202 var vadj_pos = this.el.get_vadjustment().get_value();
1207 var sbuf = (GtkSource.Buffer) buf;
1211 if (_this.file == null || _this.file.xtype != "Roo") {
1212 print("xtype != Roo");
1213 this.loading = false;
1217 // get the string from the rendered tree...
1219 var str = _this.file.toSource();
1221 // print("setting str %d\n", str.length);
1222 buf.set_text(str, str.length);
1223 var lm = GtkSource.LanguageManager.get_default();
1225 //?? is javascript going to work as js?
1227 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
1230 _this.main_window.windowstate.updateErrorMarksAll();
1232 // restore the cursor position?
1233 // after reloading the contents.
1234 GLib.Timeout.add(500, () => {
1235 _this.buffer.in_cursor_change = true;
1236 print("RESORTING cursor to = %d\n", cpos);
1237 Gtk.TextIter cpos_iter;
1238 buf.get_iter_at_offset(out cpos_iter, cpos);
1239 buf.place_cursor(cpos_iter);
1241 this.el.get_vadjustment().set_value(vadj_pos);;
1242 _this.buffer.in_cursor_change = false;
1246 //_this.buffer.checkSyntax();
1250 this.loading = false;
1251 _this.buffer.dirty = false;
1253 public void nodeSelected (JsRender.Node? sel, bool scroll) {
1259 // this is connected in widnowstate
1260 print("Roo-view - node selected\n");
1261 var buf = this.el.get_buffer();
1263 var sbuf = (GtkSource.Buffer) buf;
1268 // clear all the marks..
1272 sbuf.get_bounds (out start, out end);
1273 sbuf.remove_source_marks (start, end, "grey");
1275 this.node_selected = sel;
1277 // no highlighting..
1281 sbuf.get_iter_at_line(out iter, sel.line_start);
1284 Gtk.TextIter cur_iter;
1285 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1287 //var cur_line = cur_iter.get_line();
1288 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1291 if (! _this.buffer.in_cursor_change) {
1292 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1297 for (var i = 0; i < buf.get_line_count();i++) {
1298 if (i < sel.line_start || i > sel.line_end) {
1300 sbuf.get_iter_at_line(out iter, i);
1301 sbuf.create_source_mark(null, "grey", iter);
1309 public void updateGreySelection (bool scroll) {
1310 var sel = this.node_selected;
1311 print("node selected\n");
1312 var buf = this.el.get_buffer();
1313 var sbuf = (GtkSource.Buffer) buf;
1316 this.clearGreySelection();
1321 print("no selected node\n");
1322 // no highlighting..
1326 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1328 sbuf.get_iter_at_line(out iter, sel.line_start);
1331 Gtk.TextIter cur_iter;
1332 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1334 var cursor_at_line = cur_iter.get_line();
1337 //var cur_line = cur_iter.get_line();
1338 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1342 print("scrolling to node -- should occur on node picking.\n");
1343 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1346 var start_line = sel.line_start;
1347 var end_line = sel.line_end;
1350 this.el.editable = false;
1352 //var colon_pos = 0;
1354 this.editable_start_pos = -1;
1356 // now if we have selected a property...
1357 if (this.prop_selected.length> 0 ) {
1360 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1361 start_line = nstart;
1363 // this.el.editable = true; << cant do this!!?
1364 print("start line = %d, end line = %d\n", start_line, end_line);
1366 // see if we are 'right of ':'
1367 // get an iter for the start of the line.
1368 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1369 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1370 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1375 if (end_first_line_iter.forward_to_line_end()) {
1376 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1378 print("first line = %s\n", first_line);
1379 if (first_line.contains(":")) {
1380 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1381 print("colon_pos = %d\n", this.editable_start_pos);
1385 //Gtk.TextIter colon_iter;
1386 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1387 //sbuf.create_source_mark(null, "active_text", colon_iter);
1392 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1393 //if (start_line - 1 == cursor_at_line) {
1394 // should be ok - current_posssion can not be less than '-1'...
1395 if (sbuf.cursor_position < this.editable_start_pos) {
1397 print("cursor is before start pos.. - turn off editable...\n");
1398 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1399 //print("before cursor string = %s\n", before_cursor_string);
1400 //if (!before_cursor_string.contains(":")) {
1401 this.el.editable = false;
1410 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1415 print("checking selection\n");
1418 // check selection - if it's out of 'bounds'
1419 if (this.el.editable && sbuf.get_has_selection()) {
1420 Gtk.TextIter sel_start_iter, sel_end_iter;
1421 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1423 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1424 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1426 this.el.editable = false;
1428 if (this.editable_start_pos > 0 &&
1429 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1432 this.el.editable = false;
1442 for (var i = 0; i < buf.get_line_count();i++) {
1443 if (i < (start_line -1) || i > (end_line -1)) {
1445 sbuf.get_iter_at_line(out iter, i);
1446 sbuf.create_source_mark(null, "grey", iter);
1451 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1452 Gtk.TextIter cpos_iter;
1453 buf.get_iter_at_line(out cpos_iter, start_line);
1455 buf.place_cursor(cpos_iter);
1460 public void highlightErrorsJson (string type, Json.Object obj) {
1461 // this is a hook for the vala code - it has no value in javascript
1462 // as we only have one error ususally....
1469 public void clearGreySelection () {
1470 // clear all the marks..
1471 var sbuf = (GtkSource.Buffer)this.el.buffer;
1476 sbuf.get_bounds (out start, out end);
1477 sbuf.remove_source_marks (start, end, "grey");
1481 public string toString () {
1484 this.el.get_buffer().get_start_iter(out s);
1485 this.el.get_buffer().get_end_iter(out e);
1486 var ret = this.el.get_buffer().get_text(s,e,true);
1487 //print("TO STRING? " + ret);
1491 public class Xcls_buffer : Object
1493 public GtkSource.Buffer el;
1494 private Xcls_WindowRooView _this;
1498 public int error_line;
1499 public bool in_cursor_change;
1501 public int last_line;
1504 public Xcls_buffer(Xcls_WindowRooView _owner )
1507 _this.buffer = this;
1508 this.el = new GtkSource.Buffer( null );
1511 this.error_line = -1;
1512 this.in_cursor_change = false;
1514 this.last_line = -1;
1516 // set gobject values
1519 this.el.cursor_moved.connect( ( ) => {
1520 GLib.debug("cursor moved called");
1523 if (this.in_cursor_change ) {
1524 GLib.debug("cursor changed : %d [ignoring nested call)", this.el.cursor_position);
1528 GLib.debug("cursor changed : %d", this.el.cursor_position);
1530 this.el.get_iter_at_offset(out cpos, this.el.cursor_position);
1532 var ln = cpos.get_line();
1533 if (this.last_line == ln ){
1536 this.last_line = ln;
1537 var node = _this.file.lineToNode(ln);
1540 print("can not find node\n");
1543 this.in_cursor_change = true;
1544 var ltree = _this.main_window.windowstate.left_tree;
1545 ltree.model.selectNode(node);
1546 this.in_cursor_change = false;
1548 this.el.changed.connect( () => {
1552 // _this.save_button.el.sensitive = true;
1553 ///?? has changed occured during loading?
1555 // only trigger this if
1560 if (_this.sourceview.loading) {
1566 print("- PREVIEW EDITOR CHANGED--");
1569 // this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1573 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1574 print("button or key not pressed to generate change?!\n");
1579 // what are we editing??
1580 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1584 // find the colon on the first line...
1586 if (_this.sourceview.editable_start_pos > -1) {
1588 var buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();
1590 //print("cursor changed : %d\n", buf.cursor_position);
1591 Gtk.TextIter spos,epos;
1592 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1593 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1596 var line = spos.get_line();
1597 var endline = buf.get_line_count();
1598 while (line < endline) {
1600 buf.get_iter_at_line(out epos, line);
1601 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1602 buf.get_iter_at_line(out epos, line);
1609 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1611 // in theory the last char will be '}' or '},' .. or ','
1612 // we should chop the ',' of the end...
1613 var str = buf.get_text(spos, epos, false);
1614 print("got string\n%s\n", str);
1622 // user defined functions
1623 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1625 this.error_line = validate_res.size;
1627 if (this.error_line < 1) {
1630 var tlines = this.el.get_line_count ();
1632 var valiter = validate_res.map_iterator();
1633 while (valiter.next()) {
1635 // print("get inter\n");
1636 var eline = valiter.get_key();
1637 if (eline > tlines) {
1640 this.el.get_iter_at_line( out iter, eline);
1641 //print("mark line\n");
1642 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1646 public string toString () {
1650 this.el.get_start_iter(out s);
1651 this.el.get_end_iter(out e);
1652 var ret = this.el.get_text(s,e,true);
1653 //print("TO STRING? " + ret);
1658 public class Xcls_EventControllerKey17 : Object
1660 public Gtk.EventControllerKey el;
1661 private Xcls_WindowRooView _this;
1667 public Xcls_EventControllerKey17(Xcls_WindowRooView _owner )
1670 this.el = new Gtk.EventControllerKey();
1674 // set gobject values
1677 this.el.key_pressed.connect( (keyval, keycode, state) => {
1681 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1682 GLib.debug("SAVE: ctrl-g pressed");
1683 _this.forwardSearch(true);
1686 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1687 GLib.debug("SAVE: ctrl-f pressed");
1688 _this.search_entry.el.grab_focus();
1692 //this.button_is_pressed = true;
1694 // print(event.key.keyval)
1702 // user defined functions
1707 public class Xcls_Box18 : Object
1710 private Xcls_WindowRooView _this;
1716 public Xcls_Box18(Xcls_WindowRooView _owner )
1719 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1723 // set gobject values
1724 this.el.homogeneous = false;
1725 this.el.vexpand = false;
1726 new Xcls_search_entry( _this );
1727 this.el.append( _this.search_entry.el );
1728 new Xcls_search_results( _this );
1729 this.el.append( _this.search_results.el );
1730 new Xcls_nextBtn( _this );
1731 this.el.append( _this.nextBtn.el );
1732 new Xcls_backBtn( _this );
1733 this.el.append( _this.backBtn.el );
1734 var child_5 = new Xcls_MenuButton24( _this );
1736 this.el.append( child_5.el );
1739 // user defined functions
1741 public class Xcls_search_entry : Object
1743 public Gtk.SearchEntry el;
1744 private Xcls_WindowRooView _this;
1748 public Gtk.CssProvider css;
1751 public Xcls_search_entry(Xcls_WindowRooView _owner )
1754 _this.search_entry = this;
1755 this.el = new Gtk.SearchEntry();
1759 // set gobject values
1760 this.el.name = "roo-search-entry";
1761 this.el.hexpand = true;
1762 this.el.placeholder_text = "Press enter to search";
1763 var child_1 = new Xcls_EventControllerKey20( _this );
1765 this.el.add_controller( child_1.el );
1769 this.css = new Gtk.CssProvider();
1771 this.css.load_from_string(
1772 "#roo-search-entry { background-color: #ccc; }"
1775 Gtk.StyleContext.add_provider_for_display(
1776 this.el.get_display(),
1778 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1782 this.el.search_changed.connect( ( ) => {
1784 _this.search(_this.search_entry.el.text);
1785 _this.search_results.updateResults();
1787 GLib.Timeout.add_seconds(1,() => {
1788 _this.search_results.updateResults();
1794 // user defined functions
1795 public void forwardSearch (bool change_focus) {
1798 _this.forwardSearch(change_focus);
1802 switch(_this.windowstate.state) {
1803 case WindowState.State.CODEONLY:
1804 //case WindowState.State.CODE:
1805 // search the code being edited..
1806 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1809 case WindowState.State.PREVIEW:
1810 if (_this.windowstate.file.xtype == "Gtk") {
1811 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1813 _this.windowstate.window_rooview.forwardSearch(change_focus);
1822 public class Xcls_EventControllerKey20 : Object
1824 public Gtk.EventControllerKey el;
1825 private Xcls_WindowRooView _this;
1831 public Xcls_EventControllerKey20(Xcls_WindowRooView _owner )
1834 this.el = new Gtk.EventControllerKey();
1838 // set gobject values
1841 this.el.key_pressed.connect( (keyval, keycode, state) => {
1843 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1844 GLib.debug("SAVE: ctrl-g pressed");
1845 _this.forwardSearch(true);
1850 if (keyval == Gdk.Key.Return) {
1851 _this.forwardSearch(true);
1857 // print(event.key.keyval)
1863 // user defined functions
1867 public class Xcls_search_results : Object
1869 public Gtk.Label el;
1870 private Xcls_WindowRooView _this;
1876 public Xcls_search_results(Xcls_WindowRooView _owner )
1879 _this.search_results = this;
1880 this.el = new Gtk.Label( "No Results" );
1884 // set gobject values
1885 this.el.margin_end = 4;
1886 this.el.margin_start = 4;
1889 // user defined functions
1890 public void updateResults () {
1891 this.el.visible = true;
1893 var res = _this.searchcontext.get_occurrences_count();
1895 _this.search_results.el.label = "??? Matches";
1899 _this.nextBtn.el.sensitive = false;
1900 _this.backBtn.el.sensitive = false;
1903 _this.search_results.el.label = "%d Matches".printf(res);
1904 _this.nextBtn.el.sensitive = true;
1905 _this.backBtn.el.sensitive = true;
1908 _this.search_results.el.label = "No Matches";
1913 public class Xcls_nextBtn : Object
1915 public Gtk.Button el;
1916 private Xcls_WindowRooView _this;
1920 public bool always_show_image;
1923 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1926 _this.nextBtn = this;
1927 this.el = new Gtk.Button();
1930 this.always_show_image = true;
1932 // set gobject values
1933 this.el.icon_name = "go-down";
1934 this.el.sensitive = false;
1937 this.el.clicked.connect( (event) => {
1939 _this.forwardSearch(true);
1944 // user defined functions
1947 public class Xcls_backBtn : Object
1949 public Gtk.Button el;
1950 private Xcls_WindowRooView _this;
1954 public bool always_show_image;
1957 public Xcls_backBtn(Xcls_WindowRooView _owner )
1960 _this.backBtn = this;
1961 this.el = new Gtk.Button();
1964 this.always_show_image = true;
1966 // set gobject values
1967 this.el.icon_name = "go-up";
1968 this.el.sensitive = false;
1971 this.el.clicked.connect( (event) => {
1973 _this.backSearch(true);
1979 // user defined functions
1982 public class Xcls_MenuButton24 : Object
1984 public Gtk.MenuButton el;
1985 private Xcls_WindowRooView _this;
1989 public bool always_show_image;
1992 public Xcls_MenuButton24(Xcls_WindowRooView _owner )
1995 this.el = new Gtk.MenuButton();
1998 this.always_show_image = true;
2000 // set gobject values
2001 this.el.icon_name = "emblem-system";
2002 new Xcls_search_settings( _this );
2003 this.el.popover = _this.search_settings.el;
2006 // user defined functions
2008 public class Xcls_search_settings : Object
2010 public Gtk.Popover el;
2011 private Xcls_WindowRooView _this;
2017 public Xcls_search_settings(Xcls_WindowRooView _owner )
2020 _this.search_settings = this;
2021 this.el = new Gtk.Popover();
2025 // set gobject values
2026 var child_1 = new Xcls_Box26( _this );
2027 this.el.child = child_1.el;
2030 // user defined functions
2032 public class Xcls_Box26 : Object
2035 private Xcls_WindowRooView _this;
2041 public Xcls_Box26(Xcls_WindowRooView _owner )
2044 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
2048 // set gobject values
2049 new Xcls_case_sensitive( _this );
2050 this.el.append( _this.case_sensitive.el );
2051 new Xcls_regex( _this );
2052 this.el.append( _this.regex.el );
2053 new Xcls_multiline( _this );
2054 this.el.append( _this.multiline.el );
2057 // user defined functions
2059 public class Xcls_case_sensitive : Object
2061 public Gtk.CheckButton el;
2062 private Xcls_WindowRooView _this;
2068 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2071 _this.case_sensitive = this;
2072 this.el = new Gtk.CheckButton();
2076 // set gobject values
2077 this.el.label = "Case Sensitive";
2086 // user defined functions
2089 public class Xcls_regex : Object
2091 public Gtk.CheckButton el;
2092 private Xcls_WindowRooView _this;
2098 public Xcls_regex(Xcls_WindowRooView _owner )
2102 this.el = new Gtk.CheckButton();
2106 // set gobject values
2107 this.el.label = "Regex";
2116 // user defined functions
2119 public class Xcls_multiline : Object
2121 public Gtk.CheckButton el;
2122 private Xcls_WindowRooView _this;
2128 public Xcls_multiline(Xcls_WindowRooView _owner )
2131 _this.multiline = this;
2132 this.el = new Gtk.CheckButton();
2136 // set gobject values
2137 this.el.label = "Multi-line (add \\n)";
2146 // user defined functions