251f311b836f1d5e9bef89bf7a19de1a6d4757cf
[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              "    ",
494              "     if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
495              "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
496              "\t\t_this.forwardSearch(true);",
497              "\t    return true;",
498              "\t}",
499              "    ",
500              "    ",
501              "  ",
502              " \tif (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {",
503              "\t\tvar res = _this.search(this.el.text);",
504              "\t\tif (res > 0) {",
505              "\t\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
506              "\t\t} else {",
507              "\t\t\t_this.search_results.el.label = \"No Matches\";",
508              "\t\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              "Xcls_ValaCompileErrors popup" : "",
560              "bool always_show_image" : true,
561              "id" : "search_results",
562              "items" : [
563               {
564                "$ xns" : "Gtk",
565                "* pack" : "set_image",
566                "bool sensitive" : false,
567                "utf8 icon_name" : "system-search",
568                "xtype" : "Image"
569               }
570              ],
571              "listeners" : {
572               "button_press_event" : [
573                "() => {",
574                "/*",
575                "    if (this.popup == null) {",
576                "        this.popup = new Xcls_ValaCompileErrors();",
577                "        this.popup.window = _this;",
578                "    }",
579                "   ",
580                "    ",
581                "    this.popup.show(this.notices, this.el);",
582                "    */",
583                "    return true;",
584                "}"
585               ]
586              },
587              "string label" : "Matches",
588              "xtype" : "ImageMenuItem"
589             }
590            ],
591            "xtype" : "MenuBar"
592           },
593           {
594            "$ xns" : "Gtk",
595            "bool always_show_image" : true,
596            "items" : [
597             {
598              "$ xns" : "Gtk",
599              "* prop" : "image",
600              "string icon_name" : "go-down",
601              "xtype" : "Image"
602             }
603            ],
604            "listeners" : {
605             "button_press_event" : [
606              "(event) => {",
607              "",
608              "\t_this.forwardSearch(true);",
609              "\t",
610              "\treturn true;",
611              "}",
612              ""
613             ]
614            },
615            "string label" : "Next",
616            "xtype" : "Button"
617           },
618           {
619            "$ xns" : "Gtk",
620            "bool always_show_image" : true,
621            "items" : [
622             {
623              "$ xns" : "Gtk",
624              "* prop" : "image",
625              "string icon_name" : "go-up",
626              "xtype" : "Image"
627             }
628            ],
629            "listeners" : {
630             "button_press_event" : [
631              "(event) => {",
632              "",
633              "\t_this.backSearch(true);",
634              "\t",
635              "\treturn true;",
636              "}",
637              ""
638             ]
639            },
640            "string label" : "Previous",
641            "xtype" : "Button"
642           },
643           {
644            "$ xns" : "Gtk",
645            "bool always_show_image" : true,
646            "items" : [
647             {
648              "$ xns" : "Gtk",
649              "* prop" : "image",
650              "string icon_name" : "emblem-system",
651              "xtype" : "Image"
652             },
653             {
654              "$ xns" : "Gtk",
655              "* prop" : "popup",
656              "id" : "search_settings",
657              "items" : [
658               {
659                "$ xns" : "Gtk",
660                "* init" : [
661                 "{",
662                 "\tthis.el.show();",
663                 "}",
664                 ""
665                ],
666                "id" : "case_sensitive",
667                "string label" : "Case Sensitive",
668                "xtype" : "CheckMenuItem"
669               },
670               {
671                "$ xns" : "Gtk",
672                "* init" : [
673                 "{",
674                 "\tthis.el.show();",
675                 "}",
676                 ""
677                ],
678                "id" : "regex",
679                "string label" : "Regex",
680                "xtype" : "CheckMenuItem"
681               },
682               {
683                "$ xns" : "Gtk",
684                "* init" : [
685                 "{",
686                 "\tthis.el.show();",
687                 "}",
688                 ""
689                ],
690                "id" : "multiline",
691                "string label" : "Multi-line (add \\n)",
692                "xtype" : "CheckMenuItem"
693               }
694              ],
695              "xtype" : "Menu"
696             }
697            ],
698            "string label" : "Settings",
699            "xtype" : "MenuButton"
700           }
701          ],
702          "xtype" : "Box"
703         }
704        ],
705        "xtype" : "Box"
706       }
707      ],
708      "xtype" : "Notebook"
709     }
710    ],
711    "listeners" : {
712     "size_allocate" : [
713      "(aloc) => {",
714      " ",
715      "    this.width = aloc.width;",
716      "    this.height =aloc.height;",
717      "}",
718      " "
719     ]
720    },
721    "xtype" : "Box",
722    "| int search" : [
723     "(string in_txt) {",
724     "\tthis.notebook.el.page = 1;",
725     "\t",
726     " ",
727     "   ",
728     "\tvar s = new Gtk.SourceSearchSettings();",
729     "\ts.case_sensitive = _this.case_sensitive.el.active;",
730     "\ts.regex_enabled = _this.regex.el.active;\t",
731     "\ts.wrap_around = false;",
732     "\t",
733     "\tthis.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);",
734     "\tthis.searchcontext.set_highlight(true);",
735     "\tvar txt = in_txt;",
736     "\t",
737     "\tif (_this.multiline.el.active) {",
738     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
739     "\t}",
740     "\t",
741     "\ts.set_search_text(txt);",
742     "\tGtk.TextIter beg, st,en;",
743     "\t ",
744     "\tthis.buffer.el.get_start_iter(out beg);",
745     "\tthis.searchcontext.forward(beg, out st, out en);",
746     "\tthis.last_search_end = 0;",
747     "\t",
748     "\treturn this.searchcontext.get_occurrences_count();",
749     "",
750     " ",
751     "    ",
752     "",
753     "}",
754     ""
755    ],
756    "| void backSearch" : [
757     "(bool change_focus) {",
758     "",
759     "\tif (this.searchcontext == null) {",
760     "\t\treturn;",
761     "\t} ",
762     "\t",
763     "\tGtk.TextIter beg, st,en;",
764     "\tbool has_wrapped_around;",
765     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
766     "\t",
767     "\tif (!this.searchcontext.backward2(beg, out st, out en, out has_wrapped_around)) {",
768     "\t",
769     "\t\tthis.last_search_end = 0;",
770     "\t\treturn;",
771     "\t}",
772     "\tthis.last_search_end = en.get_offset();",
773     "\tif (change_focus) {",
774     "\t\tthis.sourceview.el.grab_focus();",
775     "\t}",
776     "\tthis.buffer.el.place_cursor(st);",
777     "\tthis.sourceview.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
778     "\tvar ln = st.get_line();",
779     "\tthis.highlightNodeAtLine(ln);",
780     "\t",
781     " ",
782     "}",
783     ""
784    ],
785    "| void createThumb" : [
786     "() {",
787     "    ",
788     "    ",
789     "    if (this.file == null) {",
790     "        return;",
791     "    }",
792     "    // only screenshot the gtk preview..",
793     "    if (this.notebook.el.page > 0 ) {",
794     "        return;",
795     "    }",
796     "    ",
797     "    ",
798     "    var filename = this.file.getIconFileName(false);",
799     "    ",
800     "    var  win = this.el.get_parent_window();",
801     "    var width = win.get_width();",
802     "    var height = win.get_height();",
803     "    try {",
804     "         Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?",
805     "         screenshot.save(filename,\"png\");",
806     "    } catch (Error e) {",
807     "        ",
808     "    }",
809     "",
810     "   ",
811     "    return;",
812     "    ",
813     "    ",
814     "     ",
815     "     ",
816     "    ",
817     "    // should we hold until it's printed...",
818     "    ",
819     "      ",
820     "",
821     "    ",
822     "    ",
823     "",
824     "",
825     "    ",
826     "     ",
827     "}",
828     ""
829    ],
830    "| void forwardSearch" : [
831     "(bool change_focus) {",
832     "",
833     "\tif (this.searchcontext == null) {",
834     "\t\treturn;",
835     "\t}",
836     "\tthis.notebook.el.page = 1;",
837     "\tGtk.TextIter beg, st,en, stl;",
838     "\t",
839     "\tvar buf = this.sourceview.el.get_buffer();",
840     "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
841     "\tif (!this.searchcontext.forward(beg, out st, out en)) {",
842     "\t\tthis.last_search_end = 0;",
843     "\t\treturn;",
844     "\t}",
845     "\tthis.last_search_end = en.get_offset();",
846     "\tif (change_focus) {",
847     "\t\tthis.sourceview.el.grab_focus();",
848     "\t}",
849     "\tbuf.place_cursor(st);",
850     "\t",
851     " ",
852     "\t ",
853     "\tthis.sourceview.el.scroll_to_iter(st,  0.0f, true, 0.0f, 0.5f);",
854     "\t",
855     "\t",
856     "\tvar ln = st.get_line();",
857     "\t",
858     "\tthis.highlightNodeAtLine(ln);",
859     "}\t",
860     "  "
861    ],
862    "| void highlightNodeAtLine" : [
863     "(int ln) {",
864     "",
865     "",
866     "\t ",
867     "\t// highlight node...",
868     "\t",
869     "\t\t",
870     "    var node = _this.file.lineToNode(ln+1);",
871     " ",
872     "    if (node == null) {",
873     "        //print(\"can not find node\\n\");",
874     "        return;",
875     "    }",
876     "    var prop = node.lineToProp(ln+1);",
877     "    print(\"prop : %s\", prop == null ? \"???\" : prop);",
878     "        ",
879     "        ",
880     "    // ---------- this selects the tree's node...",
881     "    ",
882     "    var ltree = _this.main_window.windowstate.left_tree;",
883     "    var tp = ltree.model.treePathFromNode(node);",
884     "    print(\"got tree path %s\\n\", tp);",
885     "    if (tp == \"\") {",
886     "\t\treturn;",
887     "\t}",
888     "    //_this.sourceview.allow_node_scroll = false; /// block node scrolling..",
889     "\t       ",
890     "   ",
891     "    //print(\"changing cursor on tree..\\n\");",
892     "   ",
893     "",
894     "    ",
895     "    // let's try allowing editing on the methods.",
896     "    // a little klunky at present..",
897     "\t_this.sourceview.prop_selected = \"\";",
898     "    if (prop != null) {",
899     "\t\t//see if we can find it..",
900     "\t\tvar kv = prop.split(\":\");",
901     "\t\tif (kv[0] == \"p\") {",
902     "\t\t",
903     "    \t\t//var k = prop.get_key(kv[1]);",
904     "    \t\t// fixme -- need to determine if it's an editable property...",
905     "    \t\t_this.sourceview.prop_selected = prop;",
906     "    \t\t",
907     "\t\t} else if (kv[0] == \"l\") {",
908     "\t\t\t _this.sourceview.prop_selected = prop;",
909     "\t\t\t",
910     "\t\t}",
911     "    }",
912     "    ltree.view.setCursor(tp, \"editor\");",
913     "   // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
914     "   _this.sourceview.nodeSelected(node,false);",
915     "    ",
916     "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
917     "      //      GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
918     "\t  //          this.allow_node_scroll = true;",
919     "\t  //          return false;",
920     "      //      });",
921     "      //  }",
922     "\t\t",
923     "\t\t",
924     "\t\t",
925     "\t\t",
926     "\t\t",
927     "\t\t",
928     "\t\t",
929     "\t\t",
930     "\t\t",
931     "\t\t ",
932     "",
933     "}",
934     " "
935    ],
936    "| void loadFile" : [
937     "(JsRender.JsRender file) ",
938     "{",
939     "        this.file = null;",
940     "        ",
941     "        if (file.tree == null) {",
942     "            return;",
943     "        }",
944     "        this.notebook.el.page = 0;// gtk preview ",
945     "   ",
946     "  ",
947     "        ",
948     "       this.file = file;     ",
949     "        this.sourceview.loadFile();",
950     "        this.searchcontext = null;",
951     "        ",
952     "",
953     "        if (this.lastObj != null) {",
954     "            this.container.el.remove(this.lastObj);",
955     "        }",
956     "        ",
957     "        // hide the compile view at present..",
958     "          ",
959     "        ",
960     "        var w = this.width;",
961     "        var h = this.height;",
962     "        ",
963     "        print(\"ALLOC SET SIZES %d, %d\\n\", w,h); ",
964     "        ",
965     "        // set the container size min to 500/500 or 20 px less than max..",
966     "        w = int.max (w-20, 500);",
967     "        h = int.max (h-20, 500); ",
968     "        ",
969     "        print(\"SET SIZES %d, %d\\n\", w,h);       ",
970     "        _this.container.el.set_size_request(w,h);",
971     "        ",
972     "        _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.",
973     "        var rgba = Gdk.RGBA ();",
974     "        rgba.parse (\"#ccc\");",
975     "        _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);",
976     "        ",
977     "        ",
978     "\tvar x = new JsRender.NodeToGtk((Project.Gtk) file.project, file.tree);",
979     "    var obj = x.munge() as Gtk.Widget;",
980     "    this.lastObj = null;",
981     "\tif (obj == null) {",
982     "        \treturn;",
983     "\t}",
984     "\tthis.lastObj = obj;",
985     "        ",
986     "        this.container.el.add(obj);",
987     "        obj.show_all();",
988     "        ",
989     "         ",
990     "        ",
991     "}",
992     " "
993    ],
994    "| void scroll_to_line" : [
995     "(int line) {",
996     "   this.notebook.el.page = 1;// code preview...",
997     "   ",
998     "   GLib.Timeout.add(500, () => {",
999     "   ",
1000     "   ",
1001     "\t   ",
1002     "\t   ",
1003     "\t\t  var buf = this.sourceview.el.get_buffer();",
1004     "\t ",
1005     "\t\tvar sbuf = (Gtk.SourceBuffer) buf;",
1006     "",
1007     "",
1008     "\t\tGtk.TextIter iter;   ",
1009     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1010     "\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1011     "\t\treturn false;",
1012     "\t});   ",
1013     "",
1014     "   ",
1015     "}",
1016     ""
1017    ]
1018   }
1019  ],
1020  "modOrder" : "",
1021  "name" : "GtkView",
1022  "parent" : "",
1023  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/GtkView.bjs",
1024  "permname" : "",
1025  "title" : ""
1026 }