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