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) {
261 GLib.Timeout.add(100, () => {
263 this.notebook.el.set_current_page( 1 );
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);
1204 if (event.keyval == Gdk.Key.f && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1205 GLib.debug("SAVE: ctrl-f pressed");
1206 _this.search_entry.el.grab_focus();
1210 this.button_is_pressed = true;
1213 this.el.key_release_event.connect( () => {
1214 this.key_is_pressed = false;
1219 // user defined functions
1220 public void loadFile ( ) {
1221 this.loading = true;
1224 // get the cursor and scroll position....
1225 var buf = this.el.get_buffer();
1226 var cpos = buf.cursor_position;
1228 print("BEFORE LOAD cursor = %d\n", cpos);
1230 var vadj_pos = this.el.get_vadjustment().get_value();
1235 var sbuf = (Gtk.SourceBuffer) buf;
1239 if (_this.file == null || _this.file.xtype != "Roo") {
1240 print("xtype != Roo");
1241 this.loading = false;
1245 // get the string from the rendered tree...
1247 var str = _this.file.toSource();
1249 // print("setting str %d\n", str.length);
1250 buf.set_text(str, str.length);
1251 var lm = Gtk.SourceLanguageManager.get_default();
1253 //?? is javascript going to work as js?
1255 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
1261 sbuf.get_bounds (out start, out end);
1262 sbuf.remove_source_marks (start, end, null); // remove all marks..
1264 GLib.Timeout.add(500, () => {
1266 print("RESORTING cursor to = %d\n", cpos);
1267 Gtk.TextIter cpos_iter;
1268 buf.get_iter_at_offset(out cpos_iter, cpos);
1269 buf.place_cursor(cpos_iter);
1271 this.el.get_vadjustment().set_value(vadj_pos);;
1274 this.onCursorChanged();
1277 _this.buffer.checkSyntax();
1281 this.loading = false;
1282 _this.buffer.dirty = false;
1284 public void onCursorChanged (/*ParamSpec ps*/) {
1286 if (!this.key_is_pressed && !this.button_is_pressed) {
1293 // if (ps.name != "cursor-position") {
1297 var buf = this.el.get_buffer();
1298 //print("cursor changed : %d\n", buf.cursor_position);
1300 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1302 var ln = cpos.get_line();
1305 // --- select node at line....
1307 var node = _this.file.lineToNode(ln+1);
1310 print("can not find node\n");
1313 var prop = node.lineToProp(ln+1);
1314 print("prop : %s", prop == null ? "???" : prop);
1317 // ---------- this selects the tree's node...
1319 var ltree = _this.main_window.windowstate.left_tree;
1320 var tp = ltree.model.treePathFromNode(node);
1321 print("got tree path %s\n", tp);
1325 //print("changing cursor on tree..\n");
1329 // let's try allowing editing on the methods.
1330 // a little klunky at present..
1331 this.prop_selected = "";
1333 //see if we can find it..
1334 var kv = prop.split(":");
1337 //var k = prop.get_key(kv[1]);
1338 // fixme -- need to determine if it's an editable property...
1339 this.prop_selected = prop;
1341 } else if (kv[0] == "l") {
1342 this.prop_selected = prop;
1346 ltree.view.setCursor(tp, "editor");
1347 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
1348 //this.nodeSelected(node,false);
1350 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1354 // highlight the node..
1356 public void nodeSelected (JsRender.Node? sel, bool scroll ) {
1360 // this is connected in widnowstate
1364 while(Gtk.events_pending()) {
1365 Gtk.main_iteration();
1368 this.node_selected = sel;
1370 // this.updateGreySelection(scroll);
1375 public void updateGreySelection (bool scroll) {
1376 var sel = this.node_selected;
1377 print("node selected\n");
1378 var buf = this.el.get_buffer();
1379 var sbuf = (Gtk.SourceBuffer) buf;
1382 this.clearGreySelection();
1387 print("no selected node\n");
1388 // no highlighting..
1392 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1394 sbuf.get_iter_at_line(out iter, sel.line_start);
1397 Gtk.TextIter cur_iter;
1398 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1400 var cursor_at_line = cur_iter.get_line();
1403 //var cur_line = cur_iter.get_line();
1404 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1408 print("scrolling to node -- should occur on node picking.\n");
1409 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1412 var start_line = sel.line_start;
1413 var end_line = sel.line_end;
1416 this.el.editable = false;
1418 //var colon_pos = 0;
1420 this.editable_start_pos = -1;
1422 // now if we have selected a property...
1423 if (this.prop_selected.length> 0 ) {
1426 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1427 start_line = nstart;
1429 // this.el.editable = true; << cant do this!!?
1430 print("start line = %d, end line = %d\n", start_line, end_line);
1432 // see if we are 'right of ':'
1433 // get an iter for the start of the line.
1434 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1435 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1436 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1441 if (end_first_line_iter.forward_to_line_end()) {
1442 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1444 print("first line = %s\n", first_line);
1445 if (first_line.contains(":")) {
1446 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1447 print("colon_pos = %d\n", this.editable_start_pos);
1451 //Gtk.TextIter colon_iter;
1452 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1453 //sbuf.create_source_mark(null, "active_text", colon_iter);
1458 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1459 //if (start_line - 1 == cursor_at_line) {
1460 // should be ok - current_posssion can not be less than '-1'...
1461 if (sbuf.cursor_position < this.editable_start_pos) {
1463 print("cursor is before start pos.. - turn off editable...\n");
1464 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1465 //print("before cursor string = %s\n", before_cursor_string);
1466 //if (!before_cursor_string.contains(":")) {
1467 this.el.editable = false;
1476 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1481 print("checking selection\n");
1484 // check selection - if it's out of 'bounds'
1485 if (this.el.editable && sbuf.get_has_selection()) {
1486 Gtk.TextIter sel_start_iter, sel_end_iter;
1487 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1489 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1490 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1492 this.el.editable = false;
1494 if (this.editable_start_pos > 0 &&
1495 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1498 this.el.editable = false;
1508 for (var i = 0; i < buf.get_line_count();i++) {
1509 if (i < (start_line -1) || i > (end_line -1)) {
1511 sbuf.get_iter_at_line(out iter, i);
1512 sbuf.create_source_mark(null, "grey", iter);
1517 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1518 Gtk.TextIter cpos_iter;
1519 buf.get_iter_at_line(out cpos_iter, start_line);
1521 buf.place_cursor(cpos_iter);
1526 public void highlightErrorsJson (string type, Json.Object obj) {
1527 // this is a hook for the vala code - it has no value in javascript
1528 // as we only have one error ususally....
1535 public string toString () {
1538 this.el.get_buffer().get_start_iter(out s);
1539 this.el.get_buffer().get_end_iter(out e);
1540 var ret = this.el.get_buffer().get_text(s,e,true);
1541 //print("TO STRING? " + ret);
1544 public void clearGreySelection () {
1545 // clear all the marks..
1546 var sbuf = (Gtk.SourceBuffer)this.el.buffer;
1551 sbuf.get_bounds (out start, out end);
1552 sbuf.remove_source_marks (start, end, "grey");
1557 public class Xcls_buffer : Object
1559 public Gtk.SourceBuffer el;
1560 private Xcls_WindowRooView _this;
1564 public int error_line;
1568 public Xcls_buffer(Xcls_WindowRooView _owner )
1571 _this.buffer = this;
1572 this.el = new Gtk.SourceBuffer( null );
1575 this.error_line = -1;
1578 // set gobject values
1581 this.el.changed.connect( () => {
1586 // _this.save_button.el.sensitive = true;
1587 ///?? has changed occured during loading?
1589 // only trigger this if
1594 if (_this.sourceview.loading) {
1600 print("- PREVIEW EDITOR CHANGED--");
1603 this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1607 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1608 print("button or key not pressed to generate change?!\n");
1613 // what are we editing??
1614 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1618 // find the colon on the first line...
1620 if (_this.sourceview.editable_start_pos > -1) {
1622 var buf = (Gtk.SourceBuffer)_this.sourceview.el.get_buffer();
1624 //print("cursor changed : %d\n", buf.cursor_position);
1625 Gtk.TextIter spos,epos;
1626 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1627 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1630 var line = spos.get_line();
1631 var endline = buf.get_line_count();
1632 while (line < endline) {
1634 buf.get_iter_at_line(out epos, line);
1635 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1636 buf.get_iter_at_line(out epos, line);
1643 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1645 // in theory the last char will be '}' or '},' .. or ','
1646 // we should chop the ',' of the end...
1647 var str = buf.get_text(spos, epos, false);
1648 print("got string\n%s\n", str);
1656 // user defined functions
1657 public bool checkSyntax () {
1660 var str = this.toString();
1663 if (this.error_line > 0) {
1666 this.el.get_bounds (out start, out end);
1668 this.el.remove_source_marks (start, end, "WARN");
1669 this.el.remove_source_marks (start, end, "ERR");
1673 if (str.length < 1) {
1674 print("checkSyntax - empty string?\n");
1678 if (_this.file == null) {
1681 var p = _this.file.project.palete;
1684 if (_this.file.language != "js") {
1685 return false; // fake syntax error.
1688 //Gee.HashMap<int,string> ret_x;
1690 return p.javascriptHasErrors(
1691 _this.main_window.windowstate,
1693 null, // prop - not relivant.
1699 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1701 this.error_line = validate_res.size;
1703 if (this.error_line < 1) {
1706 var tlines = this.el.get_line_count ();
1708 var valiter = validate_res.map_iterator();
1709 while (valiter.next()) {
1711 // print("get inter\n");
1712 var eline = valiter.get_key();
1713 if (eline > tlines) {
1716 this.el.get_iter_at_line( out iter, eline);
1717 //print("mark line\n");
1718 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1722 public string toString () {
1726 this.el.get_start_iter(out s);
1727 this.el.get_end_iter(out e);
1728 var ret = this.el.get_text(s,e,true);
1729 //print("TO STRING? " + ret);
1736 public class Xcls_Box18 : Object
1739 private Xcls_WindowRooView _this;
1745 public Xcls_Box18(Xcls_WindowRooView _owner )
1748 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1752 // set gobject values
1753 this.el.homogeneous = false;
1754 this.el.vexpand = false;
1755 var child_0 = new Xcls_search_entry( _this );
1757 this.el.add( child_0.el );
1758 var child_1 = new Xcls_MenuBar20( _this );
1760 this.el.add ( child_1.el );
1761 var child_2 = new Xcls_nextBtn( _this );
1763 this.el.add( child_2.el );
1764 var child_3 = new Xcls_backBtn( _this );
1766 this.el.add( child_3.el );
1767 var child_4 = new Xcls_MenuButton26( _this );
1769 this.el.add( child_4.el );
1772 // user defined functions
1774 public class Xcls_search_entry : Object
1776 public Gtk.SearchEntry el;
1777 private Xcls_WindowRooView _this;
1783 public Xcls_search_entry(Xcls_WindowRooView _owner )
1786 _this.search_entry = this;
1787 this.el = new Gtk.SearchEntry();
1791 // set gobject values
1792 this.el.width_request = 300;
1793 this.el.hexpand = true;
1794 this.el.placeholder_text = "Press enter to search";
1798 var description = Pango.FontDescription.from_string("monospace");
1799 description.set_size(8000);
1800 this.el.override_font(description);
1803 this.el.key_press_event.connect( (event) => {
1804 if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1805 GLib.debug("SAVE: ctrl-g pressed");
1806 _this.forwardSearch(true);
1811 if (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {
1812 var res = _this.search(this.el.text);
1813 _this.search_results.updateResults();
1815 GLib.Timeout.add_seconds(2,() => {
1816 _this.search_results.updateResults();
1824 // print(event.key.keyval)
1829 this.el.changed.connect( () => {
1831 if (this.el.text == "") {
1832 _this.search_results.el.hide();
1836 switch(_this.windowstate.state) {
1837 case WindowState.State.CODEONLY:
1838 ///case WindowState.State.CODE:
1839 // search the code being edited..
1840 res = _this.windowstate.code_editor_tab.search(this.el.text);
1843 case WindowState.State.PREVIEW:
1844 if (_this.windowstate.file.xtype == "Gtk") {
1845 res = _this.windowstate.window_gladeview.search(this.el.text);
1847 res = _this.windowstate.window_rooview.search(this.el.text);
1853 _this.search_results.el.show();
1855 _this.search_results.el.label = "%d Matches".printf(res);
1857 _this.search_results.el.label = "No Matches";
1865 // user defined functions
1866 public void forwardSearch (bool change_focus) {
1869 _this.forwardSearch(change_focus);
1873 switch(_this.windowstate.state) {
1874 case WindowState.State.CODEONLY:
1875 //case WindowState.State.CODE:
1876 // search the code being edited..
1877 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1880 case WindowState.State.PREVIEW:
1881 if (_this.windowstate.file.xtype == "Gtk") {
1882 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1884 _this.windowstate.window_rooview.forwardSearch(change_focus);
1894 public class Xcls_MenuBar20 : Object
1896 public Gtk.MenuBar el;
1897 private Xcls_WindowRooView _this;
1903 public Xcls_MenuBar20(Xcls_WindowRooView _owner )
1906 this.el = new Gtk.MenuBar();
1910 // set gobject values
1911 var child_0 = new Xcls_search_results( _this );
1913 this.el.add ( child_0.el );
1916 // user defined functions
1918 public class Xcls_search_results : Object
1920 public Gtk.ImageMenuItem el;
1921 private Xcls_WindowRooView _this;
1927 public Xcls_search_results(Xcls_WindowRooView _owner )
1930 _this.search_results = this;
1931 this.el = new Gtk.ImageMenuItem();
1935 // set gobject values
1936 this.el.always_show_image = true;
1937 this.el.visible = false;
1940 this.el.button_press_event.connect( () => {
1942 if (this.popup == null) {
1943 this.popup = new Xcls_ValaCompileErrors();
1944 this.popup.window = _this;
1948 this.popup.show(this.notices, this.el);
1954 // user defined functions
1955 public void updateResults () {
1956 this.el.visible = true;
1958 var res = _this.searchcontext.get_occurrences_count();
1960 _this.search_results.el.label = "??? Matches";
1964 _this.nextBtn.el.sensitive = false;
1965 _this.backBtn.el.sensitive = false;
1968 _this.search_results.el.label = "%d Matches".printf(res);
1969 _this.nextBtn.el.sensitive = true;
1970 _this.backBtn.el.sensitive = true;
1973 _this.search_results.el.label = "No Matches";
1979 public class Xcls_nextBtn : Object
1981 public Gtk.Button el;
1982 private Xcls_WindowRooView _this;
1988 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1991 _this.nextBtn = this;
1992 this.el = new Gtk.Button();
1996 // set gobject values
1997 this.el.always_show_image = true;
1998 this.el.label = "Next";
1999 this.el.sensitive = false;
2000 var child_0 = new Xcls_Image23( _this );
2002 this.el.image = child_0.el;
2005 this.el.button_press_event.connect( (event) => {
2007 _this.forwardSearch(true);
2013 // user defined functions
2015 public class Xcls_Image23 : Object
2017 public Gtk.Image el;
2018 private Xcls_WindowRooView _this;
2024 public Xcls_Image23(Xcls_WindowRooView _owner )
2027 this.el = new Gtk.Image();
2031 // set gobject values
2032 this.el.icon_name = "go-down";
2035 // user defined functions
2039 public class Xcls_backBtn : Object
2041 public Gtk.Button el;
2042 private Xcls_WindowRooView _this;
2048 public Xcls_backBtn(Xcls_WindowRooView _owner )
2051 _this.backBtn = this;
2052 this.el = new Gtk.Button();
2056 // set gobject values
2057 this.el.always_show_image = true;
2058 this.el.label = "Previous";
2059 this.el.sensitive = false;
2060 var child_0 = new Xcls_Image25( _this );
2062 this.el.image = child_0.el;
2065 this.el.button_press_event.connect( (event) => {
2067 _this.backSearch(true);
2073 // user defined functions
2075 public class Xcls_Image25 : Object
2077 public Gtk.Image el;
2078 private Xcls_WindowRooView _this;
2084 public Xcls_Image25(Xcls_WindowRooView _owner )
2087 this.el = new Gtk.Image();
2091 // set gobject values
2092 this.el.icon_name = "go-up";
2095 // user defined functions
2099 public class Xcls_MenuButton26 : Object
2101 public Gtk.MenuButton el;
2102 private Xcls_WindowRooView _this;
2108 public Xcls_MenuButton26(Xcls_WindowRooView _owner )
2111 this.el = new Gtk.MenuButton();
2115 // set gobject values
2116 this.el.always_show_image = true;
2117 this.el.label = "Settings";
2118 var child_0 = new Xcls_Image27( _this );
2120 this.el.image = child_0.el;
2121 var child_1 = new Xcls_search_settings( _this );
2123 this.el.popup = child_1.el;
2126 // user defined functions
2128 public class Xcls_Image27 : Object
2130 public Gtk.Image el;
2131 private Xcls_WindowRooView _this;
2137 public Xcls_Image27(Xcls_WindowRooView _owner )
2140 this.el = new Gtk.Image();
2144 // set gobject values
2145 this.el.icon_name = "emblem-system";
2148 // user defined functions
2151 public class Xcls_search_settings : Object
2154 private Xcls_WindowRooView _this;
2160 public Xcls_search_settings(Xcls_WindowRooView _owner )
2163 _this.search_settings = this;
2164 this.el = new Gtk.Menu();
2168 // set gobject values
2169 var child_0 = new Xcls_case_sensitive( _this );
2171 this.el.append( child_0.el );
2172 var child_1 = new Xcls_regex( _this );
2174 this.el.append( child_1.el );
2175 var child_2 = new Xcls_multiline( _this );
2177 this.el.append( child_2.el );
2180 // user defined functions
2182 public class Xcls_case_sensitive : Object
2184 public Gtk.CheckMenuItem el;
2185 private Xcls_WindowRooView _this;
2191 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2194 _this.case_sensitive = this;
2195 this.el = new Gtk.CheckMenuItem();
2199 // set gobject values
2200 this.el.label = "Case Sensitive";
2209 // user defined functions
2212 public class Xcls_regex : Object
2214 public Gtk.CheckMenuItem el;
2215 private Xcls_WindowRooView _this;
2221 public Xcls_regex(Xcls_WindowRooView _owner )
2225 this.el = new Gtk.CheckMenuItem();
2229 // set gobject values
2230 this.el.label = "Regex";
2239 // user defined functions
2242 public class Xcls_multiline : Object
2244 public Gtk.CheckMenuItem el;
2245 private Xcls_WindowRooView _this;
2251 public Xcls_multiline(Xcls_WindowRooView _owner )
2254 _this.multiline = this;
2255 this.el = new Gtk.CheckMenuItem();
2259 // set gobject values
2260 this.el.label = "Multi-line (add \\n)";
2269 // user defined functions