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