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