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