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_viewcontainer viewcontainer;
22 public Xcls_view view;
23 public Xcls_inspectorcontainer inspectorcontainer;
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 Gtk.SourceSearchContext searchcontext;
39 public int last_search_end;
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 var child_0 = new Xcls_notebook( _this );
58 this.el.pack_start ( child_0.el , true,true,0 );
61 // user defined functions
62 public void loadFile (JsRender.JsRender file)
65 this.view.renderJS(true);
66 this.notebook.el.page = 0;// gtk preview
67 this.sourceview.loadFile();
70 public void highlightNodeAtLine (int ln) {
77 var node = _this.file.lineToNode(ln+1);
80 //print("can not find node\n");
83 var prop = node.lineToProp(ln+1);
84 print("prop : %s", prop == null ? "???" : prop);
87 // ---------- this selects the tree's node...
89 var ltree = _this.main_window.windowstate.left_tree;
90 var tp = ltree.model.treePathFromNode(node);
91 print("got tree path %s\n", tp);
95 //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
98 //print("changing cursor on tree..\n");
102 // let's try allowing editing on the methods.
103 // a little klunky at present..
104 _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;
119 ltree.view.setCursor(tp, "editor");
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, stl;
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)) {
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.backward2(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 Gtk.SourceSearchSettings();
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 Gtk.SourceSearchContext(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;
221 this.buffer.el.get_start_iter(out beg);
222 this.searchcontext.forward(beg, out st, out en);
223 this.last_search_end = 0;
225 return this.searchcontext.get_occurrences_count();
231 public void createThumb () {
234 if (this.file == null) {
237 if (this.notebook.el.page > 0 ) {
241 var filename = this.file.getIconFileName(false);
243 var win = this.el.get_parent_window();
244 var width = win.get_width();
245 // var height = win.get_height();
247 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.paned.el.position);
248 screenshot.save(filename,"png");
258 public void scroll_to_line (int line) {
259 this.notebook.el.page = 1;// code preview...
261 GLib.Timeout.add(500, () => {
266 var buf = this.sourceview.el.get_buffer();
268 var sbuf = (Gtk.SourceBuffer) buf;
272 sbuf.get_iter_at_line(out iter, line);
273 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
279 public class Xcls_notebook : Object
281 public Gtk.Notebook el;
282 private Xcls_WindowRooView _this;
288 public Xcls_notebook(Xcls_WindowRooView _owner )
291 _this.notebook = this;
292 this.el = new Gtk.Notebook();
296 // set gobject values
297 var child_0 = new Xcls_label_preview( _this );
299 var child_1 = new Xcls_label_code( _this );
301 var child_2 = new Xcls_paned( _this );
303 this.el.append_page ( child_2.el , _this.label_preview.el );
304 var child_3 = new Xcls_Box14( _this );
306 this.el.append_page ( child_3.el , _this.label_code.el );
309 // user defined functions
311 public class Xcls_label_preview : Object
314 private Xcls_WindowRooView _this;
320 public Xcls_label_preview(Xcls_WindowRooView _owner )
323 _this.label_preview = this;
324 this.el = new Gtk.Label( "Preview" );
328 // set gobject values
331 // user defined functions
334 public class Xcls_label_code : Object
337 private Xcls_WindowRooView _this;
343 public Xcls_label_code(Xcls_WindowRooView _owner )
346 _this.label_code = this;
347 this.el = new Gtk.Label( "Preview Generated Code" );
351 // set gobject values
354 // user defined functions
357 public class Xcls_paned : Object
360 private Xcls_WindowRooView _this;
366 public Xcls_paned(Xcls_WindowRooView _owner )
370 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
374 // set gobject values
375 var child_0 = new Xcls_viewbox( _this );
377 this.el.pack1 ( child_0.el , true,true );
378 var child_1 = new Xcls_inspectorcontainer( _this );
380 this.el.pack2 ( child_1.el , true,true );
383 // user defined functions
385 public class Xcls_viewbox : Object
388 private Xcls_WindowRooView _this;
394 public Xcls_viewbox(Xcls_WindowRooView _owner )
397 _this.viewbox = this;
398 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
402 // set gobject values
403 this.el.homogeneous = false;
404 var child_0 = new Xcls_Box7( _this );
406 this.el.pack_start ( child_0.el , false,true,0 );
407 var child_1 = new Xcls_viewcontainer( _this );
409 this.el.pack_end ( child_1.el , true,true,0 );
412 // user defined functions
414 public class Xcls_Box7 : Object
417 private Xcls_WindowRooView _this;
423 public Xcls_Box7(Xcls_WindowRooView _owner )
426 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
430 // set gobject values
431 this.el.homogeneous = true;
432 this.el.height_request = 20;
433 this.el.vexpand = false;
434 var child_0 = new Xcls_Button8( _this );
436 this.el.pack_start ( child_0.el , false,false,0 );
437 var child_1 = new Xcls_AutoRedraw( _this );
439 this.el.pack_start ( child_1.el , false,false,0 );
440 var child_2 = new Xcls_Button10( _this );
442 this.el.pack_start ( child_2.el , false,false,0 );
445 // user defined functions
447 public class Xcls_Button8 : Object
449 public Gtk.Button el;
450 private Xcls_WindowRooView _this;
456 public Xcls_Button8(Xcls_WindowRooView _owner )
459 this.el = new Gtk.Button();
463 // set gobject values
464 this.el.label = "Redraw";
467 this.el.clicked.connect( ( ) => {
468 _this.view.renderJS( true);
472 // user defined functions
475 public class Xcls_AutoRedraw : Object
477 public Gtk.CheckButton el;
478 private Xcls_WindowRooView _this;
484 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
487 _this.AutoRedraw = this;
488 this.el = new Gtk.CheckButton();
492 // set gobject values
493 this.el.active = true;
494 this.el.label = "Auto Redraw On";
497 this.el.toggled.connect( (state) => {
498 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
502 // user defined functions
505 public class Xcls_Button10 : Object
507 public Gtk.Button el;
508 private Xcls_WindowRooView _this;
514 public Xcls_Button10(Xcls_WindowRooView _owner )
517 this.el = new Gtk.Button();
521 // set gobject values
522 this.el.label = "Full Redraw";
525 this.el.clicked.connect( () => {
526 _this.view.redraws = 99;
527 _this.view.el.web_context.clear_cache();
528 //_this.view.renderJS(true);
529 FakeServerCache.clear();
535 // user defined functions
539 public class Xcls_viewcontainer : Object
541 public Gtk.ScrolledWindow el;
542 private Xcls_WindowRooView _this;
548 public Xcls_viewcontainer(Xcls_WindowRooView _owner )
551 _this.viewcontainer = this;
552 this.el = new Gtk.ScrolledWindow( null, null );
556 // set gobject values
557 this.el.shadow_type = Gtk.ShadowType.IN;
558 var child_0 = new Xcls_view( _this );
560 this.el.add ( child_0.el );
564 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
567 // user defined functions
569 public class Xcls_view : Object
571 public WebKit.WebView el;
572 private Xcls_WindowRooView _this;
576 public WebKit.WebInspector inspector;
577 public bool pendingRedraw;
579 public bool refreshRequired;
581 public string runhtml;
582 public string renderedData;
583 public GLib.DateTime lastRedraw;
586 public Xcls_view(Xcls_WindowRooView _owner )
590 this.el = new WebKit.WebView();
593 this.pendingRedraw = false;
595 this.refreshRequired = false;
598 this.renderedData = "";
599 this.lastRedraw = null;
601 // set gobject values
606 // this may not work!?
607 var settings = this.el.get_settings();
608 settings.enable_developer_extras = true;
611 var fs= new FakeServer(this.el);
613 // this was an attempt to change the url perms.. did not work..
614 // settings.enable_file_access_from_file_uris = true;
615 // settings.enable_offline_web_application_cache - true;
616 // settings.enable_universal_access_from_file_uris = true;
623 // FIXME - base url of script..
624 // we need it so some of the database features work.
625 this.el.load_html( "Render not ready" ,
626 //fixme - should be a config option!
627 // or should we catch stuff and fix it up..
628 "http://localhost/app.Builder/"
632 //this.el.open('file:///' + __script_path__ + '/../builder.html');
637 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
638 null, // list of targets
639 Gdk.DragAction.COPY // what to do with data after dropped
642 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
643 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
645 GLib.Timeout.add_seconds(1, () =>{
646 //print("run refresh?");
647 if (this.el == null) {
658 this.el.script_dialog.connect( (dialog) => {
661 if (this.el == null) {
665 var msg = dialog.get_message();
666 if (msg.length < 4) {
669 if (msg.substring(0,4) != "IPC:") {
672 var ar = msg.split(":", 3);
679 print("GOT saveHTML %d?\n", ar[2].length);
680 _this.file.saveHTML(ar[2]);
687 this.el.show.connect( ( ) => {
688 this.initInspector();;
690 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
693 print("TARGET: drag-drop");
694 var is_valid_drop_site = true;
699 w, // will receive 'drag-data-received' signal
700 ctx, /* represents the current state of the DnD
701 this.get('/Window').atoms["STRING"], /* the target type we want
706 /* No target offered by source => error
709 return is_valid_drop_site;
712 this.el.load_changed.connect( (le) => {
713 if (le != WebKit.LoadEvent.FINISHED) {
716 if (this.runjs.length < 1) {
719 // this.el.run_javascript(this.runjs, null);
720 FakeServerCache.remove( this.runjs);
725 // user defined functions
726 public void initInspector () {
728 /* if (this.inspector == this.el.get_inspector()) {
729 this.inspector.show();
730 this.inspector.open_window();
731 print("init inspecter called, and inspector is the same as existing\n");
734 print("new inspector?\n");
736 this.inspector = this.el.get_inspector();
737 this.inspector.ref();
739 // got a new inspector...
741 this.inspector.open_window.connect(() => {
742 this.inspector = this.el.get_inspector();
743 print("inspector attach\n");
744 var wv = this.inspector.get_web_view();
746 print("got inspector web view\n");
748 var cn = _this.inspectorcontainer.el.get_child();
750 _this.inspectorcontainer.el.remove(cn);
753 _this.inspectorcontainer.el.add(wv);
756 //this.inspector.close();
758 //this.inspector = null;
766 this.inspector.closed.connect(() => {
767 print("inspector closed?!?");
768 // if this happens destroy the webkit..
770 this.el.stop_loading();
772 if (_this.viewbox.el.get_parent() == null) {
777 _this.viewbox.el.remove(_this.viewcontainer.el);
778 _this.el.remove(_this.inspectorcontainer.el);
780 // destory seems to cause problems.
782 //_this.viewcontainer.el.destroy();
783 //_this.inspectorcontainer.el.destroy();
786 var nv =new Xcls_viewcontainer(_this);
788 _this.viewbox.el.pack_end(nv.el,true,true,0);
790 var inv =new Xcls_inspectorcontainer(_this);
792 _this.el.pack2(inv.el,true,true);
796 //while(Gtk.events_pending ()) Gtk.main_iteration ();
797 //_this.view.renderJS(true);
798 _this.view.refreshRequired = true;
803 this.inspector.show();
805 public void renderJS (bool force) {
807 // this is the public redraw call..
808 // we refresh in a loop privately..
809 var autodraw = _this.AutoRedraw.el.active;
810 if (!autodraw && !force) {
811 print("Skipping redraw - no force, and autodraw off");
815 this.refreshRequired = true;
817 public void reInit () {
819 // if this happens destroy the webkit..
821 this.el.stop_loading();
823 if (_this.viewbox.el.get_parent() == null) {
828 _this.viewbox.el.remove(_this.viewcontainer.el);
829 _this.paned.el.remove(_this.inspectorcontainer.el);
831 // destory seems to cause problems.
833 //_this.viewcontainer.el.destroy();
834 //_this.inspectorcontainer.el.destroy();
835 var inv =new Xcls_inspectorcontainer(_this);
837 _this.paned.el.pack2(inv.el,true,true);
841 var nv =new Xcls_viewcontainer(_this);
843 _this.viewbox.el.pack_end(nv.el,true,true,0);
848 //while(Gtk.events_pending ()) Gtk.main_iteration ();
849 //_this.view.renderJS(true);
850 _this.view.refreshRequired = true;
852 public void runRefresh ()
854 // this is run every 2 seconds from the init..
858 if (!this.refreshRequired) {
859 // print("no refresh required");
863 if (this.lastRedraw != null) {
864 // do not redraw if last redraw was less that 5 seconds ago.
865 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
870 if (_this.file == null) {
875 this.refreshRequired = false;
876 // print("HTML RENDERING");
879 //this.get('/BottomPane').el.show();
880 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
881 _this.file.webkit_page_id = this.el.get_page_id();
883 var js = _this.file.toSourcePreview();
892 var project = _this.file.project;
894 //print (project.fn);
895 // set it to non-empty.
897 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
900 // this.runhtml = this.runhtml || '';
903 // then we need to reload the browser using
904 // load_html_string..
906 // then trigger a redraw once it's loaded..
907 this.pendingRedraw = true;
909 var runhtml = "<script type=\"text/javascript\">\n" ;
913 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
918 runhtml += builderhtml + "\n";
919 runhtml += "</script>\n" ;
921 // fix to make sure they are the same..
922 this.runhtml = project.runhtml;
923 // need to modify paths
926 var base_template = _this.file.project.base_template;
928 if (base_template.length > 0 && !FileUtils.test(
929 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
931 print("invalid base_template name - using default: %s\n", base_template);
936 GLib.FileUtils.get_contents(
937 BuilderApplication.configDirectory() + "/resources/" +
938 (base_template.length > 0 ? base_template : "roo.builder.html")
944 this.renderedData = js;
947 string js_src = js + "\n" +
948 "Roo.onReady(function() {\n" +
949 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
950 "Roo.XComponent.build();\n" +
953 // print("render js: " + js);
955 // console.log('not loaded yet');
957 this.lastRedraw = new DateTime.now_local();
960 //this.runjs = js_src;
961 var fc = FakeServerCache.factory_with_data(js_src);
962 this.runjs = fc.fname;
964 var html = inhtml.replace("</head>", runhtml + this.runhtml +
965 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
966 // "<script type=\"text/javascript\">\n" +
971 //print("LOAD HTML " + html);
973 var rootURL = _this.file.project.rootURL;
977 this.el.load_html( html ,
978 //fixme - should be a config option!
979 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
982 // force the inspector...
983 // this.initInspector();
985 // - no need for this, the builder javascript will call it when build is complete
986 //GLib.Timeout.add_seconds(1, () => {
987 // this.el.run_javascript("Builder.saveHTML()",null);
990 // print( "before render" + this.lastRedraw);
991 // print( "after render" + (new Date()));
998 public class Xcls_inspectorcontainer : Object
1000 public Gtk.ScrolledWindow el;
1001 private Xcls_WindowRooView _this;
1007 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
1010 _this.inspectorcontainer = this;
1011 this.el = new Gtk.ScrolledWindow( null, null );
1015 // set gobject values
1016 this.el.shadow_type = Gtk.ShadowType.IN;
1020 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1023 // user defined functions
1027 public class Xcls_Box14 : Object
1030 private Xcls_WindowRooView _this;
1036 public Xcls_Box14(Xcls_WindowRooView _owner )
1039 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1043 // set gobject values
1044 var child_0 = new Xcls_ScrolledWindow15( _this );
1046 this.el.add( child_0.el );
1047 var child_1 = new Xcls_Box18( _this );
1049 this.el.add( child_1.el );
1052 // user defined functions
1054 public class Xcls_ScrolledWindow15 : Object
1056 public Gtk.ScrolledWindow el;
1057 private Xcls_WindowRooView _this;
1063 public Xcls_ScrolledWindow15(Xcls_WindowRooView _owner )
1066 this.el = new Gtk.ScrolledWindow( null, null );
1070 // set gobject values
1071 this.el.vexpand = true;
1072 var child_0 = new Xcls_sourceview( _this );
1074 this.el.add ( child_0.el );
1077 // user defined functions
1079 public class Xcls_sourceview : Object
1081 public Gtk.SourceView el;
1082 private Xcls_WindowRooView _this;
1086 public bool loading;
1087 public int editable_start_pos;
1088 public bool button_is_pressed;
1089 public string prop_selected;
1090 public bool key_is_pressed;
1091 public JsRender.Node? node_selected;
1094 public Xcls_sourceview(Xcls_WindowRooView _owner )
1097 _this.sourceview = this;
1098 this.el = new Gtk.SourceView();
1101 this.loading = true;
1102 this.editable_start_pos = -1;
1103 this.button_is_pressed = false;
1104 this.prop_selected = "";
1105 this.key_is_pressed = false;
1106 this.node_selected = null;
1108 // set gobject values
1109 this.el.editable = false;
1110 this.el.show_line_marks = true;
1111 this.el.show_line_numbers = true;
1112 var child_0 = new Xcls_buffer( _this );
1114 this.el.set_buffer ( child_0.el );
1121 var description = Pango.FontDescription.from_string("monospace");
1122 description.set_size(8000);
1123 this.el.override_font(description);
1125 this.loading = true;
1126 //var buf = this.el.get_buffer();
1127 //buf.notify.connect(this.onCursorChanged);
1130 var attrs = new Gtk.SourceMarkAttributes();
1131 var pink = Gdk.RGBA();
1132 pink.parse ( "pink");
1133 attrs.set_background ( pink);
1134 attrs.set_icon_name ( "process-stop");
1135 attrs.query_tooltip_text.connect(( mark) => {
1136 //print("tooltip query? %s\n", mark.name);
1140 this.el.set_mark_attributes ("ERR", attrs, 1);
1142 var wattrs = new Gtk.SourceMarkAttributes();
1143 var blue = Gdk.RGBA();
1144 blue.parse ( "#ABF4EB");
1145 wattrs.set_background ( blue);
1146 wattrs.set_icon_name ( "process-stop");
1147 wattrs.query_tooltip_text.connect(( mark) => {
1148 //print("tooltip query? %s\n", mark.name);
1152 this.el.set_mark_attributes ("WARN", wattrs, 1);
1156 var dattrs = new Gtk.SourceMarkAttributes();
1157 var purple = Gdk.RGBA();
1158 purple.parse ( "#EEA9FF");
1159 dattrs.set_background ( purple);
1160 dattrs.set_icon_name ( "process-stop");
1161 dattrs.query_tooltip_text.connect(( mark) => {
1162 //print("tooltip query? %s\n", mark.name);
1166 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1169 var gattrs = new Gtk.SourceMarkAttributes();
1170 var grey = Gdk.RGBA();
1171 grey.parse ( "#ccc");
1172 gattrs.set_background ( grey);
1175 this.el.set_mark_attributes ("grey", gattrs, 1);
1185 this.el.button_release_event.connect( () => {
1187 print("BUTTON RELEASE EVENT\n");
1188 this.onCursorChanged();
1189 this.button_is_pressed = false;
1192 this.el.button_press_event.connect( ( ) => {
1194 this.button_is_pressed = true;
1197 this.el.key_press_event.connect( (event) => {
1199 if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1200 GLib.debug("SAVE: ctrl-g pressed");
1201 _this.forwardSearch(true);
1205 this.button_is_pressed = true;
1208 this.el.key_release_event.connect( () => {
1209 this.key_is_pressed = false;
1214 // user defined functions
1215 public void loadFile ( ) {
1216 this.loading = true;
1219 // get the cursor and scroll position....
1220 var buf = this.el.get_buffer();
1221 var cpos = buf.cursor_position;
1223 print("BEFORE LOAD cursor = %d\n", cpos);
1225 var vadj_pos = this.el.get_vadjustment().get_value();
1230 var sbuf = (Gtk.SourceBuffer) buf;
1234 if (_this.file == null || _this.file.xtype != "Roo") {
1235 print("xtype != Roo");
1236 this.loading = false;
1240 // get the string from the rendered tree...
1242 var str = _this.file.toSource();
1244 // print("setting str %d\n", str.length);
1245 buf.set_text(str, str.length);
1246 var lm = Gtk.SourceLanguageManager.get_default();
1248 //?? is javascript going to work as js?
1250 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
1256 sbuf.get_bounds (out start, out end);
1257 sbuf.remove_source_marks (start, end, null); // remove all marks..
1259 GLib.Timeout.add(500, () => {
1261 print("RESORTING cursor to = %d\n", cpos);
1262 Gtk.TextIter cpos_iter;
1263 buf.get_iter_at_offset(out cpos_iter, cpos);
1264 buf.place_cursor(cpos_iter);
1266 this.el.get_vadjustment().set_value(vadj_pos);;
1269 this.onCursorChanged();
1272 _this.buffer.checkSyntax();
1276 this.loading = false;
1277 _this.buffer.dirty = false;
1279 public void onCursorChanged (/*ParamSpec ps*/) {
1281 if (!this.key_is_pressed && !this.button_is_pressed) {
1288 // if (ps.name != "cursor-position") {
1292 var buf = this.el.get_buffer();
1293 //print("cursor changed : %d\n", buf.cursor_position);
1295 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1297 var ln = cpos.get_line();
1300 // --- select node at line....
1302 var node = _this.file.lineToNode(ln+1);
1305 print("can not find node\n");
1308 var prop = node.lineToProp(ln+1);
1309 print("prop : %s", prop == null ? "???" : prop);
1312 // ---------- this selects the tree's node...
1314 var ltree = _this.main_window.windowstate.left_tree;
1315 var tp = ltree.model.treePathFromNode(node);
1316 print("got tree path %s\n", tp);
1320 //print("changing cursor on tree..\n");
1324 // let's try allowing editing on the methods.
1325 // a little klunky at present..
1326 this.prop_selected = "";
1328 //see if we can find it..
1329 var kv = prop.split(":");
1332 //var k = prop.get_key(kv[1]);
1333 // fixme -- need to determine if it's an editable property...
1334 this.prop_selected = prop;
1336 } else if (kv[0] == "l") {
1337 this.prop_selected = prop;
1341 ltree.view.setCursor(tp, "editor");
1342 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
1343 this.nodeSelected(node,false);
1345 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1349 // highlight the node..
1351 public void nodeSelected (JsRender.Node? sel, bool scroll ) {
1355 // this is connected in widnowstate
1359 while(Gtk.events_pending()) {
1360 Gtk.main_iteration();
1363 this.node_selected = sel;
1365 this.updateGreySelection(scroll);
1370 public void updateGreySelection (bool scroll) {
1371 var sel = this.node_selected;
1372 print("node selected\n");
1373 var buf = this.el.get_buffer();
1374 var sbuf = (Gtk.SourceBuffer) buf;
1377 this.clearGreySelection();
1382 print("no selected node\n");
1383 // no highlighting..
1387 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1389 sbuf.get_iter_at_line(out iter, sel.line_start);
1392 Gtk.TextIter cur_iter;
1393 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1395 var cursor_at_line = cur_iter.get_line();
1398 //var cur_line = cur_iter.get_line();
1399 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1403 print("scrolling to node -- should occur on node picking.\n");
1404 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1407 var start_line = sel.line_start;
1408 var end_line = sel.line_end;
1411 this.el.editable = false;
1413 //var colon_pos = 0;
1415 this.editable_start_pos = -1;
1417 // now if we have selected a property...
1418 if (this.prop_selected.length> 0 ) {
1421 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1422 start_line = nstart;
1424 this.el.editable = true;
1425 print("start line = %d, end line = %d\n", start_line, end_line);
1427 // see if we are 'right of ':'
1428 // get an iter for the start of the line.
1429 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1430 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1431 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1436 if (end_first_line_iter.forward_to_line_end()) {
1437 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1439 print("first line = %s\n", first_line);
1440 if (first_line.contains(":")) {
1441 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1442 print("colon_pos = %d\n", this.editable_start_pos);
1446 //Gtk.TextIter colon_iter;
1447 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1448 //sbuf.create_source_mark(null, "active_text", colon_iter);
1453 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1454 //if (start_line - 1 == cursor_at_line) {
1455 // should be ok - current_posssion can not be less than '-1'...
1456 if (sbuf.cursor_position < this.editable_start_pos) {
1458 print("cursor is before start pos.. - turn off editable...\n");
1459 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1460 //print("before cursor string = %s\n", before_cursor_string);
1461 //if (!before_cursor_string.contains(":")) {
1462 this.el.editable = false;
1471 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1476 print("checking selection\n");
1479 // check selection - if it's out of 'bounds'
1480 if (this.el.editable && sbuf.get_has_selection()) {
1481 Gtk.TextIter sel_start_iter, sel_end_iter;
1482 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1484 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1485 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1487 this.el.editable = false;
1489 if (this.editable_start_pos > 0 &&
1490 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1493 this.el.editable = false;
1503 for (var i = 0; i < buf.get_line_count();i++) {
1504 if (i < (start_line -1) || i > (end_line -1)) {
1506 sbuf.get_iter_at_line(out iter, i);
1507 sbuf.create_source_mark(null, "grey", iter);
1512 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1513 Gtk.TextIter cpos_iter;
1514 buf.get_iter_at_line(out cpos_iter, start_line);
1516 buf.place_cursor(cpos_iter);
1521 public void highlightErrorsJson (string type, Json.Object obj) {
1522 // this is a hook for the vala code - it has no value in javascript
1523 // as we only have one error ususally....
1530 public string toString () {
1533 this.el.get_buffer().get_start_iter(out s);
1534 this.el.get_buffer().get_end_iter(out e);
1535 var ret = this.el.get_buffer().get_text(s,e,true);
1536 //print("TO STRING? " + ret);
1539 public void clearGreySelection () {
1540 // clear all the marks..
1541 var sbuf = (Gtk.SourceBuffer)this.el.buffer;
1546 sbuf.get_bounds (out start, out end);
1547 sbuf.remove_source_marks (start, end, "grey");
1552 public class Xcls_buffer : Object
1554 public Gtk.SourceBuffer el;
1555 private Xcls_WindowRooView _this;
1559 public int error_line;
1563 public Xcls_buffer(Xcls_WindowRooView _owner )
1566 _this.buffer = this;
1567 this.el = new Gtk.SourceBuffer( null );
1570 this.error_line = -1;
1573 // set gobject values
1576 this.el.changed.connect( () => {
1581 // _this.save_button.el.sensitive = true;
1582 ///?? has changed occured during loading?
1584 // only trigger this if
1589 if (_this.sourceview.loading) {
1595 print("- PREVIEW EDITOR CHANGED--");
1598 this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1602 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1603 print("button or key not pressed to generate change?!\n");
1608 // what are we editing??
1609 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1613 // find the colon on the first line...
1615 if (_this.sourceview.editable_start_pos > -1) {
1617 var buf = (Gtk.SourceBuffer)_this.sourceview.el.get_buffer();
1619 //print("cursor changed : %d\n", buf.cursor_position);
1620 Gtk.TextIter spos,epos;
1621 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1622 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1625 var line = spos.get_line();
1626 var endline = buf.get_line_count();
1627 while (line < endline) {
1629 buf.get_iter_at_line(out epos, line);
1630 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1631 buf.get_iter_at_line(out epos, line);
1638 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1640 // in theory the last char will be '}' or '},' .. or ','
1641 // we should chop the ',' of the end...
1642 var str = buf.get_text(spos, epos, false);
1643 print("got string\n%s\n", str);
1651 // user defined functions
1652 public bool checkSyntax () {
1655 var str = this.toString();
1658 if (this.error_line > 0) {
1661 this.el.get_bounds (out start, out end);
1663 this.el.remove_source_marks (start, end, "WARN");
1664 this.el.remove_source_marks (start, end, "ERR");
1668 if (str.length < 1) {
1669 print("checkSyntax - empty string?\n");
1673 if (_this.file == null) {
1676 var p = _this.file.project.palete;
1679 if (_this.file.language != "js") {
1680 return false; // fake syntax error.
1683 //Gee.HashMap<int,string> ret_x;
1685 return p.javascriptHasErrors(
1686 _this.main_window.windowstate,
1688 null, // prop - not relivant.
1694 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1696 this.error_line = validate_res.size;
1698 if (this.error_line < 1) {
1701 var tlines = this.el.get_line_count ();
1703 var valiter = validate_res.map_iterator();
1704 while (valiter.next()) {
1706 // print("get inter\n");
1707 var eline = valiter.get_key();
1708 if (eline > tlines) {
1711 this.el.get_iter_at_line( out iter, eline);
1712 //print("mark line\n");
1713 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1717 public string toString () {
1721 this.el.get_start_iter(out s);
1722 this.el.get_end_iter(out e);
1723 var ret = this.el.get_text(s,e,true);
1724 //print("TO STRING? " + ret);
1731 public class Xcls_Box18 : Object
1734 private Xcls_WindowRooView _this;
1740 public Xcls_Box18(Xcls_WindowRooView _owner )
1743 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1747 // set gobject values
1748 this.el.homogeneous = false;
1749 this.el.vexpand = false;
1750 var child_0 = new Xcls_search_entry( _this );
1752 this.el.add( child_0.el );
1753 var child_1 = new Xcls_MenuBar20( _this );
1755 this.el.add ( child_1.el );
1756 var child_2 = new Xcls_nextBtn( _this );
1758 this.el.add( child_2.el );
1759 var child_3 = new Xcls_backBtn( _this );
1761 this.el.add( child_3.el );
1762 var child_4 = new Xcls_MenuButton26( _this );
1764 this.el.add( child_4.el );
1767 // user defined functions
1769 public class Xcls_search_entry : Object
1771 public Gtk.SearchEntry el;
1772 private Xcls_WindowRooView _this;
1778 public Xcls_search_entry(Xcls_WindowRooView _owner )
1781 _this.search_entry = this;
1782 this.el = new Gtk.SearchEntry();
1786 // set gobject values
1787 this.el.width_request = 300;
1788 this.el.hexpand = true;
1789 this.el.placeholder_text = "Press enter to search";
1793 var description = Pango.FontDescription.from_string("monospace");
1794 description.set_size(8000);
1795 this.el.override_font(description);
1798 this.el.key_press_event.connect( (event) => {
1799 if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1800 GLib.debug("SAVE: ctrl-g pressed");
1801 _this.forwardSearch(true);
1806 if (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {
1807 var res = _this.search(this.el.text);
1808 _this.search_results.updateResults();
1810 GLib.Timeout.add_seconds(2,() => {
1811 _this.search_results.updateResults();
1819 // print(event.key.keyval)
1824 this.el.changed.connect( () => {
1826 if (this.el.text == "") {
1827 _this.search_results.el.hide();
1831 switch(_this.windowstate.state) {
1832 case WindowState.State.CODEONLY:
1833 ///case WindowState.State.CODE:
1834 // search the code being edited..
1835 res = _this.windowstate.code_editor_tab.search(this.el.text);
1838 case WindowState.State.PREVIEW:
1839 if (_this.windowstate.file.xtype == "Gtk") {
1840 res = _this.windowstate.window_gladeview.search(this.el.text);
1842 res = _this.windowstate.window_rooview.search(this.el.text);
1848 _this.search_results.el.show();
1850 _this.search_results.el.label = "%d Matches".printf(res);
1852 _this.search_results.el.label = "No Matches";
1860 // user defined functions
1861 public void forwardSearch (bool change_focus) {
1864 _this.forwardSearch(change_focus);
1868 switch(_this.windowstate.state) {
1869 case WindowState.State.CODEONLY:
1870 //case WindowState.State.CODE:
1871 // search the code being edited..
1872 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1875 case WindowState.State.PREVIEW:
1876 if (_this.windowstate.file.xtype == "Gtk") {
1877 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1879 _this.windowstate.window_rooview.forwardSearch(change_focus);
1889 public class Xcls_MenuBar20 : Object
1891 public Gtk.MenuBar el;
1892 private Xcls_WindowRooView _this;
1898 public Xcls_MenuBar20(Xcls_WindowRooView _owner )
1901 this.el = new Gtk.MenuBar();
1905 // set gobject values
1906 var child_0 = new Xcls_search_results( _this );
1908 this.el.add ( child_0.el );
1911 // user defined functions
1913 public class Xcls_search_results : Object
1915 public Gtk.ImageMenuItem el;
1916 private Xcls_WindowRooView _this;
1922 public Xcls_search_results(Xcls_WindowRooView _owner )
1925 _this.search_results = this;
1926 this.el = new Gtk.ImageMenuItem();
1930 // set gobject values
1931 this.el.always_show_image = true;
1932 this.el.visible = false;
1935 this.el.button_press_event.connect( () => {
1937 if (this.popup == null) {
1938 this.popup = new Xcls_ValaCompileErrors();
1939 this.popup.window = _this;
1943 this.popup.show(this.notices, this.el);
1949 // user defined functions
1950 public void updateResults () {
1951 this.el.visible = true;
1953 var res = _this.searchcontext.get_occurrences_count();
1955 _this.search_results.el.label = "??? Matches";
1959 _this.nextBtn.el.sensitive = false;
1960 _this.backBtn.el.sensitive = false;
1963 _this.search_results.el.label = "%d Matches".printf(res);
1964 _this.nextBtn.el.sensitive = true;
1965 _this.backBtn.el.sensitive = true;
1968 _this.search_results.el.label = "No Matches";
1974 public class Xcls_nextBtn : Object
1976 public Gtk.Button el;
1977 private Xcls_WindowRooView _this;
1983 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1986 _this.nextBtn = this;
1987 this.el = new Gtk.Button();
1991 // set gobject values
1992 this.el.always_show_image = true;
1993 this.el.label = "Next";
1994 this.el.sensitive = false;
1995 var child_0 = new Xcls_Image23( _this );
1997 this.el.image = child_0.el;
2000 this.el.button_press_event.connect( (event) => {
2002 _this.forwardSearch(true);
2008 // user defined functions
2010 public class Xcls_Image23 : Object
2012 public Gtk.Image el;
2013 private Xcls_WindowRooView _this;
2019 public Xcls_Image23(Xcls_WindowRooView _owner )
2022 this.el = new Gtk.Image();
2026 // set gobject values
2027 this.el.icon_name = "go-down";
2030 // user defined functions
2034 public class Xcls_backBtn : Object
2036 public Gtk.Button el;
2037 private Xcls_WindowRooView _this;
2043 public Xcls_backBtn(Xcls_WindowRooView _owner )
2046 _this.backBtn = this;
2047 this.el = new Gtk.Button();
2051 // set gobject values
2052 this.el.always_show_image = true;
2053 this.el.label = "Previous";
2054 this.el.sensitive = false;
2055 var child_0 = new Xcls_Image25( _this );
2057 this.el.image = child_0.el;
2060 this.el.button_press_event.connect( (event) => {
2062 _this.backSearch(true);
2068 // user defined functions
2070 public class Xcls_Image25 : Object
2072 public Gtk.Image el;
2073 private Xcls_WindowRooView _this;
2079 public Xcls_Image25(Xcls_WindowRooView _owner )
2082 this.el = new Gtk.Image();
2086 // set gobject values
2087 this.el.icon_name = "go-up";
2090 // user defined functions
2094 public class Xcls_MenuButton26 : Object
2096 public Gtk.MenuButton el;
2097 private Xcls_WindowRooView _this;
2103 public Xcls_MenuButton26(Xcls_WindowRooView _owner )
2106 this.el = new Gtk.MenuButton();
2110 // set gobject values
2111 this.el.always_show_image = true;
2112 this.el.label = "Settings";
2113 var child_0 = new Xcls_Image27( _this );
2115 this.el.image = child_0.el;
2116 var child_1 = new Xcls_search_settings( _this );
2118 this.el.popup = child_1.el;
2121 // user defined functions
2123 public class Xcls_Image27 : Object
2125 public Gtk.Image el;
2126 private Xcls_WindowRooView _this;
2132 public Xcls_Image27(Xcls_WindowRooView _owner )
2135 this.el = new Gtk.Image();
2139 // set gobject values
2140 this.el.icon_name = "emblem-system";
2143 // user defined functions
2146 public class Xcls_search_settings : Object
2149 private Xcls_WindowRooView _this;
2155 public Xcls_search_settings(Xcls_WindowRooView _owner )
2158 _this.search_settings = this;
2159 this.el = new Gtk.Menu();
2163 // set gobject values
2164 var child_0 = new Xcls_case_sensitive( _this );
2166 this.el.append( child_0.el );
2167 var child_1 = new Xcls_regex( _this );
2169 this.el.append( child_1.el );
2170 var child_2 = new Xcls_multiline( _this );
2172 this.el.append( child_2.el );
2175 // user defined functions
2177 public class Xcls_case_sensitive : Object
2179 public Gtk.CheckMenuItem el;
2180 private Xcls_WindowRooView _this;
2186 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2189 _this.case_sensitive = this;
2190 this.el = new Gtk.CheckMenuItem();
2194 // set gobject values
2195 this.el.label = "Case Sensitive";
2204 // user defined functions
2207 public class Xcls_regex : Object
2209 public Gtk.CheckMenuItem el;
2210 private Xcls_WindowRooView _this;
2216 public Xcls_regex(Xcls_WindowRooView _owner )
2220 this.el = new Gtk.CheckMenuItem();
2224 // set gobject values
2225 this.el.label = "Regex";
2234 // user defined functions
2237 public class Xcls_multiline : Object
2239 public Gtk.CheckMenuItem el;
2240 private Xcls_WindowRooView _this;
2246 public Xcls_multiline(Xcls_WindowRooView _owner )
2249 _this.multiline = this;
2250 this.el = new Gtk.CheckMenuItem();
2254 // set gobject values
2255 this.el.label = "Multi-line (add \\n)";
2264 // user defined functions