missing refs, slight change to completion provider
[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          "$ xns" : "Gtk",
471          "listeners" : {
472           "key_released" : [
473            "(keyval, keycode, state) => {",
474            "",
475            "  ",
476            "    if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
477            "        GLib.debug(\"SAVE: ctrl-S  pressed\");",
478            "        _this.saveContents();",
479            "        return;",
480            "    }",
481            "    ",
482            "    if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
483            "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
484            "\t\t_this.forwardSearch(true);",
485            "\t    return;",
486            "\t}",
487            "\tif (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
488            "\t    GLib.debug(\"SAVE: ctrl-f  pressed\");",
489            "\t\t_this.search_entry.el.grab_focus();",
490            "\t\t_this.search_entry.el.select_region(0,-1);",
491            "\t    return;",
492            "\t}",
493            "\tif (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
494            "\t\t_this.view.el.show_completion();",
495            "\t}",
496            "\t",
497            "\tGtk.TextIter iter;",
498            "\t_this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);  ",
499            "\tvar line  = iter.get_line();",
500            "\tvar offset = iter.get_line_offset();",
501            "\tGLib.debug(\"line  %d  off %d\", line ,offset);",
502            "\tif (_this.prop != null) {",
503            "\t\tline += _this.prop.start_line + 1; // i think..",
504            "\t\toffset += 12; // should probably be 8 without namespaced ",
505            "\t\tGLib.debug(\"guess line  %d  off %d\", line ,offset);",
506            "\t} ",
507            "    //_this.view.el.show_completion();",
508            "   // print(event.key.keyval)",
509            "   ",
510            "   ",
511            "   ",
512            "    ",
513            "    return;",
514            " ",
515            " ",
516            "}",
517            ""
518           ]
519          },
520          "xtype" : "EventControllerKey"
521         }
522        ],
523        "listeners" : {
524         "query_tooltip" : [
525          "(x, y, keyboard_tooltip, tooltip) => {",
526          "\t",
527          "\t//GLib.debug(\"query tooltip\");",
528          "\tGtk.TextIter iter;",
529          "\tint trailing;",
530          "\t",
531          "\tvar yoff = (int) _this.RightEditor.el.vadjustment.value;",
532          "\t",
533          "\t// I think this is problematic - if it's compliing  / updating at same time as query.",
534          "\t",
535          "\t//if (_this.window.statusbar_compile_spinner.el.spinning) {",
536          "\t//\treturn false;",
537          "\t//}",
538          "\t",
539          "\tthis.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);",
540          "\t ",
541          "\tvar l = iter.get_line();",
542          "",
543          "\t",
544          "\t ",
545          "\t// GLib.debug(\"query tooltip line %d\", (int) l);",
546          "\tif (l < 0) {",
547          "",
548          "\t\treturn false;",
549          "\t}",
550          "\t/*",
551          "\tif (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {",
552          "\t\tGLib.debug(\"line %d setting tip to %s\", l,  _this.buffer.marks.get(l));",
553          "\t\ttooltip.set_text(_this.buffer.marks.get(l).dup());",
554          "\t\treturn true;",
555          "\t}",
556          " ",
557          "\treturn false;",
558          "\t*/",
559          "\t",
560          "\t  ",
561          "\t// this crashes?? - not sure why.",
562          "\tvar marks = _this.buffer.el.get_source_marks_at_line(l, \"ERR\");",
563          "\tif (marks.is_empty()) {",
564          "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"WARN\");",
565          "\t}",
566          "\tif (marks.is_empty()) {",
567          "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"DEPR\");",
568          "\t}",
569          "\t",
570          "\t// GLib.debug(\"query tooltip line %d marks %d\", (int)l, (int) marks.length());",
571          "\tvar str = \"\";",
572          "\tmarks.@foreach((m) => { ",
573          "\t\t//GLib.debug(\"got mark %s\", m.name);",
574          "\t\tstr += (str.length > 0 ? \"\\n\" : \"\") + m.category + \": \" + m.name;",
575          "\t});",
576          "\t// true if there is a mark..",
577          "\tif (str.length > 0 ) {",
578          "\t\ttooltip.set_text( str );",
579          "\t}",
580          "\treturn str.length > 0 ? true : false;",
581          "\t ",
582          "}",
583          ""
584         ]
585        },
586        "string name" : "editor-view",
587        "uint tab_width" : 4,
588        "xtype" : "View",
589        "| void load" : [
590         " (string str) {",
591         "",
592         "// show the help page for the active node..",
593         "   //this.get('/Help').show();",
594         " ",
595         "  // this.get('/BottomPane').el.set_current_page(0);",
596         "  \tGLib.debug(\"load called - Reset undo buffer\");",
597         "  \t",
598         "    var buf = (GtkSource.Buffer)this.el.get_buffer();",
599         "    buf.begin_irreversible_action();",
600         "    buf.set_text(str, str.length);",
601         "    buf.end_irreversible_action();",
602         "    ",
603         "    var lm = GtkSource.LanguageManager.get_default();",
604         "    var lang = \"vala\";",
605         "    if (_this.file != null) {",
606         "         lang = _this.file.language;",
607         "    }",
608         "    print(\"lang=%s, content_type = %s\\n\", lang, _this.file.content_type);",
609         "    var lg = _this.file.content_type.length > 0  ?",
610         "            lm.guess_language(_this.file.path, _this.file.content_type) :",
611         "            lm.get_language(lang);",
612         "     ",
613         "   ",
614         "    ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg); ",
615         "",
616         "    this.el.insert_spaces_instead_of_tabs = true;",
617         "    if (lg != null) {",
618         "\t\tprint(\"sourcelanguage  = %s\\n\", lg.name);",
619         "\t\tif (lg.name == \"Vala\") {",
620         "\t\t    this.el.insert_spaces_instead_of_tabs = false;",
621         "\t\t}",
622         "     }",
623         "    _this.dirty = false;",
624         "    this.el.grab_focus();",
625         "    _this.save_button.el.sensitive = false;",
626         "    _this.last_error_counter = -1;",
627         "}"
628        ]
629       }
630      ],
631      "xtype" : "ScrolledWindow"
632     },
633     {
634      "$ xns" : "Gtk",
635      "* pack" : "append",
636      "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
637      "bool homogeneous" : false,
638      "bool vexpand" : false,
639      "int spacing" : 0,
640      "items" : [
641       {
642        "$ xns" : "Gtk",
643        "Gtk.CssProvider css" : "",
644        "bool hexpand" : true,
645        "id" : "search_entry",
646        "items" : [
647         {
648          "$ xns" : "Gtk",
649          "listeners" : {
650           "key_pressed" : [
651            "(keyval, keycode, state) => {",
652            "",
653            "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
654            "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
655            "\t\t_this.forwardSearch(true);",
656            "\t    return true;",
657            "\t}",
658            "    ",
659            "  ",
660            " \tif (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {",
661            "\t\t_this.forwardSearch(true);",
662            "\t\t",
663            "\t\t",
664            "\t    return true;",
665            "",
666            "\t}    ",
667            "   // print(event.key.keyval)",
668            "   ",
669            "    return false;",
670            "}",
671            ""
672           ]
673          },
674          "xtype" : "EventControllerKey"
675         }
676        ],
677        "listeners" : {
678         "search_changed" : [
679          "( ) => {",
680          "",
681          "_this.search(_this.search_entry.el.text);",
682          "\t _this.search_results.updateResults();",
683          "",
684          "\tGLib.Timeout.add_seconds(1,() => {",
685          "\t\t _this.search_results.updateResults();",
686          "\t\t return false;",
687          "\t });",
688          "}",
689          ""
690         ]
691        },
692        "string name" : "editor-search-entry",
693        "string placeholder_text" : "Press enter to search",
694        "uint search_delay" : 3,
695        "xtype" : "SearchEntry",
696        "| void forwardSearch" : [
697         "(bool change_focus) {",
698         "",
699         "",
700         "\t_this.forwardSearch(change_focus);",
701         "",
702         "/*",
703         "",
704         "\tswitch(_this.windowstate.state) {",
705         "\t\tcase WindowState.State.CODEONLY:",
706         "\t\t//case WindowState.State.CODE:",
707         "\t\t\t// search the code being edited..",
708         "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
709         "\t\t\t ",
710         "\t\t\tbreak;",
711         "\t\tcase WindowState.State.PREVIEW:",
712         "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
713         "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
714         "\t\t\t} else { ",
715         "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
716         "\t\t\t}",
717         "\t\t",
718         "\t\t\tbreak;",
719         "\t}",
720         "\t*/",
721         "\t",
722         "}",
723         ""
724        ]
725       },
726       {
727        "$ xns" : "Gtk",
728        "id" : "search_results",
729        "int margin_end" : 4,
730        "int margin_start" : 4,
731        "string label" : "No Results",
732        "xtype" : "Label",
733        "| void updateResults" : [
734         "() {",
735         "\tthis.el.visible = true;",
736         "\t",
737         "\tvar res = _this.searchcontext.get_occurrences_count();",
738         "\tif (res < 0) {",
739         "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
740         "\t\treturn;",
741         "\t}",
742         "",
743         "\t_this.nextBtn.el.sensitive = false;",
744         "\t_this.backBtn.el.sensitive = false;\t",
745         "",
746         "\tif (res > 0) {",
747         "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
748         "\t\t_this.nextBtn.el.sensitive = true;",
749         "\t\t_this.backBtn.el.sensitive = true;",
750         "\t\treturn;",
751         "\t} ",
752         "\t_this.search_results.el.label = \"No Matches\";",
753         "\t",
754         "}"
755        ]
756       },
757       {
758        "$ xns" : "Gtk",
759        "bool always_show_image" : true,
760        "bool sensitive" : false,
761        "id" : "nextBtn",
762        "listeners" : {
763         "clicked" : [
764          "(event) => {",
765          "",
766          "\t_this.forwardSearch(true);",
767          "\t",
768          "\t ",
769          "}",
770          ""
771         ]
772        },
773        "string icon_name" : "go-down",
774        "xtype" : "Button"
775       },
776       {
777        "$ xns" : "Gtk",
778        "bool always_show_image" : true,
779        "bool sensitive" : false,
780        "id" : "backBtn",
781        "listeners" : {
782         "clicked" : [
783          "(event) => {",
784          "",
785          "\t_this.backSearch(true);",
786          "\t ",
787          "}",
788          ""
789         ]
790        },
791        "string icon_name" : "go-up",
792        "xtype" : "Button"
793       },
794       {
795        "$ xns" : "Gtk",
796        "bool always_show_arrow" : true,
797        "bool always_show_image" : true,
798        "items" : [
799         {
800          "$ xns" : "Gtk",
801          "* prop" : "popover",
802          "id" : "search_settings",
803          "items" : [
804           {
805            "$ xns" : "Gtk",
806            "* prop" : "child",
807            "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
808            "int spacing" : 0,
809            "items" : [
810             {
811              "$ xns" : "Gtk",
812              "* init" : [
813               "{",
814               "\tthis.el.show();",
815               "}",
816               ""
817              ],
818              "id" : "case_sensitive",
819              "string label" : "Case Sensitive",
820              "xtype" : "CheckButton"
821             },
822             {
823              "$ xns" : "Gtk",
824              "* init" : [
825               "{",
826               "\tthis.el.show();",
827               "}",
828               ""
829              ],
830              "id" : "regex",
831              "string label" : "Regex",
832              "xtype" : "CheckButton"
833             },
834             {
835              "$ xns" : "Gtk",
836              "id" : "multiline",
837              "string label" : "Multi-line (add \\n)",
838              "xtype" : "CheckButton"
839             }
840            ],
841            "xtype" : "Box"
842           }
843          ],
844          "xtype" : "Popover"
845         }
846        ],
847        "string icon_name" : "emblem-system",
848        "xtype" : "MenuButton"
849       }
850      ],
851      "xtype" : "Box"
852     }
853    ],
854    "xtype" : "Box",
855    "| bool saveContents" : [
856     "  ()  {",
857     "    ",
858     "    ",
859     "    if (_this.file == null) {",
860     "        return true;",
861     "    }",
862     "    ",
863     "     ",
864     "     ",
865     "     var str = _this.buffer.toString();",
866     "     ",
867     "     _this.buffer.checkSyntax();",
868     "     ",
869     "     ",
870     "     ",
871     "     // LeftPanel.model.changed(  str , false);",
872     "     _this.dirty = false;",
873     "     _this.save_button.el.sensitive = false;",
874     "     ",
875     "    // find the text for the node..",
876     "    if (_this.file.xtype != \"PlainFile\") {",
877     "       // in theory these properties have to exist!?!",
878     "    \tthis.prop.val = str;",
879     "        //this.window.windowstate.left_props.reload();",
880     "    } else {",
881     "        _this.file.setSource(  str );",
882     "     }",
883     "    ",
884     "    // call the signal..",
885     "    this.save();",
886     "    ",
887     "    return true;",
888     "",
889     "} "
890    ],
891    "| int search" : [
892     "(string in_txt) {",
893     "",
894     "\tvar s = new GtkSource.SearchSettings();",
895     "\ts.case_sensitive = _this.case_sensitive.el.active;",
896     "\ts.regex_enabled = _this.regex.el.active;\t",
897     "\ts.wrap_around = false;",
898     "\t",
899     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
900     "\tthis.searchcontext.set_highlight(true);",
901     "\tvar txt = in_txt;",
902     "\t",
903     "\tif (_this.multiline.el.active) {",
904     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
905     "\t}",
906     "\t",
907     "\ts.set_search_text(txt);",
908     "\tGtk.TextIter beg, st,en;",
909     "\t ",
910     "\tthis.buffer.el.get_start_iter(out beg);",
911     "\tbool has_wrapped_around;",
912     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
913     "\tthis.last_search_end = 0;",
914     "\t",
915     "\treturn this.searchcontext.get_occurrences_count();",
916     "",
917     " ",
918     "   ",
919     "",
920     "}",
921     ""
922    ],
923    "| string tempFileContents" : [
924     "() {",
925     "   ",
926     "   ",
927     "   if (_this.file == null) {",
928     "       return \"\";",
929     "   }",
930     "\tvar str= this.buffer.toString();",
931     "\tif (_this.file.xtype == \"PlainFile\") {",
932     "    ",
933     "     \treturn str;",
934     "    ",
935     "    }",
936     "  ",
937     "      ",
938     "     ",
939     "    GLib.debug(\"calling validate\");    ",
940     "    // clear the buttons.",
941     " \tif (_this.prop.name == \"xns\" || _this.prop.name == \"xtype\") {",
942     "\t\treturn this.file.toSource(); ;",
943     "\t}",
944     "\t",
945     "\tvar oldcode  = _this.prop.val;",
946     "\t_this.prop.val = str;",
947     "    var ret = _this.file.toSource();",
948     "    _this.prop.val = oldcode;",
949     "    return ret;",
950     "    ",
951     "}"
952    ],
953    "| void backSearch" : [
954     "(bool change_focus) {",
955     "",
956     "\tif (this.searchcontext == null) {",
957     "\t\treturn;",
958     "\t}",
959     "\t",
960     "\tGtk.TextIter beg, st,en;",
961     "\tbool has_wrapped_around;",
962     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
963     "\t",
964     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
965     "\t\tthis.last_search_end = 0;",
966     "\t} else {",
967     "\t\tthis.last_search_end = en.get_offset();",
968     "\t\tif (change_focus) {",
969     "\t\t\tthis.view.el.grab_focus();",
970     "\t\t}",
971     "\t\tthis.buffer.el.place_cursor(st);",
972     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
973     "\t}",
974     "",
975     "}",
976     ""
977    ],
978    "| void forwardSearch" : [
979     "(bool change_focus) {",
980     "",
981     "\tif (this.searchcontext == null) {",
982     "\t\treturn;",
983     "\t} ",
984     "",
985     "\tGtk.TextIter beg, st,en;",
986     "\t bool has_wrapped_around;",
987     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end);",
988     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
989     "\t",
990     "\t\tthis.last_search_end = 0; // not sure if this should happen",
991     "\t} else {",
992     "\t\tif (has_wrapped_around) {",
993     "\t\t\treturn;",
994     "\t\t}",
995     "\t",
996     "\t\tthis.last_search_end = en.get_offset();",
997     "\t\tif (change_focus) {",
998     "\t\t\tthis.view.el.grab_focus();",
999     "\t\t}",
1000     "\t\tthis.buffer.el.place_cursor(st);",
1001     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1002     "\t}",
1003     " ",
1004     "}",
1005     ""
1006    ],
1007    "| void reset" : [
1008     "() {",
1009     "\t this.file = null;    ",
1010     "     ",
1011     "    this.node = null;",
1012     "    this.prop = null;",
1013     "\tthis.searchcontext = null;",
1014     "  ",
1015     "}",
1016     ""
1017    ],
1018    "| void scroll_to_line" : [
1019     "(int line) {",
1020     "",
1021     "\tGLib.Timeout.add(500, () => {",
1022     "   ",
1023     "\t\tvar buf = this.view.el.get_buffer();",
1024     "",
1025     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1026     "",
1027     "",
1028     "\t\tGtk.TextIter iter;   ",
1029     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1030     "\t\tthis.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1031     "\t\treturn false;",
1032     "\t});   ",
1033     "}",
1034     ""
1035    ],
1036    "| void show" : [
1037     "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
1038     "{",
1039     "    this.reset();",
1040     "    this.file = file;    ",
1041     "    ",
1042     "    if (file.xtype != \"PlainFile\") {",
1043     "    \tthis.prop = prop;",
1044     "        this.node = node;",
1045     "",
1046     "        // find the text for the node..",
1047     "        this.view.load( prop.val );",
1048     "        this.updateErrorMarks();",
1049     "        ",
1050     "        this.close_btn.el.show();       ",
1051     "    ",
1052     "    } else {",
1053     "        this.view.load(        file.toSource() );",
1054     "         this.updateErrorMarks();",
1055     "        this.close_btn.el.hide();",
1056     "        ",
1057     "    }",
1058     " ",
1059     "}"
1060    ],
1061    "| void updateErrorMarks" : [
1062     "() {",
1063     "\t",
1064     " ",
1065     "",
1066     "\tvar buf = _this.buffer.el;",
1067     "\tGtk.TextIter start;",
1068     "\tGtk.TextIter end;     ",
1069     "\tbuf.get_bounds (out start, out end);",
1070     "",
1071     "\t",
1072     "",
1073     " ",
1074     "\t//GLib.debug(\"highlight errors\");\t\t ",
1075     "",
1076     "\t // we should highlight other types of errors..",
1077     "",
1078     "\tif (_this.window.windowstate.state != WindowState.State.CODEONLY ",
1079     "\t\t&&",
1080     "\t\t_this.window.windowstate.state != WindowState.State.CODE",
1081     "\t\t) {",
1082     "\t\t//GLib.debug(\"windowstate != CODEONLY?\");",
1083     "\t\t",
1084     "\t\treturn;",
1085     "\t} ",
1086     "",
1087     "\t ",
1088     "\tif (_this.file == null) {",
1089     "\t\tGLib.debug(\"file is null?\");",
1090     "\t\treturn;",
1091     "",
1092     "\t}",
1093     "\tvar ar = this.file.getErrors();",
1094     "\tif (ar.size < 1) {",
1095     "\t\tbuf.remove_source_marks (start, end, \"ERR\");",
1096     "\t\tbuf.remove_source_marks (start, end, \"WARN\");",
1097     "\t\tbuf.remove_source_marks (start, end, \"DEPR\");",
1098     "\t\tbuf.remove_tag_by_name (\"ERR\", start, end);",
1099     "\t\tbuf.remove_tag_by_name (\"WARN\", start, end);",
1100     "\t\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
1101     "\t\tthis.last_error_counter = file.error_counter ;",
1102     "\t\t//GLib.debug(\"highlight %s :  %s has no errors\", this.file.relpath, category);",
1103     "\t\treturn;",
1104     "\t}",
1105     "\t",
1106     "",
1107     " // basicaly check if there is no change, then we do not do any update..",
1108     " // we can do this by just using an error counter?",
1109     " // if that's changed then we will do an update, otherwise dont bother.",
1110     "\t  ",
1111     "\t",
1112     "\tvar offset = 0;",
1113     "\tvar hoffset = 0;",
1114     "",
1115     "\tvar tlines = buf.get_line_count () +1;",
1116     "\t",
1117     "\tif (_this.prop != null) {",
1118     "\t\t// this still seems flaky...",
1119     "",
1120     "\t\ttlines = _this.prop.end_line;",
1121     "\t\toffset = _this.prop.start_line;",
1122     "\t\thoffset = _this.node.node_pad.length + 2; //shift it left  by 2 ? ..",
1123     "\t\t",
1124     "\t\t ",
1125     "\t} else {",
1126     "\t\t// no update...",
1127     "\t\tif (this.last_error_counter == file.error_counter) {",
1128     "\t\t",
1129     "\t\t\treturn;",
1130     "\t\t}",
1131     "\t",
1132     "\t}",
1133     "\tbuf.remove_source_marks (start, end, \"ERR\");",
1134     "\tbuf.remove_source_marks (start, end, \"WARN\");",
1135     "\tbuf.remove_source_marks (start, end, \"DEPR\");",
1136     "\tbuf.remove_tag_by_name (\"ERR\", start, end);",
1137     "\tbuf.remove_tag_by_name (\"WARN\", start, end);",
1138     "\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
1139     "\t",
1140     "\tforeach(var diag in ar) { ",
1141     "\t     Gtk.TextIter iter;",
1142     "//        print(\"get inter\\n\");",
1143     "\t    var eline = (int)diag.range.start.line - offset;",
1144     "\t    var eline_to = (int)diag.range.end.line - offset;",
1145     "\t    //var eline =  diag.range.end_line - offset;",
1146     "\t    //GLib.debug(\"GOT ERROR on line %d -- converted to %d  (offset = %d)\",",
1147     "\t    //\terr.line ,eline, offset);",
1148     "\t    ",
1149     "\t    ",
1150     "\t    if (eline > tlines || eline < 0) {",
1151     "\t        continue;",
1152     "\t    }",
1153     "\t    ",
1154     "\t    buf.get_iter_at_line( out iter, eline);",
1155     "\t   \tvar msg = \"Line: %d %s : %s\".printf(eline+1, diag.category, diag.message);",
1156     "\t    buf.create_source_mark( msg, diag.category, iter);",
1157     "\t    ",
1158     " \t    var spos = (int)diag.range.start.character - hoffset;",
1159     " \t    if (spos < 0) { spos =0 ; }",
1160     " \t    if (spos > iter.get_chars_in_line()) {",
1161     " \t    \tspos = iter.get_chars_in_line();",
1162     "    \t}",
1163     "\t\tbuf.get_iter_at_line( out iter, eline_to);",
1164     "\t\tvar epos = (int)diag.range.end.character - hoffset;",
1165     " \t    if (epos < 0) { epos =0 ; }",
1166     " \t    if (epos > iter.get_chars_in_line()) {",
1167     " \t    \tepos = iter.get_chars_in_line();",
1168     "    \t}",
1169     " \t     ",
1170     " \t    ",
1171     " \t    buf.get_iter_at_line_offset( out start, eline, spos); ",
1172     " \t   ",
1173     " \t    buf.get_iter_at_line_offset( out end, eline_to,epos); ",
1174     " \t    \t",
1175     "\t    buf.apply_tag_by_name(diag.category, start, end);",
1176     "\t    ",
1177     "\t   // GLib.debug(\"set line %d to %s\", eline, msg);",
1178     "\t    //this.marks.set(eline, msg);",
1179     "\t}",
1180     "\tthis.last_error_counter = file.error_counter ;",
1181     "",
1182     "",
1183     "",
1184     " ",
1185     "",
1186     "}"
1187    ]
1188   }
1189  ],
1190  "name" : "Editor"
1191 }