2 "build_module" : "builder",
5 "# Gtk.Widget lastObj" : "null",
6 "# JsRender.JsRender file" : "null",
7 "# Xcls_MainWindow main_window" : "",
9 "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
10 "Gtk.SourceSearchContext searchcontext" : "",
11 "bool hexpand" : true,
12 "bool vexpand" : true,
15 "int last_search_end" : 0,
20 "* pack" : "pack_start,true,true,0",
26 "id" : "label_preview",
27 "utf8 label" : "Preview",
34 "utf8 label" : "Preview Generated Code",
39 "* pack" : "append_page,_this.label_preview.el",
48 "* pack" : "put,10,10",
49 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
57 "xtype" : "ScrolledWindow"
61 "* pack" : "append_page,_this.label_code.el",
62 "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
67 "bool vexpand" : true,
70 "# JsRender.Node? node_selected" : "",
71 "# string prop_selected" : "\"\"",
76 " var description = Pango.FontDescription.from_string(\"monospace\");",
77 " description.set_size(8000);",
78 " this.el.override_font(description);",
80 " this.loading = true;",
81 " var buf = this.el.get_buffer();",
82 " buf.notify.connect((ps) => {",
83 " if (this.loading) {",
86 " if (ps.name != \"cursor-position\") {",
89 " print(\"cursor changed : %d\\n\", buf.cursor_position);",
90 " Gtk.TextIter cpos;",
91 " buf.get_iter_at_offset(out cpos, buf.cursor_position);",
93 " var ln = cpos.get_line();",
95 " var node = _this.file.lineToNode(ln);",
97 " if (node == null) {",
98 " print(\"can not find node\\n\");",
101 " var ltree = _this.main_window.windowstate.left_tree;",
102 " var tp = ltree.model.treePathFromNode(node);",
103 " print(\"got tree path %s\\n\", tp);",
104 " if (tp != \"\") {",
105 "\t this.allow_node_scroll = false; ",
106 "\t print(\"changing cursor on tree..\\n\");",
107 " ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);",
108 " // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
109 " GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
110 "\t this.allow_node_scroll = true;",
115 " // highlight the node..",
121 " var attrs = new Gtk.SourceMarkAttributes();",
122 " var pink = Gdk.RGBA();",
123 " pink.parse ( \"pink\");",
124 " attrs.set_background ( pink);",
125 " attrs.set_icon_name ( \"process-stop\"); ",
126 " attrs.query_tooltip_text.connect(( mark) => {",
127 " //print(\"tooltip query? %s\\n\", mark.name);",
128 " return mark.name;",
131 " this.el.set_mark_attributes (\"ERR\", attrs, 1);",
133 " var wattrs = new Gtk.SourceMarkAttributes();",
134 " var blue = Gdk.RGBA();",
135 " blue.parse ( \"#ABF4EB\");",
136 " wattrs.set_background ( blue);",
137 " wattrs.set_icon_name ( \"process-stop\"); ",
138 " wattrs.query_tooltip_text.connect(( mark) => {",
139 " //print(\"tooltip query? %s\\n\", mark.name);",
140 " return mark.name;",
143 " this.el.set_mark_attributes (\"WARN\", wattrs, 1);",
147 " var dattrs = new Gtk.SourceMarkAttributes();",
148 " var purple = Gdk.RGBA();",
149 " purple.parse ( \"#EEA9FF\");",
150 " dattrs.set_background ( purple);",
151 " dattrs.set_icon_name ( \"process-stop\"); ",
152 " dattrs.query_tooltip_text.connect(( mark) => {",
153 " //print(\"tooltip query? %s\\n\", mark.name);",
154 " return mark.name;",
157 " this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
160 " var gattrs = new Gtk.SourceMarkAttributes();",
161 " var grey = Gdk.RGBA();",
162 " grey.parse ( \"#ccc\");",
163 " gattrs.set_background ( grey);",
166 " this.el.set_mark_attributes (\"grey\", gattrs, 1);",
177 "bool allow_node_scroll" : true,
178 "bool loading" : true,
179 "gboolean editable" : false,
180 "gboolean show_line_marks" : true,
181 "gboolean show_line_numbers" : true,
186 "* pack" : "set_buffer",
187 "bool dirty" : false,
189 "int error_line" : "-1",
190 "xtype" : "SourceBuffer"
194 "key_press_event" : [
197 "\t if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
198 "\t GLib.debug(\"SAVE: ctrl-g pressed\");",
199 "\t\t_this.forwardSearch(true);",
209 "xtype" : "SourceView",
210 "| string toString" : [
214 " this.el.get_buffer().get_start_iter(out s);",
215 " this.el.get_buffer().get_end_iter(out e);",
216 " var ret = this.el.get_buffer().get_text(s,e,true);",
217 " //print(\"TO STRING? \" + ret);",
222 "| void highlightErrorsJson" : [
223 " (string type, Json.Object obj) {",
224 " Gtk.TextIter start;",
225 " Gtk.TextIter end; ",
227 " var buf = this.el.get_buffer();",
228 " var sbuf = (Gtk.SourceBuffer)buf;",
229 " buf.get_bounds (out start, out end);",
231 " sbuf.remove_source_marks (start, end, type);",
234 " // we should highlight other types of errors..",
236 " if (!obj.has_member(type)) {",
237 " print(\"Return has no errors\\n\");",
240 " var err = obj.get_object_member(type);",
242 " if (_this.file == null) { ",
243 " return; // just in case the file has not loaded yet?",
247 " var valafn = \"\";",
249 " var regex = new Regex(\"\\\\.bjs$\");",
252 " valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
253 " } catch (GLib.RegexError e) {",
257 " if (!err.has_member(valafn)) {",
258 " print(\"File path has no errors\\n\");",
261 " var lines = err.get_object_member(valafn);",
265 " var tlines = buf.get_line_count () +1;",
267 " lines.foreach_member((obj, line, node) => {",
269 " Gtk.TextIter iter;",
270 " // print(\"get inter\\n\");",
271 " var eline = int.parse(line) -1 ;",
272 " print(\"GOT ERROR on line %s -- converted to %d\\n\", line,eline);",
275 " if (eline > tlines || eline < 0) {",
278 " sbuf.get_iter_at_line( out iter, eline);",
279 " //print(\"mark line\\n\");",
280 " var msg = type + \" on line: %d - %s\".printf(eline+1, valafn);",
281 " var ar = lines.get_array_member(line);",
282 " for (var i = 0 ; i < ar.get_length(); i++) {",
283 "\t\t msg += (msg.length > 0) ? \"\\n\" : \"\";",
284 "\t\t msg += ar.get_string_element(i);",
288 " sbuf.create_source_mark(msg, type, iter);",
297 "| void loadFile" : [
299 " this.loading = true;",
300 " var buf = this.el.get_buffer();",
301 " buf.set_text(\"\",0);",
302 " var sbuf = (Gtk.SourceBuffer) buf;",
306 " if (_this.file == null || _this.file.xtype != \"Gtk\") {",
307 " print(\"xtype != Gtk\");",
308 " this.loading = false;",
312 " var valafn = \"\";",
314 " var regex = new Regex(\"\\\\.bjs$\");",
317 " valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
318 " } catch (GLib.RegexError e) {",
319 " this.loading = false;",
324 " if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {",
325 " print(\"File path has no errors\\n\");",
326 " this.loading = false;",
333 " GLib.FileUtils.get_contents (valafn, out str);",
334 " } catch (Error e) {",
335 " this.loading = false;",
339 "// print(\"setting str %d\\n\", str.length);",
340 " buf.set_text(str, str.length);",
341 " var lm = Gtk.SourceLanguageManager.get_default();",
343 " //?? is javascript going to work as js?",
345 " ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));",
348 " Gtk.TextIter start;",
349 " Gtk.TextIter end; ",
351 " sbuf.get_bounds (out start, out end);",
352 " sbuf.remove_source_marks (start, end, null); // remove all marks..",
355 " if (_this.main_window.windowstate.last_compile_result != null) {",
356 " var obj = _this.main_window.windowstate.last_compile_result;",
357 " this.highlightErrorsJson(\"ERR\", obj);",
358 " this.highlightErrorsJson(\"WARN\", obj);",
359 " this.highlightErrorsJson(\"DEPR\", obj);\t\t\t",
361 " //while (Gtk.events_pending()) {",
362 " // Gtk.main_iteration();",
365 " this.loading = false; ",
369 "| void nodeSelected" : [
370 "(JsRender.Node? sel, bool scroll) {",
374 " // this is connected in widnowstate",
375 " print(\"Roo-view - node selected\\n\");",
376 " var buf = this.el.get_buffer();",
378 " var sbuf = (Gtk.SourceBuffer) buf;",
381 " while(Gtk.events_pending()) {",
382 " Gtk.main_iteration();",
386 " // clear all the marks..",
387 " Gtk.TextIter start;",
388 " Gtk.TextIter end; ",
390 " sbuf.get_bounds (out start, out end);",
391 " sbuf.remove_source_marks (start, end, \"grey\");",
393 " this.node_selected = sel;",
394 " if (sel == null) {",
395 " // no highlighting..",
398 " Gtk.TextIter iter; ",
399 " sbuf.get_iter_at_line(out iter, sel.line_start);",
402 " Gtk.TextIter cur_iter;",
403 " sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
405 " //var cur_line = cur_iter.get_line();",
406 " //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
409 " if (this.allow_node_scroll) {",
411 " \tthis.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);",
416 " for (var i = 0; i < buf.get_line_count();i++) {",
417 " if (i < sel.line_start || i > sel.line_end) {",
419 " sbuf.get_iter_at_line(out iter, i);",
420 " sbuf.create_source_mark(null, \"grey\", iter);",
432 "xtype" : "ScrolledWindow"
436 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
437 "bool homogeneous" : false,
438 "bool vexpand" : false,
444 "var description = Pango.FontDescription.from_string(\"monospace\");",
445 "\tdescription.set_size(8000);",
446 "\t this.el.override_font(description);",
450 "bool hexpand" : true,
451 "id" : "search_entry",
452 "int width_request" : 300,
457 "\tif (this.el.text == \"\") {",
458 "\t\t_this.search_results.el.hide();",
462 "\tswitch(_this.windowstate.state) {",
463 "\t\tcase WindowState.State.CODEONLY:",
464 "\t\t///case WindowState.State.CODE:",
465 "\t\t\t// search the code being edited..",
466 "\t\t\tres = _this.windowstate.code_editor_tab.search(this.el.text);",
469 "\t\tcase WindowState.State.PREVIEW:",
470 "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
471 "\t\t\t\t res = _this.windowstate.window_gladeview.search(this.el.text);",
473 "\t\t\t\t res = _this.windowstate.window_rooview.search(this.el.text);\t\t\t",
479 "\t_this.search_results.el.show();",
481 "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
483 "\t\t_this.search_results.el.label = \"No Matches\";",
491 "key_press_event" : [
493 " if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
494 "\t GLib.debug(\"SAVE: ctrl-g pressed\");",
495 "\t\t_this.forwardSearch(true);",
500 " \tif (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {",
501 "\t\tvar res = _this.search(this.el.text);",
502 "\t\t _this.search_results.updateResults();",
504 "\t\tGLib.Timeout.add_seconds(2,() => {",
505 "\t\t\t _this.search_results.updateResults();",
506 "\t\t\t return false;",
513 " // print(event.key.keyval)",
520 "string placeholder_text" : "Press enter to search",
521 "xtype" : "SearchEntry",
522 "| void forwardSearch" : [
523 "(bool change_focus) {",
526 "\t_this.forwardSearch(change_focus);",
530 "\tswitch(_this.windowstate.state) {",
531 "\t\tcase WindowState.State.CODEONLY:",
532 "\t\t//case WindowState.State.CODE:",
533 "\t\t\t// search the code being edited..",
534 "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
537 "\t\tcase WindowState.State.PREVIEW:",
538 "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
539 "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
541 "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
559 "bool always_show_image" : true,
560 "bool visible" : false,
561 "id" : "search_results",
563 "button_press_event" : [
566 " if (this.popup == null) {",
567 " this.popup = new Xcls_ValaCompileErrors();",
568 " this.popup.window = _this;",
572 " this.popup.show(this.notices, this.el);",
578 "xtype" : "ImageMenuItem",
579 "| void updateResults" : [
581 "\tthis.el.visible = true;",
583 "\tvar res = _this.searchcontext.get_occurrences_count();",
585 "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
589 "\t_this.nextBtn.el.sensitive = false;",
590 "\t_this.backBtn.el.sensitive = false;\t",
593 "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
594 "\t\t_this.nextBtn.el.sensitive = true;",
595 "\t\t_this.backBtn.el.sensitive = true;",
598 "\t_this.search_results.el.label = \"No Matches\";",
608 "bool always_show_image" : true,
609 "bool sensitive" : false,
615 "string icon_name" : "go-down",
620 "button_press_event" : [
623 "\t_this.forwardSearch(true);",
630 "string label" : "Next",
635 "bool always_show_image" : true,
636 "bool sensitive" : false,
642 "string icon_name" : "go-up",
647 "button_press_event" : [
650 "\t_this.backSearch(true);",
657 "string label" : "Previous",
662 "bool always_show_image" : true,
667 "string icon_name" : "emblem-system",
673 "id" : "search_settings",
683 "id" : "case_sensitive",
684 "string label" : "Case Sensitive",
685 "xtype" : "CheckMenuItem"
696 "string label" : "Regex",
697 "xtype" : "CheckMenuItem"
708 "string label" : "Multi-line (add \\n)",
709 "xtype" : "CheckMenuItem"
715 "string label" : "Settings",
716 "xtype" : "MenuButton"
732 " this.width = aloc.width;",
733 " this.height =aloc.height;",
741 "\tthis.notebook.el.page = 1;",
745 "\tvar s = new Gtk.SourceSearchSettings();",
746 "\ts.case_sensitive = _this.case_sensitive.el.active;",
747 "\ts.regex_enabled = _this.regex.el.active;\t",
748 "\ts.wrap_around = false;",
750 "\tthis.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);",
751 "\tthis.searchcontext.set_highlight(true);",
752 "\tvar txt = in_txt;",
754 "\tif (_this.multiline.el.active) {",
755 "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
758 "\ts.set_search_text(txt);",
759 "\tGtk.TextIter beg, st,en;",
761 "\tthis.buffer.el.get_start_iter(out beg);",
762 "\tthis.searchcontext.forward(beg, out st, out en);",
763 "\tthis.last_search_end = 0;",
765 "\treturn this.searchcontext.get_occurrences_count();",
773 "| void backSearch" : [
774 "(bool change_focus) {",
776 "\tif (this.searchcontext == null) {",
780 "\tGtk.TextIter beg, st,en;",
781 "\tbool has_wrapped_around;",
782 "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
784 "\tif (!this.searchcontext.backward2(beg, out st, out en, out has_wrapped_around)) {",
786 "\t\tthis.last_search_end = 0;",
789 "\tthis.last_search_end = en.get_offset();",
790 "\tif (change_focus) {",
791 "\t\tthis.sourceview.el.grab_focus();",
793 "\tthis.buffer.el.place_cursor(st);",
794 "\tthis.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);",
795 "\tvar ln = st.get_line();",
796 "\tthis.highlightNodeAtLine(ln);",
802 "| void createThumb" : [
806 " if (this.file == null) {",
809 " // only screenshot the gtk preview..",
810 " if (this.notebook.el.page > 0 ) {",
815 " var filename = this.file.getIconFileName(false);",
817 " var win = this.el.get_parent_window();",
818 " var width = win.get_width();",
819 " var height = win.get_height();",
821 " Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?",
822 " screenshot.save(filename,\"png\");",
823 " } catch (Error e) {",
834 " // should we hold until it's printed...",
847 "| void forwardSearch" : [
848 "(bool change_focus) {",
850 "\tif (this.searchcontext == null) {",
853 "\tthis.notebook.el.page = 1;",
854 "\tGtk.TextIter beg, st,en, stl;",
856 "\tvar buf = this.sourceview.el.get_buffer();",
857 "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
858 "\tif (!this.searchcontext.forward(beg, out st, out en)) {",
859 "\t\tthis.last_search_end = 0;",
862 "\tthis.last_search_end = en.get_offset();",
863 "\tif (change_focus) {",
864 "\t\tthis.sourceview.el.grab_focus();",
866 "\tbuf.place_cursor(st);",
870 "\tthis.sourceview.el.scroll_to_iter(st, 0.0f, true, 0.0f, 0.5f);",
873 "\tvar ln = st.get_line();",
875 "\tthis.highlightNodeAtLine(ln);",
879 "| void highlightNodeAtLine" : [
884 "\t// highlight node...",
887 " var node = _this.file.lineToNode(ln+1);",
889 " if (node == null) {",
890 " //print(\"can not find node\\n\");",
893 " var prop = node.lineToProp(ln+1);",
894 " print(\"prop : %s\", prop == null ? \"???\" : prop);",
897 " // ---------- this selects the tree's node...",
899 " var ltree = _this.main_window.windowstate.left_tree;",
900 " var tp = ltree.model.treePathFromNode(node);",
901 " print(\"got tree path %s\\n\", tp);",
902 " if (tp == \"\") {",
905 " //_this.sourceview.allow_node_scroll = false; /// block node scrolling..",
908 " //print(\"changing cursor on tree..\\n\");",
912 " // let's try allowing editing on the methods.",
913 " // a little klunky at present..",
914 "\t_this.sourceview.prop_selected = \"\";",
915 " if (prop != null) {",
916 "\t\t//see if we can find it..",
917 "\t\tvar kv = prop.split(\":\");",
918 "\t\tif (kv[0] == \"p\") {",
920 " \t\t//var k = prop.get_key(kv[1]);",
921 " \t\t// fixme -- need to determine if it's an editable property...",
922 " \t\t_this.sourceview.prop_selected = prop;",
924 "\t\t} else if (kv[0] == \"l\") {",
925 "\t\t\t _this.sourceview.prop_selected = prop;",
929 " ltree.view.setCursor(tp, \"editor\");",
930 " // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
931 " _this.sourceview.nodeSelected(node,false);",
933 " // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
934 " // GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
935 "\t // this.allow_node_scroll = true;",
936 "\t // return false;",
953 "| void loadFile" : [
954 "(JsRender.JsRender file) ",
956 " this.file = null;",
958 " if (file.tree == null) {",
961 " this.notebook.el.page = 0;// gtk preview ",
965 " this.file = file; ",
966 " this.sourceview.loadFile();",
967 " this.searchcontext = null;",
970 " if (this.lastObj != null) {",
971 " this.container.el.remove(this.lastObj);",
974 " // hide the compile view at present..",
977 " var w = this.width;",
978 " var h = this.height;",
980 " print(\"ALLOC SET SIZES %d, %d\\n\", w,h); ",
982 " // set the container size min to 500/500 or 20 px less than max..",
983 " w = int.max (w-20, 500);",
984 " h = int.max (h-20, 500); ",
986 " print(\"SET SIZES %d, %d\\n\", w,h); ",
987 " _this.container.el.set_size_request(w,h);",
989 " _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.",
990 " var rgba = Gdk.RGBA ();",
991 " rgba.parse (\"#ccc\");",
992 " _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);",
995 "\tvar x = new JsRender.NodeToGtk((Project.Gtk) file.project, file.tree);",
996 " var obj = x.munge() as Gtk.Widget;",
997 " this.lastObj = null;",
998 "\tif (obj == null) {",
1001 "\tthis.lastObj = obj;",
1003 " this.container.el.add(obj);",
1011 "| void scroll_to_line" : [
1013 " this.notebook.el.page = 1;// code preview...",
1015 " GLib.Timeout.add(500, () => {",
1020 "\t\t var buf = this.sourceview.el.get_buffer();",
1022 "\t\tvar sbuf = (Gtk.SourceBuffer) buf;",
1025 "\t\tGtk.TextIter iter; ",
1026 "\t\tsbuf.get_iter_at_line(out iter, line);",
1027 "\t\tthis.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);",
1028 "\t\treturn false;",
1040 "path" : "/home/alan/gitlive/roobuilder/src/Builder4/GtkView.bjs",