Fix #8104 - update nav tree by comparing changes
[roobuilder] / src / Builder4 / Editor.bjs
1 {
2  "build_module" : "builder",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "# GtkSource.SearchContext searchcontext" : "null",
7    "# JsRender.JsRender? file" : "null",
8    "# JsRender.Node node" : "null",
9    "# JsRender.NodeProp? prop" : "null",
10    "# Xcls_MainWindow window" : "null",
11    "# bool dirty" : false,
12    "# bool pos" : false,
13    "# int last_error_counter" : 0,
14    "# int pos_root_x" : "",
15    "# int pos_root_y" : "",
16    "# string activeEditor" : "\"\"",
17    "$ homogeneous" : false,
18    "$ xns" : "Gtk",
19    "@ void save" : "()",
20    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
21    "bool hexpand" : true,
22    "bool vexpand" : true,
23    "int last_search_end" : 0,
24    "items" : [
25     {
26      "$ xns" : "Gtk",
27      "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
28      "items" : [
29       {
30        "$ xns" : "Gtk",
31        "* prop" : "start_child",
32        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
33        "int spacing" : 0,
34        "items" : [
35         {
36          "$ homogeneous" : false,
37          "$ xns" : "Gtk",
38          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
39          "bool hexpand" : true,
40          "items" : [
41           {
42            "$ xns" : "Gtk",
43            "id" : "save_button",
44            "label" : "Save",
45            "listeners" : {
46             "clicked" : [
47              " () => { ",
48              "    _this.saveContents();",
49              "}",
50              "  "
51             ]
52            },
53            "xtype" : "Button"
54           },
55           {
56            "$ xns" : "Gtk",
57            "bool hexpand" : true,
58            "xtype" : "Label"
59           },
60           {
61            "$ xns" : "Gtk",
62            "* ctor" : "new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1)",
63            "* init" : [
64             "{",
65             "\t//this.el.set_range(6,30);",
66             " \tthis.el.set_value ( BuilderApplication.settings.editor_font_size);",
67             " \tBuilderApplication.settings.editor_font_size_updated.connect(",
68             " \t\t() => {",
69             " \t\t\tBuilderApplication.settings.editor_font_size_inchange = true;",
70             " \t\t//\tGLib.debug(\"update range\");",
71             " \t\t \tthis.el.set_value (BuilderApplication.settings.editor_font_size);",
72             " \t\t \tBuilderApplication.settings.editor_font_size_inchange = false;",
73             " \t\t}",
74             "\t);",
75             "\t",
76             " ",
77             "}",
78             ""
79            ],
80            "bool draw_value" : false,
81            "bool has_origin" : true,
82            "bool sensitive" : true,
83            "int digits" : 0,
84            "int width_request" : 200,
85            "listeners" : {
86             "change_value" : [
87              "(st, val ) => {",
88              "\tif (BuilderApplication.settings.editor_font_size_inchange) {",
89              "\t\treturn false;",
90              "\t}",
91              "  \tBuilderApplication.settings.editor_font_size = val;",
92              " \treturn false;",
93              "}"
94             ]
95            },
96            "xtype" : "Scale"
97           },
98           {
99            "$ xns" : "Gtk",
100            "id" : "close_btn",
101            "items" : [
102             {
103              "$ xns" : "Gtk",
104              "* prop" : "child",
105              "Gtk.IconSize icon_size" : "Gtk.IconSize.NORMAL",
106              "string icon_name" : "window-close",
107              "xtype" : "Image"
108             }
109            ],
110            "listeners" : {
111             "clicked" : [
112              " () => { ",
113              "    _this.saveContents();",
114              "    _this.window.windowstate.switchState(WindowState.State.PREVIEW);",
115              "}",
116              "  "
117             ]
118            },
119            "string icon_name" : "window-close",
120            "xtype" : "Button"
121           }
122          ],
123          "xtype" : "Box"
124         },
125         {
126          "$ xns" : "Gtk",
127          "Gtk.PolicyType hscrollbar_policy" : "Gtk.PolicyType.AUTOMATIC",
128          "Gtk.PolicyType vscrollbar_policy" : "Gtk.PolicyType.AUTOMATIC",
129          "bool overlay_scrolling" : false,
130          "bool vexpand" : true,
131          "id" : "RightEditor",
132          "items" : [
133           {
134            "# Gtk.CssProvider css" : "null",
135            "$ gboolean auto_indent" : true,
136            "$ xns" : "GtkSource",
137            "* init" : [
138             "",
139             " ",
140             "\t",
141             " ",
142             " ",
143             "this.el.completion.add_provider(",
144             "\tnew Palete.CompletionProvider(_this)",
145             ");",
146             "",
147             "// hover seems pretty useless.. - ??",
148             "//var hover = this.el.get_hover();",
149             "//hover.add_provider(new Palete.HoverProvider(_this));",
150             "",
151             "//this.el.completion.unblock_interactive();",
152             "this.el.completion.select_on_show = true; // select",
153             "//this.el.completion.remember_info_visibility\t = true;",
154             "",
155             "",
156             "var attrs = new GtkSource.MarkAttributes();",
157             "",
158             "attrs.set_icon_name ( \"process-stop\");    ",
159             "attrs.query_tooltip_text.connect(( mark) => {",
160             "     GLib.debug(\"tooltip query? %s\", mark.name);",
161             "    return strdup( mark.name);",
162             "});",
163             " attrs.query_tooltip_markup.connect(( mark) => {",
164             "     GLib.debug(\"tooltip query? %s\", mark.name);",
165             "    return strdup( mark.name);",
166             "});",
167             "this.el.set_mark_attributes (\"ERR\", attrs, 1);",
168             "attrs.ref();",
169             "",
170             "",
171             "var wattrs = new GtkSource.MarkAttributes();",
172             "wattrs.set_icon_name ( \"process-stop\");    ",
173             "wattrs.query_tooltip_text.connect(( mark) => {",
174             "     GLib.debug(\"tooltip query? %s\", mark.name);",
175             "    return strdup(mark.name);",
176             "});",
177             "wattrs.query_tooltip_markup.connect(( mark) => {",
178             "     GLib.debug(\"tooltip query? %s\", mark.name);",
179             "    return strdup(mark.name);",
180             "});",
181             "this.el.set_mark_attributes (\"WARN\", wattrs, 1);",
182             "wattrs.ref();",
183             "",
184             " ",
185             "var dattrs = new GtkSource.MarkAttributes();",
186             " ",
187             "dattrs.set_icon_name ( \"process-stop\"); ",
188             "",
189             "dattrs.query_tooltip_text.connect(( mark) => {",
190             "\tGLib.debug(\"tooltip query? %s\", mark.name);",
191             "    return strdup(mark.name);",
192             "});",
193             "//dattrs.query_tooltip_markup.connect(( mark) => {",
194             "//\tGLib.debug(\"tooltip query? %s\", mark.name);",
195             " //   return strdup(mark.name);",
196             "//});",
197             "this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
198             "dattrs.ref();    ",
199             "",
200             " this.el.get_space_drawer().set_matrix(null);",
201             " this.el.get_space_drawer().set_types_for_locations( ",
202             "\tGtkSource.SpaceLocationFlags.ALL,",
203             "\tGtkSource.SpaceTypeFlags.ALL",
204             ");",
205             "this.el.get_space_drawer().set_enable_matrix(true);",
206             ""
207            ],
208            "* prop" : "child",
209            "bool has_tooltip" : true,
210            "bool hexpand" : true,
211            "bool insert_spaces_instead_of_tabs" : true,
212            "bool vexpand" : true,
213            "boolean show_line_marks" : true,
214            "boolean show_line_numbers" : true,
215            "css_classes" : "{ \"code-editor\" }",
216            "gboolean highlight_current_line" : true,
217            "id" : "view",
218            "indent_width" : 4,
219            "items" : [
220             {
221              "$ Gee.HashMap<int,string>? xmarks" : "null",
222              "$ xns" : "GtkSource",
223              "$ xtype" : "Buffer",
224              "* init" : [
225               "",
226               "var buf = this.el;",
227               "buf.create_tag (\"bold\", \"weight\", Pango.Weight.BOLD);",
228               "buf.create_tag (\"type\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#204a87\");",
229               "buf.create_tag (\"keyword\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#a40000\");",
230               "buf.create_tag (\"text\", \"weight\", Pango.Weight.NORMAL, \"foreground\", \"#729fcf\");",
231               "buf.create_tag (\"number\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#ad7fa8\");",
232               "buf.create_tag (\"method\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#729fcf\");",
233               "buf.create_tag (\"property\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#BC1F51\");",
234               "buf.create_tag (\"variable\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#A518B5\");",
235               "",
236               "",
237               "buf.create_tag (\"ERR\", \"weight\", Pango.Weight.BOLD, \"background\", \"pink\");",
238               "buf.create_tag (\"WARN\", \"weight\", Pango.Weight.BOLD, \"background\", \"#ABF4EB\");",
239               "buf.create_tag (\"DEPR\", \"weight\", Pango.Weight.BOLD, \"background\", \"#EEA9FF\");",
240               "",
241               "",
242               ""
243              ],
244              "* prop" : "buffer",
245              "bool check_queued" : false,
246              "bool enable_undo" : true,
247              "bool highlight_matching_brackets" : true,
248              "bool highlight_syntax" : true,
249              "id" : "buffer",
250              "int error_line" : "-1",
251              "listeners" : {
252               "changed" : [
253                " () => {",
254                "    // check syntax??",
255                "    // ??needed..??",
256                "    _this.save_button.el.sensitive = true;",
257                "    print(\"EDITOR CHANGED\");",
258                "    this.checkSyntax();",
259                "   ",
260                "    _this.dirty = true;",
261                "",
262                "    // this.get('/LeftPanel.model').changed(  str , false);",
263                "    return ;",
264                "}",
265                ""
266               ],
267               "cursor_moved" : [
268                "( ) => {",
269                "",
270                "\tGtk.TextIter iter;",
271                "\tthis.el.get_iter_at_offset (",
272                "\t\t\tout iter, this.el.cursor_position);",
273                "",
274                "\t_this.navigation.updateSelectedLine(",
275                "\t\t\t(uint)iter.get_line(),",
276                "\t\t\t(uint)iter.get_line_offset()",
277                "\t\t);",
278                "",
279                "",
280                "}",
281                ""
282               ]
283              },
284              "| bool OLDhighlightErrorsJson" : [
285               "(string type, Json.Object obj) {",
286               "\tGtk.TextIter start;",
287               "\tGtk.TextIter end;     ",
288               "\tthis.el.get_bounds (out start, out end);",
289               "",
290               "\tthis.el.remove_source_marks (start, end, type);",
291               "\tGLib.debug(\"highlight errors\");\t\t ",
292               "",
293               "\t // we should highlight other types of errors..",
294               "",
295               "\tif (!obj.has_member(type)) {",
296               "\t\tGLib.debug(\"Return has no errors\\n\");",
297               "\t\treturn true;",
298               "\t}",
299               "",
300               "\tif (_this.window.windowstate.state != WindowState.State.CODEONLY ",
301               "\t\t&&",
302               "\t\t_this.window.windowstate.state != WindowState.State.CODE",
303               "\t\t) {",
304               "\t\tGLib.debug(\"windowstate != CODEONLY?\");",
305               "\t\t",
306               "\t\treturn true;",
307               "\t} ",
308               "",
309               "\t//this.marks = new Gee.HashMap<int,string>();",
310               "\tvar err = obj.get_object_member(type);",
311               " ",
312               "\tif (_this.file == null) {",
313               "\t\tGLib.debug(\"file is null?\");",
314               "\t\treturn true;",
315               "",
316               "\t}",
317               "\tvar valafn = _this.file.path;",
318               "",
319               "\tif (_this.file.xtype != \"PlainFile\") {",
320               "",
321               "\t\tvalafn = \"\";",
322               "\t\ttry {             ",
323               "\t\t\tvar  regex = new Regex(\"\\\\.bjs$\");",
324               "\t\t\t// should not happen",
325               "\t      \t\tvalafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
326               "\t\t} catch (GLib.RegexError e) {",
327               "\t\t\treturn true;",
328               "\t\t}   ",
329               "",
330               "",
331               "",
332               "\t}",
333               "\tif (!err.has_member(valafn)) {",
334               "\t\tGLib.debug(\"File path has no errors\");",
335               "\t\treturn  true;",
336               "\t}",
337               "",
338               "\tvar lines = err.get_object_member(valafn);",
339               "\t",
340               "\tvar offset = 1;",
341               "\tif (obj.has_member(\"line_offset\")) { // ?? why??",
342               "\t\toffset = (int)obj.get_int_member(\"line_offset\") + 1;",
343               "\t}",
344               "",
345               "",
346               "\tvar tlines = this.el.get_line_count () +1;",
347               "\t",
348               "\tif (_this.prop != null) {",
349               "\t",
350               "\t\ttlines = _this.prop.end_line + 1;",
351               "\t\toffset = _this.prop.start_line + 1;",
352               "\t",
353               "\t}",
354               "\t",
355               "",
356               "",
357               "\tlines.foreach_member((obj, line, node) => {",
358               "\t\t",
359               "\t     Gtk.TextIter iter;",
360               "//        print(\"get inter\\n\");",
361               "\t    var eline = int.parse(line) - offset;",
362               "\t    GLib.debug(\"GOT ERROR on line %s -- converted to %d  (offset = %d)\\n\", line,eline, offset);",
363               "\t    ",
364               "\t    ",
365               "\t    if (eline > tlines || eline < 0) {",
366               "\t        return;",
367               "\t    }",
368               "\t   ",
369               "\t    ",
370               "\t    this.el.get_iter_at_line( out iter, eline);",
371               "\t    //print(\"mark line\\n\");",
372               "\t    var msg  = \"\";",
373               "\t    var ar = lines.get_array_member(line);",
374               "\t    for (var i = 0 ; i < ar.get_length(); i++) {",
375               "\t    \tif (ar.get_string_element(i) == \"Success\") {",
376               "\t    \t\tcontinue;",
377               "    \t\t}",
378               "\t\t\tmsg += (msg.length > 0) ? \"\\n\" : \"\";",
379               "\t\t\tmsg += ar.get_string_element(i);",
380               "\t\t}",
381               "\t\tif (msg == \"\") {",
382               "\t\t\treturn;",
383               "\t\t}",
384               "\t\tmsg = \"Line: %d\".printf(eline+1) +  \" \" + msg;",
385               "\t    this.el.create_source_mark(msg, type, iter);",
386               "\t    GLib.debug(\"set line %d to %m\", eline, msg);",
387               "\t   // this.marks.set(eline, msg);",
388               "\t} );",
389               "\treturn false;",
390               "",
391               "",
392               "",
393               "",
394               "",
395               "\t}",
396               ""
397              ],
398              "| bool checkSyntax" : [
399               " () {",
400               " ",
401               "    ",
402               "    var str = this.toString();",
403               "    ",
404               "    // needed???",
405               "    if (this.error_line > 0) {",
406               "         Gtk.TextIter start;",
407               "         Gtk.TextIter end;     ",
408               "        this.el.get_bounds (out start, out end);",
409               "",
410               "        this.el.remove_source_marks (start, end, null);",
411               "    }",
412               "    if (str.length < 1) {",
413               "        print(\"checkSyntax - empty string?\\n\");",
414               "        return true;",
415               "    }",
416               "    ",
417               "    // bit presumptiona",
418               "    if (_this.file.xtype == \"PlainFile\") {",
419               "    ",
420               "        // assume it's gtk...",
421               "         var  oldcode =_this.file.toSource();",
422               "        _this.file.setSource(str);",
423               "\t    BuilderApplication.showSpinner(\"appointment soon\",\"document change pending\");",
424               "    \t_this.file.getLanguageServer().document_change(_this.file);",
425               "\t\t_this.file.getLanguageServer().queueDocumentSymbols(_this.file);",
426               "        _this.file.setSource(oldcode);",
427               "        ",
428               "\t\t ",
429               "        return true;",
430               "    ",
431               "    }",
432               "   if (_this.file == null) {",
433               "       return true;",
434               "   }",
435               " ",
436               "    ",
437               "",
438               "      ",
439               "     ",
440               "    GLib.debug(\"calling validate\");    ",
441               "    // clear the buttons.",
442               " \tif (_this.prop.name == \"xns\" || _this.prop.name == \"xtype\") {",
443               "\t\treturn true ;",
444               "\t}",
445               "\tvar oldcode  = _this.prop.val;",
446               "\t",
447               "\t_this.prop.val = str;",
448               "\t_this.node.updated_count++;",
449               "    _this.file.getLanguageServer().document_change(_this.file);",
450               "    _this.node.updated_count++;",
451               "    _this.prop.val = oldcode;",
452               "    ",
453               "    ",
454               "    //print(\"done mark line\\n\");",
455               "     ",
456               "    return true; // at present allow saving - even if it's invalid..",
457               "}",
458               ""
459              ],
460              "| bool highlightErrors" : [
461               "( Gee.HashMap<int,string> validate_res) {",
462               "         ",
463               "\tthis.error_line = validate_res.size;",
464               "",
465               "\tif (this.error_line < 1) {",
466               "\t\treturn true;",
467               "\t}",
468               "\tvar tlines = this.el.get_line_count ();",
469               "\tGtk.TextIter iter;",
470               "\tvar valiter = validate_res.map_iterator();",
471               "\twhile (valiter.next()) {",
472               "",
473               "\t//        print(\"get inter\\n\");",
474               "\t\tvar eline = valiter.get_key();",
475               "\t\tif (eline > tlines) {",
476               "\t\t\tcontinue;",
477               "\t\t}",
478               "\t\tthis.el.get_iter_at_line( out iter, eline);",
479               "\t\t//print(\"mark line\\n\");",
480               "\t\tthis.el.create_source_mark(valiter.get_value(), \"ERR\", iter);",
481               "\t}   ",
482               "\treturn false;",
483               "}"
484              ],
485              "| string toString" : [
486               "  () {",
487               "    ",
488               "    Gtk.TextIter s;",
489               "    Gtk.TextIter e;",
490               "    this.el.get_start_iter(out s);",
491               "    this.el.get_end_iter(out e);",
492               "    var ret = this.el.get_text(s,e,true);",
493               "    //print(\"TO STRING? \" + ret);",
494               "    return ret;",
495               "}",
496               " "
497              ]
498             },
499             {
500              "# bool is_control" : false,
501              "$ xns" : "Gtk",
502              "id" : "keystate",
503              "listeners" : {
504               "key_pressed" : [
505                "(keyval, keycode, state) => {",
506                "",
507                " \tif (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {",
508                " \t\tthis.is_control = true;",
509                "\t}",
510                "\treturn false;",
511                "}",
512                ""
513               ],
514               "key_released" : [
515                "(keyval, keycode, state) => {",
516                "",
517                " \t if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {",
518                " \t\tthis.is_control = false;",
519                "\t}",
520                "    if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
521                "        GLib.debug(\"SAVE: ctrl-S  pressed\");",
522                "        _this.saveContents();",
523                "        return;",
524                "    }",
525                "    ",
526                "    if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
527                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
528                "\t\t_this.forwardSearch(true);",
529                "\t    return;",
530                "\t}",
531                "\tif (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
532                "\t    GLib.debug(\"SAVE: ctrl-f  pressed\");",
533                "\t\t_this.search_entry.el.grab_focus();",
534                "\t\t_this.search_entry.el.select_region(0,-1);",
535                "\t    return;",
536                "\t}",
537                "\tif (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
538                "\t\t_this.view.el.show_completion();",
539                "\t}",
540                "\t",
541                "\tGtk.TextIter iter;",
542                "\t_this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);  ",
543                "\tvar line  = iter.get_line();",
544                "\tvar offset = iter.get_line_offset();",
545                "\tGLib.debug(\"line  %d  off %d\", line ,offset);",
546                "\tif (_this.prop != null) {",
547                "\t\tline += _this.prop.start_line + 1; // i think..",
548                "\t\toffset += 12; // should probably be 8 without namespaced ",
549                "\t\tGLib.debug(\"guess line  %d  off %d\", line ,offset);",
550                "\t} ",
551                "    //_this.view.el.show_completion();",
552                "   // print(event.key.keyval)",
553                "    ",
554                "    ",
555                "    return;",
556                " ",
557                " ",
558                "}",
559                ""
560               ]
561              },
562              "xtype" : "EventControllerKey"
563             },
564             {
565              "# double distance" : "0.0f",
566              "$ xns" : "Gtk",
567              "Gtk.EventControllerScrollFlags flags" : "Gtk.EventControllerScrollFlags.VERTICAL",
568              "listeners" : {
569               "scroll" : [
570                "(dx, dy) => {",
571                "\tif (!_this.keystate.is_control) {",
572                "\t\treturn false;",
573                "\t}",
574                "\t //GLib.debug(\"scroll %f\",  dy);",
575                "\t",
576                "\tthis.distance += dy;",
577                "\t",
578                "\t//GLib.debug(\"scroll %f / %f\",  dy, this.distance);",
579                " ",
580                "\t if (this.distance < -1) {",
581                " ",
582                "\t\tBuilderApplication.settings.editor_font_size ++;",
583                "\t\tthis.distance = 0;",
584                "\t}",
585                "\tif (this.distance > 1) {",
586                "\t\tBuilderApplication.settings.editor_font_size --;",
587                "\t\tthis.distance = 0;",
588                "\t}",
589                "\t ",
590                "\treturn true;",
591                "}",
592                ""
593               ]
594              },
595              "xtype" : "EventControllerScroll"
596             },
597             {
598              "$ xns" : "Gtk",
599              "xtype" : "GestureClick"
600             }
601            ],
602            "listeners" : {
603             "query_tooltip" : [
604              "(x, y, keyboard_tooltip, tooltip) => {",
605              "\t",
606              "\t//GLib.debug(\"query tooltip\");",
607              "\tGtk.TextIter iter;",
608              "\tint trailing;",
609              "\t",
610              "\tvar yoff = (int) _this.RightEditor.el.vadjustment.value;",
611              "\t",
612              "\t// I think this is problematic - if it's compliing  / updating at same time as query.",
613              "\t",
614              "\t//if (_this.window.statusbar_compile_spinner.el.spinning) {",
615              "\t//\treturn false;",
616              "\t//}",
617              "\t",
618              "\tthis.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);",
619              "\t ",
620              "\tvar l = iter.get_line();",
621              "",
622              "\t",
623              "\t ",
624              "\t// GLib.debug(\"query tooltip line %d\", (int) l);",
625              "\tif (l < 0) {",
626              "",
627              "\t\treturn false;",
628              "\t}",
629              "\t/*",
630              "\tif (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {",
631              "\t\tGLib.debug(\"line %d setting tip to %s\", l,  _this.buffer.marks.get(l));",
632              "\t\ttooltip.set_text(_this.buffer.marks.get(l).dup());",
633              "\t\treturn true;",
634              "\t}",
635              " ",
636              "\treturn false;",
637              "\t*/",
638              "\t",
639              "\t  ",
640              "\t// this crashes?? - not sure why.",
641              "\tvar marks = _this.buffer.el.get_source_marks_at_line(l, \"ERR\");",
642              "\tif (marks.is_empty()) {",
643              "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"WARN\");",
644              "\t}",
645              "\tif (marks.is_empty()) {",
646              "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"DEPR\");",
647              "\t}",
648              "\t",
649              "\t// GLib.debug(\"query tooltip line %d marks %d\", (int)l, (int) marks.length());",
650              "\tvar str = \"\";",
651              "\tmarks.@foreach((m) => { ",
652              "\t\t//GLib.debug(\"got mark %s\", m.name);",
653              "\t\tstr += (str.length > 0 ? \"\\n\" : \"\") + m.category + \": \" + m.name;",
654              "\t});",
655              "\t// true if there is a mark..",
656              "\tif (str.length > 0 ) {",
657              "\t\ttooltip.set_text( str );",
658              "\t}",
659              "\treturn str.length > 0 ? true : false;",
660              "\t ",
661              "}",
662              ""
663             ]
664            },
665            "string name" : "editor-view",
666            "uint tab_width" : 4,
667            "xtype" : "View",
668            "| void load" : [
669             " (string str) {",
670             "",
671             "// show the help page for the active node..",
672             "   //this.get('/Help').show();",
673             " ",
674             "  // this.get('/BottomPane').el.set_current_page(0);",
675             "  \tGLib.debug(\"load called - Reset undo buffer\");",
676             "  \t",
677             "    var buf = (GtkSource.Buffer)this.el.get_buffer();",
678             "    buf.begin_irreversible_action();",
679             "    buf.set_text(str, str.length);",
680             "    buf.end_irreversible_action();",
681             "    ",
682             "    var lm = GtkSource.LanguageManager.get_default();",
683             "    var lang = \"vala\";",
684             "    if (_this.file != null) {",
685             "         lang = _this.file.language;",
686             "    }",
687             "    print(\"lang=%s, content_type = %s\\n\", lang, _this.file.content_type);",
688             "    var lg = _this.file.content_type.length > 0  ?",
689             "            lm.guess_language(_this.file.path, _this.file.content_type) :",
690             "            lm.get_language(lang);",
691             "     ",
692             "   ",
693             "    ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg); ",
694             "",
695             "    this.el.insert_spaces_instead_of_tabs = true;",
696             "    if (lg != null) {",
697             "\t\tprint(\"sourcelanguage  = %s\\n\", lg.name);",
698             "\t\tif (lg.name == \"Vala\") {",
699             "\t\t    this.el.insert_spaces_instead_of_tabs = false;",
700             "\t\t}",
701             "     }",
702             "    _this.dirty = false;",
703             "    this.el.grab_focus();",
704             "    _this.save_button.el.sensitive = false;",
705             "    _this.last_error_counter = -1;",
706             "}"
707            ]
708           }
709          ],
710          "xtype" : "ScrolledWindow"
711         },
712         {
713          "$ xns" : "Gtk",
714          "* pack" : "append",
715          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
716          "bool homogeneous" : false,
717          "bool vexpand" : false,
718          "int spacing" : 0,
719          "items" : [
720           {
721            "$ xns" : "Gtk",
722            "Gtk.CssProvider css" : "",
723            "bool hexpand" : true,
724            "id" : "search_entry",
725            "items" : [
726             {
727              "$ xns" : "Gtk",
728              "listeners" : {
729               "key_pressed" : [
730                "(keyval, keycode, state) => {",
731                "",
732                "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
733                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
734                "\t\t_this.forwardSearch(true);",
735                "\t    return true;",
736                "\t}",
737                "    ",
738                "  ",
739                " \tif (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {",
740                "\t\t_this.forwardSearch(true);",
741                "\t\t",
742                "\t\t",
743                "\t    return true;",
744                "",
745                "\t}    ",
746                "   // print(event.key.keyval)",
747                "   ",
748                "    return false;",
749                "}",
750                ""
751               ]
752              },
753              "xtype" : "EventControllerKey"
754             }
755            ],
756            "listeners" : {
757             "search_changed" : [
758              "( ) => {",
759              "",
760              "_this.search(_this.search_entry.el.text);",
761              "\t _this.search_results.updateResults();",
762              "",
763              "\tGLib.Timeout.add_seconds(1,() => {",
764              "\t\t _this.search_results.updateResults();",
765              "\t\t return false;",
766              "\t });",
767              "}",
768              ""
769             ]
770            },
771            "string name" : "editor-search-entry",
772            "string placeholder_text" : "Press enter to search",
773            "uint search_delay" : 3,
774            "xtype" : "SearchEntry",
775            "| void forwardSearch" : [
776             "(bool change_focus) {",
777             "",
778             "",
779             "\t_this.forwardSearch(change_focus);",
780             "",
781             "/*",
782             "",
783             "\tswitch(_this.windowstate.state) {",
784             "\t\tcase WindowState.State.CODEONLY:",
785             "\t\t//case WindowState.State.CODE:",
786             "\t\t\t// search the code being edited..",
787             "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
788             "\t\t\t ",
789             "\t\t\tbreak;",
790             "\t\tcase WindowState.State.PREVIEW:",
791             "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
792             "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
793             "\t\t\t} else { ",
794             "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
795             "\t\t\t}",
796             "\t\t",
797             "\t\t\tbreak;",
798             "\t}",
799             "\t*/",
800             "\t",
801             "}",
802             ""
803            ]
804           },
805           {
806            "$ xns" : "Gtk",
807            "id" : "search_results",
808            "int margin_end" : 4,
809            "int margin_start" : 4,
810            "string label" : "No Results",
811            "xtype" : "Label",
812            "| void updateResults" : [
813             "() {",
814             "\tthis.el.visible = true;",
815             "\t",
816             "\tvar res = _this.searchcontext.get_occurrences_count();",
817             "\tif (res < 0) {",
818             "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
819             "\t\treturn;",
820             "\t}",
821             "",
822             "\t_this.nextBtn.el.sensitive = false;",
823             "\t_this.backBtn.el.sensitive = false;\t",
824             "",
825             "\tif (res > 0) {",
826             "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
827             "\t\t_this.nextBtn.el.sensitive = true;",
828             "\t\t_this.backBtn.el.sensitive = true;",
829             "\t\treturn;",
830             "\t} ",
831             "\t_this.search_results.el.label = \"No Matches\";",
832             "\t",
833             "}"
834            ]
835           },
836           {
837            "$ xns" : "Gtk",
838            "bool always_show_image" : true,
839            "bool sensitive" : false,
840            "id" : "nextBtn",
841            "listeners" : {
842             "clicked" : [
843              "(event) => {",
844              "",
845              "\t_this.forwardSearch(true);",
846              "\t",
847              "\t ",
848              "}",
849              ""
850             ]
851            },
852            "string icon_name" : "go-down",
853            "xtype" : "Button"
854           },
855           {
856            "$ xns" : "Gtk",
857            "bool always_show_image" : true,
858            "bool sensitive" : false,
859            "id" : "backBtn",
860            "listeners" : {
861             "clicked" : [
862              "(event) => {",
863              "",
864              "\t_this.backSearch(true);",
865              "\t ",
866              "}",
867              ""
868             ]
869            },
870            "string icon_name" : "go-up",
871            "xtype" : "Button"
872           },
873           {
874            "$ xns" : "Gtk",
875            "bool always_show_arrow" : true,
876            "bool always_show_image" : true,
877            "items" : [
878             {
879              "$ xns" : "Gtk",
880              "* prop" : "popover",
881              "id" : "search_settings",
882              "items" : [
883               {
884                "$ xns" : "Gtk",
885                "* prop" : "child",
886                "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
887                "int spacing" : 0,
888                "items" : [
889                 {
890                  "$ xns" : "Gtk",
891                  "* init" : [
892                   "{",
893                   "\tthis.el.show();",
894                   "}",
895                   ""
896                  ],
897                  "id" : "case_sensitive",
898                  "string label" : "Case Sensitive",
899                  "xtype" : "CheckButton"
900                 },
901                 {
902                  "$ xns" : "Gtk",
903                  "* init" : [
904                   "{",
905                   "\tthis.el.show();",
906                   "}",
907                   ""
908                  ],
909                  "id" : "regex",
910                  "string label" : "Regex",
911                  "xtype" : "CheckButton"
912                 },
913                 {
914                  "$ xns" : "Gtk",
915                  "id" : "multiline",
916                  "string label" : "Multi-line (add \\n)",
917                  "xtype" : "CheckButton"
918                 }
919                ],
920                "xtype" : "Box"
921               }
922              ],
923              "xtype" : "Popover"
924             }
925            ],
926            "string icon_name" : "emblem-system",
927            "xtype" : "MenuButton"
928           }
929          ],
930          "xtype" : "Box"
931         }
932        ],
933        "xtype" : "Box"
934       },
935       {
936        "$ xns" : "Gtk",
937        "* prop" : "end_child",
938        "bool visible" : false,
939        "id" : "navigationwindow",
940        "items" : [
941         {
942          "# int last_selected_line" : "-1",
943          "$ Gtk.Widget? selected_row" : "null",
944          "$ xns" : "Gtk",
945          "* prop" : "child",
946          "id" : "navigation",
947          "items" : [
948           {
949            "$ xns" : "Gtk",
950            "bool expand" : true,
951            "items" : [
952             {
953              "$ xns" : "Gtk",
954              "* prop" : "factory",
955              "listeners" : {
956               "bind" : [
957                "(listitem) => {",
958                "\t// GLib.debug(\"listitme is is %s\", ((Gtk.ListItem)listitem).get_type().name());",
959                "\t",
960                "\t//var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();",
961                "\tvar expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();",
962                "\t ",
963                "\t ",
964                "\tvar hbox = (Gtk.Box) expand.child;",
965                " ",
966                "\t",
967                "\tvar img = (Gtk.Image) hbox.get_first_child();",
968                "\tvar lbl = (Gtk.Label) img.get_next_sibling();",
969                "\t",
970                "\tvar lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();",
971                "\tvar sym = (Lsp.DocumentSymbol) lr.get_item();",
972                "\t",
973                "\tsym.set_data<Gtk.Widget>(\"widget\", expand.get_parent());",
974                "\texpand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>(\"symbol\", sym);",
975                "\t",
976                "\t//GLib.debug(\"save sym on %s\", expand.get_parent().get_parent().get_type().name());",
977                "\t",
978                "\t//GLib.debug(\"got %d children for %s\" , (int)sym.children.get_n_items(), sym.name);",
979                "    ",
980                "    expand.set_hide_expander( sym.children.get_n_items()  < 1);",
981                " \texpand.set_list_row(lr);",
982                " \t",
983                " \tsym.bind_property(\"symbol_icon\",",
984                "                    img, \"icon_name\",",
985                "                   GLib.BindingFlags.SYNC_CREATE);",
986                " \t",
987                " \thbox.add_css_class(sym.symbol_icon);",
988                " \t",
989                " \tsym.bind_property(\"name\",",
990                "                    lbl, \"label\",",
991                "                   GLib.BindingFlags.SYNC_CREATE);",
992                " \t// should be better?- --line no?",
993                " \tsym.bind_property(\"tooltip\",",
994                "                    lbl, \"tooltip_markup\",",
995                "                   GLib.BindingFlags.SYNC_CREATE);",
996                " \t// bind image...",
997                " \t",
998                "}",
999                ""
1000               ],
1001               "setup" : [
1002                "(listitem) => {",
1003                "\t",
1004                "\tvar expand = new Gtk.TreeExpander();",
1005                "\t ",
1006                "\texpand.set_indent_for_depth(true);",
1007                "\texpand.set_indent_for_icon(true);",
1008                "\tvar hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);",
1009                "\tvar icon = new Gtk.Image();",
1010                "\tvar lbl = new Gtk.Label(\"\");",
1011                "\tlbl.use_markup = true;",
1012                "\tlbl.ellipsize = Pango.EllipsizeMode.END;",
1013                "\t",
1014                "\ticon.margin_end = 4;",
1015                " \tlbl.justify = Gtk.Justification.LEFT;",
1016                " \tlbl.xalign = 0;",
1017                "",
1018                "//\tlistitem.activatable = true; ??",
1019                "\t",
1020                "\thbox.append(icon);",
1021                "\thbox.append(lbl);",
1022                "\texpand.set_child(hbox);",
1023                "\t((Gtk.ListItem)listitem).set_child(expand);",
1024                "\t",
1025                "}",
1026                ""
1027               ]
1028              },
1029              "xtype" : "SignalListItemFactory"
1030             }
1031            ],
1032            "string title" : "Code Navigation",
1033            "xtype" : "ColumnViewColumn"
1034           },
1035           {
1036            "$ xns" : "Gtk",
1037            "* prop" : "model",
1038            "id" : "navigationselmodel",
1039            "items" : [
1040             {
1041              "$ xns" : "Gtk",
1042              "* prop" : "model",
1043              "id" : "navigationsort",
1044              "items" : [
1045               {
1046                "$ Gtk.TreeListModelCreateModelFunc create_func" : [
1047                 "(item) => {",
1048                 " ",
1049                 "\treturn ((Lsp.DocumentSymbol)item).children;",
1050                 "}",
1051                 ""
1052                ],
1053                "$ xns" : "Gtk",
1054                "* prop" : "model",
1055                "bool autoexpand" : true,
1056                "bool passthrough" : false,
1057                "items" : [
1058                 {
1059                  "$ GLib.Type item_type" : "typeof(Lsp.DocumentSymbol)",
1060                  "$ xns" : "GLib",
1061                  "* prop" : "root",
1062                  "id" : "navliststore",
1063                  "xtype" : "ListStore",
1064                  "| Lsp.DocumentSymbol? symbolAtLine" : [
1065                   "(uint line, uint chr) {",
1066                   " ",
1067                   "\t",
1068                   "\tfor(var i = 0; i < this.el.get_n_items();i++) {",
1069                   "\t\tvar el = (Lsp.DocumentSymbol)this.el.get_item(i);",
1070                   "\t\t//GLib.debug(\"Check sym %s : %d-%d\",",
1071                   "\t\t//\tel.name , (int)el.range.start.line,",
1072                   "\t\t//\t(int)el.range.end.line",
1073                   "\t\t//);",
1074                   "\t\tvar ret = el.containsLine(line,chr);",
1075                   "\t\tif (ret != null) {",
1076                   "\t\t\treturn ret;",
1077                   "\t\t}",
1078                   "\t\t",
1079                   "\t}",
1080                   "\t",
1081                   "\treturn null;",
1082                   "}"
1083                  ]
1084                 }
1085                ],
1086                "xtype" : "TreeListModel"
1087               },
1088               {
1089                "$ xns" : "Gtk",
1090                "* prop" : "sorter",
1091                "items" : [
1092                 {
1093                  "$ xns" : "Gtk",
1094                  "* prop" : "sorter",
1095                  "items" : [
1096                   {
1097                    "$ GLib.Type this_type" : "typeof(Lsp.DocumentSymbol)",
1098                    "$ xns" : "Gtk",
1099                    "* prop" : "expression",
1100                    "string property_name" : "sort_key",
1101                    "xtype" : "PropertyExpression"
1102                   }
1103                  ],
1104                  "xtype" : "StringSorter"
1105                 }
1106                ],
1107                "xtype" : "TreeListRowSorter"
1108               }
1109              ],
1110              "xtype" : "SortListModel",
1111              "| Lsp.DocumentSymbol? getSymbolAt" : [
1112               "(uint row) {",
1113               "",
1114               "   var tr = (Gtk.TreeListRow)this.el.get_item(row);",
1115               "   ",
1116               "   var a = tr.get_item();;   ",
1117               "   GLib.debug(\"get_item (2) = %s\", a.get_type().name());",
1118               "  \t",
1119               "   ",
1120               "   return (Lsp.DocumentSymbol)tr.get_item();",
1121               "\t ",
1122               "}"
1123              ],
1124              "| int getRowFromSymbol" : [
1125               "(Lsp.DocumentSymbol sym) {",
1126               "",
1127               "\tfor (var i=0;i < this.el.get_n_items(); i++) {",
1128               "\t\tvar tr = (Gtk.TreeListRow)this.el.get_item(i);",
1129               "\t   ",
1130               "\t\tif (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {",
1131               "\t\t\treturn i;",
1132               "\t\t}",
1133               "\t}",
1134               "   \treturn -1;",
1135               "}"
1136              ]
1137             }
1138            ],
1139            "xtype" : "NoSelection"
1140           },
1141           {
1142            "$ xns" : "Gtk",
1143            "listeners" : {
1144             "pressed" : [
1145              "(n_press, x, y) => {",
1146              "\tstring pos;",
1147              "  \tvar row = _this.navigation.getRowWidgetAt(x,y, out pos );",
1148              "",
1149              "    if (row == null) {",
1150              "\t    GLib.debug(\"no row selected items\");",
1151              "\t    return;",
1152              "    }",
1153              "\tGLib.debug(\"got click on %s\", row.get_type().name());    ",
1154              "    //Lsp.DocumentSymbol",
1155              "    var sym =  row.get_data<Lsp.DocumentSymbol>(\"symbol\");",
1156              "    if (sym == null) {",
1157              "    \treturn;",
1158              "\t}",
1159              "\t/*",
1160              "\t \"range\" : {",
1161              "              \"start\" : {",
1162              "                \"line\" : 1410,",
1163              "                \"character\" : 8",
1164              "              },",
1165              "              \"end\" : {",
1166              "                \"line\" : 1410,",
1167              "                \"character\" : 39",
1168              "              }",
1169              "            },",
1170              "        */",
1171              "     GLib.debug(\"goto line %d\",   (int)sym.range.start.line); ",
1172              "    _this.scroll_to_line((int)sym.range.start.line);",
1173              "    Gtk.TextIter iter;",
1174              "    _this.buffer.el.get_iter_at_line_offset(out iter, ",
1175              "    \t(int)sym.range.start.line,",
1176              "    \t(int)sym.range.start.character",
1177              "\t);",
1178              "    _this.buffer.el.place_cursor(iter);",
1179              "\t",
1180              "}"
1181             ]
1182            },
1183            "xtype" : "GestureClick"
1184           }
1185          ],
1186          "string name" : "editor-navigation",
1187          "xtype" : "ColumnView",
1188          "| Gtk.Widget? getRowWidgetAt" : [
1189           "(double x,  double  y, out string pos) {",
1190           "",
1191           "\tpos = \"\";",
1192           "\tvar w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);",
1193           "\t//GLib.debug(\"got widget %s\", w == null ? \"nothing\" : w.get_type().name());",
1194           "\tif (w == null) {",
1195           "\t\treturn null;",
1196           "\t}",
1197           "\t",
1198           "\tvar row= w.get_ancestor(GLib.Type.from_name(\"GtkColumnViewRowWidget\"));",
1199           "\tif (row == null) {",
1200           "\t\treturn null;",
1201           "\t}",
1202           "\t",
1203           "\t//GLib.debug(\"got colview %s\", row == null ? \"nothing\" : row.get_type().name());",
1204           "\t ",
1205           " ",
1206           "\t",
1207           "\t//GLib.debug(\"row number is %d\", rn);",
1208           "\t//GLib.debug(\"click %d, %d\", (int)x, (int)y);",
1209           "\t// above or belw",
1210           "\tGraphene.Rect  bounds;",
1211           "\trow.compute_bounds(this.el, out bounds);",
1212           "\t//GLib.debug(\"click x=%d, y=%d, w=%d, h=%d\", ",
1213           "\t//\t(int)bounds.get_x(), (int)bounds.get_y(),",
1214           "\t//\t(int)bounds.get_width(), (int)bounds.get_height()",
1215           "\t//\t);",
1216           "\tvar ypos = y - bounds.get_y();",
1217           "\t//GLib.debug(\"rel ypos = %d\", (int)ypos);\t",
1218           "\tvar rpos = 100.0 * (ypos / bounds.get_height());",
1219           "\t//GLib.debug(\"rel pos = %d %%\", (int)rpos);",
1220           "\tpos = \"over\";",
1221           "\t",
1222           "\tif (rpos > 80) {",
1223           "\t\tpos = \"below\";",
1224           "\t} else if (rpos < 20) {",
1225           "\t\tpos = \"above\";",
1226           "\t} ",
1227           "\treturn row;",
1228           " }"
1229          ],
1230          "| int getRowAt" : [
1231           "(double x,  double  y, out string pos) {",
1232           "",
1233           "\tpos = \"\";",
1234           "\tvar w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);",
1235           "\t//GLib.debug(\"got widget %s\", w == null ? \"nothing\" : w.get_type().name());",
1236           "\tif (w == null) {",
1237           "\t\treturn -1;",
1238           "\t}",
1239           "\t",
1240           "\tvar row= w.get_ancestor(GLib.Type.from_name(\"GtkColumnViewRowWidget\"));",
1241           "\tif (row == null) {",
1242           "\t\treturn -1;",
1243           "\t}",
1244           "\t",
1245           "\t//GLib.debug(\"got colview %s\", row == null ? \"nothing\" : row.get_type().name());",
1246           "\t ",
1247           "\tvar rn = 0;",
1248           "\tvar cr = row;",
1249           "\t ",
1250           "\twhile (cr.get_prev_sibling() != null) {",
1251           "\t\trn++;",
1252           "\t\tcr = cr.get_prev_sibling();",
1253           "\t}",
1254           "\t",
1255           "\t//GLib.debug(\"row number is %d\", rn);",
1256           "\t//GLib.debug(\"click %d, %d\", (int)x, (int)y);",
1257           "\t// above or belw",
1258           "\tGraphene.Rect  bounds;",
1259           "\trow.compute_bounds(this.el, out bounds);",
1260           "\t//GLib.debug(\"click x=%d, y=%d, w=%d, h=%d\", ",
1261           "\t//\t(int)bounds.get_x(), (int)bounds.get_y(),",
1262           "\t//\t(int)bounds.get_width(), (int)bounds.get_height()",
1263           "\t//\t);",
1264           "\tvar ypos = y - bounds.get_y();",
1265           "\t//GLib.debug(\"rel ypos = %d\", (int)ypos);\t",
1266           "\tvar rpos = 100.0 * (ypos / bounds.get_height());",
1267           "\t//GLib.debug(\"rel pos = %d %%\", (int)rpos);",
1268           "\tpos = \"over\";",
1269           "\t",
1270           "\tif (rpos > 80) {",
1271           "\t\tpos = \"below\";",
1272           "\t} else if (rpos < 20) {",
1273           "\t\tpos = \"above\";",
1274           "\t} ",
1275           "\treturn rn;",
1276           " }"
1277          ],
1278          "| void show" : [
1279           "(Gee.ArrayList<Lsp.DocumentSymbol> syms) {",
1280           "\t_this.navigationwindow.el.show();",
1281           "\t//_this.navliststore.el.remove_all();",
1282           "\t",
1283           "\t",
1284           "\tvar ls  = new GLib.ListStore(typeof(Lsp.DocumentSymbol));",
1285           "\t",
1286           "\tforeach(var sym in syms) {",
1287           "\t\tls.append(sym);",
1288           "\t}",
1289           "\tLsp.DocumentSymbol.copyList(ls, _this.navliststore.el);",
1290           "\t//_this.navliststore.el.append(sym);",
1291           "\tthis.last_selected_line = -1;",
1292           "\tGLib.Idle.add(() => {",
1293           "",
1294           "\t\tGtk.TextIter iter;",
1295           "\t\t_this.buffer.el.get_iter_at_offset (",
1296           "\t\t\t\tout iter, _this.buffer.el.cursor_position);",
1297           "\t\t",
1298           "\t\tGLib.debug(\"idle update scroll %d, %d\", iter.get_line(),",
1299           "\t\t\t\titer.get_line_offset());",
1300           "\t\tthis.updateSelectedLine(",
1301           "\t\t\t\t(uint)iter.get_line(),",
1302           "\t\t\t\t(uint)iter.get_line_offset()",
1303           "\t\t);",
1304           "\t\treturn false;",
1305           "\t});",
1306           "",
1307           "}"
1308          ],
1309          "| void updateSelectedLine" : [
1310           "(uint line, uint chr) {",
1311           "\tif (line == this.last_selected_line) {",
1312           "\t\treturn;",
1313           "\t}",
1314           "\tGLib.debug(\"select line %d\", (int)line);",
1315           "\tthis.last_selected_line = (int)line;",
1316           "\t",
1317           "\t",
1318           "\tvar new_row = -1;",
1319           "\tvar sym = _this.navliststore.symbolAtLine(line, chr);",
1320           "\tif (sym != null) {",
1321           "\t \tnew_row = _this.navigationsort.getRowFromSymbol(sym);",
1322           " \t\tGLib.debug(\"select line %d - row found %d\", (int)line, new_row);",
1323           " \t} else {",
1324           " \t\tGLib.debug(\" no symbol found at line %d\", (int)line);",
1325           " \t}",
1326           " \t",
1327           "\tif (this.selected_row != null) { ",
1328           "\t\tGLib.debug(\" remove selected row\");",
1329           "\t\tthis.selected_row.remove_css_class(\"selected-row\");",
1330           "\t}",
1331           "\tthis.selected_row  = null;",
1332           "\tif (new_row > -1) {",
1333           "\t\tthis.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);",
1334           "\t\tvar row = sym.get_data<Gtk.Widget>(\"widget\");",
1335           "\t\tif (row != null) {",
1336           "\t\t\tGLib.debug(\" Add selected row\");",
1337           " \t\t\t",
1338           "\t\t\trow.add_css_class(\"selected-row\");",
1339           "\t\t\tthis.selected_row = row;",
1340           "",
1341           "\t\t\t",
1342           "\t\t} else {",
1343           "\t\t\tGLib.debug(\"could not find widget on row %d\", new_row);",
1344           "\t\t}",
1345           "",
1346           "\t}",
1347           "",
1348           "",
1349           "}"
1350          ]
1351         }
1352        ],
1353        "xtype" : "ScrolledWindow"
1354       }
1355      ],
1356      "xtype" : "Paned"
1357     }
1358    ],
1359    "xtype" : "Box",
1360    "| bool saveContents" : [
1361     "  ()  {",
1362     "    ",
1363     "    ",
1364     "    if (_this.file == null) {",
1365     "        return true;",
1366     "    }",
1367     "    ",
1368     "     ",
1369     "     ",
1370     "     var str = _this.buffer.toString();",
1371     "     ",
1372     "     _this.buffer.checkSyntax();",
1373     "     ",
1374     "     ",
1375     "     ",
1376     "     // LeftPanel.model.changed(  str , false);",
1377     "     _this.dirty = false;",
1378     "     _this.save_button.el.sensitive = false;",
1379     "     ",
1380     "    // find the text for the node..",
1381     "    if (_this.file.xtype != \"PlainFile\") {",
1382     "       // in theory these properties have to exist!?!",
1383     "    \tthis.prop.val = str;",
1384     "        //this.window.windowstate.left_props.reload();",
1385     "    } else {",
1386     "        _this.file.setSource(  str );",
1387     "     }",
1388     "    ",
1389     "    // call the signal..",
1390     "    this.save();",
1391     "    ",
1392     "    return true;",
1393     "",
1394     "} "
1395    ],
1396    "| int search" : [
1397     "(string in_txt) {",
1398     "",
1399     "\tvar s = new GtkSource.SearchSettings();",
1400     "\ts.case_sensitive = _this.case_sensitive.el.active;",
1401     "\ts.regex_enabled = _this.regex.el.active;\t",
1402     "\ts.wrap_around = false;",
1403     "\t",
1404     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
1405     "\tthis.searchcontext.set_highlight(true);",
1406     "\tvar txt = in_txt;",
1407     "\t",
1408     "\tif (_this.multiline.el.active) {",
1409     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
1410     "\t}",
1411     "\t",
1412     "\ts.set_search_text(txt);",
1413     "\tGtk.TextIter beg, st,en;",
1414     "\t ",
1415     "\tthis.buffer.el.get_start_iter(out beg);",
1416     "\tbool has_wrapped_around;",
1417     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
1418     "\tthis.last_search_end = 0;",
1419     "\t",
1420     "\treturn this.searchcontext.get_occurrences_count();",
1421     "",
1422     " ",
1423     "   ",
1424     "",
1425     "}",
1426     ""
1427    ],
1428    "| string tempFileContents" : [
1429     "() {",
1430     "   ",
1431     "   ",
1432     "   if (_this.file == null) {",
1433     "       return \"\";",
1434     "   }",
1435     "\tvar str= this.buffer.toString();",
1436     "\tif (_this.file.xtype == \"PlainFile\") {",
1437     "    ",
1438     "     \treturn str;",
1439     "    ",
1440     "    }",
1441     "  ",
1442     "      ",
1443     "     ",
1444     "    GLib.debug(\"calling validate\");    ",
1445     "    // clear the buttons.",
1446     " \tif (_this.prop.name == \"xns\" || _this.prop.name == \"xtype\") {",
1447     "\t\treturn this.file.toSource(); ;",
1448     "\t}",
1449     "\t",
1450     "\tvar oldcode  = _this.prop.val;",
1451     "\t_this.prop.val = str;",
1452     "    var ret = _this.file.toSource();",
1453     "    _this.prop.val = oldcode;",
1454     "    return ret;",
1455     "    ",
1456     "}"
1457    ],
1458    "| void backSearch" : [
1459     "(bool change_focus) {",
1460     "",
1461     "\tif (this.searchcontext == null) {",
1462     "\t\treturn;",
1463     "\t}",
1464     "\t",
1465     "\tGtk.TextIter beg, st,en;",
1466     "\tbool has_wrapped_around;",
1467     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
1468     "\t",
1469     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
1470     "\t\tthis.last_search_end = 0;",
1471     "\t} else {",
1472     "\t\tthis.last_search_end = en.get_offset();",
1473     "\t\tif (change_focus) {",
1474     "\t\t\tthis.view.el.grab_focus();",
1475     "\t\t}",
1476     "\t\tthis.buffer.el.place_cursor(st);",
1477     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1478     "\t}",
1479     "",
1480     "}",
1481     ""
1482    ],
1483    "| void forwardSearch" : [
1484     "(bool change_focus) {",
1485     "",
1486     "\tif (this.searchcontext == null) {",
1487     "\t\treturn;",
1488     "\t} ",
1489     "",
1490     "\tGtk.TextIter beg, st,en;",
1491     "\t bool has_wrapped_around;",
1492     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end);",
1493     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
1494     "\t",
1495     "\t\tthis.last_search_end = 0; // not sure if this should happen",
1496     "\t} else {",
1497     "\t\tif (has_wrapped_around) {",
1498     "\t\t\treturn;",
1499     "\t\t}",
1500     "\t",
1501     "\t\tthis.last_search_end = en.get_offset();",
1502     "\t\tif (change_focus) {",
1503     "\t\t\tthis.view.el.grab_focus();",
1504     "\t\t}",
1505     "\t\tthis.buffer.el.place_cursor(st);",
1506     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1507     "\t}",
1508     " ",
1509     "}",
1510     ""
1511    ],
1512    "| void reset" : [
1513     "() {",
1514     "\t this.file = null;    ",
1515     "     ",
1516     "    this.node = null;",
1517     "    this.prop = null;",
1518     "\tthis.searchcontext = null;",
1519     "  ",
1520     "}",
1521     ""
1522    ],
1523    "| void scroll_to_line" : [
1524     "(int line) {",
1525     "",
1526     "\tGLib.Timeout.add(500, () => {",
1527     "   ",
1528     "\t\tvar buf = this.view.el.get_buffer();",
1529     "",
1530     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1531     "",
1532     "",
1533     "\t\tGtk.TextIter iter;   ",
1534     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1535     "\t\tthis.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1536     "\t\treturn false;",
1537     "\t});   ",
1538     "}",
1539     ""
1540    ],
1541    "| void show" : [
1542     "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
1543     "{",
1544     "    this.reset();",
1545     "    if (this.file != null) {",
1546     "    \tthis.file.navigation_tree_updated.disconnect(",
1547     "    \t\t_this.navigation.show",
1548     "    \t);",
1549     "    }",
1550     "    this.file = file;    ",
1551     "    this.file.navigation_tree_updated.connect(",
1552     "\t\t_this.navigation.show",
1553     "\t);",
1554     "    if (file.xtype != \"PlainFile\") {",
1555     "    \tthis.prop = prop;",
1556     "        this.node = node;",
1557     "",
1558     "        // find the text for the node..",
1559     "        this.view.load( prop.val );",
1560     "        this.updateErrorMarks();",
1561     "        ",
1562     "        ",
1563     "        ",
1564     "        this.close_btn.el.show();       ",
1565     "    ",
1566     "    } else {",
1567     "        this.view.load(        file.toSource() );",
1568     "        this.updateErrorMarks();",
1569     "        this.close_btn.el.hide();",
1570     "        var ls = file.getLanguageServer();",
1571     "        ls.queueDocumentSymbols(file);",
1572     "        ////ls.documentSymbols.begin(file, (a,o) => {",
1573     "        //\t_this.navigation.show(ls.documentSymbols.end(o)); ",
1574     "       //});",
1575     "        //documentSymbols",
1576     "        ",
1577     "    }",
1578     " ",
1579     "}"
1580    ],
1581    "| void updateErrorMarks" : [
1582     "() {",
1583     "\t",
1584     " ",
1585     "",
1586     "\tvar buf = _this.buffer.el;",
1587     "\tGtk.TextIter start;",
1588     "\tGtk.TextIter end;     ",
1589     "\tbuf.get_bounds (out start, out end);",
1590     "",
1591     "\t",
1592     "",
1593     " ",
1594     "\t//GLib.debug(\"highlight errors\");\t\t ",
1595     "",
1596     "\t // we should highlight other types of errors..",
1597     "",
1598     "\tif (_this.window.windowstate.state != WindowState.State.CODEONLY ",
1599     "\t\t&&",
1600     "\t\t_this.window.windowstate.state != WindowState.State.CODE",
1601     "\t\t) {",
1602     "\t\t//GLib.debug(\"windowstate != CODEONLY?\");",
1603     "\t\t",
1604     "\t\treturn;",
1605     "\t} ",
1606     "",
1607     "\t ",
1608     "\tif (_this.file == null) {",
1609     "\t\tGLib.debug(\"file is null?\");",
1610     "\t\treturn;",
1611     "",
1612     "\t}",
1613     "\tvar ar = this.file.getErrors();",
1614     "\tif (ar.size < 1) {",
1615     "\t\tbuf.remove_source_marks (start, end, \"ERR\");",
1616     "\t\tbuf.remove_source_marks (start, end, \"WARN\");",
1617     "\t\tbuf.remove_source_marks (start, end, \"DEPR\");",
1618     "\t\tbuf.remove_tag_by_name (\"ERR\", start, end);",
1619     "\t\tbuf.remove_tag_by_name (\"WARN\", start, end);",
1620     "\t\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
1621     "\t\tthis.last_error_counter = file.error_counter ;",
1622     "\t\t//GLib.debug(\"highlight %s :  %s has no errors\", this.file.relpath, category);",
1623     "\t\treturn;",
1624     "\t}",
1625     "\t",
1626     "",
1627     " // basicaly check if there is no change, then we do not do any update..",
1628     " // we can do this by just using an error counter?",
1629     " // if that's changed then we will do an update, otherwise dont bother.",
1630     "\t  ",
1631     "\t",
1632     "\tvar offset = 0;",
1633     "\tvar hoffset = 0;",
1634     "",
1635     "\tvar tlines = buf.get_line_count () +1;",
1636     "\t",
1637     "\tif (_this.prop != null) {",
1638     "\t\t// this still seems flaky...",
1639     "",
1640     "\t\ttlines = _this.prop.end_line;",
1641     "\t\toffset = _this.prop.start_line;",
1642     "\t\thoffset = _this.node.node_pad.length + 2; //shift it left  by 2 ? ..",
1643     "\t\t",
1644     "\t\t ",
1645     "\t} else {",
1646     "\t\t// no update...",
1647     "\t\tif (this.last_error_counter == file.error_counter) {",
1648     "\t\t",
1649     "\t\t\treturn;",
1650     "\t\t}",
1651     "\t",
1652     "\t}",
1653     "\tbuf.remove_source_marks (start, end, \"ERR\");",
1654     "\tbuf.remove_source_marks (start, end, \"WARN\");",
1655     "\tbuf.remove_source_marks (start, end, \"DEPR\");",
1656     "\tbuf.remove_tag_by_name (\"ERR\", start, end);",
1657     "\tbuf.remove_tag_by_name (\"WARN\", start, end);",
1658     "\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
1659     "\t",
1660     "\tforeach(var diag in ar) { ",
1661     "\t     Gtk.TextIter iter;",
1662     "//        print(\"get inter\\n\");",
1663     "\t    var eline = (int)diag.range.start.line - offset;",
1664     "\t    var eline_to = (int)diag.range.end.line - offset;",
1665     "\t    //var eline =  diag.range.end_line - offset;",
1666     "\t    //GLib.debug(\"GOT ERROR on line %d -- converted to %d  (offset = %d)\",",
1667     "\t    //\terr.line ,eline, offset);",
1668     "\t    ",
1669     "\t    ",
1670     "\t    if (eline > tlines || eline < 0) {",
1671     "\t        continue;",
1672     "\t    }",
1673     "\t    ",
1674     "\t    buf.get_iter_at_line( out iter, eline);",
1675     "\t   \tvar msg = \"Line: %d %s : %s\".printf(eline+1, diag.category, diag.message);",
1676     "\t    buf.create_source_mark( msg, diag.category, iter);",
1677     "\t    ",
1678     " \t    var spos = (int)diag.range.start.character - hoffset;",
1679     " \t    if (spos < 0) { spos =0 ; }",
1680     " \t    if (spos > iter.get_chars_in_line()) {",
1681     " \t    \tspos = iter.get_chars_in_line();",
1682     "    \t}",
1683     "\t\tbuf.get_iter_at_line( out iter, eline_to);",
1684     "\t\tvar epos = (int)diag.range.end.character - hoffset;",
1685     " \t    if (epos < 0) { epos =0 ; }",
1686     " \t    if (epos > iter.get_chars_in_line()) {",
1687     " \t    \tepos = iter.get_chars_in_line();",
1688     "    \t}",
1689     " \t     ",
1690     " \t    ",
1691     " \t    buf.get_iter_at_line_offset( out start, eline, spos); ",
1692     " \t   ",
1693     " \t    buf.get_iter_at_line_offset( out end, eline_to,epos); ",
1694     " \t    \t",
1695     "\t    buf.apply_tag_by_name(diag.category, start, end);",
1696     "\t    ",
1697     "\t   // GLib.debug(\"set line %d to %s\", eline, msg);",
1698     "\t    //this.marks.set(eline, msg);",
1699     "\t}",
1700     "\tthis.last_error_counter = file.error_counter ;",
1701     "",
1702     "",
1703     "",
1704     " ",
1705     "",
1706     "}"
1707    ]
1708   }
1709  ],
1710  "name" : "Editor"
1711 }