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