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