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