3e9a9751a897db329db8f72cd90b89976e56b185
[roobuilder] / src / Builder4 / GtkView.bjs
1 {
2  "build_module" : "builder",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "# Gtk.Widget lastObj" : "null",
7    "# GtkSource.SearchContext searchcontext" : "",
8    "# JsRender.JsRender file" : "null",
9    "# Xcls_MainWindow main_window" : "",
10    "$ xns" : "Gtk",
11    "* init" : [
12     "{",
13     "",
14     "\tthis.css = new Gtk.CssProvider();",
15     "\t ",
16     "\tthis.css.load_from_string(",
17     "\t\t\"#gtkview-view-layout { background-color: #ccc; }\"",
18     "\t);",
19     "\t ",
20     "\tGtk.StyleContext.add_provider_for_display(",
21     "\t\tthis.el.get_display(),",
22     "\t\tthis.css,",
23     "\t\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
24     "\t);",
25     "\t\t",
26     "        ",
27     "}",
28     ""
29    ],
30    "Gtk.CssProvider css" : "",
31    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
32    "bool hexpand" : true,
33    "bool vexpand" : true,
34    "id" : "GtkView",
35    "int last_search_end" : 0,
36    "items" : [
37     {
38      "$ xns" : "Gtk",
39      "Gtk.Overflow overflow" : "Gtk.Overflow.VISIBLE",
40      "id" : "notebook",
41      "items" : [
42       {
43        "$ xns" : "Gtk",
44        "* pack" : false,
45        "id" : "label_preview",
46        "utf8 label" : "Preview",
47        "xtype" : "Label"
48       },
49       {
50        "$ xns" : "Gtk",
51        "* pack" : false,
52        "id" : "label_code",
53        "utf8 label" : "Preview Generated Code",
54        "xtype" : "Label"
55       },
56       {
57        "$ xns" : "Gtk",
58        "* pack" : "append_page,_this.label_preview.el",
59        "items" : [
60         {
61          "$ xns" : "Gtk",
62          "* pack" : "set_child",
63          "id" : "view_layout",
64          "items" : [
65           {
66            "$ xns" : "Gtk",
67            "* pack" : "put,10,10",
68            "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
69            "id" : "container",
70            "xtype" : "Box"
71           }
72          ],
73          "string name" : "gtkview-view-layout",
74          "xtype" : "Fixed"
75         }
76        ],
77        "xtype" : "ScrolledWindow"
78       },
79       {
80        "$ xns" : "Gtk",
81        "* pack" : "append_page,_this.label_code.el",
82        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
83        "int spacing" : 0,
84        "items" : [
85         {
86          "$ xns" : "Gtk",
87          "bool vexpand" : true,
88          "id" : "sourceviewscroll",
89          "items" : [
90           {
91            "# JsRender.Node? node_selected" : "",
92            "# string prop_selected" : "\"\"",
93            "$ xns" : "GtkSource",
94            "* init" : [
95             "{",
96             "   ",
97             "   ",
98             "   \tthis.css = new Gtk.CssProvider();",
99             "\t ",
100             "\tthis.css.load_from_string(\"#gtkview-view { font: 10px monospace ;}\");",
101             "\t ",
102             "\tGtk.StyleContext.add_provider_for_display(",
103             "\t\tthis.el.get_display(),",
104             "\t\tthis.css,",
105             "\t\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
106             "\t);",
107             "\t\t",
108             "\t\t ",
109             "    this.loading = true;",
110             "    ",
111             "  ",
112             "  ",
113             "    var attrs = new GtkSource.MarkAttributes();",
114             "    var  pink =   Gdk.RGBA();",
115             "    pink.parse ( \"pink\");",
116             "    attrs.set_background ( pink);",
117             "    attrs.set_icon_name ( \"process-stop\");    ",
118             "    attrs.query_tooltip_text.connect(( mark) => {",
119             "        //print(\"tooltip query? %s\\n\", mark.name);",
120             "        return mark.name;",
121             "    });",
122             "    ",
123             "    this.el.set_mark_attributes (\"ERR\", attrs, 1);",
124             "    ",
125             "     var wattrs = new GtkSource.MarkAttributes();",
126             "    var  blue =   Gdk.RGBA();",
127             "    blue.parse ( \"#ABF4EB\");",
128             "    wattrs.set_background ( blue);",
129             "    wattrs.set_icon_name ( \"process-stop\");    ",
130             "    wattrs.query_tooltip_text.connect(( mark) => {",
131             "        //print(\"tooltip query? %s\\n\", mark.name);",
132             "        return mark.name;",
133             "    });",
134             "    ",
135             "    this.el.set_mark_attributes (\"WARN\", wattrs, 1);",
136             "    ",
137             " ",
138             "    ",
139             "     var dattrs = new GtkSource.MarkAttributes();",
140             "    var  purple =   Gdk.RGBA();",
141             "    purple.parse ( \"#EEA9FF\");",
142             "    dattrs.set_background ( purple);",
143             "    dattrs.set_icon_name ( \"process-stop\");    ",
144             "    dattrs.query_tooltip_text.connect(( mark) => {",
145             "        //print(\"tooltip query? %s\\n\", mark.name);",
146             "        return mark.name;",
147             "    });",
148             "    ",
149             "    this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
150             "    ",
151             "    ",
152             "    var gattrs = new GtkSource.MarkAttributes();",
153             "    var  grey =   Gdk.RGBA();",
154             "    grey.parse ( \"#ccc\");",
155             "    gattrs.set_background ( grey);",
156             " ",
157             "    ",
158             "    this.el.set_mark_attributes (\"grey\", gattrs, 1);",
159             "    ",
160             "    ",
161             "    ",
162             "    ",
163             "    ",
164             "    ",
165             "}",
166             " "
167            ],
168            "* pack" : "set_child",
169            "Gtk.CssProvider css" : "",
170            "bool allow_node_scroll" : true,
171            "bool loading" : true,
172            "gboolean editable" : false,
173            "gboolean show_line_marks" : true,
174            "gboolean show_line_numbers" : true,
175            "id" : "sourceview",
176            "items" : [
177             {
178              "$ xns" : "GtkSource",
179              "* pack" : "set_buffer",
180              "bool dirty" : false,
181              "id" : "buffer",
182              "int error_line" : "-1",
183              "listeners" : {
184               "notify[\"cursor_position\"]" : [
185                "() => {",
186                "",
187                "",
188                "    if (_this.sourceview.loading) {",
189                "        return;",
190                "    }",
191                "   ",
192                "    GLib.debug(\"cursor changed : %d\", this.el.cursor_position);",
193                "    Gtk.TextIter cpos;",
194                "    this.el.get_iter_at_offset(out cpos, this.el.cursor_position);",
195                "    ",
196                "    var ln = cpos.get_line();",
197                "",
198                "    var node = _this.file.lineToNode(ln);",
199                "",
200                "    if (node == null) {",
201                "        print(\"can not find node\\n\");",
202                "        return;",
203                "    }",
204                "    _this.sourceview.loading = true;",
205                "    var ltree = _this.main_window.windowstate.left_tree;",
206                "    ltree.model.selectNode(node);",
207                "    _this.sourceview.loading = false;",
208                "    ",
209                "    //print(\"got tree path %s\\n\", tp);",
210                "    //if (tp != \"\") {",
211                "      // this.allow_node_scroll = false;        ",
212                "     //  print(\"changing cursor on tree..\\n\");",
213                "        //ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);",
214                "        // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
215                "        ///GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
216                "         //   this.allow_node_scroll = true;",
217                "         //   return false;",
218                "      //  });",
219                "   // }",
220                "    ",
221                "    // highlight the node..",
222                "    ",
223                "  ",
224                "",
225                " }"
226               ]
227              },
228              "xtype" : "Buffer"
229             },
230             {
231              "$ xns" : "Gtk",
232              "listeners" : {
233               "key_pressed" : [
234                "(keyval, keycode, state) => {",
235                "",
236                "\t",
237                "\t ",
238                "\t if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
239                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
240                "\t\t_this.forwardSearch(true);",
241                "\t    return true;",
242                "\t}",
243                "    if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
244                "\t    GLib.debug(\"SAVE: ctrl-f  pressed\");",
245                "\t\t_this.search_entry.el.grab_focus();",
246                "\t    return true;",
247                "\t}",
248                "\t ",
249                "\treturn false;",
250                "}\t ",
251                "\t"
252               ]
253              },
254              "xtype" : "EventControllerKey"
255             }
256            ],
257            "listeners" : {
258             "query_tooltip" : [
259              "(x, y, keyboard_tooltip, tooltip) => {",
260              "\t",
261              "\t//GLib.debug(\"query tooltip\");",
262              "\tGtk.TextIter iter;",
263              "\tint trailing;",
264              "\t",
265              "\tvar yoff = (int) _this.sourceviewscroll.el.vadjustment.value;",
266              "\t",
267              "\tthis.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);",
268              "\t ",
269              "\tvar l = iter.get_line();",
270              "\t// GLib.debug(\"query tooltip line %d\", (int) l);",
271              "\tvar marks = _this.buffer.el.get_source_marks_at_line(l, \"ERR\");",
272              "\tif (marks.is_empty()) {",
273              "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"WARN\");",
274              "\t}",
275              "\tif (marks.is_empty()) {",
276              "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"DEPR\");",
277              "\t}",
278              "\t",
279              "\t// GLib.debug(\"query tooltip line marks %d\", (int) marks.length());",
280              "\tvar str = \"\";",
281              "\tmarks.@foreach((m) => { ",
282              "\t\t//GLib.debug(\"got mark %s\", m.name);",
283              "\t\tstr += (str.length > 0 ? \"\\n\" : \"\") + m.name;",
284              "\t});",
285              "\t",
286              "\t// true if there is a mark..",
287              "\ttooltip.set_text( str);",
288              "\treturn str.length > 0 ? true : false;",
289              "",
290              "}",
291              ""
292             ]
293            },
294            "string name" : "gtkview-view",
295            "xtype" : "View",
296            "| string toString" : [
297             "() {",
298             "   Gtk.TextIter s;",
299             "    Gtk.TextIter e;",
300             "    this.el.get_buffer().get_start_iter(out s);",
301             "    this.el.get_buffer().get_end_iter(out e);",
302             "    var ret = this.el.get_buffer().get_text(s,e,true);",
303             "    //print(\"TO STRING? \" + ret);",
304             "    return ret;",
305             "}",
306             ""
307            ],
308            "| void highlightErrorsJson" : [
309             " (string type, Json.Object obj) {",
310             "      Gtk.TextIter start;",
311             "     Gtk.TextIter end;   ",
312             "     ",
313             "     var buf =  this.el.get_buffer();",
314             "       var sbuf = (GtkSource.Buffer)buf;",
315             "        buf.get_bounds (out start, out end);",
316             "        ",
317             "        sbuf.remove_source_marks (start, end, type);",
318             "                 ",
319             "     ",
320             "     // we should highlight other types of errors..",
321             "    ",
322             "    if (!obj.has_member(type)) {",
323             "        GLib.debug(\"Return has no errors\\n\");",
324             "        return  ;",
325             "    }",
326             "    var err = obj.get_object_member(type);",
327             "    ",
328             "    if (_this.file == null) { ",
329             "\t",
330             "        return; // just in case the file has not loaded yet?",
331             "    }",
332             " ",
333             "",
334             "    var valafn = \"\";",
335             "      try {             ",
336             "           var  regex = new Regex(\"\\\\.bjs$\");",
337             "        ",
338             "         ",
339             "            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
340             "         } catch (GLib.RegexError e) {",
341             "            return;",
342             "        }   ",
343             "",
344             "   if (!err.has_member(valafn)) {",
345             "        GLib.debug(\"File path has no errors\\n\");",
346             "        return  ;",
347             "    }",
348             "    var lines = err.get_object_member(valafn);",
349             "    ",
350             "   ",
351             "    ",
352             "    var tlines = buf.get_line_count () +1;",
353             "    ",
354             "    lines.foreach_member((obj, line, node) => {",
355             "        ",
356             "             Gtk.TextIter iter;",
357             "    //        print(\"get inter\\n\");",
358             "            var eline = int.parse(line) -1  ;",
359             "            GLib.debug(\"GOT ERROR on line %s -- converted to %d\\n\", line,eline);",
360             "            ",
361             "            ",
362             "            if (eline > tlines || eline < 0) {",
363             "                return;",
364             "            }",
365             "            sbuf.get_iter_at_line( out iter, eline);",
366             "            //print(\"mark line\\n\");",
367             "            var msg  = type + \" on line: %d - %s\".printf(eline+1, valafn);",
368             "            var ar = lines.get_array_member(line);",
369             "            for (var i = 0 ; i < ar.get_length(); i++) {",
370             "\t\t    msg += (msg.length > 0) ? \"\\n\" : \"\";",
371             "\t\t    msg += ar.get_string_element(i);",
372             "\t    }",
373             "            ",
374             "            ",
375             "            sbuf.create_source_mark(msg, type, iter);",
376             "        } );",
377             "        return  ;",
378             "    ",
379             " ",
380             "",
381             "",
382             "}"
383            ],
384            "| void loadFile" : [
385             "( ) {",
386             "    this.loading = true;",
387             "    var buf = this.el.get_buffer();",
388             "    buf.set_text(\"\",0);",
389             "    var sbuf = (GtkSource.Buffer) buf;",
390             "",
391             "    ",
392             "",
393             "    if (_this.file == null || _this.file.xtype != \"Gtk\") {",
394             "        print(\"xtype != Gtk\");",
395             "        this.loading = false;",
396             "        return;",
397             "    }",
398             "    ",
399             "    var valafn = \"\";",
400             "      try {             ",
401             "           var  regex = new Regex(\"\\\\.bjs$\");",
402             "        ",
403             "         ",
404             "            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
405             "         } catch (GLib.RegexError e) {",
406             "             this.loading = false;",
407             "            return;",
408             "        }   ",
409             "    ",
410             "",
411             "   if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {",
412             "        print(\"File path has no errors\\n\");",
413             "        this.loading = false;",
414             "        return  ;",
415             "    }",
416             "    ",
417             "    string str;",
418             "    try {",
419             "    ",
420             "        GLib.FileUtils.get_contents (valafn, out str);",
421             "    } catch (Error e) {",
422             "        this.loading = false;",
423             "        return  ;",
424             "    }",
425             "",
426             "//    print(\"setting str %d\\n\", str.length);",
427             "    buf.set_text(str, str.length);",
428             "    var lm = GtkSource.LanguageManager.get_default();",
429             "     ",
430             "    //?? is javascript going to work as js?",
431             "    ",
432             "    ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));",
433             "  ",
434             "    ",
435             "    Gtk.TextIter start;",
436             "    Gtk.TextIter end;     ",
437             "        ",
438             "    sbuf.get_bounds (out start, out end);",
439             "    sbuf.remove_source_marks (start, end, null); // remove all marks..",
440             "    ",
441             "    ",
442             "    if (_this.main_window.windowstate.last_compile_result != null) {",
443             "        var obj = _this.main_window.windowstate.last_compile_result;",
444             "        this.highlightErrorsJson(\"ERR\", obj);",
445             "        this.highlightErrorsJson(\"WARN\", obj);",
446             "        this.highlightErrorsJson(\"DEPR\", obj);\t\t\t",
447             "    }",
448             "    // while (Gtk.events_pending()) {",
449             "     //   Gtk.main_iteration();",
450             "   // }",
451             "    ",
452             "    this.loading = false; ",
453             "}",
454             ""
455            ],
456            "| void nodeSelected" : [
457             "(JsRender.Node? sel, bool scroll) {",
458             "  ",
459             "    ",
460             "    if (this.loading) {",
461             "    \treturn;",
462             "\t}",
463             "    // this is connected in widnowstate",
464             "    print(\"Roo-view - node selected\\n\");",
465             "    var buf = this.el.get_buffer();",
466             " ",
467             "    var sbuf = (GtkSource.Buffer) buf;",
468             "",
469             "   ",
470             "    // while(Gtk.events_pending()) {",
471             "     //    Gtk.main_iteration();",
472             "   //  }",
473             "    ",
474             "   ",
475             "    // clear all the marks..",
476             "     Gtk.TextIter start;",
477             "    Gtk.TextIter end;     ",
478             "        ",
479             "    sbuf.get_bounds (out start, out end);",
480             "    sbuf.remove_source_marks (start, end, \"grey\");",
481             "    ",
482             "        this.node_selected = sel;",
483             "     if (sel == null) {",
484             "        // no highlighting..",
485             "        return;",
486             "    }",
487             "    Gtk.TextIter iter;   ",
488             "    sbuf.get_iter_at_line(out iter,  sel.line_start);",
489             "    ",
490             "    ",
491             "    Gtk.TextIter cur_iter;",
492             "    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
493             "    ",
494             "    //var cur_line = cur_iter.get_line();",
495             "    //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
496             "    ",
497             "    //} else {",
498             "    if (this.allow_node_scroll) {",
499             "\t\t ",
500             "    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
501             "\t}",
502             "    ",
503             "     ",
504             "    ",
505             "    for (var i = 0; i < buf.get_line_count();i++) {",
506             "        if (i < sel.line_start || i > sel.line_end) {",
507             "           ",
508             "            sbuf.get_iter_at_line(out iter, i);",
509             "            sbuf.create_source_mark(null, \"grey\", iter);",
510             "            ",
511             "        }",
512             "    ",
513             "    }",
514             "    ",
515             "",
516             "}",
517             ""
518            ]
519           }
520          ],
521          "xtype" : "ScrolledWindow"
522         },
523         {
524          "$ xns" : "Gtk",
525          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
526          "bool homogeneous" : false,
527          "bool vexpand" : false,
528          "int spacing" : 0,
529          "items" : [
530           {
531            "$ xns" : "Gtk",
532            "* init" : [
533             " ",
534             "this.css = new Gtk.CssProvider();",
535             "",
536             "this.css.load_from_string(\"",
537             "\t#gtkview-search-entry { font: 10px monospace ;}\"",
538             ");",
539             "",
540             "Gtk.StyleContext.add_provider_for_display(",
541             "\tthis.el.get_display(),",
542             "\tthis.css,",
543             "\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
544             ");",
545             "\t\t",
546             "",
547             ""
548            ],
549            "Gtk.CssProvider css" : "",
550            "bool hexpand" : true,
551            "id" : "search_entry",
552            "items" : [
553             {
554              "$ xns" : "Gtk",
555              "listeners" : {
556               "key_pressed" : [
557                "(keyval, keycode, state) => {",
558                "",
559                "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
560                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
561                "\t\t_this.forwardSearch(true);",
562                "\t    return true;",
563                "\t}",
564                "    ",
565                "  ",
566                " \tif (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {",
567                "\t\t_this.forwardSearch(true);",
568                "\t\t",
569                "\t\t",
570                "\t    return true;",
571                "",
572                "\t}    ",
573                "   // print(event.key.keyval)",
574                "   ",
575                "    return false;",
576                "}",
577                ""
578               ]
579              },
580              "xtype" : "EventControllerKey"
581             }
582            ],
583            "listeners" : {
584             "search_changed" : [
585              " () => {",
586              "  \t ",
587              "\t_this.search(_this.search_entry.el.text);",
588              "\t _this.search_results.updateResults();",
589              "",
590              "\tGLib.Timeout.add_seconds(1,() => {",
591              "\t\t _this.search_results.updateResults();",
592              "\t\t return false;",
593              "\t });",
594              "\t  ",
595              "   ",
596              "    ",
597              "}"
598             ]
599            },
600            "string name" : "gtkview-search-entry",
601            "string placeholder_text" : "Press enter to search",
602            "uint search_delay" : 3,
603            "xtype" : "SearchEntry",
604            "| void forwardSearch" : [
605             "(bool change_focus) {",
606             "",
607             "",
608             "\t_this.forwardSearch(change_focus);",
609             "",
610             "/*",
611             "",
612             "\tswitch(_this.windowstate.state) {",
613             "\t\tcase WindowState.State.CODEONLY:",
614             "\t\t//case WindowState.State.CODE:",
615             "\t\t\t// search the code being edited..",
616             "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
617             "\t\t\t ",
618             "\t\t\tbreak;",
619             "\t\tcase WindowState.State.PREVIEW:",
620             "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
621             "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
622             "\t\t\t} else { ",
623             "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
624             "\t\t\t}",
625             "\t\t",
626             "\t\t\tbreak;",
627             "\t}",
628             "\t*/",
629             "\t",
630             "}",
631             ""
632            ]
633           },
634           {
635            "$ xns" : "Gtk",
636            "id" : "search_results",
637            "int margin_end" : 4,
638            "int margin_start" : 4,
639            "string label" : "No Results",
640            "xtype" : "Label",
641            "| void updateResults" : [
642             "() {",
643             "\tthis.el.visible = true;",
644             "\t",
645             "\tvar res = _this.searchcontext.get_occurrences_count();",
646             "\tif (res < 0) {",
647             "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
648             "\t\treturn;",
649             "\t}",
650             "",
651             "\t_this.nextBtn.el.sensitive = false;",
652             "\t_this.backBtn.el.sensitive = false;\t",
653             "",
654             "\tif (res > 0) {",
655             "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
656             "\t\t_this.nextBtn.el.sensitive = true;",
657             "\t\t_this.backBtn.el.sensitive = true;",
658             "\t\treturn;",
659             "\t} ",
660             "\t_this.search_results.el.label = \"No Matches\";",
661             "\t",
662             "}"
663            ]
664           },
665           {
666            "$ xns" : "Gtk",
667            "bool always_show_image" : true,
668            "bool sensitive" : false,
669            "id" : "nextBtn",
670            "listeners" : {
671             "clicked" : [
672              "( ) => {",
673              "_this.forwardSearch(true);",
674              "\t ",
675              "",
676              "}",
677              ""
678             ]
679            },
680            "string icon_name" : "go-down",
681            "xtype" : "Button"
682           },
683           {
684            "$ xns" : "Gtk",
685            "bool always_show_image" : true,
686            "bool sensitive" : false,
687            "id" : "backBtn",
688            "listeners" : {
689             "clicked" : [
690              "( ) => {",
691              "",
692              "_this.backSearch(true);",
693              "\t",
694              "}",
695              ""
696             ]
697            },
698            "string icon_name" : "go-up",
699            "xtype" : "Button"
700           },
701           {
702            "$ xns" : "Gtk",
703            "bool always_show_arrow" : true,
704            "bool always_show_image" : true,
705            "items" : [
706             {
707              "$ xns" : "Gtk",
708              "* ctor" : "new Gtk.PopoverMenu.from_model(null)",
709              "* prop" : "popover",
710              "id" : "search_settings",
711              "items" : [
712               {
713                "$ xns" : "Gtk",
714                "* pack" : "set_child",
715                "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
716                "int spacing" : 0,
717                "items" : [
718                 {
719                  "$ xns" : "Gtk",
720                  "id" : "case_sensitive",
721                  "string label" : "Case Sensitive",
722                  "xtype" : "CheckButton"
723                 },
724                 {
725                  "$ xns" : "Gtk",
726                  "id" : "regex",
727                  "string label" : "Regex",
728                  "xtype" : "CheckButton"
729                 },
730                 {
731                  "$ xns" : "Gtk",
732                  "id" : "multiline",
733                  "string label" : "Multi-line (add \\n)",
734                  "xtype" : "CheckButton"
735                 }
736                ],
737                "xtype" : "Box"
738               }
739              ],
740              "xtype" : "PopoverMenu"
741             }
742            ],
743            "string icon_name" : "emblem-system",
744            "xtype" : "MenuButton"
745           }
746          ],
747          "xtype" : "Box"
748         }
749        ],
750        "xtype" : "Box"
751       }
752      ],
753      "xtype" : "Notebook"
754     }
755    ],
756    "xtype" : "Box",
757    "| int search" : [
758     "(string in_txt) {",
759     "\tthis.notebook.el.page = 1;",
760     "\t",
761     " ",
762     "   ",
763     "\tvar s = new GtkSource.SearchSettings();",
764     "\ts.case_sensitive = _this.case_sensitive.el.active;",
765     "\ts.regex_enabled = _this.regex.el.active;\t",
766     "\ts.wrap_around = false;",
767     "\t",
768     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
769     "\tthis.searchcontext.set_highlight(true);",
770     "\tvar txt = in_txt;",
771     "\t",
772     "\tif (_this.multiline.el.active) {",
773     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
774     "\t}",
775     "\t",
776     "\ts.set_search_text(txt);",
777     "\tGtk.TextIter beg, st,en;",
778     "\tbool has_wrapped_around;",
779     "\tthis.buffer.el.get_start_iter(out beg);",
780     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
781     "\tthis.last_search_end = 0;",
782     "\t",
783     "\treturn this.searchcontext.get_occurrences_count();",
784     "",
785     " ",
786     "    ",
787     "",
788     "}",
789     ""
790    ],
791    "| void backSearch" : [
792     "(bool change_focus) {",
793     "",
794     "\tif (this.searchcontext == null) {",
795     "\t\treturn;",
796     "\t} ",
797     "\t",
798     "\tGtk.TextIter beg, st,en;",
799     "\tbool has_wrapped_around;",
800     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
801     "\t",
802     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
803     "\t",
804     "\t\tthis.last_search_end = 0;",
805     "\t\treturn;",
806     "\t}",
807     "\tthis.last_search_end = en.get_offset();",
808     "\tif (change_focus) {",
809     "\t\tthis.sourceview.el.grab_focus();",
810     "\t}",
811     "\tthis.buffer.el.place_cursor(st);",
812     "\tthis.sourceview.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
813     "\tvar ln = st.get_line();",
814     "\tthis.highlightNodeAtLine(ln);",
815     "\t ",
816     "}",
817     ""
818    ],
819    "| void createThumb" : [
820     "() {",
821     "    ",
822     "    ",
823     "    if (this.file == null) {",
824     "        return;",
825     "    }",
826     "    // only screenshot the gtk preview..",
827     "    if (this.notebook.el.page > 0 ) {",
828     "        return;",
829     "    }",
830     "    ",
831     "    ",
832     " \tthis.file.widgetToIcon(this.container.el); ",
833     "",
834     "    ",
835     "    return;",
836     "    ",
837     "    ",
838     "     ",
839     "     ",
840     "    ",
841     "    // should we hold until it's printed...",
842     "     ",
843     "",
844     "    ",
845     "     ",
846     "}",
847     ""
848    ],
849    "| void forwardSearch" : [
850     "(bool change_focus) {",
851     "",
852     "\tif (this.searchcontext == null) {",
853     "\t\treturn;",
854     "\t}",
855     "\tthis.notebook.el.page = 1;",
856     "\tGtk.TextIter beg, st,en;",
857     "\tbool has_wrapped_around;",
858     "\tvar buf = this.sourceview.el.get_buffer();",
859     "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
860     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
861     "\t\tthis.last_search_end = 0;",
862     "\t\treturn;",
863     "\t}",
864     "\tthis.last_search_end = en.get_offset();",
865     "\tif (change_focus) {",
866     "\t\tthis.sourceview.el.grab_focus();",
867     "\t}",
868     "\tbuf.place_cursor(st);",
869     "\t",
870     " ",
871     "\t ",
872     "\tthis.sourceview.el.scroll_to_iter(st,  0.0f, true, 0.0f, 0.5f);",
873     "\t",
874     "\t",
875     "\tvar ln = st.get_line();",
876     "\t",
877     "\tthis.highlightNodeAtLine(ln);",
878     "}\t",
879     "  "
880    ],
881    "| void highlightNodeAtLine" : [
882     "(int ln) {",
883     "",
884     "\t// this is done from clicking on the editor..",
885     "\t ",
886     "\t// highlight node...",
887     "\t",
888     "\t\t",
889     "    var node = _this.file.lineToNode(ln+1);",
890     " ",
891     "    if (node == null) {",
892     "        //print(\"can not find node\\n\");",
893     "        return;",
894     "    }",
895     "    var prop = node.lineToProp(ln+1);",
896     "    print(\"prop : %s\", prop == null ? \"???\" : prop.name);",
897     "        ",
898     "        ",
899     "    // ---------- this selects the tree's node...",
900     "    ",
901     "    var ltree = _this.main_window.windowstate.left_tree;",
902     "    ltree.model.selectNode(node);",
903     "    //var tp = ltree.model.treePathFromNode(node);",
904     "    ",
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     "\t/*",
920     "    if (prop != null) {",
921     "\t\t//see if we can find it..",
922     "\t\tvar kv = prop.split(\":\");",
923     "\t\tif (kv[0] == \"p\") {",
924     "\t\t",
925     "    \t\t//var k = prop.get_key(kv[1]);",
926     "    \t\t// fixme -- need to determine if it's an editable property...",
927     "    \t\t_this.sourceview.prop_selected = prop;",
928     "    \t\t",
929     "\t\t} else if (kv[0] == \"l\") {",
930     "\t\t\t _this.sourceview.prop_selected = prop;",
931     "\t\t\t",
932     "\t\t}",
933     "    }",
934     "    */",
935     "    //ltree.view.setCursor(tp, \"editor\");",
936     "   // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
937     "   _this.sourceview.nodeSelected(node,false);",
938     "    ",
939     "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
940     "      //      GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
941     "\t  //          this.allow_node_scroll = true;",
942     "\t  //          return false;",
943     "      //      });",
944     "      //  }",
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     "\t\t",
954     "\t\t ",
955     "",
956     "}",
957     " "
958    ],
959    "| void loadFile" : [
960     "(JsRender.JsRender file) ",
961     "{",
962     "        this.file = null;",
963     "        ",
964     "        if (file.tree == null) {",
965     "            return;",
966     "        }",
967     "        this.notebook.el.page = 0;// gtk preview ",
968     "   ",
969     "  ",
970     "        ",
971     "       this.file = file;     ",
972     "        this.sourceview.loadFile();",
973     "        this.searchcontext = null;",
974     "        ",
975     "",
976     "        if (this.lastObj != null) {",
977     "            this.container.el.remove(this.lastObj);",
978     "        }",
979     "        ",
980     "        // hide the compile view at present..",
981     "          ",
982     "        ",
983     "        var w = this.el.get_width();",
984     "        var h = this.el.get_height();",
985     "        ",
986     "        print(\"ALLOC SET SIZES %d, %d\\n\", w,h); ",
987     "        ",
988     "        // set the container size min to 500/500 or 20 px less than max..",
989     "        w = int.max (w-20, 500);",
990     "        h = int.max (h-20, 500); ",
991     "        ",
992     "        print(\"SET SIZES %d, %d\\n\", w,h);       ",
993     "        _this.container.el.set_size_request(w,h);",
994     "        ",
995     "        _this.view_layout.el.set_size_request(w,h); ",
996     "        // should be baded on calc.. -- see update_scrolled.",
997     "       ",
998     "       var fc = this.container.el.get_first_child();",
999     "       if (fc != null) {",
1000     "       \t\tthis.container.el.remove(fc);",
1001     "   \t\t}",
1002     "        ",
1003     "   \t\tvar xmlstr = JsRender.NodeToGlade.mungeFile( file);",
1004     "   \t\tvar builder = new Gtk.Builder.from_string (xmlstr, xmlstr.length);",
1005     "   \t\tvar obj = (Gtk.Widget) builder.get_object(\"w\"+ file.tree.oid.to_string());",
1006     "   \t\t this.container.el.append(obj);",
1007     "\t    obj.show();",
1008     "        this.createThumb();",
1009     "         ",
1010     "        \t ",
1011     "       return;/*",
1012     "\tvar x = new JsRender.NodeToGtk((Project.Gtk) file.project, file.tree);",
1013     "    var obj = x.munge() as Gtk.Widget;",
1014     "    this.lastObj = null;",
1015     "\tif (obj == null) {",
1016     "        \treturn;",
1017     "\t}",
1018     "\tthis.lastObj = obj;",
1019     "        ",
1020     "        this.container.el.append(obj);",
1021     "        obj.show();",
1022     "        ",
1023     "         */",
1024     "        ",
1025     "}",
1026     " "
1027    ],
1028    "| void scroll_to_line" : [
1029     "(int line) {",
1030     "  // code preview...",
1031     "   ",
1032     "   GLib.Timeout.add(100, () => {",
1033     "   ",
1034     "   ",
1035     "\t    this.notebook.el.set_current_page(1);",
1036     "\t   ",
1037     "\t\t  var buf = this.sourceview.el.get_buffer();",
1038     "\t ",
1039     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1040     "",
1041     "",
1042     "\t\tGtk.TextIter iter;   ",
1043     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1044     "\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1045     "\t\treturn false;",
1046     "\t});   ",
1047     "",
1048     "   ",
1049     "}",
1050     ""
1051    ]
1052   }
1053  ],
1054  "name" : "GtkView"
1055 }