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