140566e35ff1c27a4b8e456e90ac52f9472d8889
[roobuilder] / src / Builder4 / GladeuiView.bjs
1 {
2  "build_module" : "",
3  "items" : [
4   {
5    "# Gtk.Widget lastObj" : "null",
6    "# JsRender.JsRender file" : "null",
7    "# Xcls_MainWindow main_window" : "",
8    "$ xns" : "Gtk",
9    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
10    "Gtk.SourceSearchContext searchcontext" : "",
11    "bool hexpand" : true,
12    "bool vexpand" : true,
13    "id" : "GladeuiView",
14    "int height" : 0,
15    "int last_search_end" : 0,
16    "int width" : 0,
17    "items" : [
18     {
19      "$ xns" : "Gtk",
20      "* pack" : "pack_start,true,true,0",
21      "id" : "notebook",
22      "items" : [
23       {
24        "$ xns" : "Gtk",
25        "* pack" : false,
26        "id" : "label_preview",
27        "utf8 label" : "Preview",
28        "xtype" : "Label"
29       },
30       {
31        "$ xns" : "Gtk",
32        "* pack" : false,
33        "id" : "label_code",
34        "utf8 label" : "Preview Generated Code",
35        "xtype" : "Label"
36       },
37       {
38        "# JsRender.JsRender file" : "null",
39        "$ xns" : "Glade",
40        "* ctor" : "_this.main_window == null ? null : new Glade.DesignView(_this.main_window.gladeproject)",
41        "* init" : [
42         " ",
43         "this.el.show();",
44         ""
45        ],
46        "* pack" : false,
47        "id" : "designview",
48        "xtype" : "DesignView",
49        "| void createThumb" : [
50         "() {",
51         "    ",
52         "    ",
53         "    if (this.file == null) {",
54         "        return;",
55         "    }",
56         "    var filename = this.file.getIconFileName(false);",
57         "    ",
58         "    var  win = this.el.get_parent_window();",
59         "    var width = win.get_width();",
60         "    var height = win.get_height();",
61         "",
62         "    Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?",
63         "",
64         "    screenshot.save(filename,\"png\");",
65         "    return;",
66         "    ",
67         "    ",
68         "     ",
69         "}",
70         ""
71        ],
72        "| void test" : [
73         "() {",
74         "",
75         "}"
76        ]
77       },
78       {
79        "$ xns" : "Gtk",
80        "* init" : [
81         "{",
82         "   ",
83         "    var description =   Pango.FontDescription.from_string(\"monospace\");",
84         "    description.set_size(8000);",
85         "    this.el.override_font(description);",
86         "",
87         "    this.loading = true;",
88         "    var buf = this.el.get_buffer();",
89         "    buf.notify.connect((ps) => {",
90         "        if (this.loading) {",
91         "            return;",
92         "        }",
93         "        if (ps.name != \"cursor-position\") {",
94         "            return;",
95         "        }",
96         "        print(\"cursor changed : %d\\n\", buf.cursor_position);",
97         "        Gtk.TextIter cpos;",
98         "        buf.get_iter_at_offset(out cpos, buf.cursor_position);",
99         "        ",
100         "        var ln = cpos.get_line();",
101         " ",
102         "        var node = _this.file.lineToNode(ln);",
103         " ",
104         "        if (node == null) {",
105         "            print(\"can not find node\\n\");",
106         "            return;",
107         "        }",
108         "        var ltree = _this.main_window.windowstate.left_tree;",
109         "        var tp = ltree.model.treePathFromNode(node);",
110         "        print(\"got tree path %s\\n\", tp);",
111         "        if (tp != \"\") {",
112         "\t       this.allow_node_scroll = false;        ",
113         "\t       print(\"changing cursor on tree..\\n\");",
114         "            ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);",
115         "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
116         "            GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
117         "\t            this.allow_node_scroll = true;",
118         "\t            return false;",
119         "            });",
120         "        }",
121         "        ",
122         "        // highlight the node..",
123         "        ",
124         "    });",
125         "  ",
126         "  ",
127         "  ",
128         "    var attrs = new Gtk.SourceMarkAttributes();",
129         "    var  pink =   Gdk.RGBA();",
130         "    pink.parse ( \"pink\");",
131         "    attrs.set_background ( pink);",
132         "    attrs.set_icon_name ( \"process-stop\");    ",
133         "    attrs.query_tooltip_text.connect(( mark) => {",
134         "        //print(\"tooltip query? %s\\n\", mark.name);",
135         "        return mark.name;",
136         "    });",
137         "    ",
138         "    this.el.set_mark_attributes (\"ERR\", attrs, 1);",
139         "    ",
140         "     var wattrs = new Gtk.SourceMarkAttributes();",
141         "    var  blue =   Gdk.RGBA();",
142         "    blue.parse ( \"#ABF4EB\");",
143         "    wattrs.set_background ( blue);",
144         "    wattrs.set_icon_name ( \"process-stop\");    ",
145         "    wattrs.query_tooltip_text.connect(( mark) => {",
146         "        //print(\"tooltip query? %s\\n\", mark.name);",
147         "        return mark.name;",
148         "    });",
149         "    ",
150         "    this.el.set_mark_attributes (\"WARN\", wattrs, 1);",
151         "    ",
152         " ",
153         "    ",
154         "     var dattrs = new Gtk.SourceMarkAttributes();",
155         "    var  purple =   Gdk.RGBA();",
156         "    purple.parse ( \"#EEA9FF\");",
157         "    dattrs.set_background ( purple);",
158         "    dattrs.set_icon_name ( \"process-stop\");    ",
159         "    dattrs.query_tooltip_text.connect(( mark) => {",
160         "        //print(\"tooltip query? %s\\n\", mark.name);",
161         "        return mark.name;",
162         "    });",
163         "    ",
164         "    this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
165         "    ",
166         "    ",
167         "    var gattrs = new Gtk.SourceMarkAttributes();",
168         "    var  grey =   Gdk.RGBA();",
169         "    grey.parse ( \"#ccc\");",
170         "    gattrs.set_background ( grey);",
171         " ",
172         "    ",
173         "    this.el.set_mark_attributes (\"grey\", gattrs, 1);",
174         "    ",
175         "    ",
176         "    ",
177         "    ",
178         "    ",
179         "    ",
180         "}",
181         " "
182        ],
183        "* pack" : "append_page,_this.label_code.el",
184        "bool allow_node_scroll" : true,
185        "bool loading" : true,
186        "gboolean editable" : false,
187        "gboolean show_line_marks" : true,
188        "gboolean show_line_numbers" : true,
189        "id" : "sourceview",
190        "xtype" : "SourceView",
191        "| string toString" : [
192         "() {",
193         "   Gtk.TextIter s;",
194         "    Gtk.TextIter e;",
195         "    this.el.get_buffer().get_start_iter(out s);",
196         "    this.el.get_buffer().get_end_iter(out e);",
197         "    var ret = this.el.get_buffer().get_text(s,e,true);",
198         "    //print(\"TO STRING? \" + ret);",
199         "    return ret;",
200         "}",
201         ""
202        ],
203        "| void highlightErrorsJson" : [
204         " (string type, Json.Object obj) {",
205         "      Gtk.TextIter start;",
206         "     Gtk.TextIter end;   ",
207         "     ",
208         "     var buf =  this.el.get_buffer();",
209         "       var sbuf = (Gtk.SourceBuffer)buf;",
210         "        buf.get_bounds (out start, out end);",
211         "        ",
212         "        sbuf.remove_source_marks (start, end, type);",
213         "                 ",
214         "     ",
215         "     // we should highlight other types of errors..",
216         "    ",
217         "    if (!obj.has_member(type)) {",
218         "        print(\"Return has no errors\\n\");",
219         "        return  ;",
220         "    }",
221         "    var err = obj.get_object_member(type);",
222         "    ",
223         "    if (_this.file == null) { ",
224         "        return; // just in case the file has not loaded yet?",
225         "    }",
226         " ",
227         "",
228         "    var valafn = \"\";",
229         "      try {             ",
230         "           var  regex = new Regex(\"\\\\.bjs$\");",
231         "        ",
232         "         ",
233         "            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
234         "         } catch (GLib.RegexError e) {",
235         "            return;",
236         "        }   ",
237         "",
238         "   if (!err.has_member(valafn)) {",
239         "        print(\"File path has no errors\\n\");",
240         "        return  ;",
241         "    }",
242         "    var lines = err.get_object_member(valafn);",
243         "    ",
244         "   ",
245         "    ",
246         "    var tlines = buf.get_line_count () +1;",
247         "    ",
248         "    lines.foreach_member((obj, line, node) => {",
249         "        ",
250         "             Gtk.TextIter iter;",
251         "    //        print(\"get inter\\n\");",
252         "            var eline = int.parse(line) -1  ;",
253         "            print(\"GOT ERROR on line %s -- converted to %d\\n\", line,eline);",
254         "            ",
255         "            ",
256         "            if (eline > tlines || eline < 0) {",
257         "                return;",
258         "            }",
259         "            sbuf.get_iter_at_line( out iter, eline);",
260         "            //print(\"mark line\\n\");",
261         "            var msg  = type + \" on line: %d - %s\".printf(eline+1, valafn);",
262         "            var ar = lines.get_array_member(line);",
263         "            for (var i = 0 ; i < ar.get_length(); i++) {",
264         "\t\t    msg += (msg.length > 0) ? \"\\n\" : \"\";",
265         "\t\t    msg += ar.get_string_element(i);",
266         "\t    }",
267         "            ",
268         "            ",
269         "            sbuf.create_source_mark(msg, type, iter);",
270         "        } );",
271         "        return  ;",
272         "    ",
273         " ",
274         "",
275         "",
276         "}"
277        ],
278        "| void loadFile" : [
279         "( ) {",
280         "",
281         "    ",
282         "    this.loading = true;",
283         "    var buf = this.el.get_buffer();",
284         "    buf.set_text(\"\",0);",
285         "    var sbuf = (Gtk.SourceBuffer) buf;",
286         "",
287         "    ",
288         "",
289         "    if (_this.file == null || _this.file.xtype != \"Gtk\") {",
290         "        print(\"xtype != Gtk\");",
291         "        this.loading = false;",
292         "        return;",
293         "    }",
294         "    ",
295         "    var valafn = \"\";",
296         "      try {             ",
297         "           var  regex = new Regex(\"\\\\.bjs$\");",
298         "        ",
299         "         ",
300         "            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
301         "         } catch (GLib.RegexError e) {",
302         "             this.loading = false;",
303         "            return;",
304         "        }   ",
305         "    ",
306         "",
307         "   if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {",
308         "        print(\"File path has no errors\\n\");",
309         "        this.loading = false;",
310         "        return  ;",
311         "    }",
312         "    ",
313         "    string str;",
314         "    try {",
315         "    ",
316         "        GLib.FileUtils.get_contents (valafn, out str);",
317         "    } catch (Error e) {",
318         "        this.loading = false;",
319         "        return  ;",
320         "    }",
321         "",
322         "//    print(\"setting str %d\\n\", str.length);",
323         "    buf.set_text(str, str.length);",
324         "    var lm = Gtk.SourceLanguageManager.get_default();",
325         "     ",
326         "    //?? is javascript going to work as js?",
327         "    ",
328         "    ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));",
329         "  ",
330         "    ",
331         "    Gtk.TextIter start;",
332         "    Gtk.TextIter end;     ",
333         "        ",
334         "    sbuf.get_bounds (out start, out end);",
335         "    sbuf.remove_source_marks (start, end, null); // remove all marks..",
336         "    ",
337         "    ",
338         "    if (_this.main_window.windowstate.last_compile_result != null) {",
339         "        var obj = _this.main_window.windowstate.last_compile_result;",
340         "        this.highlightErrorsJson(\"ERR\", obj);",
341         "        this.highlightErrorsJson(\"WARN\", obj);",
342         "        this.highlightErrorsJson(\"DEPR\", obj);\t\t\t",
343         "    }",
344         "    //while (Gtk.events_pending()) {",
345         "     //   Gtk.main_iteration();",
346         "   // }",
347         "    ",
348         "    this.loading = false; ",
349         "}",
350         ""
351        ],
352        "| void nodeSelected" : [
353         "(JsRender.Node? sel) {",
354         "  ",
355         "    ",
356         "  ",
357         "    // this is connected in widnowstate",
358         "    print(\"Roo-view - node selected\\n\");",
359         "    var buf = this.el.get_buffer();",
360         " ",
361         "    var sbuf = (Gtk.SourceBuffer) buf;",
362         "",
363         "   ",
364         "    while(Gtk.events_pending()) {",
365         "        Gtk.main_iteration();",
366         "    }",
367         "    ",
368         "   ",
369         "    // clear all the marks..",
370         "     Gtk.TextIter start;",
371         "    Gtk.TextIter end;     ",
372         "        ",
373         "    sbuf.get_bounds (out start, out end);",
374         "    sbuf.remove_source_marks (start, end, \"grey\");",
375         "    ",
376         "    ",
377         "     if (sel == null) {",
378         "        // no highlighting..",
379         "        return;",
380         "    }",
381         "    Gtk.TextIter iter;   ",
382         "    sbuf.get_iter_at_line(out iter,  sel.line_start);",
383         "    ",
384         "    ",
385         "    Gtk.TextIter cur_iter;",
386         "    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
387         "    ",
388         "    //var cur_line = cur_iter.get_line();",
389         "    //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
390         "    ",
391         "    //} else {",
392         "    if (this.allow_node_scroll) {",
393         "\t\t ",
394         "    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
395         "\t}",
396         "    ",
397         "     ",
398         "    ",
399         "    for (var i = 0; i < buf.get_line_count();i++) {",
400         "        if (i < sel.line_start || i > sel.line_end) {",
401         "           ",
402         "            sbuf.get_iter_at_line(out iter, i);",
403         "            sbuf.create_source_mark(null, \"grey\", iter);",
404         "            ",
405         "        }",
406         "    ",
407         "    }",
408         "    ",
409         "",
410         "}",
411         ""
412        ]
413       }
414      ],
415      "xtype" : "Notebook"
416     }
417    ],
418    "listeners" : {
419     "size_allocate" : [
420      "(aloc) => {",
421      " ",
422      "    this.width = aloc.width;",
423      "    this.height =aloc.height;",
424      "}",
425      " "
426     ]
427    },
428    "xtype" : "Box",
429    "| int search" : [
430     "(string txt) {",
431     "\tthis.notebook.el.page = 1;",
432     " \tvar s = new Gtk.SourceSearchSettings();",
433     "\tvar buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();",
434     "\tthis.searchcontext = new Gtk.SourceSearchContext(buf,s);",
435     "\tthis.searchcontext.set_highlight(true);",
436     "\ts.set_search_text(txt);",
437     "\t",
438     "\tGtk.TextIter beg, st,en;",
439     "\t ",
440     "\tbuf.get_start_iter(out beg);",
441     "\tthis.searchcontext.forward(beg, out st, out en);",
442     "\tthis.last_search_end  = 0;",
443     "\treturn this.searchcontext.get_occurrences_count();",
444     "",
445     "   ",
446     "}",
447     ""
448    ],
449    "| void createThumb" : [
450     "() {",
451     "    ",
452     "    ",
453     "    if (this.file == null) {",
454     "        return;",
455     "    }",
456     "    // only screenshot the gtk preview..",
457     "    if (this.notebook.el.page > 0 ) {",
458     "        return;",
459     "    }",
460     "    ",
461     "    ",
462     "    var filename = this.file.getIconFileName(false);",
463     "    ",
464     "    var  win = this.designview.el.get_parent_window();",
465     "    var width = win.get_width();",
466     "    var height = win.get_height();",
467     "    try {",
468     "         Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?",
469     "         screenshot.save(filename,\"png\");",
470     "    } catch (Error e) {",
471     "        ",
472     "    }",
473     "",
474     "   ",
475     "    return;",
476     "    ",
477     "    ",
478     "     ",
479     "     ",
480     "    ",
481     "    // should we hold until it's printed...",
482     "    ",
483     "      ",
484     "",
485     "    ",
486     "    ",
487     "",
488     "",
489     "    ",
490     "     ",
491     "}",
492     ""
493    ],
494    "| void forwardSearch" : [
495     "(bool change_focus) {",
496     "",
497     "\tif (this.searchcontext == null) {",
498     "\t\treturn;",
499     "\t}",
500     "\tthis.notebook.el.page = 1;",
501     "\tGtk.TextIter beg, st,en, stl;",
502     "\t",
503     "\tvar buf = this.sourceview.el.get_buffer();",
504     "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
505     "\tif (!this.searchcontext.forward(beg, out st, out en)) {",
506     "\t\tthis.last_search_end = 0;",
507     "\t} else { ",
508     "\t\tthis.last_search_end = en.get_offset();",
509     "\t\tif (change_focus) {",
510     "\t\t\tthis.sourceview.el.grab_focus();\t",
511     "\t\t}",
512     "\t\tbuf.place_cursor(st);",
513     "\t\tvar ln = st.get_line();",
514     "\t\tbuf.get_iter_at_line(out stl,ln);",
515     "\t\t ",
516     "\t\tthis.sourceview.el.scroll_to_iter(stl,  0.0f, true, 0.0f, 0.5f);",
517     "\t}",
518     "",
519     "}",
520     ""
521    ],
522    "| void initGlade" : [
523     "() {",
524     "\t _this.designview =  new Xcls_designview( _this );",
525     "\t ",
526     "\t var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);",
527     "\t ",
528     "\t _this.notebook.el.append_page(box, _this.label_preview.el);",
529     "\t     Glade.App.set_window(this.main_window.el);",
530     "\t// var  pal = new Glade.Palette();",
531     "    //var ins = new Glade.Inspector();",
532     "",
533     "\t box.pack_start(_this.designview.el);",
534     "\t// box.pack_start(pal);",
535     "\t //box.pack_start(ins);",
536     "\t  // pal.show();",
537     "   // ins.show();",
538     "    _this.designview.el.show();",
539     "\t box.show_all();\t ",
540     "\t ",
541     "} ",
542     ""
543    ],
544    "| void loadFile" : [
545     "(JsRender.JsRender file)",
546     "{",
547     "    ",
548     "",
549     "    this.file = file;",
550     "    ",
551     "",
552     "        // clear existing elements from project?",
553     "        ",
554     "        var  p = this.designview.el.get_project();",
555     "        var    li = p.get_objects().copy();",
556     "        // should remove all..",
557     "        for (var i =0;    i < li.length(); i++) {   ",
558     "            p.remove_object(li.nth_data(i)); ",
559     "        }",
560     "",
561     "        if (file.tree == null) {",
562     "            return;",
563     "        }",
564     "",
565     "//        print(\"%s\\n\",tf.tree.toJsonString());",
566     "\tvar x =  new JsRender.NodeToGlade((Project.Gtk) file.project, file.tree,  null);",
567     "    Glade.App.set_window(_this.main_window.el); // see if setting it again forces it to go to the irght locations.",
568     "\t ",
569     "FileIOStream iostream;",
570     "\tvar  f = File.new_tmp (\"tpl-XXXXXX.glade\", out iostream);",
571     "\tvar ostream = iostream.output_stream;",
572     "\tvar dostream = new DataOutputStream (ostream);",
573     "\tdostream.put_string (x.munge());",
574     "\tthis.el.show();",
575     "\t print(\"LOADING %s\\n\",f.get_path ());",
576     "      //p.load_from_file(f.get_path ());",
577     "        ",
578     "     p.load_from_file(\"/tmp/glade.xml\");",
579     "",
580     "}"
581    ],
582    "| void scroll_to_line" : [
583     "(int line) {",
584     "   this.notebook.el.page = 1;// code preview...",
585     "   ",
586     "   GLib.Timeout.add(500, () => {",
587     "   ",
588     "   ",
589     "\t   ",
590     "\t   ",
591     "\t\t  var buf = this.sourceview.el.get_buffer();",
592     "\t ",
593     "\t\tvar sbuf = (Gtk.SourceBuffer) buf;",
594     "",
595     "",
596     "\t\tGtk.TextIter iter;   ",
597     "\t\tsbuf.get_iter_at_line(out iter,  line);",
598     "\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
599     "\t\treturn false;",
600     "\t});   ",
601     "",
602     "   ",
603     "}",
604     ""
605    ]
606   }
607  ],
608  "modOrder" : "",
609  "name" : "GladeuiView",
610  "parent" : "",
611  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/GladeuiView.bjs",
612  "permname" : "",
613  "title" : ""
614 }