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