5d46166c686cbef4e5501cea75986431ce28817c
[roobuilder] / src / Builder4 / GtkView.bjs
1 {
2  "build_module" : "builder",
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" : "GtkView",
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        "$ xns" : "Gtk",
39        "* pack" : "append_page,_this.label_preview.el",
40        "items" : [
41         {
42          "$ xns" : "Gtk",
43          "* pack" : "add",
44          "id" : "view_layout",
45          "items" : [
46           {
47            "$ xns" : "Gtk",
48            "* pack" : "put,10,10",
49            "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
50            "id" : "container",
51            "xtype" : "Box"
52           }
53          ],
54          "xtype" : "Layout"
55         }
56        ],
57        "xtype" : "ScrolledWindow"
58       },
59       {
60        "$ xns" : "Gtk",
61        "* pack" : "append_page,_this.label_code.el",
62        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
63        "int spacing" : 0,
64        "items" : [
65         {
66          "$ xns" : "Gtk",
67          "bool vexpand" : true,
68          "items" : [
69           {
70            "# JsRender.Node? node_selected" : "",
71            "# string prop_selected" : "\"\"",
72            "$ xns" : "Gtk",
73            "* init" : [
74             "{",
75             "   ",
76             "    var description =   Pango.FontDescription.from_string(\"monospace\");",
77             "    description.set_size(8000);",
78             "    this.el.override_font(description);",
79             "",
80             "    this.loading = true;",
81             "    var buf = this.el.get_buffer();",
82             "    buf.notify.connect((ps) => {",
83             "        if (this.loading) {",
84             "            return;",
85             "        }",
86             "        if (ps.name != \"cursor-position\") {",
87             "            return;",
88             "        }",
89             "        print(\"cursor changed : %d\\n\", buf.cursor_position);",
90             "        Gtk.TextIter cpos;",
91             "        buf.get_iter_at_offset(out cpos, buf.cursor_position);",
92             "        ",
93             "        var ln = cpos.get_line();",
94             " ",
95             "        var node = _this.file.lineToNode(ln);",
96             " ",
97             "        if (node == null) {",
98             "            print(\"can not find node\\n\");",
99             "            return;",
100             "        }",
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;",
111             "\t            return false;",
112             "            });",
113             "        }",
114             "        ",
115             "        // highlight the node..",
116             "        ",
117             "    });",
118             "  ",
119             "  ",
120             "  ",
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;",
129             "    });",
130             "    ",
131             "    this.el.set_mark_attributes (\"ERR\", attrs, 1);",
132             "    ",
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;",
141             "    });",
142             "    ",
143             "    this.el.set_mark_attributes (\"WARN\", wattrs, 1);",
144             "    ",
145             " ",
146             "    ",
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;",
155             "    });",
156             "    ",
157             "    this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
158             "    ",
159             "    ",
160             "    var gattrs = new Gtk.SourceMarkAttributes();",
161             "    var  grey =   Gdk.RGBA();",
162             "    grey.parse ( \"#ccc\");",
163             "    gattrs.set_background ( grey);",
164             " ",
165             "    ",
166             "    this.el.set_mark_attributes (\"grey\", gattrs, 1);",
167             "    ",
168             "    ",
169             "    ",
170             "    ",
171             "    ",
172             "    ",
173             "}",
174             " "
175            ],
176            "* pack" : "add",
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,
182            "id" : "sourceview",
183            "items" : [
184             {
185              "$ xns" : "Gtk",
186              "* pack" : "set_buffer",
187              "bool dirty" : false,
188              "id" : "buffer",
189              "int error_line" : "-1",
190              "xtype" : "SourceBuffer"
191             }
192            ],
193            "listeners" : {
194             "key_press_event" : [
195              "(event) => {",
196              "\t",
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);",
200              "\t    return true;",
201              "\t}",
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();",
205              "\t    return true;",
206              "\t}",
207              "\t ",
208              "\treturn false;",
209              "}\t ",
210              ""
211             ]
212            },
213            "xtype" : "SourceView",
214            "| string toString" : [
215             "() {",
216             "   Gtk.TextIter s;",
217             "    Gtk.TextIter e;",
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);",
222             "    return ret;",
223             "}",
224             ""
225            ],
226            "| void highlightErrorsJson" : [
227             " (string type, Json.Object obj) {",
228             "      Gtk.TextIter start;",
229             "     Gtk.TextIter end;   ",
230             "     ",
231             "     var buf =  this.el.get_buffer();",
232             "       var sbuf = (Gtk.SourceBuffer)buf;",
233             "        buf.get_bounds (out start, out end);",
234             "        ",
235             "        sbuf.remove_source_marks (start, end, type);",
236             "                 ",
237             "     ",
238             "     // we should highlight other types of errors..",
239             "    ",
240             "    if (!obj.has_member(type)) {",
241             "        print(\"Return has no errors\\n\");",
242             "        return  ;",
243             "    }",
244             "    var err = obj.get_object_member(type);",
245             "    ",
246             "    if (_this.file == null) { ",
247             "        return; // just in case the file has not loaded yet?",
248             "    }",
249             " ",
250             "",
251             "    var valafn = \"\";",
252             "      try {             ",
253             "           var  regex = new Regex(\"\\\\.bjs$\");",
254             "        ",
255             "         ",
256             "            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
257             "         } catch (GLib.RegexError e) {",
258             "            return;",
259             "        }   ",
260             "",
261             "   if (!err.has_member(valafn)) {",
262             "        print(\"File path has no errors\\n\");",
263             "        return  ;",
264             "    }",
265             "    var lines = err.get_object_member(valafn);",
266             "    ",
267             "   ",
268             "    ",
269             "    var tlines = buf.get_line_count () +1;",
270             "    ",
271             "    lines.foreach_member((obj, line, node) => {",
272             "        ",
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);",
277             "            ",
278             "            ",
279             "            if (eline > tlines || eline < 0) {",
280             "                return;",
281             "            }",
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);",
289             "\t    }",
290             "            ",
291             "            ",
292             "            sbuf.create_source_mark(msg, type, iter);",
293             "        } );",
294             "        return  ;",
295             "    ",
296             " ",
297             "",
298             "",
299             "}"
300            ],
301            "| void loadFile" : [
302             "( ) {",
303             "    this.loading = true;",
304             "    var buf = this.el.get_buffer();",
305             "    buf.set_text(\"\",0);",
306             "    var sbuf = (Gtk.SourceBuffer) buf;",
307             "",
308             "    ",
309             "",
310             "    if (_this.file == null || _this.file.xtype != \"Gtk\") {",
311             "        print(\"xtype != Gtk\");",
312             "        this.loading = false;",
313             "        return;",
314             "    }",
315             "    ",
316             "    var valafn = \"\";",
317             "      try {             ",
318             "           var  regex = new Regex(\"\\\\.bjs$\");",
319             "        ",
320             "         ",
321             "            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
322             "         } catch (GLib.RegexError e) {",
323             "             this.loading = false;",
324             "            return;",
325             "        }   ",
326             "    ",
327             "",
328             "   if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {",
329             "        print(\"File path has no errors\\n\");",
330             "        this.loading = false;",
331             "        return  ;",
332             "    }",
333             "    ",
334             "    string str;",
335             "    try {",
336             "    ",
337             "        GLib.FileUtils.get_contents (valafn, out str);",
338             "    } catch (Error e) {",
339             "        this.loading = false;",
340             "        return  ;",
341             "    }",
342             "",
343             "//    print(\"setting str %d\\n\", str.length);",
344             "    buf.set_text(str, str.length);",
345             "    var lm = Gtk.SourceLanguageManager.get_default();",
346             "     ",
347             "    //?? is javascript going to work as js?",
348             "    ",
349             "    ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));",
350             "  ",
351             "    ",
352             "    Gtk.TextIter start;",
353             "    Gtk.TextIter end;     ",
354             "        ",
355             "    sbuf.get_bounds (out start, out end);",
356             "    sbuf.remove_source_marks (start, end, null); // remove all marks..",
357             "    ",
358             "    ",
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",
364             "    }",
365             "    //while (Gtk.events_pending()) {",
366             "     //   Gtk.main_iteration();",
367             "   // }",
368             "    ",
369             "    this.loading = false; ",
370             "}",
371             ""
372            ],
373            "| void nodeSelected" : [
374             "(JsRender.Node? sel, bool scroll) {",
375             "  ",
376             "    ",
377             "  ",
378             "    // this is connected in widnowstate",
379             "    print(\"Roo-view - node selected\\n\");",
380             "    var buf = this.el.get_buffer();",
381             " ",
382             "    var sbuf = (Gtk.SourceBuffer) buf;",
383             "",
384             "   ",
385             "    while(Gtk.events_pending()) {",
386             "        Gtk.main_iteration();",
387             "    }",
388             "    ",
389             "   ",
390             "    // clear all the marks..",
391             "     Gtk.TextIter start;",
392             "    Gtk.TextIter end;     ",
393             "        ",
394             "    sbuf.get_bounds (out start, out end);",
395             "    sbuf.remove_source_marks (start, end, \"grey\");",
396             "    ",
397             "        this.node_selected = sel;",
398             "     if (sel == null) {",
399             "        // no highlighting..",
400             "        return;",
401             "    }",
402             "    Gtk.TextIter iter;   ",
403             "    sbuf.get_iter_at_line(out iter,  sel.line_start);",
404             "    ",
405             "    ",
406             "    Gtk.TextIter cur_iter;",
407             "    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
408             "    ",
409             "    //var cur_line = cur_iter.get_line();",
410             "    //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
411             "    ",
412             "    //} else {",
413             "    if (this.allow_node_scroll) {",
414             "\t\t ",
415             "    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
416             "\t}",
417             "    ",
418             "     ",
419             "    ",
420             "    for (var i = 0; i < buf.get_line_count();i++) {",
421             "        if (i < sel.line_start || i > sel.line_end) {",
422             "           ",
423             "            sbuf.get_iter_at_line(out iter, i);",
424             "            sbuf.create_source_mark(null, \"grey\", iter);",
425             "            ",
426             "        }",
427             "    ",
428             "    }",
429             "    ",
430             "",
431             "}",
432             ""
433            ]
434           }
435          ],
436          "xtype" : "ScrolledWindow"
437         },
438         {
439          "$ xns" : "Gtk",
440          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
441          "bool homogeneous" : false,
442          "bool vexpand" : false,
443          "int spacing" : 0,
444          "items" : [
445           {
446            "$ xns" : "Gtk",
447            "* init" : [
448             "var description =   Pango.FontDescription.from_string(\"monospace\");",
449             "\tdescription.set_size(8000);",
450             "\t this.el.override_font(description);",
451             "",
452             ""
453            ],
454            "bool hexpand" : true,
455            "id" : "search_entry",
456            "int width_request" : 300,
457            "listeners" : {
458             "changed" : [
459              "() => {",
460              "\t/*",
461              "\tif (this.el.text == \"\") {",
462              "\t\t_this.search_results.el.hide();",
463              "\t\treturn;",
464              "\t}",
465              "\tvar res = 0;",
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);",
471              "\t\t\t",
472              "\t\t\tbreak;",
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);",
476              "\t\t\t} else { ",
477              "\t\t\t\t res = _this.windowstate.window_rooview.search(this.el.text);\t\t\t",
478              "\t\t\t}",
479              "\t\t",
480              "\t\t",
481              "\t\t\tbreak;",
482              "\t}",
483              "\t_this.search_results.el.show();",
484              "\tif (res > 0) {",
485              "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
486              "\t} else {",
487              "\t\t_this.search_results.el.label = \"No Matches\";",
488              "\t}",
489              "\t\t",
490              "\t*/",
491              "\t",
492              "}",
493              ""
494             ],
495             "key_press_event" : [
496              "(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);",
500              "\t    return true;",
501              "\t}",
502              "    ",
503              "  ",
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();",
507              "",
508              "\t\tGLib.Timeout.add_seconds(2,() => {",
509              "\t\t\t _this.search_results.updateResults();",
510              "\t\t\t return false;",
511              "\t\t });",
512              "\t ",
513              "\t\t",
514              "\t    return true;",
515              "",
516              "\t}    ",
517              "   // print(event.key.keyval)",
518              "   ",
519              "    return false;",
520              "",
521              "} "
522             ]
523            },
524            "string placeholder_text" : "Press enter to search",
525            "xtype" : "SearchEntry",
526            "| void forwardSearch" : [
527             "(bool change_focus) {",
528             "",
529             "",
530             "\t_this.forwardSearch(change_focus);",
531             "",
532             "/*",
533             "",
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);",
539             "\t\t\t ",
540             "\t\t\tbreak;",
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);",
544             "\t\t\t} else { ",
545             "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
546             "\t\t\t}",
547             "\t\t",
548             "\t\t\tbreak;",
549             "\t}",
550             "\t*/",
551             "\t",
552             "}",
553             ""
554            ]
555           },
556           {
557            "$ xns" : "Gtk",
558            "* pack" : "add",
559            "items" : [
560             {
561              "$ xns" : "Gtk",
562              "* pack" : "add",
563              "bool always_show_image" : true,
564              "bool visible" : false,
565              "id" : "search_results",
566              "listeners" : {
567               "button_press_event" : [
568                "() => {",
569                "/*",
570                "    if (this.popup == null) {",
571                "        this.popup = new Xcls_ValaCompileErrors();",
572                "        this.popup.window = _this;",
573                "    }",
574                "   ",
575                "    ",
576                "    this.popup.show(this.notices, this.el);",
577                "    */",
578                "    return true;",
579                "}"
580               ]
581              },
582              "xtype" : "ImageMenuItem",
583              "| void updateResults" : [
584               "() {",
585               "\tthis.el.visible = true;",
586               "\t",
587               "\tvar res = _this.searchcontext.get_occurrences_count();",
588               "\tif (res < 0) {",
589               "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
590               "\t\treturn;",
591               "\t}",
592               "",
593               "\t_this.nextBtn.el.sensitive = false;",
594               "\t_this.backBtn.el.sensitive = false;\t",
595               "",
596               "\tif (res > 0) {",
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;",
600               "\t\treturn;",
601               "\t} ",
602               "\t_this.search_results.el.label = \"No Matches\";",
603               "\t",
604               "}"
605              ]
606             }
607            ],
608            "xtype" : "MenuBar"
609           },
610           {
611            "$ xns" : "Gtk",
612            "bool always_show_image" : true,
613            "bool sensitive" : false,
614            "id" : "nextBtn",
615            "items" : [
616             {
617              "$ xns" : "Gtk",
618              "* prop" : "image",
619              "string icon_name" : "go-down",
620              "xtype" : "Image"
621             }
622            ],
623            "listeners" : {
624             "button_press_event" : [
625              "(event) => {",
626              "",
627              "\t_this.forwardSearch(true);",
628              "\t",
629              "\treturn true;",
630              "}",
631              ""
632             ]
633            },
634            "string label" : "Next",
635            "xtype" : "Button"
636           },
637           {
638            "$ xns" : "Gtk",
639            "bool always_show_image" : true,
640            "bool sensitive" : false,
641            "id" : "backBtn",
642            "items" : [
643             {
644              "$ xns" : "Gtk",
645              "* prop" : "image",
646              "string icon_name" : "go-up",
647              "xtype" : "Image"
648             }
649            ],
650            "listeners" : {
651             "button_press_event" : [
652              "(event) => {",
653              "",
654              "\t_this.backSearch(true);",
655              "\t",
656              "\treturn true;",
657              "}",
658              ""
659             ]
660            },
661            "string label" : "Previous",
662            "xtype" : "Button"
663           },
664           {
665            "$ xns" : "Gtk",
666            "bool always_show_image" : true,
667            "items" : [
668             {
669              "$ xns" : "Gtk",
670              "* prop" : "image",
671              "string icon_name" : "emblem-system",
672              "xtype" : "Image"
673             },
674             {
675              "$ xns" : "Gtk",
676              "* prop" : "popup",
677              "id" : "search_settings",
678              "items" : [
679               {
680                "$ xns" : "Gtk",
681                "* init" : [
682                 "{",
683                 "\tthis.el.show();",
684                 "}",
685                 ""
686                ],
687                "id" : "case_sensitive",
688                "string label" : "Case Sensitive",
689                "xtype" : "CheckMenuItem"
690               },
691               {
692                "$ xns" : "Gtk",
693                "* init" : [
694                 "{",
695                 "\tthis.el.show();",
696                 "}",
697                 ""
698                ],
699                "id" : "regex",
700                "string label" : "Regex",
701                "xtype" : "CheckMenuItem"
702               },
703               {
704                "$ xns" : "Gtk",
705                "* init" : [
706                 "{",
707                 "\tthis.el.show();",
708                 "}",
709                 ""
710                ],
711                "id" : "multiline",
712                "string label" : "Multi-line (add \\n)",
713                "xtype" : "CheckMenuItem"
714               }
715              ],
716              "xtype" : "Menu"
717             }
718            ],
719            "string label" : "Settings",
720            "xtype" : "MenuButton"
721           }
722          ],
723          "xtype" : "Box"
724         }
725        ],
726        "xtype" : "Box"
727       }
728      ],
729      "xtype" : "Notebook"
730     }
731    ],
732    "listeners" : {
733     "size_allocate" : [
734      "(aloc) => {",
735      " ",
736      "    this.width = aloc.width;",
737      "    this.height =aloc.height;",
738      "}",
739      " "
740     ]
741    },
742    "xtype" : "Box",
743    "| int search" : [
744     "(string in_txt) {",
745     "\tthis.notebook.el.page = 1;",
746     "\t",
747     " ",
748     "   ",
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;",
753     "\t",
754     "\tthis.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);",
755     "\tthis.searchcontext.set_highlight(true);",
756     "\tvar txt = in_txt;",
757     "\t",
758     "\tif (_this.multiline.el.active) {",
759     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
760     "\t}",
761     "\t",
762     "\ts.set_search_text(txt);",
763     "\tGtk.TextIter beg, st,en;",
764     "\t ",
765     "\tthis.buffer.el.get_start_iter(out beg);",
766     "\tthis.searchcontext.forward(beg, out st, out en);",
767     "\tthis.last_search_end = 0;",
768     "\t",
769     "\treturn this.searchcontext.get_occurrences_count();",
770     "",
771     " ",
772     "    ",
773     "",
774     "}",
775     ""
776    ],
777    "| void backSearch" : [
778     "(bool change_focus) {",
779     "",
780     "\tif (this.searchcontext == null) {",
781     "\t\treturn;",
782     "\t} ",
783     "\t",
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 );",
787     "\t",
788     "\tif (!this.searchcontext.backward2(beg, out st, out en, out has_wrapped_around)) {",
789     "\t",
790     "\t\tthis.last_search_end = 0;",
791     "\t\treturn;",
792     "\t}",
793     "\tthis.last_search_end = en.get_offset();",
794     "\tif (change_focus) {",
795     "\t\tthis.sourceview.el.grab_focus();",
796     "\t}",
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);",
801     "\t",
802     " ",
803     "}",
804     ""
805    ],
806    "| void createThumb" : [
807     "() {",
808     "    ",
809     "    ",
810     "    if (this.file == null) {",
811     "        return;",
812     "    }",
813     "    // only screenshot the gtk preview..",
814     "    if (this.notebook.el.page > 0 ) {",
815     "        return;",
816     "    }",
817     "    ",
818     "    ",
819     "    var filename = this.file.getIconFileName(false);",
820     "    ",
821     "    var  win = this.el.get_parent_window();",
822     "    var width = win.get_width();",
823     "    var height = win.get_height();",
824     "    try {",
825     "         Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?",
826     "         screenshot.save(filename,\"png\");",
827     "    } catch (Error e) {",
828     "        ",
829     "    }",
830     "",
831     "   ",
832     "    return;",
833     "    ",
834     "    ",
835     "     ",
836     "     ",
837     "    ",
838     "    // should we hold until it's printed...",
839     "    ",
840     "      ",
841     "",
842     "    ",
843     "    ",
844     "",
845     "",
846     "    ",
847     "     ",
848     "}",
849     ""
850    ],
851    "| void forwardSearch" : [
852     "(bool change_focus) {",
853     "",
854     "\tif (this.searchcontext == null) {",
855     "\t\treturn;",
856     "\t}",
857     "\tthis.notebook.el.page = 1;",
858     "\tGtk.TextIter beg, st,en, stl;",
859     "\t",
860     "\tvar buf = this.sourceview.el.get_buffer();",
861     "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
862     "\tif (!this.searchcontext.forward(beg, out st, out en)) {",
863     "\t\tthis.last_search_end = 0;",
864     "\t\treturn;",
865     "\t}",
866     "\tthis.last_search_end = en.get_offset();",
867     "\tif (change_focus) {",
868     "\t\tthis.sourceview.el.grab_focus();",
869     "\t}",
870     "\tbuf.place_cursor(st);",
871     "\t",
872     " ",
873     "\t ",
874     "\tthis.sourceview.el.scroll_to_iter(st,  0.0f, true, 0.0f, 0.5f);",
875     "\t",
876     "\t",
877     "\tvar ln = st.get_line();",
878     "\t",
879     "\tthis.highlightNodeAtLine(ln);",
880     "}\t",
881     "  "
882    ],
883    "| void highlightNodeAtLine" : [
884     "(int ln) {",
885     "",
886     "",
887     "\t ",
888     "\t// highlight node...",
889     "\t",
890     "\t\t",
891     "    var node = _this.file.lineToNode(ln+1);",
892     " ",
893     "    if (node == null) {",
894     "        //print(\"can not find node\\n\");",
895     "        return;",
896     "    }",
897     "    var prop = node.lineToProp(ln+1);",
898     "    print(\"prop : %s\", prop == null ? \"???\" : prop);",
899     "        ",
900     "        ",
901     "    // ---------- this selects the tree's node...",
902     "    ",
903     "    var ltree = _this.main_window.windowstate.left_tree;",
904     "    var tp = ltree.model.treePathFromNode(node);",
905     "    print(\"got tree path %s\\n\", tp);",
906     "    if (tp == \"\") {",
907     "\t\treturn;",
908     "\t}",
909     "    //_this.sourceview.allow_node_scroll = false; /// block node scrolling..",
910     "\t       ",
911     "   ",
912     "    //print(\"changing cursor on tree..\\n\");",
913     "   ",
914     "",
915     "    ",
916     "    // let's try allowing editing on the methods.",
917     "    // a little klunky at present..",
918     "\t_this.sourceview.prop_selected = \"\";",
919     "    if (prop != null) {",
920     "\t\t//see if we can find it..",
921     "\t\tvar kv = prop.split(\":\");",
922     "\t\tif (kv[0] == \"p\") {",
923     "\t\t",
924     "    \t\t//var k = prop.get_key(kv[1]);",
925     "    \t\t// fixme -- need to determine if it's an editable property...",
926     "    \t\t_this.sourceview.prop_selected = prop;",
927     "    \t\t",
928     "\t\t} else if (kv[0] == \"l\") {",
929     "\t\t\t _this.sourceview.prop_selected = prop;",
930     "\t\t\t",
931     "\t\t}",
932     "    }",
933     "    ltree.view.setCursor(tp, \"editor\");",
934     "   // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
935     "   _this.sourceview.nodeSelected(node,false);",
936     "    ",
937     "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
938     "      //      GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
939     "\t  //          this.allow_node_scroll = true;",
940     "\t  //          return false;",
941     "      //      });",
942     "      //  }",
943     "\t\t",
944     "\t\t",
945     "\t\t",
946     "\t\t",
947     "\t\t",
948     "\t\t",
949     "\t\t",
950     "\t\t",
951     "\t\t",
952     "\t\t ",
953     "",
954     "}",
955     " "
956    ],
957    "| void loadFile" : [
958     "(JsRender.JsRender file) ",
959     "{",
960     "        this.file = null;",
961     "        ",
962     "        if (file.tree == null) {",
963     "            return;",
964     "        }",
965     "        this.notebook.el.page = 0;// gtk preview ",
966     "   ",
967     "  ",
968     "        ",
969     "       this.file = file;     ",
970     "        this.sourceview.loadFile();",
971     "        this.searchcontext = null;",
972     "        ",
973     "",
974     "        if (this.lastObj != null) {",
975     "            this.container.el.remove(this.lastObj);",
976     "        }",
977     "        ",
978     "        // hide the compile view at present..",
979     "          ",
980     "        ",
981     "        var w = this.width;",
982     "        var h = this.height;",
983     "        ",
984     "        print(\"ALLOC SET SIZES %d, %d\\n\", w,h); ",
985     "        ",
986     "        // set the container size min to 500/500 or 20 px less than max..",
987     "        w = int.max (w-20, 500);",
988     "        h = int.max (h-20, 500); ",
989     "        ",
990     "        print(\"SET SIZES %d, %d\\n\", w,h);       ",
991     "        _this.container.el.set_size_request(w,h);",
992     "        ",
993     "        _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.",
994     "        var rgba = Gdk.RGBA ();",
995     "        rgba.parse (\"#ccc\");",
996     "        _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);",
997     "        ",
998     "        ",
999     "\tvar x = new JsRender.NodeToGtk((Project.Gtk) file.project, file.tree);",
1000     "    var obj = x.munge() as Gtk.Widget;",
1001     "    this.lastObj = null;",
1002     "\tif (obj == null) {",
1003     "        \treturn;",
1004     "\t}",
1005     "\tthis.lastObj = obj;",
1006     "        ",
1007     "        this.container.el.add(obj);",
1008     "        obj.show_all();",
1009     "        ",
1010     "         ",
1011     "        ",
1012     "}",
1013     " "
1014    ],
1015    "| void scroll_to_line" : [
1016     "(int line) {",
1017     "  // code preview...",
1018     "   ",
1019     "   GLib.Timeout.add(100, () => {",
1020     "   ",
1021     "   ",
1022     "\t    this.notebook.el.set_current_page(1);",
1023     "\t   ",
1024     "\t\t  var buf = this.sourceview.el.get_buffer();",
1025     "\t ",
1026     "\t\tvar sbuf = (Gtk.SourceBuffer) buf;",
1027     "",
1028     "",
1029     "\t\tGtk.TextIter iter;   ",
1030     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1031     "\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1032     "\t\treturn false;",
1033     "\t});   ",
1034     "",
1035     "   ",
1036     "}",
1037     ""
1038    ]
1039   }
1040  ],
1041  "modOrder" : "",
1042  "name" : "GtkView",
1043  "parent" : "",
1044  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/GtkView.bjs",
1045  "permname" : "",
1046  "title" : ""
1047 }