16e7df7081c6c0eb2e33bdd16528447cf2276f5f
[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           "\t_this.node.updated_count++;",
313           "    _this.file.getLanguageServer().document_change(_this.file);",
314           "    _this.node.updated_count++;",
315           "    _this.prop.val = oldcode;",
316           "    ",
317           "    ",
318           "    //print(\"done mark line\\n\");",
319           "     ",
320           "    return true; // at present allow saving - even if it's invalid..",
321           "}",
322           ""
323          ],
324          "| bool highlightErrors" : [
325           "( Gee.HashMap<int,string> validate_res) {",
326           "         ",
327           "\tthis.error_line = validate_res.size;",
328           "",
329           "\tif (this.error_line < 1) {",
330           "\t\treturn true;",
331           "\t}",
332           "\tvar tlines = this.el.get_line_count ();",
333           "\tGtk.TextIter iter;",
334           "\tvar valiter = validate_res.map_iterator();",
335           "\twhile (valiter.next()) {",
336           "",
337           "\t//        print(\"get inter\\n\");",
338           "\t\tvar eline = valiter.get_key();",
339           "\t\tif (eline > tlines) {",
340           "\t\t\tcontinue;",
341           "\t\t}",
342           "\t\tthis.el.get_iter_at_line( out iter, eline);",
343           "\t\t//print(\"mark line\\n\");",
344           "\t\tthis.el.create_source_mark(valiter.get_value(), \"ERR\", iter);",
345           "\t}   ",
346           "\treturn false;",
347           "}"
348          ],
349          "| bool highlightErrorsJson" : [
350           "(string type, Json.Object obj) {",
351           "\tGtk.TextIter start;",
352           "\tGtk.TextIter end;     ",
353           "\tthis.el.get_bounds (out start, out end);",
354           "",
355           "\tthis.el.remove_source_marks (start, end, type);",
356           "\tGLib.debug(\"highlight errors\");\t\t ",
357           "",
358           "\t // we should highlight other types of errors..",
359           "",
360           "\tif (!obj.has_member(type)) {",
361           "\t\tGLib.debug(\"Return has no errors\\n\");",
362           "\t\treturn true;",
363           "\t}",
364           "",
365           "\tif (_this.window.windowstate.state != WindowState.State.CODEONLY ",
366           "\t\t&&",
367           "\t\t_this.window.windowstate.state != WindowState.State.CODE",
368           "\t\t) {",
369           "\t\tGLib.debug(\"windowstate != CODEONLY?\");",
370           "\t\t",
371           "\t\treturn true;",
372           "\t} ",
373           "",
374           "\t//this.marks = new Gee.HashMap<int,string>();",
375           "\tvar err = obj.get_object_member(type);",
376           " ",
377           "\tif (_this.file == null) {",
378           "\t\tGLib.debug(\"file is null?\");",
379           "\t\treturn true;",
380           "",
381           "\t}",
382           "\tvar valafn = _this.file.path;",
383           "",
384           "\tif (_this.file.xtype != \"PlainFile\") {",
385           "",
386           "\t\tvalafn = \"\";",
387           "\t\ttry {             ",
388           "\t\t\tvar  regex = new Regex(\"\\\\.bjs$\");",
389           "\t\t\t// should not happen",
390           "\t      \t\tvalafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
391           "\t\t} catch (GLib.RegexError e) {",
392           "\t\t\treturn true;",
393           "\t\t}   ",
394           "",
395           "",
396           "",
397           "\t}",
398           "\tif (!err.has_member(valafn)) {",
399           "\t\tGLib.debug(\"File path has no errors\");",
400           "\t\treturn  true;",
401           "\t}",
402           "",
403           "\tvar lines = err.get_object_member(valafn);",
404           "\t",
405           "\tvar offset = 1;",
406           "\tif (obj.has_member(\"line_offset\")) { // ?? why??",
407           "\t\toffset = (int)obj.get_int_member(\"line_offset\") + 1;",
408           "\t}",
409           "",
410           "",
411           "\tvar tlines = this.el.get_line_count () +1;",
412           "\t",
413           "\tif (_this.prop != null) {",
414           "\t",
415           "\t\ttlines = _this.prop.end_line + 1;",
416           "\t\toffset = _this.prop.start_line + 1;",
417           "\t",
418           "\t}",
419           "\t",
420           "",
421           "",
422           "\tlines.foreach_member((obj, line, node) => {",
423           "\t\t",
424           "\t     Gtk.TextIter iter;",
425           "//        print(\"get inter\\n\");",
426           "\t    var eline = int.parse(line) - offset;",
427           "\t    GLib.debug(\"GOT ERROR on line %s -- converted to %d  (offset = %d)\\n\", line,eline, offset);",
428           "\t    ",
429           "\t    ",
430           "\t    if (eline > tlines || eline < 0) {",
431           "\t        return;",
432           "\t    }",
433           "\t   ",
434           "\t    ",
435           "\t    this.el.get_iter_at_line( out iter, eline);",
436           "\t    //print(\"mark line\\n\");",
437           "\t    var msg  = \"\";",
438           "\t    var ar = lines.get_array_member(line);",
439           "\t    for (var i = 0 ; i < ar.get_length(); i++) {",
440           "\t    \tif (ar.get_string_element(i) == \"Success\") {",
441           "\t    \t\tcontinue;",
442           "    \t\t}",
443           "\t\t\tmsg += (msg.length > 0) ? \"\\n\" : \"\";",
444           "\t\t\tmsg += ar.get_string_element(i);",
445           "\t\t}",
446           "\t\tif (msg == \"\") {",
447           "\t\t\treturn;",
448           "\t\t}",
449           "\t\tmsg = \"Line: %d\".printf(eline+1) +  \" \" + msg;",
450           "\t    this.el.create_source_mark(msg, type, iter);",
451           "\t    GLib.debug(\"set line %d to %m\", eline, msg);",
452           "\t   // this.marks.set(eline, msg);",
453           "\t} );",
454           "\treturn false;",
455           "",
456           "",
457           "",
458           "",
459           "",
460           "\t}",
461           ""
462          ],
463          "| string toString" : [
464           "  () {",
465           "    ",
466           "    Gtk.TextIter s;",
467           "    Gtk.TextIter e;",
468           "    this.el.get_start_iter(out s);",
469           "    this.el.get_end_iter(out e);",
470           "    var ret = this.el.get_text(s,e,true);",
471           "    //print(\"TO STRING? \" + ret);",
472           "    return ret;",
473           "}",
474           " "
475          ]
476         },
477         {
478          "$ xns" : "Gtk",
479          "listeners" : {
480           "key_released" : [
481            "(keyval, keycode, state) => {",
482            "",
483            "  ",
484            "    if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
485            "        GLib.debug(\"SAVE: ctrl-S  pressed\");",
486            "        _this.saveContents();",
487            "        return;",
488            "    }",
489            "    ",
490            "    if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
491            "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
492            "\t\t_this.forwardSearch(true);",
493            "\t    return;",
494            "\t}",
495            "\tif (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
496            "\t    GLib.debug(\"SAVE: ctrl-f  pressed\");",
497            "\t\t_this.search_entry.el.grab_focus();",
498            "\t\t_this.search_entry.el.select_region(0,-1);",
499            "\t    return;",
500            "\t}",
501            "\tif (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
502            "\t\t_this.view.el.show_completion();",
503            "\t}",
504            "\t",
505            "\tGtk.TextIter iter;",
506            "\t_this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);  ",
507            "\tvar line  = iter.get_line();",
508            "\tvar offset = iter.get_line_offset();",
509            "\tGLib.debug(\"line  %d  off %d\", line ,offset);",
510            "\tif (_this.prop != null) {",
511            "\t\tline += _this.prop.start_line + 1; // i think..",
512            "\t\toffset += 12; // should probably be 8 without namespaced ",
513            "\t\tGLib.debug(\"guess line  %d  off %d\", line ,offset);",
514            "\t} ",
515            "    //_this.view.el.show_completion();",
516            "   // print(event.key.keyval)",
517            "   ",
518            "   ",
519            "   ",
520            "    ",
521            "    return;",
522            " ",
523            " ",
524            "}",
525            ""
526           ]
527          },
528          "xtype" : "EventControllerKey"
529         }
530        ],
531        "listeners" : {
532         "query_tooltip" : [
533          "(x, y, keyboard_tooltip, tooltip) => {",
534          "\t",
535          "\t//GLib.debug(\"query tooltip\");",
536          "\tGtk.TextIter iter;",
537          "\tint trailing;",
538          "\t",
539          "\tvar yoff = (int) _this.RightEditor.el.vadjustment.value;",
540          "\t",
541          "\t// I think this is problematic - if it's compliing  / updating at same time as query.",
542          "\t",
543          "\t//if (_this.window.statusbar_compile_spinner.el.spinning) {",
544          "\t//\treturn false;",
545          "\t//}",
546          "\t",
547          "\tthis.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);",
548          "\t ",
549          "\tvar l = iter.get_line();",
550          "",
551          "\t",
552          "\t ",
553          "\t// GLib.debug(\"query tooltip line %d\", (int) l);",
554          "\tif (l < 0) {",
555          "",
556          "\t\treturn false;",
557          "\t}",
558          "\t/*",
559          "\tif (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {",
560          "\t\tGLib.debug(\"line %d setting tip to %s\", l,  _this.buffer.marks.get(l));",
561          "\t\ttooltip.set_text(_this.buffer.marks.get(l).dup());",
562          "\t\treturn true;",
563          "\t}",
564          " ",
565          "\treturn false;",
566          "\t*/",
567          "\t",
568          "\t  ",
569          "\t// this crashes?? - not sure why.",
570          "\tvar marks = _this.buffer.el.get_source_marks_at_line(l, \"ERR\");",
571          "\tif (marks.is_empty()) {",
572          "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"WARN\");",
573          "\t}",
574          "\tif (marks.is_empty()) {",
575          "\t\tmarks = _this.buffer.el.get_source_marks_at_line(l, \"DEPR\");",
576          "\t}",
577          "\t",
578          "\t// GLib.debug(\"query tooltip line %d marks %d\", (int)l, (int) marks.length());",
579          "\tvar str = \"\";",
580          "\tmarks.@foreach((m) => { ",
581          "\t\t//GLib.debug(\"got mark %s\", m.name);",
582          "\t\tstr += (str.length > 0 ? \"\\n\" : \"\") + m.category + \": \" + m.name;",
583          "\t});",
584          "\t// true if there is a mark..",
585          "\tif (str.length > 0 ) {",
586          "\t\ttooltip.set_text( str );",
587          "\t}",
588          "\treturn str.length > 0 ? true : false;",
589          "\t ",
590          "}",
591          ""
592         ]
593        },
594        "string name" : "editor-view",
595        "uint tab_width" : 4,
596        "xtype" : "View",
597        "| void load" : [
598         " (string str) {",
599         "",
600         "// show the help page for the active node..",
601         "   //this.get('/Help').show();",
602         " ",
603         "  // this.get('/BottomPane').el.set_current_page(0);",
604         "  \tGLib.debug(\"load called - Reset undo buffer\");",
605         "  \t",
606         "    var buf = (GtkSource.Buffer)this.el.get_buffer();",
607         "    buf.begin_irreversible_action();",
608         "    buf.set_text(str, str.length);",
609         "    buf.end_irreversible_action();",
610         "    ",
611         "    var lm = GtkSource.LanguageManager.get_default();",
612         "    var lang = \"vala\";",
613         "    if (_this.file != null) {",
614         "         lang = _this.file.language;",
615         "    }",
616         "    print(\"lang=%s, content_type = %s\\n\", lang, _this.file.content_type);",
617         "    var lg = _this.file.content_type.length > 0  ?",
618         "            lm.guess_language(_this.file.path, _this.file.content_type) :",
619         "            lm.get_language(lang);",
620         "     ",
621         "   ",
622         "    ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg); ",
623         "",
624         "    this.el.insert_spaces_instead_of_tabs = true;",
625         "    if (lg != null) {",
626         "\t\tprint(\"sourcelanguage  = %s\\n\", lg.name);",
627         "\t\tif (lg.name == \"Vala\") {",
628         "\t\t    this.el.insert_spaces_instead_of_tabs = false;",
629         "\t\t}",
630         "     }",
631         "    _this.dirty = false;",
632         "    this.el.grab_focus();",
633         "    _this.save_button.el.sensitive = false;",
634         "}"
635        ]
636       }
637      ],
638      "xtype" : "ScrolledWindow"
639     },
640     {
641      "$ xns" : "Gtk",
642      "* pack" : "append",
643      "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
644      "bool homogeneous" : false,
645      "bool vexpand" : false,
646      "int spacing" : 0,
647      "items" : [
648       {
649        "$ xns" : "Gtk",
650        "Gtk.CssProvider css" : "",
651        "bool hexpand" : true,
652        "id" : "search_entry",
653        "items" : [
654         {
655          "$ xns" : "Gtk",
656          "listeners" : {
657           "key_pressed" : [
658            "(keyval, keycode, state) => {",
659            "",
660            "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
661            "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
662            "\t\t_this.forwardSearch(true);",
663            "\t    return true;",
664            "\t}",
665            "    ",
666            "  ",
667            " \tif (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {",
668            "\t\t_this.forwardSearch(true);",
669            "\t\t",
670            "\t\t",
671            "\t    return true;",
672            "",
673            "\t}    ",
674            "   // print(event.key.keyval)",
675            "   ",
676            "    return false;",
677            "}",
678            ""
679           ]
680          },
681          "xtype" : "EventControllerKey"
682         }
683        ],
684        "listeners" : {
685         "search_changed" : [
686          "( ) => {",
687          "",
688          "_this.search(_this.search_entry.el.text);",
689          "\t _this.search_results.updateResults();",
690          "",
691          "\tGLib.Timeout.add_seconds(1,() => {",
692          "\t\t _this.search_results.updateResults();",
693          "\t\t return false;",
694          "\t });",
695          "}",
696          ""
697         ]
698        },
699        "string name" : "editor-search-entry",
700        "string placeholder_text" : "Press enter to search",
701        "uint search_delay" : 3,
702        "xtype" : "SearchEntry",
703        "| void forwardSearch" : [
704         "(bool change_focus) {",
705         "",
706         "",
707         "\t_this.forwardSearch(change_focus);",
708         "",
709         "/*",
710         "",
711         "\tswitch(_this.windowstate.state) {",
712         "\t\tcase WindowState.State.CODEONLY:",
713         "\t\t//case WindowState.State.CODE:",
714         "\t\t\t// search the code being edited..",
715         "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
716         "\t\t\t ",
717         "\t\t\tbreak;",
718         "\t\tcase WindowState.State.PREVIEW:",
719         "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
720         "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
721         "\t\t\t} else { ",
722         "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
723         "\t\t\t}",
724         "\t\t",
725         "\t\t\tbreak;",
726         "\t}",
727         "\t*/",
728         "\t",
729         "}",
730         ""
731        ]
732       },
733       {
734        "$ xns" : "Gtk",
735        "id" : "search_results",
736        "int margin_end" : 4,
737        "int margin_start" : 4,
738        "string label" : "No Results",
739        "xtype" : "Label",
740        "| void updateResults" : [
741         "() {",
742         "\tthis.el.visible = true;",
743         "\t",
744         "\tvar res = _this.searchcontext.get_occurrences_count();",
745         "\tif (res < 0) {",
746         "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
747         "\t\treturn;",
748         "\t}",
749         "",
750         "\t_this.nextBtn.el.sensitive = false;",
751         "\t_this.backBtn.el.sensitive = false;\t",
752         "",
753         "\tif (res > 0) {",
754         "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
755         "\t\t_this.nextBtn.el.sensitive = true;",
756         "\t\t_this.backBtn.el.sensitive = true;",
757         "\t\treturn;",
758         "\t} ",
759         "\t_this.search_results.el.label = \"No Matches\";",
760         "\t",
761         "}"
762        ]
763       },
764       {
765        "$ xns" : "Gtk",
766        "bool always_show_image" : true,
767        "bool sensitive" : false,
768        "id" : "nextBtn",
769        "listeners" : {
770         "clicked" : [
771          "(event) => {",
772          "",
773          "\t_this.forwardSearch(true);",
774          "\t",
775          "\t ",
776          "}",
777          ""
778         ]
779        },
780        "string icon_name" : "go-down",
781        "xtype" : "Button"
782       },
783       {
784        "$ xns" : "Gtk",
785        "bool always_show_image" : true,
786        "bool sensitive" : false,
787        "id" : "backBtn",
788        "listeners" : {
789         "clicked" : [
790          "(event) => {",
791          "",
792          "\t_this.backSearch(true);",
793          "\t ",
794          "}",
795          ""
796         ]
797        },
798        "string icon_name" : "go-up",
799        "xtype" : "Button"
800       },
801       {
802        "$ xns" : "Gtk",
803        "bool always_show_arrow" : true,
804        "bool always_show_image" : true,
805        "items" : [
806         {
807          "$ xns" : "Gtk",
808          "* prop" : "popover",
809          "id" : "search_settings",
810          "items" : [
811           {
812            "$ xns" : "Gtk",
813            "* prop" : "child",
814            "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
815            "int spacing" : 0,
816            "items" : [
817             {
818              "$ xns" : "Gtk",
819              "* init" : [
820               "{",
821               "\tthis.el.show();",
822               "}",
823               ""
824              ],
825              "id" : "case_sensitive",
826              "string label" : "Case Sensitive",
827              "xtype" : "CheckButton"
828             },
829             {
830              "$ xns" : "Gtk",
831              "* init" : [
832               "{",
833               "\tthis.el.show();",
834               "}",
835               ""
836              ],
837              "id" : "regex",
838              "string label" : "Regex",
839              "xtype" : "CheckButton"
840             },
841             {
842              "$ xns" : "Gtk",
843              "id" : "multiline",
844              "string label" : "Multi-line (add \\n)",
845              "xtype" : "CheckButton"
846             }
847            ],
848            "xtype" : "Box"
849           }
850          ],
851          "xtype" : "Popover"
852         }
853        ],
854        "string icon_name" : "emblem-system",
855        "xtype" : "MenuButton"
856       }
857      ],
858      "xtype" : "Box"
859     }
860    ],
861    "xtype" : "Box",
862    "| bool saveContents" : [
863     "  ()  {",
864     "    ",
865     "    ",
866     "    if (_this.file == null) {",
867     "        return true;",
868     "    }",
869     "    ",
870     "     ",
871     "     ",
872     "     var str = _this.buffer.toString();",
873     "     ",
874     "     _this.buffer.checkSyntax();",
875     "     ",
876     "     ",
877     "     ",
878     "     // LeftPanel.model.changed(  str , false);",
879     "     _this.dirty = false;",
880     "     _this.save_button.el.sensitive = false;",
881     "     ",
882     "    // find the text for the node..",
883     "    if (_this.file.xtype != \"PlainFile\") {",
884     "       // in theory these properties have to exist!?!",
885     "    \tthis.prop.val = str;",
886     "        //this.window.windowstate.left_props.reload();",
887     "    } else {",
888     "        _this.file.setSource(  str );",
889     "     }",
890     "    ",
891     "    // call the signal..",
892     "    this.save();",
893     "    ",
894     "    return true;",
895     "",
896     "} "
897    ],
898    "| int search" : [
899     "(string in_txt) {",
900     "",
901     "\tvar s = new GtkSource.SearchSettings();",
902     "\ts.case_sensitive = _this.case_sensitive.el.active;",
903     "\ts.regex_enabled = _this.regex.el.active;\t",
904     "\ts.wrap_around = false;",
905     "\t",
906     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
907     "\tthis.searchcontext.set_highlight(true);",
908     "\tvar txt = in_txt;",
909     "\t",
910     "\tif (_this.multiline.el.active) {",
911     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
912     "\t}",
913     "\t",
914     "\ts.set_search_text(txt);",
915     "\tGtk.TextIter beg, st,en;",
916     "\t ",
917     "\tthis.buffer.el.get_start_iter(out beg);",
918     "\tbool has_wrapped_around;",
919     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
920     "\tthis.last_search_end = 0;",
921     "\t",
922     "\treturn this.searchcontext.get_occurrences_count();",
923     "",
924     " ",
925     "   ",
926     "",
927     "}",
928     ""
929    ],
930    "| string tempFileContents" : [
931     "() {",
932     "   ",
933     "   ",
934     "   if (_this.file == null) {",
935     "       return \"\";",
936     "   }",
937     "\tvar str= this.buffer.toString();",
938     "\tif (_this.file.xtype == \"PlainFile\") {",
939     "    ",
940     "     \treturn str;",
941     "    ",
942     "    }",
943     "  ",
944     "      ",
945     "     ",
946     "    GLib.debug(\"calling validate\");    ",
947     "    // clear the buttons.",
948     " \tif (_this.prop.name == \"xns\" || _this.prop.name == \"xtype\") {",
949     "\t\treturn this.file.toSource(); ;",
950     "\t}",
951     "\t",
952     "\tvar oldcode  = _this.prop.val;",
953     "\t_this.prop.val = str;",
954     "    var ret = _this.file.toSource();",
955     "    _this.prop.val = oldcode;",
956     "    return ret;",
957     "    ",
958     "}"
959    ],
960    "| void backSearch" : [
961     "(bool change_focus) {",
962     "",
963     "\tif (this.searchcontext == null) {",
964     "\t\treturn;",
965     "\t} ",
966     "\t",
967     "\tGtk.TextIter beg, st,en;",
968     "\tbool has_wrapped_around;",
969     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
970     "\t",
971     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
972     "\t\tthis.last_search_end = 0;",
973     "\t} else {",
974     "\t\tthis.last_search_end = en.get_offset();",
975     "\t\tif (change_focus) {",
976     "\t\t\tthis.view.el.grab_focus();",
977     "\t\t}",
978     "\t\tthis.buffer.el.place_cursor(st);",
979     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
980     "\t}",
981     "",
982     "}",
983     ""
984    ],
985    "| void forwardSearch" : [
986     "(bool change_focus) {",
987     "",
988     "\tif (this.searchcontext == null) {",
989     "\t\treturn;",
990     "\t} ",
991     "",
992     "\tGtk.TextIter beg, st,en;",
993     "\t bool has_wrapped_around;",
994     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end);",
995     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
996     "\t",
997     "\t\tthis.last_search_end = 0; // not sure if this should happen",
998     "\t} else {",
999     "\t\tif (has_wrapped_around) {",
1000     "\t\t\treturn;",
1001     "\t\t}",
1002     "\t",
1003     "\t\tthis.last_search_end = en.get_offset();",
1004     "\t\tif (change_focus) {",
1005     "\t\t\tthis.view.el.grab_focus();",
1006     "\t\t}",
1007     "\t\tthis.buffer.el.place_cursor(st);",
1008     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1009     "\t}",
1010     " ",
1011     "}",
1012     ""
1013    ],
1014    "| void reset" : [
1015     "() {",
1016     "\t this.file = null;    ",
1017     "     ",
1018     "    this.node = null;",
1019     "    this.prop = null;",
1020     "\tthis.searchcontext = null;",
1021     "  ",
1022     "}",
1023     ""
1024    ],
1025    "| void scroll_to_line" : [
1026     "(int line) {",
1027     "",
1028     "\tGLib.Timeout.add(500, () => {",
1029     "   ",
1030     "\t\tvar buf = this.view.el.get_buffer();",
1031     "",
1032     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1033     "",
1034     "",
1035     "\t\tGtk.TextIter iter;   ",
1036     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1037     "\t\tthis.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1038     "\t\treturn false;",
1039     "\t});   ",
1040     "}",
1041     ""
1042    ],
1043    "| void show" : [
1044     "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
1045     "{",
1046     "    this.reset();",
1047     "    this.file = file;    ",
1048     "    ",
1049     "    if (file.xtype != \"PlainFile\") {",
1050     "    \tthis.prop = prop;",
1051     "        this.node = node;",
1052     "",
1053     "        // find the text for the node..",
1054     "        this.view.load( prop.val );",
1055     "        ",
1056     "        ",
1057     "        this.close_btn.el.show();       ",
1058     "    ",
1059     "    } else {",
1060     "        this.view.load(        file.toSource() );",
1061     "        this.close_btn.el.hide();",
1062     "    }",
1063     " ",
1064     "}"
1065    ],
1066    "| void updateErrorMarks" : [
1067     "(string category) {",
1068     "\t",
1069     " ",
1070     "",
1071     "\tvar buf = _this.buffer.el;",
1072     "\tGtk.TextIter start;",
1073     "\tGtk.TextIter end;     ",
1074     "\tbuf.get_bounds (out start, out end);",
1075     "",
1076     "\tbuf.remove_source_marks (start, end, category);",
1077     " ",
1078     "\t//GLib.debug(\"highlight errors\");\t\t ",
1079     "",
1080     "\t // we should highlight other types of errors..",
1081     "",
1082     "\tif (_this.window.windowstate.state != WindowState.State.CODEONLY ",
1083     "\t\t&&",
1084     "\t\t_this.window.windowstate.state != WindowState.State.CODE",
1085     "\t\t) {",
1086     "\t\t//GLib.debug(\"windowstate != CODEONLY?\");",
1087     "\t\t",
1088     "\t\treturn;",
1089     "\t} ",
1090     "",
1091     "\t ",
1092     "\tif (_this.file == null) {",
1093     "\t\tGLib.debug(\"file is null?\");",
1094     "\t\treturn;",
1095     "",
1096     "\t}",
1097     "\tvar ar = this.file.getErrors(category);",
1098     "\tif (ar == null || ar.get_n_items() < 1) {",
1099     "\t\t//GLib.debug(\"highlight %s :  %s has no errors\", this.file.relpath, category);",
1100     "\t\treturn;",
1101     "\t}",
1102     " ",
1103     "",
1104     " ",
1105     "\t",
1106     "\tvar offset = 0;",
1107     "\t ",
1108     "",
1109     "\tvar tlines = buf.get_line_count () +1;",
1110     "\t",
1111     "\tif (_this.prop != null) {",
1112     "\t\t// this still seems flaky...",
1113     "\t\t",
1114     "\t\ttlines = _this.prop.end_line;",
1115     "\t\toffset = _this.prop.start_line;",
1116     "\t\t ",
1117     "\t}",
1118     "\t ",
1119     "\tfor (var i = 0; i < ar.get_n_items();i++) {",
1120     "\t\tvar err = (Palete.CompileError) ar.get_item(i);",
1121     "\t\t",
1122     "\t     Gtk.TextIter iter;",
1123     "//        print(\"get inter\\n\");",
1124     "\t    var eline = err.line - offset;",
1125     "\t    //GLib.debug(\"GOT ERROR on line %d -- converted to %d  (offset = %d)\",",
1126     "\t    //\terr.line ,eline, offset);",
1127     "\t    ",
1128     "\t    ",
1129     "\t    if (eline > tlines || eline < 0) {",
1130     "\t        return;",
1131     "\t    }",
1132     "\t   ",
1133     "\t    ",
1134     "\t    buf.get_iter_at_line( out iter, eline);",
1135     "\t   ",
1136     "\t   ",
1137     "\t\tvar msg = \"Line: %d %s : %s\".printf(eline+1, err.category, err.msg);",
1138     "\t    buf.create_source_mark( msg, err.category, iter);",
1139     "\t   // GLib.debug(\"set line %d to %s\", eline, msg);",
1140     "\t    //this.marks.set(eline, msg);",
1141     "\t}",
1142     "\treturn ;",
1143     "",
1144     "",
1145     "",
1146     " ",
1147     "",
1148     "}"
1149    ]
1150   }
1151  ],
1152  "name" : "Editor"
1153 }