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