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