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