Fix #8033 - text size zoom
[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      "$ homogeneous" : false,
27      "$ xns" : "Gtk",
28      "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
29      "bool hexpand" : true,
30      "items" : [
31       {
32        "$ xns" : "Gtk",
33        "id" : "save_button",
34        "label" : "Save",
35        "listeners" : {
36         "clicked" : [
37          " () => { ",
38          "    _this.saveContents();",
39          "}",
40          "  "
41         ]
42        },
43        "xtype" : "Button"
44       },
45       {
46        "$ xns" : "Gtk",
47        "bool hexpand" : true,
48        "xtype" : "Label"
49       },
50       {
51        "$ xns" : "Gtk",
52        "* ctor" : "new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1)",
53        "* init" : [
54         "{",
55         "\t//this.el.set_range(6,30);",
56         " \tthis.el.set_value ( BuilderApplication.settings.editor_font_size);",
57         " \tBuilderApplication.settings.editor_font_size_updated.connect(",
58         " \t\t() => {",
59         " \t\t\tBuilderApplication.settings.editor_font_size_inchange = true;",
60         " \t\t\tGLib.debug(\"update range\");",
61         " \t\t \tthis.el.set_value (BuilderApplication.settings.editor_font_size);",
62         " \t\t \tBuilderApplication.settings.editor_font_size_inchange = false;",
63         " \t\t}",
64         "\t);",
65         "\t",
66         " ",
67         "}",
68         ""
69        ],
70        "bool draw_value" : false,
71        "bool has_origin" : true,
72        "bool sensitive" : true,
73        "int digits" : 0,
74        "int width_request" : 200,
75        "listeners" : {
76         "change_value" : [
77          "(st, val ) => {",
78          "\tif (BuilderApplication.settings.editor_font_size_inchange) {",
79          "\t\treturn false;",
80          "\t}",
81          "  \tBuilderApplication.settings.editor_font_size = val;",
82          " \treturn false;",
83          "}"
84         ]
85        },
86        "xtype" : "Scale"
87       },
88       {
89        "$ xns" : "Gtk",
90        "id" : "close_btn",
91        "items" : [
92         {
93          "$ xns" : "Gtk",
94          "* prop" : "child",
95          "Gtk.IconSize icon_size" : "Gtk.IconSize.NORMAL",
96          "string icon_name" : "window-close",
97          "xtype" : "Image"
98         }
99        ],
100        "listeners" : {
101         "clicked" : [
102          " () => { ",
103          "    _this.saveContents();",
104          "    _this.window.windowstate.switchState(WindowState.State.PREVIEW);",
105          "}",
106          "  "
107         ]
108        },
109        "string icon_name" : "window-close",
110        "xtype" : "Button"
111       }
112      ],
113      "xtype" : "Box"
114     },
115     {
116      "$ xns" : "Gtk",
117      "Gtk.PolicyType hscrollbar_policy" : "Gtk.PolicyType.AUTOMATIC",
118      "Gtk.PolicyType vscrollbar_policy" : "Gtk.PolicyType.AUTOMATIC",
119      "bool overlay_scrolling" : false,
120      "bool vexpand" : true,
121      "id" : "RightEditor",
122      "items" : [
123       {
124        "# Gtk.CssProvider css" : "null",
125        "$ gboolean auto_indent" : true,
126        "$ xns" : "GtkSource",
127        "* init" : [
128         "",
129         " ",
130         "\t",
131         " ",
132         " ",
133         "this.el.completion.add_provider(",
134         "\tnew Palete.CompletionProvider(_this)",
135         ");",
136         "  ",
137         "//this.el.completion.unblock_interactive();",
138         "this.el.completion.select_on_show = true; // select",
139         "//this.el.completion.remember_info_visibility\t = true;",
140         "",
141         "",
142         "var attrs = new GtkSource.MarkAttributes();",
143         "",
144         "attrs.set_icon_name ( \"process-stop\");    ",
145         "attrs.query_tooltip_text.connect(( mark) => {",
146         "     GLib.debug(\"tooltip query? %s\", mark.name);",
147         "    return strdup( mark.name);",
148         "});",
149         " attrs.query_tooltip_markup.connect(( mark) => {",
150         "     GLib.debug(\"tooltip query? %s\", mark.name);",
151         "    return strdup( mark.name);",
152         "});",
153         "this.el.set_mark_attributes (\"ERR\", attrs, 1);",
154         "attrs.ref();",
155         "",
156         "",
157         "var wattrs = new GtkSource.MarkAttributes();",
158         "wattrs.set_icon_name ( \"process-stop\");    ",
159         "wattrs.query_tooltip_text.connect(( mark) => {",
160         "     GLib.debug(\"tooltip query? %s\", mark.name);",
161         "    return strdup(mark.name);",
162         "});",
163         "wattrs.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 (\"WARN\", wattrs, 1);",
168         "wattrs.ref();",
169         "",
170         " ",
171         "var dattrs = new GtkSource.MarkAttributes();",
172         " ",
173         "dattrs.set_icon_name ( \"process-stop\"); ",
174         "",
175         "dattrs.query_tooltip_text.connect(( mark) => {",
176         "\tGLib.debug(\"tooltip query? %s\", mark.name);",
177         "    return strdup(mark.name);",
178         "});",
179         "//dattrs.query_tooltip_markup.connect(( mark) => {",
180         "//\tGLib.debug(\"tooltip query? %s\", mark.name);",
181         " //   return strdup(mark.name);",
182         "//});",
183         "this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
184         "dattrs.ref();    ",
185         "",
186         " this.el.get_space_drawer().set_matrix(null);",
187         " this.el.get_space_drawer().set_types_for_locations( ",
188         "\tGtkSource.SpaceLocationFlags.ALL,",
189         "\tGtkSource.SpaceTypeFlags.ALL",
190         ");",
191         "this.el.get_space_drawer().set_enable_matrix(true);",
192         ""
193        ],
194        "* prop" : "child",
195        "bool has_tooltip" : true,
196        "bool hexpand" : true,
197        "bool insert_spaces_instead_of_tabs" : true,
198        "bool vexpand" : true,
199        "boolean show_line_marks" : true,
200        "boolean show_line_numbers" : true,
201        "css_classes" : "{ \"code-editor\" }",
202        "gboolean highlight_current_line" : true,
203        "id" : "view",
204        "indent_width" : 4,
205        "items" : [
206         {
207          "$ Gee.HashMap<int,string>? xmarks" : "null",
208          "$ xns" : "GtkSource",
209          "$ xtype" : "Buffer",
210          "* init" : [
211           "",
212           "var buf = this.el;",
213           "buf.create_tag (\"bold\", \"weight\", Pango.Weight.BOLD);",
214           "buf.create_tag (\"type\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#204a87\");",
215           "buf.create_tag (\"keyword\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#a40000\");",
216           "buf.create_tag (\"text\", \"weight\", Pango.Weight.NORMAL, \"foreground\", \"#729fcf\");",
217           "buf.create_tag (\"number\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#ad7fa8\");",
218           "buf.create_tag (\"method\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#729fcf\");",
219           "buf.create_tag (\"property\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#BC1F51\");",
220           "buf.create_tag (\"variable\", \"weight\", Pango.Weight.BOLD, \"foreground\", \"#A518B5\");",
221           "",
222           "",
223           "buf.create_tag (\"ERR\", \"weight\", Pango.Weight.BOLD, \"background\", \"pink\");",
224           "buf.create_tag (\"WARN\", \"weight\", Pango.Weight.BOLD, \"background\", \"#ABF4EB\");",
225           "buf.create_tag (\"DEPR\", \"weight\", Pango.Weight.BOLD, \"background\", \"#EEA9FF\");",
226           "",
227           "",
228           ""
229          ],
230          "* prop" : "buffer",
231          "bool check_queued" : false,
232          "bool enable_undo" : true,
233          "bool highlight_matching_brackets" : true,
234          "bool highlight_syntax" : true,
235          "id" : "buffer",
236          "int error_line" : "-1",
237          "listeners" : {
238           "changed" : [
239            " () => {",
240            "    // check syntax??",
241            "    // ??needed..??",
242            "    _this.save_button.el.sensitive = true;",
243            "    print(\"EDITOR CHANGED\");",
244            "    this.checkSyntax();",
245            "   ",
246            "    _this.dirty = true;",
247            "",
248            "    // this.get('/LeftPanel.model').changed(  str , false);",
249            "    return ;",
250            "}",
251            ""
252           ]
253          },
254          "| bool OLDhighlightErrorsJson" : [
255           "(string type, Json.Object obj) {",
256           "\tGtk.TextIter start;",
257           "\tGtk.TextIter end;     ",
258           "\tthis.el.get_bounds (out start, out end);",
259           "",
260           "\tthis.el.remove_source_marks (start, end, type);",
261           "\tGLib.debug(\"highlight errors\");\t\t ",
262           "",
263           "\t // we should highlight other types of errors..",
264           "",
265           "\tif (!obj.has_member(type)) {",
266           "\t\tGLib.debug(\"Return has no errors\\n\");",
267           "\t\treturn true;",
268           "\t}",
269           "",
270           "\tif (_this.window.windowstate.state != WindowState.State.CODEONLY ",
271           "\t\t&&",
272           "\t\t_this.window.windowstate.state != WindowState.State.CODE",
273           "\t\t) {",
274           "\t\tGLib.debug(\"windowstate != CODEONLY?\");",
275           "\t\t",
276           "\t\treturn true;",
277           "\t} ",
278           "",
279           "\t//this.marks = new Gee.HashMap<int,string>();",
280           "\tvar err = obj.get_object_member(type);",
281           " ",
282           "\tif (_this.file == null) {",
283           "\t\tGLib.debug(\"file is null?\");",
284           "\t\treturn true;",
285           "",
286           "\t}",
287           "\tvar valafn = _this.file.path;",
288           "",
289           "\tif (_this.file.xtype != \"PlainFile\") {",
290           "",
291           "\t\tvalafn = \"\";",
292           "\t\ttry {             ",
293           "\t\t\tvar  regex = new Regex(\"\\\\.bjs$\");",
294           "\t\t\t// should not happen",
295           "\t      \t\tvalafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
296           "\t\t} catch (GLib.RegexError e) {",
297           "\t\t\treturn true;",
298           "\t\t}   ",
299           "",
300           "",
301           "",
302           "\t}",
303           "\tif (!err.has_member(valafn)) {",
304           "\t\tGLib.debug(\"File path has no errors\");",
305           "\t\treturn  true;",
306           "\t}",
307           "",
308           "\tvar lines = err.get_object_member(valafn);",
309           "\t",
310           "\tvar offset = 1;",
311           "\tif (obj.has_member(\"line_offset\")) { // ?? why??",
312           "\t\toffset = (int)obj.get_int_member(\"line_offset\") + 1;",
313           "\t}",
314           "",
315           "",
316           "\tvar tlines = this.el.get_line_count () +1;",
317           "\t",
318           "\tif (_this.prop != null) {",
319           "\t",
320           "\t\ttlines = _this.prop.end_line + 1;",
321           "\t\toffset = _this.prop.start_line + 1;",
322           "\t",
323           "\t}",
324           "\t",
325           "",
326           "",
327           "\tlines.foreach_member((obj, line, node) => {",
328           "\t\t",
329           "\t     Gtk.TextIter iter;",
330           "//        print(\"get inter\\n\");",
331           "\t    var eline = int.parse(line) - offset;",
332           "\t    GLib.debug(\"GOT ERROR on line %s -- converted to %d  (offset = %d)\\n\", line,eline, offset);",
333           "\t    ",
334           "\t    ",
335           "\t    if (eline > tlines || eline < 0) {",
336           "\t        return;",
337           "\t    }",
338           "\t   ",
339           "\t    ",
340           "\t    this.el.get_iter_at_line( out iter, eline);",
341           "\t    //print(\"mark line\\n\");",
342           "\t    var msg  = \"\";",
343           "\t    var ar = lines.get_array_member(line);",
344           "\t    for (var i = 0 ; i < ar.get_length(); i++) {",
345           "\t    \tif (ar.get_string_element(i) == \"Success\") {",
346           "\t    \t\tcontinue;",
347           "    \t\t}",
348           "\t\t\tmsg += (msg.length > 0) ? \"\\n\" : \"\";",
349           "\t\t\tmsg += ar.get_string_element(i);",
350           "\t\t}",
351           "\t\tif (msg == \"\") {",
352           "\t\t\treturn;",
353           "\t\t}",
354           "\t\tmsg = \"Line: %d\".printf(eline+1) +  \" \" + msg;",
355           "\t    this.el.create_source_mark(msg, type, iter);",
356           "\t    GLib.debug(\"set line %d to %m\", eline, msg);",
357           "\t   // this.marks.set(eline, msg);",
358           "\t} );",
359           "\treturn false;",
360           "",
361           "",
362           "",
363           "",
364           "",
365           "\t}",
366           ""
367          ],
368          "| bool checkSyntax" : [
369           " () {",
370           " ",
371           "    ",
372           "    var str = this.toString();",
373           "    ",
374           "    // needed???",
375           "    if (this.error_line > 0) {",
376           "         Gtk.TextIter start;",
377           "         Gtk.TextIter end;     ",
378           "        this.el.get_bounds (out start, out end);",
379           "",
380           "        this.el.remove_source_marks (start, end, null);",
381           "    }",
382           "    if (str.length < 1) {",
383           "        print(\"checkSyntax - empty string?\\n\");",
384           "        return true;",
385           "    }",
386           "    ",
387           "    // bit presumptiona",
388           "    if (_this.file.xtype == \"PlainFile\") {",
389           "    ",
390           "        // assume it's gtk...",
391           "         var  oldcode =_this.file.toSource();",
392           "        _this.file.setSource(str);",
393           "\t    BuilderApplication.showSpinner(\"appointment soon\",\"document change pending\");",
394           "    \t_this.file.getLanguageServer().document_change(_this.file);",
395           "",
396           "        _this.file.setSource(oldcode);",
397           "        ",
398           "\t\t ",
399           "        return true;",
400           "    ",
401           "    }",
402           "   if (_this.file == null) {",
403           "       return true;",
404           "   }",
405           " ",
406           "    ",
407           "",
408           "      ",
409           "     ",
410           "    GLib.debug(\"calling validate\");    ",
411           "    // clear the buttons.",
412           " \tif (_this.prop.name == \"xns\" || _this.prop.name == \"xtype\") {",
413           "\t\treturn true ;",
414           "\t}",
415           "\tvar oldcode  = _this.prop.val;",
416           "\t",
417           "\t_this.prop.val = str;",
418           "\t_this.node.updated_count++;",
419           "    _this.file.getLanguageServer().document_change(_this.file);",
420           "    _this.node.updated_count++;",
421           "    _this.prop.val = oldcode;",
422           "    ",
423           "    ",
424           "    //print(\"done mark line\\n\");",
425           "     ",
426           "    return true; // at present allow saving - even if it's invalid..",
427           "}",
428           ""
429          ],
430          "| bool highlightErrors" : [
431           "( Gee.HashMap<int,string> validate_res) {",
432           "         ",
433           "\tthis.error_line = validate_res.size;",
434           "",
435           "\tif (this.error_line < 1) {",
436           "\t\treturn true;",
437           "\t}",
438           "\tvar tlines = this.el.get_line_count ();",
439           "\tGtk.TextIter iter;",
440           "\tvar valiter = validate_res.map_iterator();",
441           "\twhile (valiter.next()) {",
442           "",
443           "\t//        print(\"get inter\\n\");",
444           "\t\tvar eline = valiter.get_key();",
445           "\t\tif (eline > tlines) {",
446           "\t\t\tcontinue;",
447           "\t\t}",
448           "\t\tthis.el.get_iter_at_line( out iter, eline);",
449           "\t\t//print(\"mark line\\n\");",
450           "\t\tthis.el.create_source_mark(valiter.get_value(), \"ERR\", iter);",
451           "\t}   ",
452           "\treturn false;",
453           "}"
454          ],
455          "| string toString" : [
456           "  () {",
457           "    ",
458           "    Gtk.TextIter s;",
459           "    Gtk.TextIter e;",
460           "    this.el.get_start_iter(out s);",
461           "    this.el.get_end_iter(out e);",
462           "    var ret = this.el.get_text(s,e,true);",
463           "    //print(\"TO STRING? \" + ret);",
464           "    return ret;",
465           "}",
466           " "
467          ]
468         },
469         {
470          "# bool is_control" : false,
471          "$ xns" : "Gtk",
472          "id" : "keystate",
473          "listeners" : {
474           "key_pressed" : [
475            "(keyval, keycode, state) => {",
476            "",
477            " \tif (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {",
478            " \t\tthis.is_control = true;",
479            "\t}",
480            "\treturn false;",
481            "}",
482            ""
483           ],
484           "key_released" : [
485            "(keyval, keycode, state) => {",
486            "",
487            " \t if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {",
488            " \t\tthis.is_control = false;",
489            "\t}",
490            "    if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
491            "        GLib.debug(\"SAVE: ctrl-S  pressed\");",
492            "        _this.saveContents();",
493            "        return;",
494            "    }",
495            "    ",
496            "    if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
497            "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
498            "\t\t_this.forwardSearch(true);",
499            "\t    return;",
500            "\t}",
501            "\tif (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
502            "\t    GLib.debug(\"SAVE: ctrl-f  pressed\");",
503            "\t\t_this.search_entry.el.grab_focus();",
504            "\t\t_this.search_entry.el.select_region(0,-1);",
505            "\t    return;",
506            "\t}",
507            "\tif (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
508            "\t\t_this.view.el.show_completion();",
509            "\t}",
510            "\t",
511            "\tGtk.TextIter iter;",
512            "\t_this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);  ",
513            "\tvar line  = iter.get_line();",
514            "\tvar offset = iter.get_line_offset();",
515            "\tGLib.debug(\"line  %d  off %d\", line ,offset);",
516            "\tif (_this.prop != null) {",
517            "\t\tline += _this.prop.start_line + 1; // i think..",
518            "\t\toffset += 12; // should probably be 8 without namespaced ",
519            "\t\tGLib.debug(\"guess line  %d  off %d\", line ,offset);",
520            "\t} ",
521            "    //_this.view.el.show_completion();",
522            "   // print(event.key.keyval)",
523            "   ",
524            "   ",
525            "   ",
526            "    ",
527            "    return;",
528            " ",
529            " ",
530            "}",
531            ""
532           ]
533          },
534          "xtype" : "EventControllerKey"
535         },
536         {
537          "# double distance" : "0.0f",
538          "$ xns" : "Gtk",
539          "Gtk.EventControllerScrollFlags flags" : "Gtk.EventControllerScrollFlags.VERTICAL",
540          "listeners" : {
541           "scroll" : [
542            "(dx, dy) => {",
543            "\tif (!_this.keystate.is_control) {",
544            "\t\treturn false;",
545            "\t}",
546            "\t//GLib.debug(\"scroll %f\",  dy);",
547            "\t",
548            "\tthis.distance += dy;",
549            "\tif (this.distance < 1) {",
550            "\t\tBuilderApplication.settings.editor_font_size ++;",
551            "\t\tthis.distance = 0;",
552            "\t}",
553            "\tif (this.distance > -1) {",
554            "\t\tBuilderApplication.settings.editor_font_size --;",
555            "\t\tthis.distance = 0;",
556            "\t}",
557            "",
558            "\treturn true;",
559            "}",
560            ""
561           ]
562          },
563          "xtype" : "EventControllerScroll"
564         }
565        ],
566        "listeners" : {
567         "query_tooltip" : [
568          "(x, y, keyboard_tooltip, tooltip) => {",
569          "\t",
570          "\t//GLib.debug(\"query tooltip\");",
571          "\tGtk.TextIter iter;",
572          "\tint trailing;",
573          "\t",
574          "\tvar yoff = (int) _this.RightEditor.el.vadjustment.value;",
575          "\t",
576          "\t// I think this is problematic - if it's compliing  / updating at same time as query.",
577          "\t",
578          "\t//if (_this.window.statusbar_compile_spinner.el.spinning) {",
579          "\t//\treturn false;",
580          "\t//}",
581          "\t",
582          "\tthis.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);",
583          "\t ",
584          "\tvar l = iter.get_line();",
585          "",
586          "\t",
587          "\t ",
588          "\t// GLib.debug(\"query tooltip line %d\", (int) l);",
589          "\tif (l < 0) {",
590          "",
591          "\t\treturn false;",
592          "\t}",
593          "\t/*",
594          "\tif (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {",
595          "\t\tGLib.debug(\"line %d setting tip to %s\", l,  _this.buffer.marks.get(l));",
596          "\t\ttooltip.set_text(_this.buffer.marks.get(l).dup());",
597          "\t\treturn true;",
598          "\t}",
599          " ",
600          "\treturn false;",
601          "\t*/",
602          "\t",
603          "\t  ",
604          "\t// this crashes?? - not sure why.",
605          "\tvar marks = _this.buffer.el.get_source_marks_at_line(l, \"ERR\");",
606          "\tif (marks.is_empty()) {",
607          "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"WARN\");",
608          "\t}",
609          "\tif (marks.is_empty()) {",
610          "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"DEPR\");",
611          "\t}",
612          "\t",
613          "\t// GLib.debug(\"query tooltip line %d marks %d\", (int)l, (int) marks.length());",
614          "\tvar str = \"\";",
615          "\tmarks.@foreach((m) => { ",
616          "\t\t//GLib.debug(\"got mark %s\", m.name);",
617          "\t\tstr += (str.length > 0 ? \"\\n\" : \"\") + m.category + \": \" + m.name;",
618          "\t});",
619          "\t// true if there is a mark..",
620          "\tif (str.length > 0 ) {",
621          "\t\ttooltip.set_text( str );",
622          "\t}",
623          "\treturn str.length > 0 ? true : false;",
624          "\t ",
625          "}",
626          ""
627         ]
628        },
629        "string name" : "editor-view",
630        "uint tab_width" : 4,
631        "xtype" : "View",
632        "| void load" : [
633         " (string str) {",
634         "",
635         "// show the help page for the active node..",
636         "   //this.get('/Help').show();",
637         " ",
638         "  // this.get('/BottomPane').el.set_current_page(0);",
639         "  \tGLib.debug(\"load called - Reset undo buffer\");",
640         "  \t",
641         "    var buf = (GtkSource.Buffer)this.el.get_buffer();",
642         "    buf.begin_irreversible_action();",
643         "    buf.set_text(str, str.length);",
644         "    buf.end_irreversible_action();",
645         "    ",
646         "    var lm = GtkSource.LanguageManager.get_default();",
647         "    var lang = \"vala\";",
648         "    if (_this.file != null) {",
649         "         lang = _this.file.language;",
650         "    }",
651         "    print(\"lang=%s, content_type = %s\\n\", lang, _this.file.content_type);",
652         "    var lg = _this.file.content_type.length > 0  ?",
653         "            lm.guess_language(_this.file.path, _this.file.content_type) :",
654         "            lm.get_language(lang);",
655         "     ",
656         "   ",
657         "    ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg); ",
658         "",
659         "    this.el.insert_spaces_instead_of_tabs = true;",
660         "    if (lg != null) {",
661         "\t\tprint(\"sourcelanguage  = %s\\n\", lg.name);",
662         "\t\tif (lg.name == \"Vala\") {",
663         "\t\t    this.el.insert_spaces_instead_of_tabs = false;",
664         "\t\t}",
665         "     }",
666         "    _this.dirty = false;",
667         "    this.el.grab_focus();",
668         "    _this.save_button.el.sensitive = false;",
669         "    _this.last_error_counter = -1;",
670         "}"
671        ]
672       }
673      ],
674      "xtype" : "ScrolledWindow"
675     },
676     {
677      "$ xns" : "Gtk",
678      "* pack" : "append",
679      "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
680      "bool homogeneous" : false,
681      "bool vexpand" : false,
682      "int spacing" : 0,
683      "items" : [
684       {
685        "$ xns" : "Gtk",
686        "Gtk.CssProvider css" : "",
687        "bool hexpand" : true,
688        "id" : "search_entry",
689        "items" : [
690         {
691          "$ xns" : "Gtk",
692          "listeners" : {
693           "key_pressed" : [
694            "(keyval, keycode, state) => {",
695            "",
696            "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
697            "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
698            "\t\t_this.forwardSearch(true);",
699            "\t    return true;",
700            "\t}",
701            "    ",
702            "  ",
703            " \tif (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {",
704            "\t\t_this.forwardSearch(true);",
705            "\t\t",
706            "\t\t",
707            "\t    return true;",
708            "",
709            "\t}    ",
710            "   // print(event.key.keyval)",
711            "   ",
712            "    return false;",
713            "}",
714            ""
715           ]
716          },
717          "xtype" : "EventControllerKey"
718         }
719        ],
720        "listeners" : {
721         "search_changed" : [
722          "( ) => {",
723          "",
724          "_this.search(_this.search_entry.el.text);",
725          "\t _this.search_results.updateResults();",
726          "",
727          "\tGLib.Timeout.add_seconds(1,() => {",
728          "\t\t _this.search_results.updateResults();",
729          "\t\t return false;",
730          "\t });",
731          "}",
732          ""
733         ]
734        },
735        "string name" : "editor-search-entry",
736        "string placeholder_text" : "Press enter to search",
737        "uint search_delay" : 3,
738        "xtype" : "SearchEntry",
739        "| void forwardSearch" : [
740         "(bool change_focus) {",
741         "",
742         "",
743         "\t_this.forwardSearch(change_focus);",
744         "",
745         "/*",
746         "",
747         "\tswitch(_this.windowstate.state) {",
748         "\t\tcase WindowState.State.CODEONLY:",
749         "\t\t//case WindowState.State.CODE:",
750         "\t\t\t// search the code being edited..",
751         "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
752         "\t\t\t ",
753         "\t\t\tbreak;",
754         "\t\tcase WindowState.State.PREVIEW:",
755         "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
756         "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
757         "\t\t\t} else { ",
758         "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
759         "\t\t\t}",
760         "\t\t",
761         "\t\t\tbreak;",
762         "\t}",
763         "\t*/",
764         "\t",
765         "}",
766         ""
767        ]
768       },
769       {
770        "$ xns" : "Gtk",
771        "id" : "search_results",
772        "int margin_end" : 4,
773        "int margin_start" : 4,
774        "string label" : "No Results",
775        "xtype" : "Label",
776        "| void updateResults" : [
777         "() {",
778         "\tthis.el.visible = true;",
779         "\t",
780         "\tvar res = _this.searchcontext.get_occurrences_count();",
781         "\tif (res < 0) {",
782         "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
783         "\t\treturn;",
784         "\t}",
785         "",
786         "\t_this.nextBtn.el.sensitive = false;",
787         "\t_this.backBtn.el.sensitive = false;\t",
788         "",
789         "\tif (res > 0) {",
790         "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
791         "\t\t_this.nextBtn.el.sensitive = true;",
792         "\t\t_this.backBtn.el.sensitive = true;",
793         "\t\treturn;",
794         "\t} ",
795         "\t_this.search_results.el.label = \"No Matches\";",
796         "\t",
797         "}"
798        ]
799       },
800       {
801        "$ xns" : "Gtk",
802        "bool always_show_image" : true,
803        "bool sensitive" : false,
804        "id" : "nextBtn",
805        "listeners" : {
806         "clicked" : [
807          "(event) => {",
808          "",
809          "\t_this.forwardSearch(true);",
810          "\t",
811          "\t ",
812          "}",
813          ""
814         ]
815        },
816        "string icon_name" : "go-down",
817        "xtype" : "Button"
818       },
819       {
820        "$ xns" : "Gtk",
821        "bool always_show_image" : true,
822        "bool sensitive" : false,
823        "id" : "backBtn",
824        "listeners" : {
825         "clicked" : [
826          "(event) => {",
827          "",
828          "\t_this.backSearch(true);",
829          "\t ",
830          "}",
831          ""
832         ]
833        },
834        "string icon_name" : "go-up",
835        "xtype" : "Button"
836       },
837       {
838        "$ xns" : "Gtk",
839        "bool always_show_arrow" : true,
840        "bool always_show_image" : true,
841        "items" : [
842         {
843          "$ xns" : "Gtk",
844          "* prop" : "popover",
845          "id" : "search_settings",
846          "items" : [
847           {
848            "$ xns" : "Gtk",
849            "* prop" : "child",
850            "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
851            "int spacing" : 0,
852            "items" : [
853             {
854              "$ xns" : "Gtk",
855              "* init" : [
856               "{",
857               "\tthis.el.show();",
858               "}",
859               ""
860              ],
861              "id" : "case_sensitive",
862              "string label" : "Case Sensitive",
863              "xtype" : "CheckButton"
864             },
865             {
866              "$ xns" : "Gtk",
867              "* init" : [
868               "{",
869               "\tthis.el.show();",
870               "}",
871               ""
872              ],
873              "id" : "regex",
874              "string label" : "Regex",
875              "xtype" : "CheckButton"
876             },
877             {
878              "$ xns" : "Gtk",
879              "id" : "multiline",
880              "string label" : "Multi-line (add \\n)",
881              "xtype" : "CheckButton"
882             }
883            ],
884            "xtype" : "Box"
885           }
886          ],
887          "xtype" : "Popover"
888         }
889        ],
890        "string icon_name" : "emblem-system",
891        "xtype" : "MenuButton"
892       }
893      ],
894      "xtype" : "Box"
895     }
896    ],
897    "xtype" : "Box",
898    "| bool saveContents" : [
899     "  ()  {",
900     "    ",
901     "    ",
902     "    if (_this.file == null) {",
903     "        return true;",
904     "    }",
905     "    ",
906     "     ",
907     "     ",
908     "     var str = _this.buffer.toString();",
909     "     ",
910     "     _this.buffer.checkSyntax();",
911     "     ",
912     "     ",
913     "     ",
914     "     // LeftPanel.model.changed(  str , false);",
915     "     _this.dirty = false;",
916     "     _this.save_button.el.sensitive = false;",
917     "     ",
918     "    // find the text for the node..",
919     "    if (_this.file.xtype != \"PlainFile\") {",
920     "       // in theory these properties have to exist!?!",
921     "    \tthis.prop.val = str;",
922     "        //this.window.windowstate.left_props.reload();",
923     "    } else {",
924     "        _this.file.setSource(  str );",
925     "     }",
926     "    ",
927     "    // call the signal..",
928     "    this.save();",
929     "    ",
930     "    return true;",
931     "",
932     "} "
933    ],
934    "| int search" : [
935     "(string in_txt) {",
936     "",
937     "\tvar s = new GtkSource.SearchSettings();",
938     "\ts.case_sensitive = _this.case_sensitive.el.active;",
939     "\ts.regex_enabled = _this.regex.el.active;\t",
940     "\ts.wrap_around = false;",
941     "\t",
942     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
943     "\tthis.searchcontext.set_highlight(true);",
944     "\tvar txt = in_txt;",
945     "\t",
946     "\tif (_this.multiline.el.active) {",
947     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
948     "\t}",
949     "\t",
950     "\ts.set_search_text(txt);",
951     "\tGtk.TextIter beg, st,en;",
952     "\t ",
953     "\tthis.buffer.el.get_start_iter(out beg);",
954     "\tbool has_wrapped_around;",
955     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
956     "\tthis.last_search_end = 0;",
957     "\t",
958     "\treturn this.searchcontext.get_occurrences_count();",
959     "",
960     " ",
961     "   ",
962     "",
963     "}",
964     ""
965    ],
966    "| string tempFileContents" : [
967     "() {",
968     "   ",
969     "   ",
970     "   if (_this.file == null) {",
971     "       return \"\";",
972     "   }",
973     "\tvar str= this.buffer.toString();",
974     "\tif (_this.file.xtype == \"PlainFile\") {",
975     "    ",
976     "     \treturn str;",
977     "    ",
978     "    }",
979     "  ",
980     "      ",
981     "     ",
982     "    GLib.debug(\"calling validate\");    ",
983     "    // clear the buttons.",
984     " \tif (_this.prop.name == \"xns\" || _this.prop.name == \"xtype\") {",
985     "\t\treturn this.file.toSource(); ;",
986     "\t}",
987     "\t",
988     "\tvar oldcode  = _this.prop.val;",
989     "\t_this.prop.val = str;",
990     "    var ret = _this.file.toSource();",
991     "    _this.prop.val = oldcode;",
992     "    return ret;",
993     "    ",
994     "}"
995    ],
996    "| void backSearch" : [
997     "(bool change_focus) {",
998     "",
999     "\tif (this.searchcontext == null) {",
1000     "\t\treturn;",
1001     "\t}",
1002     "\t",
1003     "\tGtk.TextIter beg, st,en;",
1004     "\tbool has_wrapped_around;",
1005     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
1006     "\t",
1007     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
1008     "\t\tthis.last_search_end = 0;",
1009     "\t} else {",
1010     "\t\tthis.last_search_end = en.get_offset();",
1011     "\t\tif (change_focus) {",
1012     "\t\t\tthis.view.el.grab_focus();",
1013     "\t\t}",
1014     "\t\tthis.buffer.el.place_cursor(st);",
1015     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1016     "\t}",
1017     "",
1018     "}",
1019     ""
1020    ],
1021    "| void forwardSearch" : [
1022     "(bool change_focus) {",
1023     "",
1024     "\tif (this.searchcontext == null) {",
1025     "\t\treturn;",
1026     "\t} ",
1027     "",
1028     "\tGtk.TextIter beg, st,en;",
1029     "\t bool has_wrapped_around;",
1030     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end);",
1031     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
1032     "\t",
1033     "\t\tthis.last_search_end = 0; // not sure if this should happen",
1034     "\t} else {",
1035     "\t\tif (has_wrapped_around) {",
1036     "\t\t\treturn;",
1037     "\t\t}",
1038     "\t",
1039     "\t\tthis.last_search_end = en.get_offset();",
1040     "\t\tif (change_focus) {",
1041     "\t\t\tthis.view.el.grab_focus();",
1042     "\t\t}",
1043     "\t\tthis.buffer.el.place_cursor(st);",
1044     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1045     "\t}",
1046     " ",
1047     "}",
1048     ""
1049    ],
1050    "| void reset" : [
1051     "() {",
1052     "\t this.file = null;    ",
1053     "     ",
1054     "    this.node = null;",
1055     "    this.prop = null;",
1056     "\tthis.searchcontext = null;",
1057     "  ",
1058     "}",
1059     ""
1060    ],
1061    "| void scroll_to_line" : [
1062     "(int line) {",
1063     "",
1064     "\tGLib.Timeout.add(500, () => {",
1065     "   ",
1066     "\t\tvar buf = this.view.el.get_buffer();",
1067     "",
1068     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1069     "",
1070     "",
1071     "\t\tGtk.TextIter iter;   ",
1072     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1073     "\t\tthis.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1074     "\t\treturn false;",
1075     "\t});   ",
1076     "}",
1077     ""
1078    ],
1079    "| void show" : [
1080     "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
1081     "{",
1082     "    this.reset();",
1083     "    this.file = file;    ",
1084     "    ",
1085     "    if (file.xtype != \"PlainFile\") {",
1086     "    \tthis.prop = prop;",
1087     "        this.node = node;",
1088     "",
1089     "        // find the text for the node..",
1090     "        this.view.load( prop.val );",
1091     "        this.updateErrorMarks();",
1092     "        ",
1093     "        this.close_btn.el.show();       ",
1094     "    ",
1095     "    } else {",
1096     "        this.view.load(        file.toSource() );",
1097     "         this.updateErrorMarks();",
1098     "        this.close_btn.el.hide();",
1099     "        ",
1100     "    }",
1101     " ",
1102     "}"
1103    ],
1104    "| void updateErrorMarks" : [
1105     "() {",
1106     "\t",
1107     " ",
1108     "",
1109     "\tvar buf = _this.buffer.el;",
1110     "\tGtk.TextIter start;",
1111     "\tGtk.TextIter end;     ",
1112     "\tbuf.get_bounds (out start, out end);",
1113     "",
1114     "\t",
1115     "",
1116     " ",
1117     "\t//GLib.debug(\"highlight errors\");\t\t ",
1118     "",
1119     "\t // we should highlight other types of errors..",
1120     "",
1121     "\tif (_this.window.windowstate.state != WindowState.State.CODEONLY ",
1122     "\t\t&&",
1123     "\t\t_this.window.windowstate.state != WindowState.State.CODE",
1124     "\t\t) {",
1125     "\t\t//GLib.debug(\"windowstate != CODEONLY?\");",
1126     "\t\t",
1127     "\t\treturn;",
1128     "\t} ",
1129     "",
1130     "\t ",
1131     "\tif (_this.file == null) {",
1132     "\t\tGLib.debug(\"file is null?\");",
1133     "\t\treturn;",
1134     "",
1135     "\t}",
1136     "\tvar ar = this.file.getErrors();",
1137     "\tif (ar.size < 1) {",
1138     "\t\tbuf.remove_source_marks (start, end, \"ERR\");",
1139     "\t\tbuf.remove_source_marks (start, end, \"WARN\");",
1140     "\t\tbuf.remove_source_marks (start, end, \"DEPR\");",
1141     "\t\tbuf.remove_tag_by_name (\"ERR\", start, end);",
1142     "\t\tbuf.remove_tag_by_name (\"WARN\", start, end);",
1143     "\t\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
1144     "\t\tthis.last_error_counter = file.error_counter ;",
1145     "\t\t//GLib.debug(\"highlight %s :  %s has no errors\", this.file.relpath, category);",
1146     "\t\treturn;",
1147     "\t}",
1148     "\t",
1149     "",
1150     " // basicaly check if there is no change, then we do not do any update..",
1151     " // we can do this by just using an error counter?",
1152     " // if that's changed then we will do an update, otherwise dont bother.",
1153     "\t  ",
1154     "\t",
1155     "\tvar offset = 0;",
1156     "\tvar hoffset = 0;",
1157     "",
1158     "\tvar tlines = buf.get_line_count () +1;",
1159     "\t",
1160     "\tif (_this.prop != null) {",
1161     "\t\t// this still seems flaky...",
1162     "",
1163     "\t\ttlines = _this.prop.end_line;",
1164     "\t\toffset = _this.prop.start_line;",
1165     "\t\thoffset = _this.node.node_pad.length + 2; //shift it left  by 2 ? ..",
1166     "\t\t",
1167     "\t\t ",
1168     "\t} else {",
1169     "\t\t// no update...",
1170     "\t\tif (this.last_error_counter == file.error_counter) {",
1171     "\t\t",
1172     "\t\t\treturn;",
1173     "\t\t}",
1174     "\t",
1175     "\t}",
1176     "\tbuf.remove_source_marks (start, end, \"ERR\");",
1177     "\tbuf.remove_source_marks (start, end, \"WARN\");",
1178     "\tbuf.remove_source_marks (start, end, \"DEPR\");",
1179     "\tbuf.remove_tag_by_name (\"ERR\", start, end);",
1180     "\tbuf.remove_tag_by_name (\"WARN\", start, end);",
1181     "\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
1182     "\t",
1183     "\tforeach(var diag in ar) { ",
1184     "\t     Gtk.TextIter iter;",
1185     "//        print(\"get inter\\n\");",
1186     "\t    var eline = (int)diag.range.start.line - offset;",
1187     "\t    var eline_to = (int)diag.range.end.line - offset;",
1188     "\t    //var eline =  diag.range.end_line - offset;",
1189     "\t    //GLib.debug(\"GOT ERROR on line %d -- converted to %d  (offset = %d)\",",
1190     "\t    //\terr.line ,eline, offset);",
1191     "\t    ",
1192     "\t    ",
1193     "\t    if (eline > tlines || eline < 0) {",
1194     "\t        continue;",
1195     "\t    }",
1196     "\t    ",
1197     "\t    buf.get_iter_at_line( out iter, eline);",
1198     "\t   \tvar msg = \"Line: %d %s : %s\".printf(eline+1, diag.category, diag.message);",
1199     "\t    buf.create_source_mark( msg, diag.category, iter);",
1200     "\t    ",
1201     " \t    var spos = (int)diag.range.start.character - hoffset;",
1202     " \t    if (spos < 0) { spos =0 ; }",
1203     " \t    if (spos > iter.get_chars_in_line()) {",
1204     " \t    \tspos = iter.get_chars_in_line();",
1205     "    \t}",
1206     "\t\tbuf.get_iter_at_line( out iter, eline_to);",
1207     "\t\tvar epos = (int)diag.range.end.character - hoffset;",
1208     " \t    if (epos < 0) { epos =0 ; }",
1209     " \t    if (epos > iter.get_chars_in_line()) {",
1210     " \t    \tepos = iter.get_chars_in_line();",
1211     "    \t}",
1212     " \t     ",
1213     " \t    ",
1214     " \t    buf.get_iter_at_line_offset( out start, eline, spos); ",
1215     " \t   ",
1216     " \t    buf.get_iter_at_line_offset( out end, eline_to,epos); ",
1217     " \t    \t",
1218     "\t    buf.apply_tag_by_name(diag.category, start, end);",
1219     "\t    ",
1220     "\t   // GLib.debug(\"set line %d to %s\", eline, msg);",
1221     "\t    //this.marks.set(eline, msg);",
1222     "\t}",
1223     "\tthis.last_error_counter = file.error_counter ;",
1224     "",
1225     "",
1226     "",
1227     " ",
1228     "",
1229     "}"
1230    ]
1231   }
1232  ],
1233  "name" : "Editor"
1234 }