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