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