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