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