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