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);",
202 " if (event.keyval == Gdk.Key.f && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
203 "\t GLib.debug(\"SAVE: ctrl-f pressed\");",
204 "\t\t_this.search_entry.el.grab_focus();",
213 "xtype" : "SourceView",
214 "| string toString" : [
218 " this.el.get_buffer().get_start_iter(out s);",
219 " this.el.get_buffer().get_end_iter(out e);",
220 " var ret = this.el.get_buffer().get_text(s,e,true);",
221 " //print(\"TO STRING? \" + ret);",
226 "| void highlightErrorsJson" : [
227 " (string type, Json.Object obj) {",
228 " Gtk.TextIter start;",
229 " Gtk.TextIter end; ",
231 " var buf = this.el.get_buffer();",
232 " var sbuf = (Gtk.SourceBuffer)buf;",
233 " buf.get_bounds (out start, out end);",
235 " sbuf.remove_source_marks (start, end, type);",
238 " // we should highlight other types of errors..",
240 " if (!obj.has_member(type)) {",
241 " print(\"Return has no errors\\n\");",
244 " var err = obj.get_object_member(type);",
246 " if (_this.file == null) { ",
247 " return; // just in case the file has not loaded yet?",
251 " var valafn = \"\";",
253 " var regex = new Regex(\"\\\\.bjs$\");",
256 " valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
257 " } catch (GLib.RegexError e) {",
261 " if (!err.has_member(valafn)) {",
262 " print(\"File path has no errors\\n\");",
265 " var lines = err.get_object_member(valafn);",
269 " var tlines = buf.get_line_count () +1;",
271 " lines.foreach_member((obj, line, node) => {",
273 " Gtk.TextIter iter;",
274 " // print(\"get inter\\n\");",
275 " var eline = int.parse(line) -1 ;",
276 " print(\"GOT ERROR on line %s -- converted to %d\\n\", line,eline);",
279 " if (eline > tlines || eline < 0) {",
282 " sbuf.get_iter_at_line( out iter, eline);",
283 " //print(\"mark line\\n\");",
284 " var msg = type + \" on line: %d - %s\".printf(eline+1, valafn);",
285 " var ar = lines.get_array_member(line);",
286 " for (var i = 0 ; i < ar.get_length(); i++) {",
287 "\t\t msg += (msg.length > 0) ? \"\\n\" : \"\";",
288 "\t\t msg += ar.get_string_element(i);",
292 " sbuf.create_source_mark(msg, type, iter);",
301 "| void loadFile" : [
303 " this.loading = true;",
304 " var buf = this.el.get_buffer();",
305 " buf.set_text(\"\",0);",
306 " var sbuf = (Gtk.SourceBuffer) buf;",
310 " if (_this.file == null || _this.file.xtype != \"Gtk\") {",
311 " print(\"xtype != Gtk\");",
312 " this.loading = false;",
316 " var valafn = \"\";",
318 " var regex = new Regex(\"\\\\.bjs$\");",
321 " valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
322 " } catch (GLib.RegexError e) {",
323 " this.loading = false;",
328 " if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {",
329 " print(\"File path has no errors\\n\");",
330 " this.loading = false;",
337 " GLib.FileUtils.get_contents (valafn, out str);",
338 " } catch (Error e) {",
339 " this.loading = false;",
343 "// print(\"setting str %d\\n\", str.length);",
344 " buf.set_text(str, str.length);",
345 " var lm = Gtk.SourceLanguageManager.get_default();",
347 " //?? is javascript going to work as js?",
349 " ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));",
352 " Gtk.TextIter start;",
353 " Gtk.TextIter end; ",
355 " sbuf.get_bounds (out start, out end);",
356 " sbuf.remove_source_marks (start, end, null); // remove all marks..",
359 " if (_this.main_window.windowstate.last_compile_result != null) {",
360 " var obj = _this.main_window.windowstate.last_compile_result;",
361 " this.highlightErrorsJson(\"ERR\", obj);",
362 " this.highlightErrorsJson(\"WARN\", obj);",
363 " this.highlightErrorsJson(\"DEPR\", obj);\t\t\t",
365 " //while (Gtk.events_pending()) {",
366 " // Gtk.main_iteration();",
369 " this.loading = false; ",
373 "| void nodeSelected" : [
374 "(JsRender.Node? sel, bool scroll) {",
378 " // this is connected in widnowstate",
379 " print(\"Roo-view - node selected\\n\");",
380 " var buf = this.el.get_buffer();",
382 " var sbuf = (Gtk.SourceBuffer) buf;",
385 " while(Gtk.events_pending()) {",
386 " Gtk.main_iteration();",
390 " // clear all the marks..",
391 " Gtk.TextIter start;",
392 " Gtk.TextIter end; ",
394 " sbuf.get_bounds (out start, out end);",
395 " sbuf.remove_source_marks (start, end, \"grey\");",
397 " this.node_selected = sel;",
398 " if (sel == null) {",
399 " // no highlighting..",
402 " Gtk.TextIter iter; ",
403 " sbuf.get_iter_at_line(out iter, sel.line_start);",
406 " Gtk.TextIter cur_iter;",
407 " sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
409 " //var cur_line = cur_iter.get_line();",
410 " //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
413 " if (this.allow_node_scroll) {",
415 " \tthis.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);",
420 " for (var i = 0; i < buf.get_line_count();i++) {",
421 " if (i < sel.line_start || i > sel.line_end) {",
423 " sbuf.get_iter_at_line(out iter, i);",
424 " sbuf.create_source_mark(null, \"grey\", iter);",
436 "xtype" : "ScrolledWindow"
440 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
441 "bool homogeneous" : false,
442 "bool vexpand" : false,
448 "var description = Pango.FontDescription.from_string(\"monospace\");",
449 "\tdescription.set_size(8000);",
450 "\t this.el.override_font(description);",
454 "bool hexpand" : true,
455 "id" : "search_entry",
456 "int width_request" : 300,
461 "\tif (this.el.text == \"\") {",
462 "\t\t_this.search_results.el.hide();",
466 "\tswitch(_this.windowstate.state) {",
467 "\t\tcase WindowState.State.CODEONLY:",
468 "\t\t///case WindowState.State.CODE:",
469 "\t\t\t// search the code being edited..",
470 "\t\t\tres = _this.windowstate.code_editor_tab.search(this.el.text);",
473 "\t\tcase WindowState.State.PREVIEW:",
474 "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
475 "\t\t\t\t res = _this.windowstate.window_gladeview.search(this.el.text);",
477 "\t\t\t\t res = _this.windowstate.window_rooview.search(this.el.text);\t\t\t",
483 "\t_this.search_results.el.show();",
485 "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
487 "\t\t_this.search_results.el.label = \"No Matches\";",
495 "key_press_event" : [
497 " if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
498 "\t GLib.debug(\"SAVE: ctrl-g pressed\");",
499 "\t\t_this.forwardSearch(true);",
504 " \tif (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {",
505 "\t\tvar res = _this.search(this.el.text);",
506 "\t\t _this.search_results.updateResults();",
508 "\t\tGLib.Timeout.add_seconds(2,() => {",
509 "\t\t\t _this.search_results.updateResults();",
510 "\t\t\t return false;",
517 " // print(event.key.keyval)",
524 "string placeholder_text" : "Press enter to search",
525 "xtype" : "SearchEntry",
526 "| void forwardSearch" : [
527 "(bool change_focus) {",
530 "\t_this.forwardSearch(change_focus);",
534 "\tswitch(_this.windowstate.state) {",
535 "\t\tcase WindowState.State.CODEONLY:",
536 "\t\t//case WindowState.State.CODE:",
537 "\t\t\t// search the code being edited..",
538 "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
541 "\t\tcase WindowState.State.PREVIEW:",
542 "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
543 "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
545 "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
563 "bool always_show_image" : true,
564 "bool visible" : false,
565 "id" : "search_results",
567 "button_press_event" : [
570 " if (this.popup == null) {",
571 " this.popup = new Xcls_ValaCompileErrors();",
572 " this.popup.window = _this;",
576 " this.popup.show(this.notices, this.el);",
582 "xtype" : "ImageMenuItem",
583 "| void updateResults" : [
585 "\tthis.el.visible = true;",
587 "\tvar res = _this.searchcontext.get_occurrences_count();",
589 "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
593 "\t_this.nextBtn.el.sensitive = false;",
594 "\t_this.backBtn.el.sensitive = false;\t",
597 "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
598 "\t\t_this.nextBtn.el.sensitive = true;",
599 "\t\t_this.backBtn.el.sensitive = true;",
602 "\t_this.search_results.el.label = \"No Matches\";",
612 "bool always_show_image" : true,
613 "bool sensitive" : false,
619 "string icon_name" : "go-down",
624 "button_press_event" : [
627 "\t_this.forwardSearch(true);",
634 "string label" : "Next",
639 "bool always_show_image" : true,
640 "bool sensitive" : false,
646 "string icon_name" : "go-up",
651 "button_press_event" : [
654 "\t_this.backSearch(true);",
661 "string label" : "Previous",
666 "bool always_show_image" : true,
671 "string icon_name" : "emblem-system",
677 "id" : "search_settings",
687 "id" : "case_sensitive",
688 "string label" : "Case Sensitive",
689 "xtype" : "CheckMenuItem"
700 "string label" : "Regex",
701 "xtype" : "CheckMenuItem"
712 "string label" : "Multi-line (add \\n)",
713 "xtype" : "CheckMenuItem"
719 "string label" : "Settings",
720 "xtype" : "MenuButton"
736 " this.width = aloc.width;",
737 " this.height =aloc.height;",
745 "\tthis.notebook.el.page = 1;",
749 "\tvar s = new Gtk.SourceSearchSettings();",
750 "\ts.case_sensitive = _this.case_sensitive.el.active;",
751 "\ts.regex_enabled = _this.regex.el.active;\t",
752 "\ts.wrap_around = false;",
754 "\tthis.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);",
755 "\tthis.searchcontext.set_highlight(true);",
756 "\tvar txt = in_txt;",
758 "\tif (_this.multiline.el.active) {",
759 "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
762 "\ts.set_search_text(txt);",
763 "\tGtk.TextIter beg, st,en;",
765 "\tthis.buffer.el.get_start_iter(out beg);",
766 "\tthis.searchcontext.forward(beg, out st, out en);",
767 "\tthis.last_search_end = 0;",
769 "\treturn this.searchcontext.get_occurrences_count();",
777 "| void backSearch" : [
778 "(bool change_focus) {",
780 "\tif (this.searchcontext == null) {",
784 "\tGtk.TextIter beg, st,en;",
785 "\tbool has_wrapped_around;",
786 "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
788 "\tif (!this.searchcontext.backward2(beg, out st, out en, out has_wrapped_around)) {",
790 "\t\tthis.last_search_end = 0;",
793 "\tthis.last_search_end = en.get_offset();",
794 "\tif (change_focus) {",
795 "\t\tthis.sourceview.el.grab_focus();",
797 "\tthis.buffer.el.place_cursor(st);",
798 "\tthis.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);",
799 "\tvar ln = st.get_line();",
800 "\tthis.highlightNodeAtLine(ln);",
806 "| void createThumb" : [
810 " if (this.file == null) {",
813 " // only screenshot the gtk preview..",
814 " if (this.notebook.el.page > 0 ) {",
820 " var win = this.el.get_parent_window();",
821 " var width = win.get_width();",
822 " var height = win.get_height();",
824 " Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?",
825 " this.file.writeIcon(screenshot);",
826 " } catch (Error e) {",
837 " // should we hold until it's printed...",
850 "| void forwardSearch" : [
851 "(bool change_focus) {",
853 "\tif (this.searchcontext == null) {",
856 "\tthis.notebook.el.page = 1;",
857 "\tGtk.TextIter beg, st,en, stl;",
859 "\tvar buf = this.sourceview.el.get_buffer();",
860 "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
861 "\tif (!this.searchcontext.forward(beg, out st, out en)) {",
862 "\t\tthis.last_search_end = 0;",
865 "\tthis.last_search_end = en.get_offset();",
866 "\tif (change_focus) {",
867 "\t\tthis.sourceview.el.grab_focus();",
869 "\tbuf.place_cursor(st);",
873 "\tthis.sourceview.el.scroll_to_iter(st, 0.0f, true, 0.0f, 0.5f);",
876 "\tvar ln = st.get_line();",
878 "\tthis.highlightNodeAtLine(ln);",
882 "| void highlightNodeAtLine" : [
887 "\t// highlight node...",
890 " var node = _this.file.lineToNode(ln+1);",
892 " if (node == null) {",
893 " //print(\"can not find node\\n\");",
896 " var prop = node.lineToProp(ln+1);",
897 " print(\"prop : %s\", prop == null ? \"???\" : prop);",
900 " // ---------- this selects the tree's node...",
902 " var ltree = _this.main_window.windowstate.left_tree;",
903 " var tp = ltree.model.treePathFromNode(node);",
904 " print(\"got tree path %s\\n\", tp);",
905 " if (tp == \"\") {",
908 " //_this.sourceview.allow_node_scroll = false; /// block node scrolling..",
911 " //print(\"changing cursor on tree..\\n\");",
915 " // let's try allowing editing on the methods.",
916 " // a little klunky at present..",
917 "\t_this.sourceview.prop_selected = \"\";",
918 " if (prop != null) {",
919 "\t\t//see if we can find it..",
920 "\t\tvar kv = prop.split(\":\");",
921 "\t\tif (kv[0] == \"p\") {",
923 " \t\t//var k = prop.get_key(kv[1]);",
924 " \t\t// fixme -- need to determine if it's an editable property...",
925 " \t\t_this.sourceview.prop_selected = prop;",
927 "\t\t} else if (kv[0] == \"l\") {",
928 "\t\t\t _this.sourceview.prop_selected = prop;",
932 " ltree.view.setCursor(tp, \"editor\");",
933 " // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
934 " _this.sourceview.nodeSelected(node,false);",
936 " // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
937 " // GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
938 "\t // this.allow_node_scroll = true;",
939 "\t // return false;",
956 "| void loadFile" : [
957 "(JsRender.JsRender file) ",
959 " this.file = null;",
961 " if (file.tree == null) {",
964 " this.notebook.el.page = 0;// gtk preview ",
968 " this.file = file; ",
969 " this.sourceview.loadFile();",
970 " this.searchcontext = null;",
973 " if (this.lastObj != null) {",
974 " this.container.el.remove(this.lastObj);",
977 " // hide the compile view at present..",
980 " var w = this.width;",
981 " var h = this.height;",
983 " print(\"ALLOC SET SIZES %d, %d\\n\", w,h); ",
985 " // set the container size min to 500/500 or 20 px less than max..",
986 " w = int.max (w-20, 500);",
987 " h = int.max (h-20, 500); ",
989 " print(\"SET SIZES %d, %d\\n\", w,h); ",
990 " _this.container.el.set_size_request(w,h);",
992 " _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.",
993 " var rgba = Gdk.RGBA ();",
994 " rgba.parse (\"#ccc\");",
995 " _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);",
998 "\tvar x = new JsRender.NodeToGtk((Project.Gtk) file.project, file.tree);",
999 " var obj = x.munge() as Gtk.Widget;",
1000 " this.lastObj = null;",
1001 "\tif (obj == null) {",
1004 "\tthis.lastObj = obj;",
1006 " this.container.el.add(obj);",
1014 "| void scroll_to_line" : [
1016 " // code preview...",
1018 " GLib.Timeout.add(100, () => {",
1021 "\t this.notebook.el.set_current_page(1);",
1023 "\t\t var buf = this.sourceview.el.get_buffer();",
1025 "\t\tvar sbuf = (Gtk.SourceBuffer) buf;",
1028 "\t\tGtk.TextIter iter; ",
1029 "\t\tsbuf.get_iter_at_line(out iter, line);",
1030 "\t\tthis.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);",
1031 "\t\treturn false;",
1043 "path" : "/home/alan/gitlive/roobuilder/src/Builder4/GtkView.bjs",