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",
68 " var description = Pango.FontDescription.from_string(\"monospace\");",
69 " description.set_size(8000);",
70 " this.el.override_font(description);",
72 " this.loading = true;",
73 " var buf = this.el.get_buffer();",
74 " buf.notify.connect((ps) => {",
75 " if (this.loading) {",
78 " if (ps.name != \"cursor-position\") {",
81 " print(\"cursor changed : %d\\n\", buf.cursor_position);",
82 " Gtk.TextIter cpos;",
83 " buf.get_iter_at_offset(out cpos, buf.cursor_position);",
85 " var ln = cpos.get_line();",
87 " var node = _this.file.lineToNode(ln);",
89 " if (node == null) {",
90 " print(\"can not find node\\n\");",
93 " var ltree = _this.main_window.windowstate.left_tree;",
94 " var tp = ltree.model.treePathFromNode(node);",
95 " print(\"got tree path %s\\n\", tp);",
97 "\t this.allow_node_scroll = false; ",
98 "\t print(\"changing cursor on tree..\\n\");",
99 " ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);",
100 " // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
101 " GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
102 "\t this.allow_node_scroll = true;",
107 " // highlight the node..",
113 " var attrs = new Gtk.SourceMarkAttributes();",
114 " var pink = Gdk.RGBA();",
115 " pink.parse ( \"pink\");",
116 " attrs.set_background ( pink);",
117 " attrs.set_icon_name ( \"process-stop\"); ",
118 " attrs.query_tooltip_text.connect(( mark) => {",
119 " //print(\"tooltip query? %s\\n\", mark.name);",
120 " return mark.name;",
123 " this.el.set_mark_attributes (\"ERR\", attrs, 1);",
125 " var wattrs = new Gtk.SourceMarkAttributes();",
126 " var blue = Gdk.RGBA();",
127 " blue.parse ( \"#ABF4EB\");",
128 " wattrs.set_background ( blue);",
129 " wattrs.set_icon_name ( \"process-stop\"); ",
130 " wattrs.query_tooltip_text.connect(( mark) => {",
131 " //print(\"tooltip query? %s\\n\", mark.name);",
132 " return mark.name;",
135 " this.el.set_mark_attributes (\"WARN\", wattrs, 1);",
139 " var dattrs = new Gtk.SourceMarkAttributes();",
140 " var purple = Gdk.RGBA();",
141 " purple.parse ( \"#EEA9FF\");",
142 " dattrs.set_background ( purple);",
143 " dattrs.set_icon_name ( \"process-stop\"); ",
144 " dattrs.query_tooltip_text.connect(( mark) => {",
145 " //print(\"tooltip query? %s\\n\", mark.name);",
146 " return mark.name;",
149 " this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
152 " var gattrs = new Gtk.SourceMarkAttributes();",
153 " var grey = Gdk.RGBA();",
154 " grey.parse ( \"#ccc\");",
155 " gattrs.set_background ( grey);",
158 " this.el.set_mark_attributes (\"grey\", gattrs, 1);",
169 "bool allow_node_scroll" : true,
170 "bool loading" : true,
171 "gboolean editable" : false,
172 "gboolean show_line_marks" : true,
173 "gboolean show_line_numbers" : true,
175 "xtype" : "SourceView",
176 "| string toString" : [
180 " this.el.get_buffer().get_start_iter(out s);",
181 " this.el.get_buffer().get_end_iter(out e);",
182 " var ret = this.el.get_buffer().get_text(s,e,true);",
183 " //print(\"TO STRING? \" + ret);",
188 "| void highlightErrorsJson" : [
189 " (string type, Json.Object obj) {",
190 " Gtk.TextIter start;",
191 " Gtk.TextIter end; ",
193 " var buf = this.el.get_buffer();",
194 " var sbuf = (Gtk.SourceBuffer)buf;",
195 " buf.get_bounds (out start, out end);",
197 " sbuf.remove_source_marks (start, end, type);",
200 " // we should highlight other types of errors..",
202 " if (!obj.has_member(type)) {",
203 " print(\"Return has no errors\\n\");",
206 " var err = obj.get_object_member(type);",
208 " if (_this.file == null) { ",
209 " return; // just in case the file has not loaded yet?",
213 " var valafn = \"\";",
215 " var regex = new Regex(\"\\\\.bjs$\");",
218 " valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
219 " } catch (GLib.RegexError e) {",
223 " if (!err.has_member(valafn)) {",
224 " print(\"File path has no errors\\n\");",
227 " var lines = err.get_object_member(valafn);",
231 " var tlines = buf.get_line_count () +1;",
233 " lines.foreach_member((obj, line, node) => {",
235 " Gtk.TextIter iter;",
236 " // print(\"get inter\\n\");",
237 " var eline = int.parse(line) -1 ;",
238 " print(\"GOT ERROR on line %s -- converted to %d\\n\", line,eline);",
241 " if (eline > tlines || eline < 0) {",
244 " sbuf.get_iter_at_line( out iter, eline);",
245 " //print(\"mark line\\n\");",
246 " var msg = type + \" on line: %d - %s\".printf(eline+1, valafn);",
247 " var ar = lines.get_array_member(line);",
248 " for (var i = 0 ; i < ar.get_length(); i++) {",
249 "\t\t msg += (msg.length > 0) ? \"\\n\" : \"\";",
250 "\t\t msg += ar.get_string_element(i);",
254 " sbuf.create_source_mark(msg, type, iter);",
263 "| void loadFile" : [
265 " this.loading = true;",
266 " var buf = this.el.get_buffer();",
267 " buf.set_text(\"\",0);",
268 " var sbuf = (Gtk.SourceBuffer) buf;",
272 " if (_this.file == null || _this.file.xtype != \"Gtk\") {",
273 " print(\"xtype != Gtk\");",
274 " this.loading = false;",
278 " var valafn = \"\";",
280 " var regex = new Regex(\"\\\\.bjs$\");",
283 " valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
284 " } catch (GLib.RegexError e) {",
285 " this.loading = false;",
290 " if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {",
291 " print(\"File path has no errors\\n\");",
292 " this.loading = false;",
299 " GLib.FileUtils.get_contents (valafn, out str);",
300 " } catch (Error e) {",
301 " this.loading = false;",
305 "// print(\"setting str %d\\n\", str.length);",
306 " buf.set_text(str, str.length);",
307 " var lm = Gtk.SourceLanguageManager.get_default();",
309 " //?? is javascript going to work as js?",
311 " ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));",
314 " Gtk.TextIter start;",
315 " Gtk.TextIter end; ",
317 " sbuf.get_bounds (out start, out end);",
318 " sbuf.remove_source_marks (start, end, null); // remove all marks..",
321 " if (_this.main_window.windowstate.last_compile_result != null) {",
322 " var obj = _this.main_window.windowstate.last_compile_result;",
323 " this.highlightErrorsJson(\"ERR\", obj);",
324 " this.highlightErrorsJson(\"WARN\", obj);",
325 " this.highlightErrorsJson(\"DEPR\", obj);\t\t\t",
327 " //while (Gtk.events_pending()) {",
328 " // Gtk.main_iteration();",
331 " this.loading = false; ",
335 "| void nodeSelected" : [
336 "(JsRender.Node? sel) {",
340 " // this is connected in widnowstate",
341 " print(\"Roo-view - node selected\\n\");",
342 " var buf = this.el.get_buffer();",
344 " var sbuf = (Gtk.SourceBuffer) buf;",
347 " while(Gtk.events_pending()) {",
348 " Gtk.main_iteration();",
352 " // clear all the marks..",
353 " Gtk.TextIter start;",
354 " Gtk.TextIter end; ",
356 " sbuf.get_bounds (out start, out end);",
357 " sbuf.remove_source_marks (start, end, \"grey\");",
360 " if (sel == null) {",
361 " // no highlighting..",
364 " Gtk.TextIter iter; ",
365 " sbuf.get_iter_at_line(out iter, sel.line_start);",
368 " Gtk.TextIter cur_iter;",
369 " sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
371 " //var cur_line = cur_iter.get_line();",
372 " //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
375 " if (this.allow_node_scroll) {",
377 " \tthis.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);",
382 " for (var i = 0; i < buf.get_line_count();i++) {",
383 " if (i < sel.line_start || i > sel.line_end) {",
385 " sbuf.get_iter_at_line(out iter, i);",
386 " sbuf.create_source_mark(null, \"grey\", iter);",
398 "xtype" : "ScrolledWindow"
408 " this.width = aloc.width;",
409 " this.height =aloc.height;",
417 "\tthis.notebook.el.page = 1;",
418 " \tvar s = new Gtk.SourceSearchSettings();",
419 "\tvar buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();",
420 "\tthis.searchcontext = new Gtk.SourceSearchContext(buf,s);",
421 "\tthis.searchcontext.set_highlight(true);",
422 "\ts.set_search_text(txt);",
424 "\tGtk.TextIter beg, st,en;",
426 "\tbuf.get_start_iter(out beg);",
427 "\tthis.searchcontext.forward(beg, out st, out en);",
428 "\tthis.last_search_end = 0;",
429 "\treturn this.searchcontext.get_occurrences_count();",
435 "| void createThumb" : [
439 " if (this.file == null) {",
442 " // only screenshot the gtk preview..",
443 " if (this.notebook.el.page > 0 ) {",
448 " var filename = this.file.getIconFileName(false);",
450 " var win = this.el.get_parent_window();",
451 " var width = win.get_width();",
452 " var height = win.get_height();",
454 " Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?",
455 " screenshot.save(filename,\"png\");",
456 " } catch (Error e) {",
467 " // should we hold until it's printed...",
480 "| void forwardSearch" : [
481 "(bool change_focus) {",
483 "\tif (this.searchcontext == null) {",
486 "\tthis.notebook.el.page = 1;",
487 "\tGtk.TextIter beg, st,en, stl;",
489 "\tvar buf = this.sourceview.el.get_buffer();",
490 "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
491 "\tif (!this.searchcontext.forward(beg, out st, out en)) {",
492 "\t\tthis.last_search_end = 0;",
494 "\t\tthis.last_search_end = en.get_offset();",
495 "\t\tif (change_focus) {",
496 "\t\t\tthis.sourceview.el.grab_focus();\t",
498 "\t\tbuf.place_cursor(st);",
499 "\t\tvar ln = st.get_line();",
500 "\t\tbuf.get_iter_at_line(out stl,ln);",
502 "\t\tthis.sourceview.el.scroll_to_iter(stl, 0.0f, true, 0.0f, 0.5f);",
508 "| void loadFile" : [
509 "(JsRender.JsRender file) ",
511 " this.file = null;",
513 " if (file.tree == null) {",
516 " this.notebook.el.page = 0;// gtk preview ",
520 " this.file = file; ",
521 " this.sourceview.loadFile();",
522 " this.searchcontext = null;",
525 " if (this.lastObj != null) {",
526 " this.container.el.remove(this.lastObj);",
529 " // hide the compile view at present..",
532 " var w = this.width;",
533 " var h = this.height;",
535 " print(\"ALLOC SET SIZES %d, %d\\n\", w,h); ",
537 " // set the container size min to 500/500 or 20 px less than max..",
538 " w = int.max (w-20, 500);",
539 " h = int.max (h-20, 500); ",
541 " print(\"SET SIZES %d, %d\\n\", w,h); ",
542 " _this.container.el.set_size_request(w,h);",
544 " _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.",
545 " var rgba = Gdk.RGBA ();",
546 " rgba.parse (\"#ccc\");",
547 " _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);",
550 "\tvar x = new JsRender.NodeToGtk((Project.Gtk) file.project, file.tree);",
551 " var obj = x.munge() as Gtk.Widget;",
552 " this.lastObj = null;",
553 "\tif (obj == null) {",
556 "\tthis.lastObj = obj;",
558 " this.container.el.add(obj);",
566 "| void scroll_to_line" : [
568 " this.notebook.el.page = 1;// code preview...",
570 " GLib.Timeout.add(500, () => {",
575 "\t\t var buf = this.sourceview.el.get_buffer();",
577 "\t\tvar sbuf = (Gtk.SourceBuffer) buf;",
580 "\t\tGtk.TextIter iter; ",
581 "\t\tsbuf.get_iter_at_line(out iter, line);",
582 "\t\tthis.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);",
595 "path" : "/home/alan/gitlive/roobuilder/src/Builder4/GtkView.bjs",