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