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