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