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