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_search_settings search_settings;
29 public Xcls_case_sensitive case_sensitive;
30 public Xcls_regex regex;
31 public Xcls_multiline multiline;
34 public Gtk.Widget lastObj;
35 public Xcls_MainWindow main_window;
36 public Gtk.SourceSearchContext searchcontext;
37 public int last_search_end;
38 public JsRender.JsRender file;
41 public Xcls_WindowRooView()
44 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
48 this.last_search_end = 0;
52 this.el.hexpand = true;
53 this.el.vexpand = true;
54 var child_0 = new Xcls_notebook( _this );
56 this.el.pack_start ( child_0.el , true,true,0 );
59 // user defined functions
60 public void loadFile (JsRender.JsRender file)
63 this.view.renderJS(true);
64 this.notebook.el.page = 0;// gtk preview
65 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);
85 // ---------- this selects the tree's node...
87 var ltree = _this.main_window.windowstate.left_tree;
88 var tp = ltree.model.treePathFromNode(node);
89 print("got tree path %s\n", tp);
93 //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
96 //print("changing cursor on tree..\n");
100 // let's try allowing editing on the methods.
101 // a little klunky at present..
102 _this.sourceview.prop_selected = "";
104 //see if we can find it..
105 var kv = prop.split(":");
108 //var k = prop.get_key(kv[1]);
109 // fixme -- need to determine if it's an editable property...
110 _this.sourceview.prop_selected = prop;
112 } else if (kv[0] == "l") {
113 _this.sourceview.prop_selected = prop;
117 ltree.view.setCursor(tp, "editor");
118 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
119 _this.sourceview.nodeSelected(node,false);
121 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
122 // GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
123 // this.allow_node_scroll = true;
139 public void requestRedraw () {
140 this.view.renderJS(false);
141 this.sourceview.loadFile();
143 public void forwardSearch (bool change_focus) {
145 if (this.searchcontext == null) {
148 this.notebook.el.page = 1;
149 Gtk.TextIter beg, st,en, stl;
151 var buf = this.sourceview.el.get_buffer();
152 buf.get_iter_at_offset(out beg, this.last_search_end);
153 if (!this.searchcontext.forward(beg, out st, out en)) {
154 this.last_search_end = 0;
157 this.last_search_end = en.get_offset();
159 this.sourceview.el.grab_focus();
161 buf.place_cursor(st);
165 this.sourceview.el.scroll_to_iter(st, 0.0f, true, 0.0f, 0.5f);
168 var ln = st.get_line();
170 this.highlightNodeAtLine(ln);
172 public void backSearch (bool change_focus) {
174 if (this.searchcontext == null) {
178 Gtk.TextIter beg, st,en;
179 bool has_wrapped_around;
180 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
182 if (!this.searchcontext.backward2(beg, out st, out en, out has_wrapped_around)) {
184 this.last_search_end = 0;
187 this.last_search_end = en.get_offset();
189 this.sourceview.el.grab_focus();
191 this.buffer.el.place_cursor(st);
192 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
193 var ln = st.get_line();
194 this.highlightNodeAtLine(ln);
198 public int search (string in_txt) {
199 this.notebook.el.page = 1;
203 var s = new Gtk.SourceSearchSettings();
204 s.case_sensitive = _this.case_sensitive.el.active;
205 s.regex_enabled = _this.regex.el.active;
206 s.wrap_around = false;
208 this.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);
209 this.searchcontext.set_highlight(true);
212 if (_this.multiline.el.active) {
213 txt = in_txt.replace("\\n", "\n");
216 s.set_search_text(txt);
217 Gtk.TextIter beg, st,en;
219 this.buffer.el.get_start_iter(out beg);
220 this.searchcontext.forward(beg, out st, out en);
221 this.last_search_end = 0;
223 return this.searchcontext.get_occurrences_count();
229 public void createThumb () {
232 if (this.file == null) {
235 if (this.notebook.el.page > 0 ) {
239 var filename = this.file.getIconFileName(false);
241 var win = this.el.get_parent_window();
242 var width = win.get_width();
243 // var height = win.get_height();
245 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.paned.el.position);
246 screenshot.save(filename,"png");
256 public void scroll_to_line (int line) {
257 this.notebook.el.page = 1;// code preview...
259 GLib.Timeout.add(500, () => {
264 var buf = this.sourceview.el.get_buffer();
266 var sbuf = (Gtk.SourceBuffer) buf;
270 sbuf.get_iter_at_line(out iter, line);
271 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
277 public class Xcls_notebook : Object
279 public Gtk.Notebook el;
280 private Xcls_WindowRooView _this;
286 public Xcls_notebook(Xcls_WindowRooView _owner )
289 _this.notebook = this;
290 this.el = new Gtk.Notebook();
294 // set gobject values
295 var child_0 = new Xcls_label_preview( _this );
297 var child_1 = new Xcls_label_code( _this );
299 var child_2 = new Xcls_paned( _this );
301 this.el.append_page ( child_2.el , _this.label_preview.el );
302 var child_3 = new Xcls_Box14( _this );
304 this.el.append_page ( child_3.el , _this.label_code.el );
307 // user defined functions
309 public class Xcls_label_preview : Object
312 private Xcls_WindowRooView _this;
318 public Xcls_label_preview(Xcls_WindowRooView _owner )
321 _this.label_preview = this;
322 this.el = new Gtk.Label( "Preview" );
326 // set gobject values
329 // user defined functions
332 public class Xcls_label_code : Object
335 private Xcls_WindowRooView _this;
341 public Xcls_label_code(Xcls_WindowRooView _owner )
344 _this.label_code = this;
345 this.el = new Gtk.Label( "Preview Generated Code" );
349 // set gobject values
352 // user defined functions
355 public class Xcls_paned : Object
358 private Xcls_WindowRooView _this;
364 public Xcls_paned(Xcls_WindowRooView _owner )
368 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
372 // set gobject values
373 var child_0 = new Xcls_viewbox( _this );
375 this.el.pack1 ( child_0.el , true,true );
376 var child_1 = new Xcls_inspectorcontainer( _this );
378 this.el.pack2 ( child_1.el , true,true );
381 // user defined functions
383 public class Xcls_viewbox : Object
386 private Xcls_WindowRooView _this;
392 public Xcls_viewbox(Xcls_WindowRooView _owner )
395 _this.viewbox = this;
396 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
400 // set gobject values
401 this.el.homogeneous = false;
402 var child_0 = new Xcls_Box7( _this );
404 this.el.pack_start ( child_0.el , false,true,0 );
405 var child_1 = new Xcls_viewcontainer( _this );
407 this.el.pack_end ( child_1.el , true,true,0 );
410 // user defined functions
412 public class Xcls_Box7 : Object
415 private Xcls_WindowRooView _this;
421 public Xcls_Box7(Xcls_WindowRooView _owner )
424 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
428 // set gobject values
429 this.el.homogeneous = true;
430 this.el.height_request = 20;
431 this.el.vexpand = false;
432 var child_0 = new Xcls_Button8( _this );
434 this.el.pack_start ( child_0.el , false,false,0 );
435 var child_1 = new Xcls_AutoRedraw( _this );
437 this.el.pack_start ( child_1.el , false,false,0 );
438 var child_2 = new Xcls_Button10( _this );
440 this.el.pack_start ( child_2.el , false,false,0 );
443 // user defined functions
445 public class Xcls_Button8 : Object
447 public Gtk.Button el;
448 private Xcls_WindowRooView _this;
454 public Xcls_Button8(Xcls_WindowRooView _owner )
457 this.el = new Gtk.Button();
461 // set gobject values
462 this.el.label = "Redraw";
465 this.el.clicked.connect( ( ) => {
466 _this.view.renderJS( true);
470 // user defined functions
473 public class Xcls_AutoRedraw : Object
475 public Gtk.CheckButton el;
476 private Xcls_WindowRooView _this;
482 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
485 _this.AutoRedraw = this;
486 this.el = new Gtk.CheckButton();
490 // set gobject values
491 this.el.active = true;
492 this.el.label = "Auto Redraw On";
495 this.el.toggled.connect( (state) => {
496 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
500 // user defined functions
503 public class Xcls_Button10 : Object
505 public Gtk.Button el;
506 private Xcls_WindowRooView _this;
512 public Xcls_Button10(Xcls_WindowRooView _owner )
515 this.el = new Gtk.Button();
519 // set gobject values
520 this.el.label = "Full Redraw";
523 this.el.clicked.connect( () => {
524 _this.view.redraws = 99;
525 _this.view.el.web_context.clear_cache();
526 //_this.view.renderJS(true);
527 FakeServerCache.clear();
533 // user defined functions
537 public class Xcls_viewcontainer : Object
539 public Gtk.ScrolledWindow el;
540 private Xcls_WindowRooView _this;
546 public Xcls_viewcontainer(Xcls_WindowRooView _owner )
549 _this.viewcontainer = this;
550 this.el = new Gtk.ScrolledWindow( null, null );
554 // set gobject values
555 this.el.shadow_type = Gtk.ShadowType.IN;
556 var child_0 = new Xcls_view( _this );
558 this.el.add ( child_0.el );
562 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
565 // user defined functions
567 public class Xcls_view : Object
569 public WebKit.WebView el;
570 private Xcls_WindowRooView _this;
574 public WebKit.WebInspector inspector;
575 public bool pendingRedraw;
577 public bool refreshRequired;
579 public string runhtml;
580 public string renderedData;
581 public GLib.DateTime lastRedraw;
584 public Xcls_view(Xcls_WindowRooView _owner )
588 this.el = new WebKit.WebView();
591 this.pendingRedraw = false;
593 this.refreshRequired = false;
596 this.renderedData = "";
597 this.lastRedraw = null;
599 // set gobject values
604 // this may not work!?
605 var settings = this.el.get_settings();
606 settings.enable_developer_extras = true;
609 var fs= new FakeServer(this.el);
611 // this was an attempt to change the url perms.. did not work..
612 // settings.enable_file_access_from_file_uris = true;
613 // settings.enable_offline_web_application_cache - true;
614 // settings.enable_universal_access_from_file_uris = true;
621 // FIXME - base url of script..
622 // we need it so some of the database features work.
623 this.el.load_html( "Render not ready" ,
624 //fixme - should be a config option!
625 // or should we catch stuff and fix it up..
626 "http://localhost/app.Builder/"
630 //this.el.open('file:///' + __script_path__ + '/../builder.html');
635 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
636 null, // list of targets
637 Gdk.DragAction.COPY // what to do with data after dropped
640 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
641 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
643 GLib.Timeout.add_seconds(1, () =>{
644 //print("run refresh?");
645 if (this.el == null) {
656 this.el.script_dialog.connect( (dialog) => {
659 if (this.el == null) {
663 var msg = dialog.get_message();
664 if (msg.length < 4) {
667 if (msg.substring(0,4) != "IPC:") {
670 var ar = msg.split(":", 3);
677 print("GOT saveHTML %d?\n", ar[2].length);
678 _this.file.saveHTML(ar[2]);
685 this.el.show.connect( ( ) => {
686 this.initInspector();;
688 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
691 print("TARGET: drag-drop");
692 var is_valid_drop_site = true;
697 w, // will receive 'drag-data-received' signal
698 ctx, /* represents the current state of the DnD
699 this.get('/Window').atoms["STRING"], /* the target type we want
704 /* No target offered by source => error
707 return is_valid_drop_site;
710 this.el.load_changed.connect( (le) => {
711 if (le != WebKit.LoadEvent.FINISHED) {
714 if (this.runjs.length < 1) {
717 // this.el.run_javascript(this.runjs, null);
718 FakeServerCache.remove( this.runjs);
723 // user defined functions
724 public void initInspector () {
726 /* if (this.inspector == this.el.get_inspector()) {
727 this.inspector.show();
728 this.inspector.open_window();
729 print("init inspecter called, and inspector is the same as existing\n");
732 print("new inspector?\n");
734 this.inspector = this.el.get_inspector();
735 this.inspector.ref();
737 // got a new inspector...
739 this.inspector.open_window.connect(() => {
740 this.inspector = this.el.get_inspector();
741 print("inspector attach\n");
742 var wv = this.inspector.get_web_view();
744 print("got inspector web view\n");
746 var cn = _this.inspectorcontainer.el.get_child();
748 _this.inspectorcontainer.el.remove(cn);
751 _this.inspectorcontainer.el.add(wv);
754 //this.inspector.close();
756 //this.inspector = null;
764 this.inspector.closed.connect(() => {
765 print("inspector closed?!?");
766 // if this happens destroy the webkit..
768 this.el.stop_loading();
770 if (_this.viewbox.el.get_parent() == null) {
775 _this.viewbox.el.remove(_this.viewcontainer.el);
776 _this.el.remove(_this.inspectorcontainer.el);
778 // destory seems to cause problems.
780 //_this.viewcontainer.el.destroy();
781 //_this.inspectorcontainer.el.destroy();
784 var nv =new Xcls_viewcontainer(_this);
786 _this.viewbox.el.pack_end(nv.el,true,true,0);
788 var inv =new Xcls_inspectorcontainer(_this);
790 _this.el.pack2(inv.el,true,true);
794 //while(Gtk.events_pending ()) Gtk.main_iteration ();
795 //_this.view.renderJS(true);
796 _this.view.refreshRequired = true;
801 this.inspector.show();
803 public void renderJS (bool force) {
805 // this is the public redraw call..
806 // we refresh in a loop privately..
807 var autodraw = _this.AutoRedraw.el.active;
808 if (!autodraw && !force) {
809 print("Skipping redraw - no force, and autodraw off");
813 this.refreshRequired = true;
815 public void reInit () {
817 // if this happens destroy the webkit..
819 this.el.stop_loading();
821 if (_this.viewbox.el.get_parent() == null) {
826 _this.viewbox.el.remove(_this.viewcontainer.el);
827 _this.paned.el.remove(_this.inspectorcontainer.el);
829 // destory seems to cause problems.
831 //_this.viewcontainer.el.destroy();
832 //_this.inspectorcontainer.el.destroy();
833 var inv =new Xcls_inspectorcontainer(_this);
835 _this.paned.el.pack2(inv.el,true,true);
839 var nv =new Xcls_viewcontainer(_this);
841 _this.viewbox.el.pack_end(nv.el,true,true,0);
846 //while(Gtk.events_pending ()) Gtk.main_iteration ();
847 //_this.view.renderJS(true);
848 _this.view.refreshRequired = true;
850 public void runRefresh ()
852 // this is run every 2 seconds from the init..
856 if (!this.refreshRequired) {
857 // print("no refresh required");
861 if (this.lastRedraw != null) {
862 // do not redraw if last redraw was less that 5 seconds ago.
863 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
868 if (_this.file == null) {
873 this.refreshRequired = false;
874 // print("HTML RENDERING");
877 //this.get('/BottomPane').el.show();
878 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
879 _this.file.webkit_page_id = this.el.get_page_id();
881 var js = _this.file.toSourcePreview();
890 var project = _this.file.project;
892 //print (project.fn);
893 // set it to non-empty.
895 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
898 // this.runhtml = this.runhtml || '';
901 // then we need to reload the browser using
902 // load_html_string..
904 // then trigger a redraw once it's loaded..
905 this.pendingRedraw = true;
907 var runhtml = "<script type=\"text/javascript\">\n" ;
911 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
916 runhtml += builderhtml + "\n";
917 runhtml += "</script>\n" ;
919 // fix to make sure they are the same..
920 this.runhtml = project.runhtml;
921 // need to modify paths
924 var base_template = _this.file.project.base_template;
926 if (base_template.length > 0 && !FileUtils.test(
927 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
929 print("invalid base_template name - using default: %s\n", base_template);
934 GLib.FileUtils.get_contents(
935 BuilderApplication.configDirectory() + "/resources/" +
936 (base_template.length > 0 ? base_template : "roo.builder.html")
942 this.renderedData = js;
945 string js_src = js + "\n" +
946 "Roo.onReady(function() {\n" +
947 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
948 "Roo.XComponent.build();\n" +
951 // print("render js: " + js);
953 // console.log('not loaded yet');
955 this.lastRedraw = new DateTime.now_local();
958 //this.runjs = js_src;
959 var fc = FakeServerCache.factory_with_data(js_src);
960 this.runjs = fc.fname;
962 var html = inhtml.replace("</head>", runhtml + this.runhtml +
963 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
964 // "<script type=\"text/javascript\">\n" +
969 //print("LOAD HTML " + html);
971 var rootURL = _this.file.project.rootURL;
975 this.el.load_html( html ,
976 //fixme - should be a config option!
977 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
980 // force the inspector...
981 // this.initInspector();
983 // - no need for this, the builder javascript will call it when build is complete
984 //GLib.Timeout.add_seconds(1, () => {
985 // this.el.run_javascript("Builder.saveHTML()",null);
988 // print( "before render" + this.lastRedraw);
989 // print( "after render" + (new Date()));
996 public class Xcls_inspectorcontainer : Object
998 public Gtk.ScrolledWindow el;
999 private Xcls_WindowRooView _this;
1005 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
1008 _this.inspectorcontainer = this;
1009 this.el = new Gtk.ScrolledWindow( null, null );
1013 // set gobject values
1014 this.el.shadow_type = Gtk.ShadowType.IN;
1018 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1021 // user defined functions
1025 public class Xcls_Box14 : Object
1028 private Xcls_WindowRooView _this;
1034 public Xcls_Box14(Xcls_WindowRooView _owner )
1037 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1041 // set gobject values
1042 var child_0 = new Xcls_ScrolledWindow15( _this );
1044 this.el.add( child_0.el );
1045 var child_1 = new Xcls_Box18( _this );
1047 this.el.add( child_1.el );
1050 // user defined functions
1052 public class Xcls_ScrolledWindow15 : Object
1054 public Gtk.ScrolledWindow el;
1055 private Xcls_WindowRooView _this;
1061 public Xcls_ScrolledWindow15(Xcls_WindowRooView _owner )
1064 this.el = new Gtk.ScrolledWindow( null, null );
1068 // set gobject values
1069 this.el.vexpand = true;
1070 var child_0 = new Xcls_sourceview( _this );
1072 this.el.add ( child_0.el );
1075 // user defined functions
1077 public class Xcls_sourceview : Object
1079 public Gtk.SourceView el;
1080 private Xcls_WindowRooView _this;
1084 public bool loading;
1085 public int editable_start_pos;
1086 public bool button_is_pressed;
1087 public string prop_selected;
1088 public bool key_is_pressed;
1089 public JsRender.Node? node_selected;
1092 public Xcls_sourceview(Xcls_WindowRooView _owner )
1095 _this.sourceview = this;
1096 this.el = new Gtk.SourceView();
1099 this.loading = true;
1100 this.editable_start_pos = -1;
1101 this.button_is_pressed = false;
1102 this.prop_selected = "";
1103 this.key_is_pressed = false;
1104 this.node_selected = null;
1106 // set gobject values
1107 this.el.editable = false;
1108 this.el.show_line_marks = true;
1109 this.el.show_line_numbers = true;
1110 var child_0 = new Xcls_buffer( _this );
1112 this.el.set_buffer ( child_0.el );
1119 var description = Pango.FontDescription.from_string("monospace");
1120 description.set_size(8000);
1121 this.el.override_font(description);
1123 this.loading = true;
1124 //var buf = this.el.get_buffer();
1125 //buf.notify.connect(this.onCursorChanged);
1128 var attrs = new Gtk.SourceMarkAttributes();
1129 var pink = Gdk.RGBA();
1130 pink.parse ( "pink");
1131 attrs.set_background ( pink);
1132 attrs.set_icon_name ( "process-stop");
1133 attrs.query_tooltip_text.connect(( mark) => {
1134 //print("tooltip query? %s\n", mark.name);
1138 this.el.set_mark_attributes ("ERR", attrs, 1);
1140 var wattrs = new Gtk.SourceMarkAttributes();
1141 var blue = Gdk.RGBA();
1142 blue.parse ( "#ABF4EB");
1143 wattrs.set_background ( blue);
1144 wattrs.set_icon_name ( "process-stop");
1145 wattrs.query_tooltip_text.connect(( mark) => {
1146 //print("tooltip query? %s\n", mark.name);
1150 this.el.set_mark_attributes ("WARN", wattrs, 1);
1154 var dattrs = new Gtk.SourceMarkAttributes();
1155 var purple = Gdk.RGBA();
1156 purple.parse ( "#EEA9FF");
1157 dattrs.set_background ( purple);
1158 dattrs.set_icon_name ( "process-stop");
1159 dattrs.query_tooltip_text.connect(( mark) => {
1160 //print("tooltip query? %s\n", mark.name);
1164 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1167 var gattrs = new Gtk.SourceMarkAttributes();
1168 var grey = Gdk.RGBA();
1169 grey.parse ( "#ccc");
1170 gattrs.set_background ( grey);
1173 this.el.set_mark_attributes ("grey", gattrs, 1);
1183 this.el.button_release_event.connect( () => {
1185 print("BUTTON RELEASE EVENT\n");
1186 this.onCursorChanged();
1187 this.button_is_pressed = false;
1190 this.el.button_press_event.connect( ( ) => {
1192 this.button_is_pressed = true;
1195 this.el.key_press_event.connect( (event) => {
1197 if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1198 GLib.debug("SAVE: ctrl-g pressed");
1199 _this.forwardSearch(true);
1203 this.button_is_pressed = true;
1206 this.el.key_release_event.connect( () => {
1207 this.key_is_pressed = false;
1212 // user defined functions
1213 public void loadFile ( ) {
1214 this.loading = true;
1217 // get the cursor and scroll position....
1218 var buf = this.el.get_buffer();
1219 var cpos = buf.cursor_position;
1221 print("BEFORE LOAD cursor = %d\n", cpos);
1223 var vadj_pos = this.el.get_vadjustment().get_value();
1228 var sbuf = (Gtk.SourceBuffer) buf;
1232 if (_this.file == null || _this.file.xtype != "Roo") {
1233 print("xtype != Roo");
1234 this.loading = false;
1238 // get the string from the rendered tree...
1240 var str = _this.file.toSource();
1242 // print("setting str %d\n", str.length);
1243 buf.set_text(str, str.length);
1244 var lm = Gtk.SourceLanguageManager.get_default();
1246 //?? is javascript going to work as js?
1248 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
1254 sbuf.get_bounds (out start, out end);
1255 sbuf.remove_source_marks (start, end, null); // remove all marks..
1257 GLib.Timeout.add(500, () => {
1259 print("RESORTING cursor to = %d\n", cpos);
1260 Gtk.TextIter cpos_iter;
1261 buf.get_iter_at_offset(out cpos_iter, cpos);
1262 buf.place_cursor(cpos_iter);
1264 this.el.get_vadjustment().set_value(vadj_pos);;
1267 this.onCursorChanged();
1270 _this.buffer.checkSyntax();
1274 this.loading = false;
1275 _this.buffer.dirty = false;
1277 public void onCursorChanged (/*ParamSpec ps*/) {
1279 if (!this.key_is_pressed && !this.button_is_pressed) {
1286 // if (ps.name != "cursor-position") {
1290 var buf = this.el.get_buffer();
1291 //print("cursor changed : %d\n", buf.cursor_position);
1293 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1295 var ln = cpos.get_line();
1298 // --- select node at line....
1300 var node = _this.file.lineToNode(ln+1);
1303 print("can not find node\n");
1306 var prop = node.lineToProp(ln+1);
1307 print("prop : %s", prop == null ? "???" : prop);
1310 // ---------- this selects the tree's node...
1312 var ltree = _this.main_window.windowstate.left_tree;
1313 var tp = ltree.model.treePathFromNode(node);
1314 print("got tree path %s\n", tp);
1318 //print("changing cursor on tree..\n");
1322 // let's try allowing editing on the methods.
1323 // a little klunky at present..
1324 this.prop_selected = "";
1326 //see if we can find it..
1327 var kv = prop.split(":");
1330 //var k = prop.get_key(kv[1]);
1331 // fixme -- need to determine if it's an editable property...
1332 this.prop_selected = prop;
1334 } else if (kv[0] == "l") {
1335 this.prop_selected = prop;
1339 ltree.view.setCursor(tp, "editor");
1340 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
1341 this.nodeSelected(node,false);
1343 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1347 // highlight the node..
1349 public void nodeSelected (JsRender.Node? sel, bool scroll ) {
1353 // this is connected in widnowstate
1357 while(Gtk.events_pending()) {
1358 Gtk.main_iteration();
1361 this.node_selected = sel;
1363 this.updateGreySelection(scroll);
1368 public void updateGreySelection (bool scroll) {
1369 var sel = this.node_selected;
1370 print("node selected\n");
1371 var buf = this.el.get_buffer();
1372 var sbuf = (Gtk.SourceBuffer) buf;
1375 this.clearGreySelection();
1380 print("no selected node\n");
1381 // no highlighting..
1385 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1387 sbuf.get_iter_at_line(out iter, sel.line_start);
1390 Gtk.TextIter cur_iter;
1391 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1393 var cursor_at_line = cur_iter.get_line();
1396 //var cur_line = cur_iter.get_line();
1397 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1401 print("scrolling to node -- should occur on node picking.\n");
1402 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1405 var start_line = sel.line_start;
1406 var end_line = sel.line_end;
1409 this.el.editable = false;
1411 //var colon_pos = 0;
1413 this.editable_start_pos = -1;
1415 // now if we have selected a property...
1416 if (this.prop_selected.length> 0 ) {
1419 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1420 start_line = nstart;
1422 this.el.editable = true;
1423 print("start line = %d, end line = %d\n", start_line, end_line);
1425 // see if we are 'right of ':'
1426 // get an iter for the start of the line.
1427 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1428 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1429 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1434 if (end_first_line_iter.forward_to_line_end()) {
1435 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1437 print("first line = %s\n", first_line);
1438 if (first_line.contains(":")) {
1439 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1440 print("colon_pos = %d\n", this.editable_start_pos);
1444 //Gtk.TextIter colon_iter;
1445 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1446 //sbuf.create_source_mark(null, "active_text", colon_iter);
1451 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1452 //if (start_line - 1 == cursor_at_line) {
1453 // should be ok - current_posssion can not be less than '-1'...
1454 if (sbuf.cursor_position < this.editable_start_pos) {
1456 print("cursor is before start pos.. - turn off editable...\n");
1457 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1458 //print("before cursor string = %s\n", before_cursor_string);
1459 //if (!before_cursor_string.contains(":")) {
1460 this.el.editable = false;
1469 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1474 print("checking selection\n");
1477 // check selection - if it's out of 'bounds'
1478 if (this.el.editable && sbuf.get_has_selection()) {
1479 Gtk.TextIter sel_start_iter, sel_end_iter;
1480 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1482 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1483 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1485 this.el.editable = false;
1487 if (this.editable_start_pos > 0 &&
1488 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1491 this.el.editable = false;
1501 for (var i = 0; i < buf.get_line_count();i++) {
1502 if (i < (start_line -1) || i > (end_line -1)) {
1504 sbuf.get_iter_at_line(out iter, i);
1505 sbuf.create_source_mark(null, "grey", iter);
1510 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1511 Gtk.TextIter cpos_iter;
1512 buf.get_iter_at_line(out cpos_iter, start_line);
1514 buf.place_cursor(cpos_iter);
1519 public void highlightErrorsJson (string type, Json.Object obj) {
1520 // this is a hook for the vala code - it has no value in javascript
1521 // as we only have one error ususally....
1528 public string toString () {
1531 this.el.get_buffer().get_start_iter(out s);
1532 this.el.get_buffer().get_end_iter(out e);
1533 var ret = this.el.get_buffer().get_text(s,e,true);
1534 //print("TO STRING? " + ret);
1537 public void clearGreySelection () {
1538 // clear all the marks..
1539 var sbuf = (Gtk.SourceBuffer)this.el.buffer;
1544 sbuf.get_bounds (out start, out end);
1545 sbuf.remove_source_marks (start, end, "grey");
1550 public class Xcls_buffer : Object
1552 public Gtk.SourceBuffer el;
1553 private Xcls_WindowRooView _this;
1557 public int error_line;
1561 public Xcls_buffer(Xcls_WindowRooView _owner )
1564 _this.buffer = this;
1565 this.el = new Gtk.SourceBuffer( null );
1568 this.error_line = -1;
1571 // set gobject values
1574 this.el.changed.connect( () => {
1579 // _this.save_button.el.sensitive = true;
1580 ///?? has changed occured during loading?
1582 // only trigger this if
1587 if (_this.sourceview.loading) {
1593 print("- PREVIEW EDITOR CHANGED--");
1596 this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1600 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1601 print("button or key not pressed to generate change?!\n");
1606 // what are we editing??
1607 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1611 // find the colon on the first line...
1613 if (_this.sourceview.editable_start_pos > -1) {
1615 var buf = (Gtk.SourceBuffer)_this.sourceview.el.get_buffer();
1617 //print("cursor changed : %d\n", buf.cursor_position);
1618 Gtk.TextIter spos,epos;
1619 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1620 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1623 var line = spos.get_line();
1624 var endline = buf.get_line_count();
1625 while (line < endline) {
1627 buf.get_iter_at_line(out epos, line);
1628 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1629 buf.get_iter_at_line(out epos, line);
1636 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1638 // in theory the last char will be '}' or '},' .. or ','
1639 // we should chop the ',' of the end...
1640 var str = buf.get_text(spos, epos, false);
1641 print("got string\n%s\n", str);
1649 // user defined functions
1650 public bool checkSyntax () {
1653 var str = this.toString();
1656 if (this.error_line > 0) {
1659 this.el.get_bounds (out start, out end);
1661 this.el.remove_source_marks (start, end, "WARN");
1662 this.el.remove_source_marks (start, end, "ERR");
1666 if (str.length < 1) {
1667 print("checkSyntax - empty string?\n");
1671 if (_this.file == null) {
1674 var p = _this.file.project.palete;
1677 if (_this.file.language != "js") {
1678 return false; // fake syntax error.
1681 //Gee.HashMap<int,string> ret_x;
1683 return p.javascriptHasErrors(
1684 _this.main_window.windowstate,
1686 null, // prop - not relivant.
1692 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1694 this.error_line = validate_res.size;
1696 if (this.error_line < 1) {
1699 var tlines = this.el.get_line_count ();
1701 var valiter = validate_res.map_iterator();
1702 while (valiter.next()) {
1704 // print("get inter\n");
1705 var eline = valiter.get_key();
1706 if (eline > tlines) {
1709 this.el.get_iter_at_line( out iter, eline);
1710 //print("mark line\n");
1711 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1715 public string toString () {
1719 this.el.get_start_iter(out s);
1720 this.el.get_end_iter(out e);
1721 var ret = this.el.get_text(s,e,true);
1722 //print("TO STRING? " + ret);
1729 public class Xcls_Box18 : Object
1732 private Xcls_WindowRooView _this;
1738 public Xcls_Box18(Xcls_WindowRooView _owner )
1741 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1745 // set gobject values
1746 this.el.homogeneous = false;
1747 this.el.vexpand = false;
1748 var child_0 = new Xcls_search_entry( _this );
1750 this.el.add( child_0.el );
1751 var child_1 = new Xcls_MenuBar20( _this );
1753 this.el.add ( child_1.el );
1754 var child_2 = new Xcls_Button23( _this );
1756 this.el.add( child_2.el );
1757 var child_3 = new Xcls_Button25( _this );
1759 this.el.add( child_3.el );
1760 var child_4 = new Xcls_MenuButton27( _this );
1762 this.el.add( child_4.el );
1765 // user defined functions
1767 public class Xcls_search_entry : Object
1769 public Gtk.SearchEntry el;
1770 private Xcls_WindowRooView _this;
1776 public Xcls_search_entry(Xcls_WindowRooView _owner )
1779 _this.search_entry = this;
1780 this.el = new Gtk.SearchEntry();
1784 // set gobject values
1785 this.el.width_request = 300;
1786 this.el.hexpand = true;
1787 this.el.placeholder_text = "Press enter to search";
1791 var description = Pango.FontDescription.from_string("monospace");
1792 description.set_size(8000);
1793 this.el.override_font(description);
1796 this.el.key_press_event.connect( (event) => {
1798 if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1799 GLib.debug("SAVE: ctrl-g pressed");
1800 _this.forwardSearch(true);
1806 if (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {
1807 var res = _this.search(this.el.text);
1809 _this.search_results.el.label = "%d Matches".printf(res);
1811 _this.search_results.el.label = "No Matches";
1817 // print(event.key.keyval)
1822 this.el.changed.connect( () => {
1824 if (this.el.text == "") {
1825 _this.search_results.el.hide();
1829 switch(_this.windowstate.state) {
1830 case WindowState.State.CODEONLY:
1831 ///case WindowState.State.CODE:
1832 // search the code being edited..
1833 res = _this.windowstate.code_editor_tab.search(this.el.text);
1836 case WindowState.State.PREVIEW:
1837 if (_this.windowstate.file.xtype == "Gtk") {
1838 res = _this.windowstate.window_gladeview.search(this.el.text);
1840 res = _this.windowstate.window_rooview.search(this.el.text);
1846 _this.search_results.el.show();
1848 _this.search_results.el.label = "%d Matches".printf(res);
1850 _this.search_results.el.label = "No Matches";
1858 // user defined functions
1859 public void forwardSearch (bool change_focus) {
1862 _this.forwardSearch(change_focus);
1866 switch(_this.windowstate.state) {
1867 case WindowState.State.CODEONLY:
1868 //case WindowState.State.CODE:
1869 // search the code being edited..
1870 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1873 case WindowState.State.PREVIEW:
1874 if (_this.windowstate.file.xtype == "Gtk") {
1875 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1877 _this.windowstate.window_rooview.forwardSearch(change_focus);
1887 public class Xcls_MenuBar20 : Object
1889 public Gtk.MenuBar el;
1890 private Xcls_WindowRooView _this;
1896 public Xcls_MenuBar20(Xcls_WindowRooView _owner )
1899 this.el = new Gtk.MenuBar();
1903 // set gobject values
1904 var child_0 = new Xcls_search_results( _this );
1906 this.el.add ( child_0.el );
1909 // user defined functions
1911 public class Xcls_search_results : Object
1913 public Gtk.ImageMenuItem el;
1914 private Xcls_WindowRooView _this;
1918 public Xcls_ValaCompileErrors popup;
1921 public Xcls_search_results(Xcls_WindowRooView _owner )
1924 _this.search_results = this;
1925 this.el = new Gtk.ImageMenuItem();
1929 // set gobject values
1930 this.el.always_show_image = true;
1931 this.el.label = "Matches";
1932 var child_0 = new Xcls_Image22( _this );
1934 this.el.set_image ( child_0.el );
1937 this.el.button_press_event.connect( () => {
1939 if (this.popup == null) {
1940 this.popup = new Xcls_ValaCompileErrors();
1941 this.popup.window = _this;
1945 this.popup.show(this.notices, this.el);
1951 // user defined functions
1953 public class Xcls_Image22 : Object
1955 public Gtk.Image el;
1956 private Xcls_WindowRooView _this;
1962 public Xcls_Image22(Xcls_WindowRooView _owner )
1965 this.el = new Gtk.Image();
1969 // set gobject values
1970 this.el.icon_name = "system-search";
1971 this.el.sensitive = false;
1974 // user defined functions
1979 public class Xcls_Button23 : Object
1981 public Gtk.Button el;
1982 private Xcls_WindowRooView _this;
1988 public Xcls_Button23(Xcls_WindowRooView _owner )
1991 this.el = new Gtk.Button();
1995 // set gobject values
1996 this.el.always_show_image = true;
1997 this.el.label = "Next";
1998 var child_0 = new Xcls_Image24( _this );
2000 this.el.image = child_0.el;
2003 this.el.button_press_event.connect( (event) => {
2005 _this.forwardSearch(true);
2011 // user defined functions
2013 public class Xcls_Image24 : Object
2015 public Gtk.Image el;
2016 private Xcls_WindowRooView _this;
2022 public Xcls_Image24(Xcls_WindowRooView _owner )
2025 this.el = new Gtk.Image();
2029 // set gobject values
2030 this.el.icon_name = "go-down";
2033 // user defined functions
2037 public class Xcls_Button25 : Object
2039 public Gtk.Button el;
2040 private Xcls_WindowRooView _this;
2046 public Xcls_Button25(Xcls_WindowRooView _owner )
2049 this.el = new Gtk.Button();
2053 // set gobject values
2054 this.el.always_show_image = true;
2055 this.el.label = "Previous";
2056 var child_0 = new Xcls_Image26( _this );
2058 this.el.image = child_0.el;
2061 this.el.button_press_event.connect( (event) => {
2063 _this.backSearch(true);
2069 // user defined functions
2071 public class Xcls_Image26 : Object
2073 public Gtk.Image el;
2074 private Xcls_WindowRooView _this;
2080 public Xcls_Image26(Xcls_WindowRooView _owner )
2083 this.el = new Gtk.Image();
2087 // set gobject values
2088 this.el.icon_name = "go-up";
2091 // user defined functions
2095 public class Xcls_MenuButton27 : Object
2097 public Gtk.MenuButton el;
2098 private Xcls_WindowRooView _this;
2104 public Xcls_MenuButton27(Xcls_WindowRooView _owner )
2107 this.el = new Gtk.MenuButton();
2111 // set gobject values
2112 this.el.always_show_image = true;
2113 this.el.label = "Settings";
2114 var child_0 = new Xcls_Image28( _this );
2116 this.el.image = child_0.el;
2117 var child_1 = new Xcls_search_settings( _this );
2119 this.el.popup = child_1.el;
2122 // user defined functions
2124 public class Xcls_Image28 : Object
2126 public Gtk.Image el;
2127 private Xcls_WindowRooView _this;
2133 public Xcls_Image28(Xcls_WindowRooView _owner )
2136 this.el = new Gtk.Image();
2140 // set gobject values
2141 this.el.icon_name = "emblem-system";
2144 // user defined functions
2147 public class Xcls_search_settings : Object
2150 private Xcls_WindowRooView _this;
2156 public Xcls_search_settings(Xcls_WindowRooView _owner )
2159 _this.search_settings = this;
2160 this.el = new Gtk.Menu();
2164 // set gobject values
2165 var child_0 = new Xcls_case_sensitive( _this );
2167 this.el.append( child_0.el );
2168 var child_1 = new Xcls_regex( _this );
2170 this.el.append( child_1.el );
2171 var child_2 = new Xcls_multiline( _this );
2173 this.el.append( child_2.el );
2176 // user defined functions
2178 public class Xcls_case_sensitive : Object
2180 public Gtk.CheckMenuItem el;
2181 private Xcls_WindowRooView _this;
2187 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2190 _this.case_sensitive = this;
2191 this.el = new Gtk.CheckMenuItem();
2195 // set gobject values
2196 this.el.label = "Case Sensitive";
2205 // user defined functions
2208 public class Xcls_regex : Object
2210 public Gtk.CheckMenuItem el;
2211 private Xcls_WindowRooView _this;
2217 public Xcls_regex(Xcls_WindowRooView _owner )
2221 this.el = new Gtk.CheckMenuItem();
2225 // set gobject values
2226 this.el.label = "Regex";
2235 // user defined functions
2238 public class Xcls_multiline : Object
2240 public Gtk.CheckMenuItem el;
2241 private Xcls_WindowRooView _this;
2247 public Xcls_multiline(Xcls_WindowRooView _owner )
2250 _this.multiline = this;
2251 this.el = new Gtk.CheckMenuItem();
2255 // set gobject values
2256 this.el.label = "Multi-line (add \\n)";
2265 // user defined functions