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