45ff4c89d652955cbf0dc51704a65e0dba679968
[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              "| void showHelp" : [
549               "() {",
550               "",
551               "}"
552              ]
553             },
554             {
555              "# bool is_control" : false,
556              "$ xns" : "Gtk",
557              "id" : "keystate",
558              "listeners" : {
559               "key_pressed" : [
560                "(keyval, keycode, state) => {",
561                "",
562                " \tif (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {",
563                " \t\tthis.is_control = true;",
564                "\t}",
565                "\treturn false;",
566                "}",
567                ""
568               ],
569               "key_released" : [
570                "(keyval, keycode, state) => {",
571                "",
572                " \t if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {",
573                " \t\tthis.is_control = false;",
574                "\t}",
575                "    if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
576                "        GLib.debug(\"SAVE: ctrl-S  pressed\");",
577                "        _this.saveContents();",
578                "        return;",
579                "    }",
580                "    ",
581                "    if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
582                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
583                "\t\t_this.forwardSearch(true);",
584                "\t    return;",
585                "\t}",
586                "\tif (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
587                "\t    GLib.debug(\"SAVE: ctrl-f  pressed\");",
588                "\t\t_this.search_entry.el.grab_focus();",
589                "\t\t_this.search_entry.el.select_region(0,-1);",
590                "\t    return;",
591                "\t}",
592                "\tif (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
593                "\t\t_this.view.el.show_completion();",
594                "\t}",
595                "\t",
596                "\tGtk.TextIter iter;",
597                "\t_this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);  ",
598                "\tvar line  = iter.get_line();",
599                "\tvar offset = iter.get_line_offset();",
600                "\tGLib.debug(\"line  %d  off %d\", line ,offset);",
601                "\tif (_this.prop != null) {",
602                "\t\tline += _this.prop.start_line + 1; // i think..",
603                "\t\toffset += 12; // should probably be 8 without namespaced ",
604                "\t\tGLib.debug(\"guess line  %d  off %d\", line ,offset);",
605                "\t} ",
606                "    //_this.view.el.show_completion();",
607                "   // print(event.key.keyval)",
608                "    ",
609                "    ",
610                "    return;",
611                " ",
612                " ",
613                "}",
614                ""
615               ]
616              },
617              "xtype" : "EventControllerKey"
618             },
619             {
620              "# double distance" : "0.0f",
621              "$ xns" : "Gtk",
622              "Gtk.EventControllerScrollFlags flags" : "Gtk.EventControllerScrollFlags.VERTICAL",
623              "listeners" : {
624               "scroll" : [
625                "(dx, dy) => {",
626                "\tif (!_this.keystate.is_control) {",
627                "\t\treturn false;",
628                "\t}",
629                "\t //GLib.debug(\"scroll %f\",  dy);",
630                "\t",
631                "\tthis.distance += dy;",
632                "\t",
633                "\t//GLib.debug(\"scroll %f / %f\",  dy, this.distance);",
634                " ",
635                "\t if (this.distance < -1) {",
636                " ",
637                "\t\tBuilderApplication.settings.editor_font_size ++;",
638                "\t\tthis.distance = 0;",
639                "\t}",
640                "\tif (this.distance > 1) {",
641                "\t\tBuilderApplication.settings.editor_font_size --;",
642                "\t\tthis.distance = 0;",
643                "\t}",
644                "\t ",
645                "\treturn true;",
646                "}",
647                ""
648               ]
649              },
650              "xtype" : "EventControllerScroll"
651             },
652             {
653              "$ xns" : "Gtk",
654              "listeners" : {
655               "pressed" : [
656                "(n_press, x, y) => {",
657                "\tGtk.TextIter iter;",
658                "\tint  buffer_x, buffer_y;",
659                "\tvar gut = _this.view.el.get_gutter(Gtk.TextWindowType.LEFT);",
660                "\t",
661                "\t _this.view.el.window_to_buffer_coords (Gtk.TextWindowType.TEXT,",
662                "\t\t(int)x - gut.get_width(),  (int)y,",
663                "  \t\tout  buffer_x, out  buffer_y);",
664                "\t_this.view.el.get_iter_at_location (out  iter,  ",
665                "\t\t\tbuffer_x,  buffer_y);;",
666                "\t",
667                "\t",
668                "\tif (_this.buffer.el.iter_has_context_class(iter, \"comment\") ||",
669                "\t\t_this.buffer.el.iter_has_context_class(iter, \"string\")",
670                "\t) { ",
671                "\t\treturn ;",
672                "\t}",
673                "\t",
674                "\t",
675                "\t",
676                "\tvar back = iter.copy();",
677                "\tback.backward_char();",
678                "\t",
679                "\tvar forward = iter.copy();",
680                "\tforward.forward_char();",
681                "\t",
682                "\t// what's the character at the iter?",
683                "\tvar str = back.get_text(iter);",
684                "\tstr += iter.get_text(forward);",
685                "\tif (str.strip().length < 1) {",
686                "\t\treturn;",
687                "\t}",
688                "\tvar offset = iter.get_line_offset();",
689                "\tvar line = iter.get_line();",
690                "\tif (_this.prop != null) {",
691                "\t\t\t\t// ",
692                "\t\tline += _this.prop.start_line ; ",
693                "\t\t\t\t\t// this is based on Gtk using tabs (hence 1/2 chars);",
694                "\t\toffset += _this.node.node_pad.length;",
695                "\t\t\t\t\t// javascript listeners are indented 2 more spaces.",
696                "\t\tif (_this.prop.ptype == JsRender.NodePropType.LISTENER) {",
697                "\t\t\toffset += 2;",
698                "\t\t}",
699                "\t} ",
700                "\t",
701                "\tvar ls = _this.file.getLanguageServer();",
702                "\tls.hover.begin(",
703                "\t\t_this.file, line, offset,",
704                "\t\t( a, o)  => {",
705                "\t\t\tvar res = ls.hover.end(o );",
706                "\t\t\t_this.helper.setHelp(res);",
707                "\t\t});",
708                "\t\t",
709                "\t\t ",
710                " ",
711                "}",
712                ""
713               ]
714              },
715              "xtype" : "GestureClick"
716             }
717            ],
718            "listeners" : {
719             "query_tooltip" : [
720              "(x, y, keyboard_tooltip, tooltip) => {",
721              "\t",
722              "\t//GLib.debug(\"query tooltip\");",
723              "\tGtk.TextIter iter;",
724              "\tint trailing;",
725              "\t",
726              "\tvar yoff = (int) _this.RightEditor.el.vadjustment.value;",
727              "\t",
728              "\t// I think this is problematic - if it's compliing  / updating at same time as query.",
729              "\t",
730              "\t//if (_this.window.statusbar_compile_spinner.el.spinning) {",
731              "\t//\treturn false;",
732              "\t//}",
733              "\t",
734              "\tthis.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);",
735              "\t ",
736              "\tvar l = iter.get_line();",
737              "",
738              "\t",
739              "\t ",
740              "\t// GLib.debug(\"query tooltip line %d\", (int) l);",
741              "\tif (l < 0) {",
742              "",
743              "\t\treturn false;",
744              "\t}",
745              "\t/*",
746              "\tif (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {",
747              "\t\tGLib.debug(\"line %d setting tip to %s\", l,  _this.buffer.marks.get(l));",
748              "\t\ttooltip.set_text(_this.buffer.marks.get(l).dup());",
749              "\t\treturn true;",
750              "\t}",
751              " ",
752              "\treturn false;",
753              "\t*/",
754              "\t",
755              "\t  ",
756              "\t// this crashes?? - not sure why.",
757              "\tvar marks = _this.buffer.el.get_source_marks_at_line(l, \"ERR\");",
758              "\tif (marks.is_empty()) {",
759              "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"WARN\");",
760              "\t}",
761              "\tif (marks.is_empty()) {",
762              "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"DEPR\");",
763              "\t}",
764              "\t",
765              "\t// GLib.debug(\"query tooltip line %d marks %d\", (int)l, (int) marks.length());",
766              "\tvar str = \"\";",
767              "\tmarks.@foreach((m) => { ",
768              "\t\t//GLib.debug(\"got mark %s\", m.name);",
769              "\t\tstr += (str.length > 0 ? \"\\n\" : \"\") + m.category + \": \" + m.name;",
770              "\t});",
771              "\t// true if there is a mark..",
772              "\tif (str.length > 0 ) {",
773              "\t\ttooltip.set_text( str );",
774              "\t}",
775              "\treturn str.length > 0 ? true : false;",
776              "\t ",
777              "}",
778              ""
779             ]
780            },
781            "string name" : "editor-view",
782            "uint tab_width" : 4,
783            "xtype" : "View",
784            "| void load" : [
785             " (string str) {",
786             "",
787             "// show the help page for the active node..",
788             "   //this.get('/Help').show();",
789             " ",
790             "  // this.get('/BottomPane').el.set_current_page(0);",
791             "  \tGLib.debug(\"load called - Reset undo buffer\");",
792             "  \t",
793             "    var buf = (GtkSource.Buffer)this.el.get_buffer();",
794             "    buf.begin_irreversible_action();",
795             "    buf.set_text(str, str.length);",
796             "    buf.end_irreversible_action();",
797             "    ",
798             "    var lm = GtkSource.LanguageManager.get_default();",
799             "    var lang = \"vala\";",
800             "    if (_this.file != null) {",
801             "         lang = _this.file.language;",
802             "    }",
803             "    print(\"lang=%s, content_type = %s\\n\", lang, _this.file.content_type);",
804             "    var lg = _this.file.content_type.length > 0  ?",
805             "            lm.guess_language(_this.file.path, _this.file.content_type) :",
806             "            lm.get_language(lang);",
807             "     ",
808             "   ",
809             "    ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg); ",
810             "",
811             "    this.el.insert_spaces_instead_of_tabs = true;",
812             "    if (lg != null) {",
813             "\t\tprint(\"sourcelanguage  = %s\\n\", lg.name);",
814             "\t\tif (lg.name == \"Vala\") {",
815             "\t\t    this.el.insert_spaces_instead_of_tabs = false;",
816             "\t\t}",
817             "     }",
818             "    _this.dirty = false;",
819             "    this.el.grab_focus();",
820             "    _this.save_button.el.sensitive = false;",
821             "    _this.last_error_counter = -1;",
822             "}"
823            ]
824           }
825          ],
826          "xtype" : "ScrolledWindow"
827         },
828         {
829          "$ xns" : "Gtk",
830          "* pack" : "append",
831          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
832          "bool homogeneous" : false,
833          "bool vexpand" : false,
834          "int spacing" : 0,
835          "items" : [
836           {
837            "$ xns" : "Gtk",
838            "Gtk.CssProvider css" : "",
839            "bool hexpand" : true,
840            "id" : "search_entry",
841            "items" : [
842             {
843              "$ xns" : "Gtk",
844              "listeners" : {
845               "key_pressed" : [
846                "(keyval, keycode, state) => {",
847                "",
848                "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
849                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
850                "\t\t_this.forwardSearch(true);",
851                "\t    return true;",
852                "\t}",
853                "    ",
854                "  ",
855                " \tif (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {",
856                "\t\t_this.forwardSearch(true);",
857                "\t\t",
858                "\t\t",
859                "\t    return true;",
860                "",
861                "\t}    ",
862                "   // print(event.key.keyval)",
863                "   ",
864                "    return false;",
865                "}",
866                ""
867               ]
868              },
869              "xtype" : "EventControllerKey"
870             }
871            ],
872            "listeners" : {
873             "search_changed" : [
874              "( ) => {",
875              "",
876              "_this.search(_this.search_entry.el.text);",
877              "\t _this.search_results.updateResults();",
878              "",
879              "\tGLib.Timeout.add_seconds(1,() => {",
880              "\t\t _this.search_results.updateResults();",
881              "\t\t return false;",
882              "\t });",
883              "}",
884              ""
885             ]
886            },
887            "string name" : "editor-search-entry",
888            "string placeholder_text" : "Press enter to search",
889            "uint search_delay" : 3,
890            "xtype" : "SearchEntry",
891            "| void forwardSearch" : [
892             "(bool change_focus) {",
893             "",
894             "",
895             "\t_this.forwardSearch(change_focus);",
896             "",
897             "/*",
898             "",
899             "\tswitch(_this.windowstate.state) {",
900             "\t\tcase WindowState.State.CODEONLY:",
901             "\t\t//case WindowState.State.CODE:",
902             "\t\t\t// search the code being edited..",
903             "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
904             "\t\t\t ",
905             "\t\t\tbreak;",
906             "\t\tcase WindowState.State.PREVIEW:",
907             "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
908             "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
909             "\t\t\t} else { ",
910             "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
911             "\t\t\t}",
912             "\t\t",
913             "\t\t\tbreak;",
914             "\t}",
915             "\t*/",
916             "\t",
917             "}",
918             ""
919            ]
920           },
921           {
922            "$ xns" : "Gtk",
923            "id" : "search_results",
924            "int margin_end" : 4,
925            "int margin_start" : 4,
926            "string label" : "No Results",
927            "xtype" : "Label",
928            "| void updateResults" : [
929             "() {",
930             "\tthis.el.visible = true;",
931             "\t",
932             "\tvar res = _this.searchcontext.get_occurrences_count();",
933             "\tif (res < 0) {",
934             "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
935             "\t\treturn;",
936             "\t}",
937             "",
938             "\t_this.nextBtn.el.sensitive = false;",
939             "\t_this.backBtn.el.sensitive = false;\t",
940             "",
941             "\tif (res > 0) {",
942             "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
943             "\t\t_this.nextBtn.el.sensitive = true;",
944             "\t\t_this.backBtn.el.sensitive = true;",
945             "\t\treturn;",
946             "\t} ",
947             "\t_this.search_results.el.label = \"No Matches\";",
948             "\t",
949             "}"
950            ]
951           },
952           {
953            "$ xns" : "Gtk",
954            "bool always_show_image" : true,
955            "bool sensitive" : false,
956            "id" : "nextBtn",
957            "listeners" : {
958             "clicked" : [
959              "(event) => {",
960              "",
961              "\t_this.forwardSearch(true);",
962              "\t",
963              "\t ",
964              "}",
965              ""
966             ]
967            },
968            "string icon_name" : "go-down",
969            "xtype" : "Button"
970           },
971           {
972            "$ xns" : "Gtk",
973            "bool always_show_image" : true,
974            "bool sensitive" : false,
975            "id" : "backBtn",
976            "listeners" : {
977             "clicked" : [
978              "(event) => {",
979              "",
980              "\t_this.backSearch(true);",
981              "\t ",
982              "}",
983              ""
984             ]
985            },
986            "string icon_name" : "go-up",
987            "xtype" : "Button"
988           },
989           {
990            "$ xns" : "Gtk",
991            "bool always_show_arrow" : true,
992            "bool always_show_image" : true,
993            "items" : [
994             {
995              "$ xns" : "Gtk",
996              "* prop" : "popover",
997              "id" : "search_settings",
998              "items" : [
999               {
1000                "$ xns" : "Gtk",
1001                "* prop" : "child",
1002                "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
1003                "int spacing" : 0,
1004                "items" : [
1005                 {
1006                  "$ xns" : "Gtk",
1007                  "* init" : [
1008                   "{",
1009                   "\tthis.el.show();",
1010                   "}",
1011                   ""
1012                  ],
1013                  "id" : "case_sensitive",
1014                  "string label" : "Case Sensitive",
1015                  "xtype" : "CheckButton"
1016                 },
1017                 {
1018                  "$ xns" : "Gtk",
1019                  "* init" : [
1020                   "{",
1021                   "\tthis.el.show();",
1022                   "}",
1023                   ""
1024                  ],
1025                  "id" : "regex",
1026                  "string label" : "Regex",
1027                  "xtype" : "CheckButton"
1028                 },
1029                 {
1030                  "$ xns" : "Gtk",
1031                  "id" : "multiline",
1032                  "string label" : "Multi-line (add \\n)",
1033                  "xtype" : "CheckButton"
1034                 }
1035                ],
1036                "xtype" : "Box"
1037               }
1038              ],
1039              "xtype" : "Popover"
1040             }
1041            ],
1042            "string icon_name" : "emblem-system",
1043            "xtype" : "MenuButton"
1044           }
1045          ],
1046          "xtype" : "Box"
1047         }
1048        ],
1049        "xtype" : "Box"
1050       },
1051       {
1052        "$ xns" : "Gtk",
1053        "* prop" : "end_child",
1054        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
1055        "bool hexpand" : true,
1056        "bool vexpand" : true,
1057        "int spacing" : 0,
1058        "items" : [
1059         {
1060          "$ xns" : "Gtk",
1061          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
1062          "int spacing" : 0,
1063          "xtype" : "Box"
1064         },
1065         {
1066          "$ xns" : "Gtk",
1067          "bool hexpand" : true,
1068          "bool vexpand" : true,
1069          "bool visible" : false,
1070          "id" : "navigationwindow",
1071          "items" : [
1072           {
1073            "# int last_selected_line" : "-1",
1074            "$ Gtk.Widget? selected_row" : "null",
1075            "$ xns" : "Gtk",
1076            "* prop" : "child",
1077            "id" : "navigation",
1078            "items" : [
1079             {
1080              "$ xns" : "Gtk",
1081              "bool expand" : true,
1082              "items" : [
1083               {
1084                "$ xns" : "Gtk",
1085                "* prop" : "factory",
1086                "listeners" : {
1087                 "bind" : [
1088                  "(listitem) => {",
1089                  "\t ",
1090                  "\t// GLib.debug(\"listitme is is %s\", ((Gtk.ListItem)listitem).get_type().name());",
1091                  "\t",
1092                  "\t//var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();",
1093                  "\tvar expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();",
1094                  "\t ",
1095                  "\t ",
1096                  "\tvar hbox = (Gtk.Box) expand.child;",
1097                  " ",
1098                  "\t",
1099                  "\tvar img = (Gtk.Image) hbox.get_first_child();",
1100                  "\tvar lbl = (Gtk.Label) img.get_next_sibling();",
1101                  "\t",
1102                  "\tvar lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();",
1103                  "\tvar sym = (Lsp.DocumentSymbol) lr.get_item();",
1104                  "\t",
1105                  "\tsym.set_data<Gtk.Widget>(\"widget\", expand.get_parent());",
1106                  "\texpand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>(\"symbol\", sym);",
1107                  "\t",
1108                  "\t//GLib.debug(\"save sym on %s\", expand.get_parent().get_parent().get_type().name());",
1109                  "\t",
1110                  "\t//GLib.debug(\"got %d children for %s\" , (int)sym.children.get_n_items(), sym.name);",
1111                  "    ",
1112                  "    expand.set_hide_expander( sym.children.get_n_items()  < 1);",
1113                  " \texpand.set_list_row(lr);",
1114                  " \t//this.in_bind = true;",
1115                  " \t// default is to expand",
1116                  " ",
1117                  " \t//this.in_bind = false;",
1118                  " \t",
1119                  " \tsym.bind_property(\"symbol_icon\",",
1120                  "                    img, \"icon_name\",",
1121                  "                   GLib.BindingFlags.SYNC_CREATE);",
1122                  " \t",
1123                  " \thbox.css_classes = { sym.symbol_icon };",
1124                  " \t",
1125                  " \tsym.bind_property(\"name\",",
1126                  "                    lbl, \"label\",",
1127                  "                   GLib.BindingFlags.SYNC_CREATE);",
1128                  " \t// should be better?- --line no?",
1129                  " \tsym.bind_property(\"tooltip\",",
1130                  "                    lbl, \"tooltip_markup\",",
1131                  "                   GLib.BindingFlags.SYNC_CREATE);",
1132                  " \t// bind image...",
1133                  " \t",
1134                  "}",
1135                  ""
1136                 ],
1137                 "setup" : [
1138                  "(listitem) => {",
1139                  "\t",
1140                  "\tvar expand = new Gtk.TreeExpander();",
1141                  "\t ",
1142                  "\texpand.set_indent_for_depth(true);",
1143                  "\texpand.set_indent_for_icon(true);",
1144                  "\tvar hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);",
1145                  "\tvar icon = new Gtk.Image();",
1146                  "\tvar lbl = new Gtk.Label(\"\");",
1147                  "\tlbl.use_markup = true;",
1148                  "\tlbl.ellipsize = Pango.EllipsizeMode.END;",
1149                  "\t",
1150                  "\ticon.margin_end = 4;",
1151                  " \tlbl.justify = Gtk.Justification.LEFT;",
1152                  " \tlbl.xalign = 0;",
1153                  "",
1154                  "//\tlistitem.activatable = true; ??",
1155                  "\t",
1156                  "\thbox.append(icon);",
1157                  "\thbox.append(lbl);",
1158                  "\texpand.set_child(hbox);",
1159                  "\t((Gtk.ListItem)listitem).set_child(expand);",
1160                  "\t",
1161                  "}",
1162                  ""
1163                 ]
1164                },
1165                "xtype" : "SignalListItemFactory"
1166               }
1167              ],
1168              "string title" : "Code Navigation",
1169              "xtype" : "ColumnViewColumn"
1170             },
1171             {
1172              "$ xns" : "Gtk",
1173              "* prop" : "model",
1174              "id" : "navigationselmodel",
1175              "items" : [
1176               {
1177                "$ xns" : "Gtk",
1178                "* prop" : "model",
1179                "id" : "navigationsort",
1180                "items" : [
1181                 {
1182                  "$ Gtk.TreeListModelCreateModelFunc create_func" : [
1183                   "(item) => {",
1184                   " ",
1185                   "\treturn ((Lsp.DocumentSymbol)item).children;",
1186                   "}",
1187                   ""
1188                  ],
1189                  "$ xns" : "Gtk",
1190                  "* prop" : "model",
1191                  "bool autoexpand" : true,
1192                  "bool passthrough" : false,
1193                  "items" : [
1194                   {
1195                    "$ GLib.Type item_type" : "typeof(Lsp.DocumentSymbol)",
1196                    "$ xns" : "GLib",
1197                    "* prop" : "root",
1198                    "id" : "navliststore",
1199                    "xtype" : "ListStore",
1200                    "| Lsp.DocumentSymbol? symbolAtLine" : [
1201                     "(uint line, uint chr) {",
1202                     " ",
1203                     "\t",
1204                     "\tfor(var i = 0; i < this.el.get_n_items();i++) {",
1205                     "\t\tvar el = (Lsp.DocumentSymbol)this.el.get_item(i);",
1206                     "\t\t//GLib.debug(\"Check sym %s : %d-%d\",",
1207                     "\t\t//\tel.name , (int)el.range.start.line,",
1208                     "\t\t//\t(int)el.range.end.line",
1209                     "\t\t//);",
1210                     "\t\tvar ret = el.containsLine(line,chr);",
1211                     "\t\tif (ret != null) {",
1212                     "\t\t\treturn ret;",
1213                     "\t\t}",
1214                     "\t\t",
1215                     "\t}",
1216                     "\t",
1217                     "\treturn null;",
1218                     "}"
1219                    ]
1220                   }
1221                  ],
1222                  "listeners" : {
1223                   "items_changed" : [
1224                    "(position, removed, added) => {",
1225                    "\tGLib.debug(\"tree item changed %d , %d , %d\",(int) position, (int)removed, (int) added);",
1226                    "\t if (added < 1) { ",
1227                    "\t \treturn;",
1228                    " \t}",
1229                    "\t//var sym = (Lsp.DocumentSymbol) this.el.get_item(position);",
1230                    "\tvar row = this.el.get_row(position);",
1231                    "\t",
1232                    "\tGLib.debug(\"got %s\", row.get_item().get_type().name());",
1233                    "\t",
1234                    "",
1235                    "}",
1236                    ""
1237                   ]
1238                  },
1239                  "xtype" : "TreeListModel"
1240                 },
1241                 {
1242                  "$ xns" : "Gtk",
1243                  "* prop" : "sorter",
1244                  "items" : [
1245                   {
1246                    "$ xns" : "Gtk",
1247                    "* prop" : "sorter",
1248                    "items" : [
1249                     {
1250                      "$ GLib.Type this_type" : "typeof(Lsp.DocumentSymbol)",
1251                      "$ xns" : "Gtk",
1252                      "* prop" : "expression",
1253                      "string property_name" : "sort_key",
1254                      "xtype" : "PropertyExpression"
1255                     }
1256                    ],
1257                    "xtype" : "StringSorter"
1258                   }
1259                  ],
1260                  "xtype" : "TreeListRowSorter"
1261                 }
1262                ],
1263                "xtype" : "SortListModel",
1264                "| Lsp.DocumentSymbol? getSymbolAt" : [
1265                 "(uint row) {",
1266                 "",
1267                 "   var tr = (Gtk.TreeListRow)this.el.get_item(row);",
1268                 "   ",
1269                 "   var a = tr.get_item();;   ",
1270                 "   GLib.debug(\"get_item (2) = %s\", a.get_type().name());",
1271                 "  \t",
1272                 "   ",
1273                 "   return (Lsp.DocumentSymbol)tr.get_item();",
1274                 "\t ",
1275                 "}"
1276                ],
1277                "| int getRowFromSymbol" : [
1278                 "(Lsp.DocumentSymbol sym) {",
1279                 "",
1280                 "\tfor (var i=0;i < this.el.get_n_items(); i++) {",
1281                 "\t\tvar tr = (Gtk.TreeListRow)this.el.get_item(i);",
1282                 "\t   ",
1283                 "\t\tif (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {",
1284                 "\t\t\treturn i;",
1285                 "\t\t}",
1286                 "\t}",
1287                 "   \treturn -1;",
1288                 "}"
1289                ],
1290                "| void collapseOnLoad" : [
1291                 "() {",
1292                 "\tfor (var i=0;i < this.el.get_n_items(); i++) {",
1293                 "\t\tvar tr = (Gtk.TreeListRow)this.el.get_item(i);",
1294                 "\t\tvar sym =  (Lsp.DocumentSymbol)tr.get_item();",
1295                 "\t\tswitch (sym.kind) {",
1296                 "\t \t\tcase Lsp.SymbolKind.Enum: ",
1297                 "\t \t\t\ttr.expanded = false;",
1298                 "\t \t\t\tbreak;",
1299                 "\t\t\tdefault:",
1300                 "\t\t\t\t//tr.expanded = true;",
1301                 "\t\t\t\tbreak;",
1302                 "\t\t}",
1303                 "\t}",
1304                 " ",
1305                 "\t",
1306                 "",
1307                 "",
1308                 "}"
1309                ]
1310               }
1311              ],
1312              "xtype" : "NoSelection"
1313             },
1314             {
1315              "$ xns" : "Gtk",
1316              "listeners" : {
1317               "pressed" : [
1318                "(n_press, x, y) => {",
1319                "\tstring pos;",
1320                "  \tvar row = _this.navigation.getRowWidgetAt(x,y, out pos );",
1321                "",
1322                "    if (row == null) {",
1323                "\t    GLib.debug(\"no row selected items\");",
1324                "\t    return;",
1325                "    }",
1326                "\tGLib.debug(\"got click on %s\", row.get_type().name());    ",
1327                "    //Lsp.DocumentSymbol",
1328                "    var sym =  row.get_data<Lsp.DocumentSymbol>(\"symbol\");",
1329                "    if (sym == null) {",
1330                "    \treturn;",
1331                "\t}",
1332                "\t/*",
1333                "\t \"range\" : {",
1334                "              \"start\" : {",
1335                "                \"line\" : 1410,",
1336                "                \"character\" : 8",
1337                "              },",
1338                "              \"end\" : {",
1339                "                \"line\" : 1410,",
1340                "                \"character\" : 39",
1341                "              }",
1342                "            },",
1343                "        */",
1344                "     GLib.debug(\"goto line %d\",   (int)sym.range.start.line); ",
1345                "    _this.scroll_to_line((int)sym.range.start.line);",
1346                "    Gtk.TextIter iter;",
1347                "    _this.buffer.el.get_iter_at_line_offset(out iter, ",
1348                "    \t(int)sym.range.start.line,",
1349                "    \t(int)sym.range.start.character",
1350                "\t);",
1351                "    _this.buffer.el.place_cursor(iter);",
1352                "\t",
1353                "}"
1354               ]
1355              },
1356              "xtype" : "GestureClick"
1357             }
1358            ],
1359            "string name" : "editor-navigation",
1360            "xtype" : "ColumnView",
1361            "| Gtk.Widget? getRowWidgetAt" : [
1362             "(double x,  double  y, out string pos) {",
1363             "",
1364             "\tpos = \"\";",
1365             "\tvar w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);",
1366             "\t//GLib.debug(\"got widget %s\", w == null ? \"nothing\" : w.get_type().name());",
1367             "\tif (w == null) {",
1368             "\t\treturn null;",
1369             "\t}",
1370             "\t",
1371             "\tvar row= w.get_ancestor(GLib.Type.from_name(\"GtkColumnViewRowWidget\"));",
1372             "\tif (row == null) {",
1373             "\t\treturn null;",
1374             "\t}",
1375             "\t",
1376             "\t//GLib.debug(\"got colview %s\", row == null ? \"nothing\" : row.get_type().name());",
1377             "\t ",
1378             " ",
1379             "\t",
1380             "\t//GLib.debug(\"row number is %d\", rn);",
1381             "\t//GLib.debug(\"click %d, %d\", (int)x, (int)y);",
1382             "\t// above or belw",
1383             "\tGraphene.Rect  bounds;",
1384             "\trow.compute_bounds(this.el, out bounds);",
1385             "\t//GLib.debug(\"click x=%d, y=%d, w=%d, h=%d\", ",
1386             "\t//\t(int)bounds.get_x(), (int)bounds.get_y(),",
1387             "\t//\t(int)bounds.get_width(), (int)bounds.get_height()",
1388             "\t//\t);",
1389             "\tvar ypos = y - bounds.get_y();",
1390             "\t//GLib.debug(\"rel ypos = %d\", (int)ypos);\t",
1391             "\tvar rpos = 100.0 * (ypos / bounds.get_height());",
1392             "\t//GLib.debug(\"rel pos = %d %%\", (int)rpos);",
1393             "\tpos = \"over\";",
1394             "\t",
1395             "\tif (rpos > 80) {",
1396             "\t\tpos = \"below\";",
1397             "\t} else if (rpos < 20) {",
1398             "\t\tpos = \"above\";",
1399             "\t} ",
1400             "\treturn row;",
1401             " }"
1402            ],
1403            "| int getRowAt" : [
1404             "(double x,  double  y, out string pos) {",
1405             "",
1406             "\tpos = \"\";",
1407             "\tvar w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);",
1408             "\t//GLib.debug(\"got widget %s\", w == null ? \"nothing\" : w.get_type().name());",
1409             "\tif (w == null) {",
1410             "\t\treturn -1;",
1411             "\t}",
1412             "\t",
1413             "\tvar row= w.get_ancestor(GLib.Type.from_name(\"GtkColumnViewRowWidget\"));",
1414             "\tif (row == null) {",
1415             "\t\treturn -1;",
1416             "\t}",
1417             "\t",
1418             "\t//GLib.debug(\"got colview %s\", row == null ? \"nothing\" : row.get_type().name());",
1419             "\t ",
1420             "\tvar rn = 0;",
1421             "\tvar cr = row;",
1422             "\t ",
1423             "\twhile (cr.get_prev_sibling() != null) {",
1424             "\t\trn++;",
1425             "\t\tcr = cr.get_prev_sibling();",
1426             "\t}",
1427             "\t",
1428             "\t//GLib.debug(\"row number is %d\", rn);",
1429             "\t//GLib.debug(\"click %d, %d\", (int)x, (int)y);",
1430             "\t// above or belw",
1431             "\tGraphene.Rect  bounds;",
1432             "\trow.compute_bounds(this.el, out bounds);",
1433             "\t//GLib.debug(\"click x=%d, y=%d, w=%d, h=%d\", ",
1434             "\t//\t(int)bounds.get_x(), (int)bounds.get_y(),",
1435             "\t//\t(int)bounds.get_width(), (int)bounds.get_height()",
1436             "\t//\t);",
1437             "\tvar ypos = y - bounds.get_y();",
1438             "\t//GLib.debug(\"rel ypos = %d\", (int)ypos);\t",
1439             "\tvar rpos = 100.0 * (ypos / bounds.get_height());",
1440             "\t//GLib.debug(\"rel pos = %d %%\", (int)rpos);",
1441             "\tpos = \"over\";",
1442             "\t",
1443             "\tif (rpos > 80) {",
1444             "\t\tpos = \"below\";",
1445             "\t} else if (rpos < 20) {",
1446             "\t\tpos = \"above\";",
1447             "\t} ",
1448             "\treturn rn;",
1449             " }"
1450            ],
1451            "| void show" : [
1452             "(Gee.ArrayList<Lsp.DocumentSymbol> syms) {",
1453             "\t_this.navigationwindow.el.show();",
1454             "\t//_this.navliststore.el.remove_all();",
1455             "\t",
1456             "\t",
1457             "\tvar ls  = new GLib.ListStore(typeof(Lsp.DocumentSymbol));",
1458             "\t",
1459             "\tforeach(var sym in syms) {",
1460             "\t\tls.append(sym);",
1461             "\t}",
1462             "\tLsp.DocumentSymbol.copyList(ls, _this.navliststore.el);",
1463             "\t//_this.navliststore.el.append(sym);",
1464             "\tthis.last_selected_line = -1;",
1465             "\tGLib.Idle.add(() => {",
1466             "\t\t_this.navigationsort.collapseOnLoad();",
1467             "\t\tGtk.TextIter iter;",
1468             "\t\t_this.buffer.el.get_iter_at_offset (",
1469             "\t\t\t\tout iter, _this.buffer.el.cursor_position);",
1470             "\t\t",
1471             "\t\tGLib.debug(\"idle update scroll %d, %d\", iter.get_line(),",
1472             "\t\t\t\titer.get_line_offset());",
1473             "\t\tthis.updateSelectedLine(",
1474             "\t\t\t\t(uint)iter.get_line(),",
1475             "\t\t\t\t(uint)iter.get_line_offset()",
1476             "\t\t);",
1477             "\t\treturn false;",
1478             "\t});",
1479             "",
1480             "}"
1481            ],
1482            "| void updateSelectedLine" : [
1483             "(uint line, uint chr) {",
1484             "\tif (line == this.last_selected_line) {",
1485             "\t\treturn;",
1486             "\t}",
1487             "\tGLib.debug(\"select line %d\", (int)line);",
1488             "\tthis.last_selected_line = (int)line;",
1489             "\t",
1490             "\t",
1491             "\tvar new_row = -1;",
1492             "\tvar sym = _this.navliststore.symbolAtLine(line, chr);",
1493             "\tif (sym != null) {",
1494             "\t \tnew_row = _this.navigationsort.getRowFromSymbol(sym);",
1495             " \t\tGLib.debug(\"select line %d - row found %d\", (int)line, new_row);",
1496             " \t} else {",
1497             " \t\tGLib.debug(\" no symbol found at line %d\", (int)line);",
1498             " \t}",
1499             " \t",
1500             "\tif (this.selected_row != null) { ",
1501             "\t\tGLib.debug(\" remove selected row\");",
1502             "\t\tthis.selected_row.remove_css_class(\"selected-row\");",
1503             "\t}",
1504             "\tthis.selected_row  = null;",
1505             "\tif (new_row > -1) {",
1506             "\t\tthis.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);",
1507             "\t\tvar row = sym.get_data<Gtk.Widget>(\"widget\");",
1508             "\t\tif (row != null) {",
1509             "\t\t\tGLib.debug(\" Add selected row\");",
1510             " \t\t\t",
1511             "\t\t\trow.add_css_class(\"selected-row\");",
1512             "\t\t\tthis.selected_row = row;",
1513             "",
1514             "\t\t\t",
1515             "\t\t} else {",
1516             "\t\t\tGLib.debug(\"could not find widget on row %d\", new_row);",
1517             "\t\t}",
1518             "",
1519             "\t}",
1520             "",
1521             "",
1522             "}"
1523            ]
1524           }
1525          ],
1526          "xtype" : "ScrolledWindow"
1527         }
1528        ],
1529        "xtype" : "Box"
1530       }
1531      ],
1532      "xtype" : "Paned"
1533     }
1534    ],
1535    "xtype" : "Box",
1536    "| bool saveContents" : [
1537     "  ()  {",
1538     "    ",
1539     "    ",
1540     "    if (_this.file == null) {",
1541     "        return true;",
1542     "    }",
1543     "    ",
1544     "     ",
1545     "     ",
1546     "     var str = _this.buffer.toString();",
1547     "     ",
1548     "     _this.buffer.checkSyntax();",
1549     "     ",
1550     "     ",
1551     "     ",
1552     "     // LeftPanel.model.changed(  str , false);",
1553     "     _this.dirty = false;",
1554     "     _this.save_button.el.sensitive = false;",
1555     "     ",
1556     "    // find the text for the node..",
1557     "    if (_this.file.xtype != \"PlainFile\") {",
1558     "       // in theory these properties have to exist!?!",
1559     "    \tthis.prop.val = str;",
1560     "        //this.window.windowstate.left_props.reload();",
1561     "    } else {",
1562     "        _this.file.setSource(  str );",
1563     "     }",
1564     "    ",
1565     "    // call the signal..",
1566     "    this.save();",
1567     "    ",
1568     "    return true;",
1569     "",
1570     "} "
1571    ],
1572    "| int search" : [
1573     "(string in_txt) {",
1574     "",
1575     "\tvar s = new GtkSource.SearchSettings();",
1576     "\ts.case_sensitive = _this.case_sensitive.el.active;",
1577     "\ts.regex_enabled = _this.regex.el.active;\t",
1578     "\ts.wrap_around = false;",
1579     "\t",
1580     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
1581     "\tthis.searchcontext.set_highlight(true);",
1582     "\tvar txt = in_txt;",
1583     "\t",
1584     "\tif (_this.multiline.el.active) {",
1585     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
1586     "\t}",
1587     "\t",
1588     "\ts.set_search_text(txt);",
1589     "\tGtk.TextIter beg, st,en;",
1590     "\t ",
1591     "\tthis.buffer.el.get_start_iter(out beg);",
1592     "\tbool has_wrapped_around;",
1593     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
1594     "\tthis.last_search_end = 0;",
1595     "\t",
1596     "\treturn this.searchcontext.get_occurrences_count();",
1597     "",
1598     " ",
1599     "   ",
1600     "",
1601     "}",
1602     ""
1603    ],
1604    "| string tempFileContents" : [
1605     "() {",
1606     "   ",
1607     "   ",
1608     "   if (_this.file == null) {",
1609     "       return \"\";",
1610     "   }",
1611     "\tvar str= this.buffer.toString();",
1612     "\tif (_this.file.xtype == \"PlainFile\") {",
1613     "    ",
1614     "     \treturn str;",
1615     "    ",
1616     "    }",
1617     "  ",
1618     "      ",
1619     "     ",
1620     "    GLib.debug(\"calling validate\");    ",
1621     "    // clear the buttons.",
1622     " \tif (_this.prop.name == \"xns\" || _this.prop.name == \"xtype\") {",
1623     "\t\treturn this.file.toSource(); ;",
1624     "\t}",
1625     "\t",
1626     "\tvar oldcode  = _this.prop.val;",
1627     "\t_this.prop.val = str;",
1628     "    var ret = _this.file.toSource();",
1629     "    _this.prop.val = oldcode;",
1630     "    return ret;",
1631     "    ",
1632     "}"
1633    ],
1634    "| void backSearch" : [
1635     "(bool change_focus) {",
1636     "",
1637     "\tif (this.searchcontext == null) {",
1638     "\t\treturn;",
1639     "\t}",
1640     "\t",
1641     "\tGtk.TextIter beg, st,en;",
1642     "\tbool has_wrapped_around;",
1643     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
1644     "\t",
1645     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
1646     "\t\tthis.last_search_end = 0;",
1647     "\t} else {",
1648     "\t\tthis.last_search_end = en.get_offset();",
1649     "\t\tif (change_focus) {",
1650     "\t\t\tthis.view.el.grab_focus();",
1651     "\t\t}",
1652     "\t\tthis.buffer.el.place_cursor(st);",
1653     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1654     "\t}",
1655     "",
1656     "}",
1657     ""
1658    ],
1659    "| void forwardSearch" : [
1660     "(bool change_focus) {",
1661     "",
1662     "\tif (this.searchcontext == null) {",
1663     "\t\treturn;",
1664     "\t} ",
1665     "",
1666     "\tGtk.TextIter beg, st,en;",
1667     "\t bool has_wrapped_around;",
1668     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end);",
1669     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
1670     "\t",
1671     "\t\tthis.last_search_end = 0; // not sure if this should happen",
1672     "\t} else {",
1673     "\t\tif (has_wrapped_around) {",
1674     "\t\t\treturn;",
1675     "\t\t}",
1676     "\t",
1677     "\t\tthis.last_search_end = en.get_offset();",
1678     "\t\tif (change_focus) {",
1679     "\t\t\tthis.view.el.grab_focus();",
1680     "\t\t}",
1681     "\t\tthis.buffer.el.place_cursor(st);",
1682     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1683     "\t}",
1684     " ",
1685     "}",
1686     ""
1687    ],
1688    "| void reset" : [
1689     "() {",
1690     "\t this.file = null;    ",
1691     "     ",
1692     "    this.node = null;",
1693     "    this.prop = null;",
1694     "\tthis.searchcontext = null;",
1695     "  ",
1696     "}",
1697     ""
1698    ],
1699    "| void scroll_to_line" : [
1700     "(int line) {",
1701     "",
1702     "\tGLib.Timeout.add(500, () => {",
1703     "   ",
1704     "\t\tvar buf = this.view.el.get_buffer();",
1705     "",
1706     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1707     "",
1708     "",
1709     "\t\tGtk.TextIter iter;   ",
1710     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1711     "\t\tthis.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1712     "\t\treturn false;",
1713     "\t});   ",
1714     "}",
1715     ""
1716    ],
1717    "| void show" : [
1718     "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
1719     "{",
1720     "    this.reset();",
1721     "    if (this.file != null) {",
1722     "    \tthis.file.navigation_tree_updated.disconnect(",
1723     "    \t\t_this.navigation.show",
1724     "    \t);",
1725     "    }",
1726     "    this.file = file;    ",
1727     "    this.file.navigation_tree_updated.connect(",
1728     "\t\t_this.navigation.show",
1729     "\t);",
1730     "    if (file.xtype != \"PlainFile\") {",
1731     "    \tthis.prop = prop;",
1732     "        this.node = node;",
1733     "",
1734     "        // find the text for the node..",
1735     "        this.view.load( prop.val );",
1736     "        this.updateErrorMarks();",
1737     "        ",
1738     "        ",
1739     "        ",
1740     "        this.close_btn.el.show();       ",
1741     "    ",
1742     "    } else {",
1743     "        this.view.load(        file.toSource() );",
1744     "        this.updateErrorMarks();",
1745     "        this.close_btn.el.hide();",
1746     "        var ls = file.getLanguageServer();",
1747     "        ls.queueDocumentSymbols(file);",
1748     "        ////ls.documentSymbols.begin(file, (a,o) => {",
1749     "        //\t_this.navigation.show(ls.documentSymbols.end(o)); ",
1750     "       //});",
1751     "        //documentSymbols",
1752     "        ",
1753     "    }",
1754     " ",
1755     "}"
1756    ],
1757    "| void updateErrorMarks" : [
1758     "() {",
1759     "\t",
1760     " ",
1761     "",
1762     "\tvar buf = _this.buffer.el;",
1763     "\tGtk.TextIter start;",
1764     "\tGtk.TextIter end;     ",
1765     "\tbuf.get_bounds (out start, out end);",
1766     "",
1767     "\t",
1768     "",
1769     " ",
1770     "\t//GLib.debug(\"highlight errors\");\t\t ",
1771     "",
1772     "\t // we should highlight other types of errors..",
1773     "",
1774     "\tif (_this.window.windowstate.state != WindowState.State.CODEONLY ",
1775     "\t\t&&",
1776     "\t\t_this.window.windowstate.state != WindowState.State.CODE",
1777     "\t\t) {",
1778     "\t\t//GLib.debug(\"windowstate != CODEONLY?\");",
1779     "\t\t",
1780     "\t\treturn;",
1781     "\t} ",
1782     "",
1783     "\t ",
1784     "\tif (_this.file == null) {",
1785     "\t\tGLib.debug(\"file is null?\");",
1786     "\t\treturn;",
1787     "",
1788     "\t}",
1789     "\tvar ar = this.file.getErrors();",
1790     "\tif (ar.size < 1) {",
1791     "\t\tbuf.remove_source_marks (start, end, \"ERR\");",
1792     "\t\tbuf.remove_source_marks (start, end, \"WARN\");",
1793     "\t\tbuf.remove_source_marks (start, end, \"DEPR\");",
1794     "\t\tbuf.remove_tag_by_name (\"ERR\", start, end);",
1795     "\t\tbuf.remove_tag_by_name (\"WARN\", start, end);",
1796     "\t\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
1797     "\t\tthis.last_error_counter = file.error_counter ;",
1798     "\t\t//GLib.debug(\"highlight %s :  %s has no errors\", this.file.relpath, category);",
1799     "\t\treturn;",
1800     "\t}",
1801     "\t",
1802     "",
1803     " // basicaly check if there is no change, then we do not do any update..",
1804     " // we can do this by just using an error counter?",
1805     " // if that's changed then we will do an update, otherwise dont bother.",
1806     "\t  ",
1807     "\t",
1808     "\tvar offset = 0;",
1809     "\tvar hoffset = 0;",
1810     "",
1811     "\tvar tlines = buf.get_line_count () +1;",
1812     "\t",
1813     "\tif (_this.prop != null) {",
1814     "\t\t// this still seems flaky...",
1815     "",
1816     "\t\ttlines = _this.prop.end_line;",
1817     "\t\toffset = _this.prop.start_line;",
1818     "\t\thoffset = _this.node.node_pad.length + 2; //shift it left  by 2 ? ..",
1819     "\t\t",
1820     "\t\t ",
1821     "\t} else {",
1822     "\t\t// no update...",
1823     "\t\tif (this.last_error_counter == file.error_counter) {",
1824     "\t\t",
1825     "\t\t\treturn;",
1826     "\t\t}",
1827     "\t",
1828     "\t}",
1829     "\tbuf.remove_source_marks (start, end, \"ERR\");",
1830     "\tbuf.remove_source_marks (start, end, \"WARN\");",
1831     "\tbuf.remove_source_marks (start, end, \"DEPR\");",
1832     "\tbuf.remove_tag_by_name (\"ERR\", start, end);",
1833     "\tbuf.remove_tag_by_name (\"WARN\", start, end);",
1834     "\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
1835     "\t",
1836     "\tforeach(var diag in ar) { ",
1837     "\t     Gtk.TextIter iter;",
1838     "//        print(\"get inter\\n\");",
1839     "\t    var eline = (int)diag.range.start.line - offset;",
1840     "\t    var eline_to = (int)diag.range.end.line - offset;",
1841     "\t    //var eline =  diag.range.end_line - offset;",
1842     "\t    //GLib.debug(\"GOT ERROR on line %d -- converted to %d  (offset = %d)\",",
1843     "\t    //\terr.line ,eline, offset);",
1844     "\t    ",
1845     "\t    ",
1846     "\t    if (eline > tlines || eline < 0) {",
1847     "\t        continue;",
1848     "\t    }",
1849     "\t    ",
1850     "\t    buf.get_iter_at_line( out iter, eline);",
1851     "\t   \tvar msg = \"Line: %d %s : %s\".printf(eline+1, diag.category, diag.message);",
1852     "\t    buf.create_source_mark( msg, diag.category, iter);",
1853     "\t    ",
1854     " \t    var spos = (int)diag.range.start.character - hoffset;",
1855     " \t    if (spos < 0) { spos =0 ; }",
1856     " \t    if (spos > iter.get_chars_in_line()) {",
1857     " \t    \tspos = iter.get_chars_in_line();",
1858     "    \t}",
1859     "\t\tbuf.get_iter_at_line( out iter, eline_to);",
1860     "\t\tvar epos = (int)diag.range.end.character - hoffset;",
1861     " \t    if (epos < 0) { epos =0 ; }",
1862     " \t    if (epos > iter.get_chars_in_line()) {",
1863     " \t    \tepos = iter.get_chars_in_line();",
1864     "    \t}",
1865     " \t     ",
1866     " \t    ",
1867     " \t    buf.get_iter_at_line_offset( out start, eline, spos); ",
1868     " \t   ",
1869     " \t    buf.get_iter_at_line_offset( out end, eline_to,epos); ",
1870     " \t    \t",
1871     "\t    buf.apply_tag_by_name(diag.category, start, end);",
1872     "\t    ",
1873     "\t   // GLib.debug(\"set line %d to %s\", eline, msg);",
1874     "\t    //this.marks.set(eline, msg);",
1875     "\t}",
1876     "\tthis.last_error_counter = file.error_counter ;",
1877     "",
1878     "",
1879     "",
1880     " ",
1881     "",
1882     "}"
1883    ]
1884   }
1885  ],
1886  "name" : "Editor"
1887 }