8a05b79f3efee711e0ff561a62fb5db8abbb84b5
[roobuilder] / src / Builder4 / WindowRooView.bjs
1 {
2  "build_module" : "builder",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "# Gtk.Widget lastObj" : "null",
7    "# JsRender.JsRender file" : "null",
8    "# Xcls_MainWindow main_window" : "",
9    "$ xns" : "Gtk",
10    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
11    "GtkSource.SearchContext searchcontext" : "",
12    "bool hexpand" : true,
13    "bool vexpand" : true,
14    "id" : "WindowRooView",
15    "int last_search_end" : 0,
16    "items" : [
17     {
18      "$ xns" : "Gtk",
19      "bool vexpand" : true,
20      "id" : "notebook",
21      "items" : [
22       {
23        "$ xns" : "Gtk",
24        "* pack" : false,
25        "id" : "label_preview",
26        "utf8 label" : "Preview",
27        "xtype" : "Label"
28       },
29       {
30        "$ xns" : "Gtk",
31        "* pack" : false,
32        "id" : "label_code",
33        "utf8 label" : "Preview Generated Code",
34        "xtype" : "Label"
35       },
36       {
37        "$ xns" : "Gtk",
38        "* pack" : "append_page,_this.label_preview.el",
39        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
40        "bool vexpand" : true,
41        "id" : "paned",
42        "items" : [
43         {
44          "$ homogeneous" : false,
45          "$ xns" : "Gtk",
46          "* pack" : "set_start_child",
47          "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
48          "bool vexpand" : true,
49          "id" : "viewbox",
50          "items" : [
51           {
52            "$ height_request" : 20,
53            "$ homogeneous" : true,
54            "$ vexpand" : false,
55            "$ xns" : "Gtk",
56            "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
57            "items" : [
58             {
59              "$ xns" : "Gtk",
60              "label" : "Redraw",
61              "listeners" : {
62               "clicked" : [
63                "( ) => {",
64                "    _this.view.renderJS(  true);",
65                "}"
66               ]
67              },
68              "xtype" : "Button"
69             },
70             {
71              "$ active" : true,
72              "$ xns" : "Gtk",
73              "id" : "AutoRedraw",
74              "label" : "Auto Redraw On",
75              "listeners" : {
76               "toggled" : [
77                " (state) => {",
78                "    this.el.set_label(this.el.active  ? \"Auto Redraw On\" : \"Auto Redraw Off\");",
79                "}"
80               ]
81              },
82              "xtype" : "CheckButton"
83             },
84             {
85              "$ xns" : "Gtk",
86              "label" : "Full Redraw",
87              "listeners" : {
88               "clicked" : [
89                " () => {",
90                "  _this.view.redraws = 99;",
91                " //   _this.view.el.web_context.clear_cache();  ",
92                "  //_this.view.renderJS(true);",
93                "  FakeServerCache.clear();",
94                "  _this.view.reInit();",
95                " ",
96                "}"
97               ]
98              },
99              "xtype" : "Button"
100             }
101            ],
102            "xtype" : "Box"
103           },
104           {
105            "# GLib.DateTime lastRedraw" : "null",
106            "# WebKit.WebInspector inspector" : "",
107            "# bool pendingRedraw" : false,
108            "# bool refreshRequired" : false,
109            "# int redraws" : 0,
110            "# string renderedData" : "\"\"",
111            "# string runhtml" : "\"\"",
112            "# string runjs" : "\"\"",
113            "$ xns" : "WebKit",
114            "* init" : [
115             " {",
116             "    // this may not work!?",
117             "    var settings =  this.el.get_settings();",
118             "    settings.enable_developer_extras = true;",
119             "    ",
120             "    ",
121             "    var fs= new FakeServer(this.el);",
122             "    fs.ref();",
123             "    // this was an attempt to change the url perms.. did not work..",
124             "    // settings.enable_file_access_from_file_uris = true;",
125             "    // settings.enable_offline_web_application_cache - true;",
126             "    // settings.enable_universal_access_from_file_uris = true;",
127             "   ",
128             "     ",
129             "    ",
130             "    ",
131             "    ",
132             "",
133             "     // FIXME - base url of script..",
134             "     // we need it so some of the database features work.",
135             "    this.el.load_html( \"Render not ready\" , ",
136             "            //fixme - should be a config option!",
137             "            // or should we catch stuff and fix it up..",
138             "            \"http://localhost/app.Builder/\"",
139             "    );",
140             "   ",
141             "        ",
142             "   //this.el.open('file:///' + __script_path__ + '/../builder.html');",
143             "    /*",
144             "    Gtk.drag_dest_set",
145             "    (",
146             "            this.el,              //",
147             "            Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,",
148             "            null,            // list of targets",
149             "            Gdk.DragAction.COPY         // what to do with data after dropped ",
150             "    );",
151             "                            ",
152             "   // print(\"RB: TARGETS : \" + LeftTree.atoms[\"STRING\"]);",
153             "    Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);",
154             "    */",
155             "    GLib.Timeout.add_seconds(1,  ()  =>{",
156             "         //print(\"run refresh?\");",
157             "         if (this.el == null) {",
158             "            return false;",
159             "         }",
160             "         this.runRefresh(); ",
161             "         return true;",
162             "     });",
163             "    ",
164             "    ",
165             "}",
166             ""
167            ],
168            "bool vexpand" : true,
169            "id" : "view",
170            "listeners" : {
171             "load_changed" : [
172              "(le) => {",
173              "    if (le != WebKit.LoadEvent.FINISHED) {",
174              "        return;",
175              "    }",
176              "    if (this.runjs.length < 1) {",
177              "        return;",
178              "    }",
179              "  //  this.el.run_javascript(this.runjs, null);",
180              "     FakeServerCache.remove(    this.runjs);",
181              "    this.runjs = \"\";",
182              "}"
183             ],
184             "ready_to_show" : [
185              "( ) => {",
186              "  this.initInspector();",
187              "",
188              "}",
189              ""
190             ],
191             "script_dialog" : [
192              " (dialog) => {",
193              "    ",
194              "    ",
195              "    if (this.el == null) {",
196              "        return true;",
197              "    }",
198              "    ",
199              "     var msg = dialog.get_message();",
200              "     if (msg.length < 4) {",
201              "        return false;",
202              "     }",
203              "     ",
204              "     GLib.debug(\"script dialog got %s\", msg);",
205              "     ",
206              "     if (msg.substring(0,4) != \"IPC:\") {",
207              "         return false;",
208              "     }",
209              "     var ar = msg.split(\":\", 3);",
210              "    if (ar.length < 3) {",
211              "        return false;",
212              "    }",
213              "",
214              "    switch(ar[1]) {",
215              "        case \"SAVEHTML\":",
216              "\t        GLib.debug(\"GOT saveHTML %d\", ar[2].length);",
217              "            _this.file.saveHTML(ar[2]);",
218              "            _this.createThumb();",
219              "            return true;",
220              "        default:",
221              "            return false;",
222              "    }",
223              "    ",
224              "}"
225             ]
226            },
227            "xtype" : "WebView",
228            "| void initInspector" : [
229             "() {",
230             "    ",
231             " ",
232             "          ",
233             "   // this.inspector.open_window.connect(() => {",
234             "         this.inspector = this.el.get_inspector();",
235             "         ",
236             "         this.inspector.open_window.connect(() => {",
237             "        print(\"inspector attach\\n\");",
238             "        var wv = this.inspector.get_web_view();",
239             "        if (wv != null) {",
240             "            print(\"got inspector web view\\n\");",
241             "            ",
242             "            var cn = _this.inspectorcontainer.el.get_first_child();",
243             "            if (cn != null) {",
244             "                 _this.inspectorcontainer.el.remove(cn);",
245             "             }",
246             "            ",
247             "            _this.inspectorcontainer.el.append(wv);",
248             "            wv.show();",
249             "        } else {",
250             "\t         print(\"got inspector web view FAILED\\n\");",
251             "            //this.inspector.close();",
252             "            ",
253             "            //this.inspector = null;",
254             "           ",
255             " ",
256             "        }",
257             "      return true;",
258             "       ",
259             "   });",
260             "     this.inspector.show();",
261             "         ",
262             "    ",
263             "  ",
264             "}",
265             ""
266            ],
267            "| void reInit" : [
268             "() {",
269             "   print(\"reInit?\");",
270             "         // if this happens destroy the webkit..",
271             "         // recreate it..",
272             "     this.el.stop_loading();",
273             "         ",
274             "     if (_this.viewbox.el.get_parent() == null) {",
275             "        return;",
276             "     }",
277             "         ",
278             "         /*",
279             "    _this.viewbox.el.remove(_this.viewcontainer.el);",
280             "    //_this.paned.el.remove(_this.inspectorcontainer.el);        ",
281             "         ",
282             "         // destory seems to cause problems.",
283             "         //this.el.destroy();",
284             "        //_this.viewcontainer.el.destroy();",
285             "         //_this.inspectorcontainer.el.destroy();",
286             "     var  inv =new Xcls_inspectorcontainer(_this);",
287             "      ",
288             "      _this.paned.el.set_end_child(inv.el);",
289             "      _this.inspectorcontainer = inv;",
290             "      ",
291             "     this.el = null;         ",
292             "     var nv =new Xcls_viewcontainer(_this);",
293             "    // nv.ref();",
294             "     _this.viewbox.el.append(nv.el);",
295             "         ",
296             "         _this.viewcontainer = nv;",
297             "     inv.el.show();",
298             "     nv.el.show();",
299             "         //while(Gtk.events_pending ()) Gtk.main_iteration ();",
300             "         //_this.view.renderJS(true); ",
301             "     _this.view.refreshRequired  = true;",
302             "     ",
303             "     */",
304             "}",
305             ""
306            ],
307            "| void renderJS" : [
308             "(bool force) {",
309             "",
310             "    // this is the public redraw call..",
311             "    // we refresh in a loop privately..",
312             "    var autodraw = _this.AutoRedraw.el.active;",
313             "    if (!autodraw && !force) {",
314             "        print(\"Skipping redraw - no force, and autodraw off\");",
315             "        return;",
316             "    }",
317             "     ",
318             "    this.refreshRequired  = true;",
319             "}",
320             ""
321            ],
322            "| void runRefresh" : [
323             " () ",
324             "{",
325             "    // this is run every 2 seconds from the init..",
326             "",
327             "  ",
328             "    ",
329             "    if (!this.refreshRequired) {",
330             "       // print(\"no refresh required\");",
331             "        return;",
332             "    }",
333             "",
334             "    if (this.lastRedraw != null) {",
335             "       // do not redraw if last redraw was less that 5 seconds ago.",
336             "       if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {",
337             "            return;",
338             "        }",
339             "    }",
340             "    ",
341             "    if (_this.file == null) {",
342             "        return;",
343             "    }",
344             "    ",
345             "    ",
346             "     this.refreshRequired = false;",
347             "   //  print(\"HTML RENDERING\");",
348             "     ",
349             "     ",
350             "     //this.get('/BottomPane').el.show();",
351             "     //this.get('/BottomPane').el.set_current_page(2);// webkit inspector",
352             "    _this.file.webkit_page_id  = this.el.get_page_id();",
353             "    ",
354             "    var js = _this.file.toSourcePreview();",
355             "",
356             "    if (js.length < 1) {",
357             "        print(\"no data\");",
358             "        return;",
359             "    }",
360             "//    var  data = js[0];",
361             "    this.redraws++;",
362             "  ",
363             "    var project = (Project.Roo) _this.file.project;  ",
364             "",
365             "     //print (project.fn);",
366             "     // set it to non-empty.",
367             "     ",
368             "//     runhtml = runhtml.length ?  runhtml : '<script type=\"text/javascript\"></script>'; ",
369             "",
370             "",
371             "//   this.runhtml  = this.runhtml || '';",
372             " ",
373             " ",
374             "    // then we need to reload the browser using",
375             "    // load_html_string..",
376             "",
377             "    // then trigger a redraw once it's loaded..",
378             "    this.pendingRedraw = true;",
379             "",
380             "    var runhtml = \"<script type=\\\"text/javascript\\\">\\n\" ;",
381             "    string builderhtml;",
382             "    ",
383             "    try {",
384             "        GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + \"/resources/roo.builder.js\", out builderhtml);",
385             "    } catch (Error e) {",
386             "        builderhtml = \"\";",
387             "    }",
388             "",
389             "    runhtml += builderhtml + \"\\n\";",
390             "    runhtml += \"</script>\\n\" ;",
391             "",
392             "    // fix to make sure they are the same..",
393             "    this.runhtml = project.runhtml;",
394             "    // need to modify paths",
395             "",
396             "    string inhtml;",
397             "    var base_template = project.base_template;",
398             "    ",
399             "    if (base_template.length > 0 && !FileUtils.test(",
400             "        BuilderApplication.configDirectory() + \"/resources/\" +  base_template, FileTest.EXISTS)  ",
401             "        ) {",
402             "           print(\"invalid base_template name - using default:  %s\\n\", base_template);",
403             "           base_template = \"\";",
404             "    ",
405             "    }",
406             "    try {",
407             "        GLib.FileUtils.get_contents(",
408             "            BuilderApplication.configDirectory() + \"/resources/\" + ",
409             "                (base_template.length > 0 ? base_template :  \"roo.builder.html\")",
410             "                , out inhtml);",
411             "    ",
412             "    } catch (Error e) {",
413             "        inhtml = \"\";",
414             "    }    ",
415             "    this.renderedData = js;",
416             "",
417             "",
418             "    string js_src = js + \"",
419             "Roo.onReady(function() {",
420             "if (\" + _this.file.name +\".show) {",
421             "\t\t\" + _this.file.name +\".show({});",
422             "\t\t(function() {  ",
423             "\t\t\tBuilder.saveHTML.defer(100, Builder);",
424             "\t\t}).defer(100);",
425             "}",
426             "Roo.XComponent.build();",
427             "});\\n\";",
428             "\t",
429             "   // print(\"render js: \" + js);",
430             "    //if (!this.ready) {",
431             "  //      console.log('not loaded yet');",
432             "    //}",
433             "    this.lastRedraw = new DateTime.now_local();",
434             "",
435             "",
436             "    //this.runjs = js_src;",
437             "    var fc =    FakeServerCache.factory_with_data(js_src);",
438             "    this.runjs = fc.fname;",
439             "    ",
440             "        var html = inhtml.replace(\"</head>\", runhtml + this.runhtml + ",
441             "            \"<script type=\\\"text/javascript\\\" src=\\\"xhttp://localhost\" + fc.fname + \"\\\"></script>\" +   ",
442             "              //  \"<script type=\\\"text/javascript\\\">\\n\" +",
443             "              //  js_src + \"\\n\" + ",
444             "              //  \"</script>\" + ",
445             "                        ",
446             "        \"</head>\");",
447             "        //print(\"LOAD HTML \" + html);",
448             "        ",
449             "         var rootURL = project.rootURL;",
450             "   ",
451             "        ",
452             "        ",
453             "        this.el.load_html( html , ",
454             "            //fixme - should be a config option!",
455             "            (rootURL.length > 0 ? rootURL : \"xhttp://localhost/roobuilder/\")",
456             "        );",
457             "          this.initInspector();   ",
458             "    // force the inspector...        ",
459             "       //   this.initInspector();",
460             "        ",
461             "        // - no need for this, the builder javascript will call it when build is complete",
462             "        //GLib.Timeout.add_seconds(1, () => {",
463             "        //    this.el.run_javascript(\"Builder.saveHTML()\",null);",
464             "        //    return false;",
465             "        //});",
466             "//     print( \"before render\" +    this.lastRedraw);",
467             "//    print( \"after render\" +    (new Date()));",
468             "    ",
469             "}",
470             "                                                                                                                                                                                                                        "
471            ]
472           }
473          ],
474          "xtype" : "Box"
475         },
476         {
477          "$ xns" : "Gtk",
478          "* pack" : "set_end_child",
479          "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
480          "bool vexpand" : true,
481          "id" : "inspectorcontainer",
482          "xtype" : "Box"
483         }
484        ],
485        "xtype" : "Paned"
486       },
487       {
488        "$ xns" : "Gtk",
489        "* pack" : "append_page,_this.label_code.el",
490        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
491        "bool vexpand" : true,
492        "int spacing" : 0,
493        "items" : [
494         {
495          "$ xns" : "Gtk",
496          "bool vexpand" : true,
497          "id" : "sourceviewscroll",
498          "items" : [
499           {
500            "# JsRender.Node? node_selected" : "null",
501            "# bool button_is_pressed" : false,
502            "# bool key_is_pressed" : false,
503            "# bool loading" : true,
504            "# int editable_start_pos" : "-1",
505            "# string prop_selected" : "\"\"",
506            "$ xns" : "GtkSource",
507            "* init" : [
508             "{",
509             "   ",
510             "   this.css = new Gtk.CssProvider();",
511             "\t ",
512             "\tthis.css.load_from_string(",
513             "\t\t\"#roo-view { font:  10px monospace; }\"",
514             "\t);",
515             " ",
516             "\tGtk.StyleContext.add_provider_for_display(",
517             "\t\tthis.el.get_display(),",
518             "\t\tthis.css,",
519             "\t\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
520             "\t);",
521             "\t\t",
522             "\t ",
523             "    ",
524             "    this.loading = true;",
525             "    //var buf = this.el.get_buffer();",
526             "    //buf.notify.connect(this.onCursorChanged);",
527             "  ",
528             "  ",
529             "    var attrs = new GtkSource.MarkAttributes();",
530             "    var  pink =   Gdk.RGBA();",
531             "    pink.parse ( \"pink\");",
532             "    attrs.set_background ( pink);",
533             "    attrs.set_icon_name ( \"process-stop\");    ",
534             "    attrs.query_tooltip_text.connect(( mark) => {",
535             "        //print(\"tooltip query? %s\\n\", mark.name);",
536             "        return mark.name;",
537             "    });",
538             "    ",
539             "    this.el.set_mark_attributes (\"ERR\", attrs, 1);",
540             "    ",
541             "     var wattrs = new GtkSource.MarkAttributes();",
542             "    var  blue =   Gdk.RGBA();",
543             "    blue.parse ( \"#ABF4EB\");",
544             "    wattrs.set_background ( blue);",
545             "    wattrs.set_icon_name ( \"process-stop\");    ",
546             "    wattrs.query_tooltip_text.connect(( mark) => {",
547             "        //print(\"tooltip query? %s\\n\", mark.name);",
548             "        return mark.name;",
549             "    });",
550             "    ",
551             "    this.el.set_mark_attributes (\"WARN\", wattrs, 1);",
552             "    ",
553             " ",
554             "    ",
555             "     var dattrs = new GtkSource.MarkAttributes();",
556             "    var  purple =   Gdk.RGBA();",
557             "    purple.parse ( \"#EEA9FF\");",
558             "    dattrs.set_background ( purple);",
559             "    dattrs.set_icon_name ( \"process-stop\");    ",
560             "    dattrs.query_tooltip_text.connect(( mark) => {",
561             "        //print(\"tooltip query? %s\\n\", mark.name);",
562             "        return mark.name;",
563             "    });",
564             "    ",
565             "    this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
566             "    ",
567             "    ",
568             "    var gattrs = new GtkSource.MarkAttributes();",
569             "    var  grey =   Gdk.RGBA();",
570             "    grey.parse ( \"#ccc\");",
571             "    gattrs.set_background ( grey);",
572             " ",
573             "    ",
574             "    this.el.set_mark_attributes (\"grey\", gattrs, 1);",
575             "    ",
576             "    ",
577             "    ",
578             "    ",
579             "    ",
580             "    ",
581             "}",
582             " "
583            ],
584            "* pack" : "set_child",
585            "Gtk.CssProvider css" : "",
586            "gboolean editable" : false,
587            "gboolean show_line_marks" : true,
588            "gboolean show_line_numbers" : true,
589            "id" : "sourceview",
590            "items" : [
591             {
592              "$ xns" : "GtkSource",
593              "* pack" : "set_buffer",
594              "bool dirty" : false,
595              "id" : "buffer",
596              "int error_line" : "-1",
597              "listeners" : {
598               "changed" : [
599                " () => {",
600                "  ",
601                "    // check syntax??",
602                "    // ??needed..??",
603                "   // _this.save_button.el.sensitive = true;",
604                "    ///?? has changed occured during loading?",
605                "    ",
606                "    // only trigger this if ",
607                "    ",
608                "    ",
609                "    ",
610                "    ",
611                "    if (_this.sourceview.loading) {",
612                "\t\treturn;",
613                "\t}",
614                "\t",
615                "",
616                "\t",
617                "    print(\"- PREVIEW EDITOR CHANGED--\");",
618                "",
619                "    this.dirty = true;  ",
620                "   // this.checkSyntax(); // this calls backs and highlights errors.. in theory...  ",
621                "",
622                "",
623                "",
624                "\tif (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {",
625                "\t\tprint(\"button or key not pressed to generate change?!\\n\");",
626                "\t\treturn;",
627                "\t}",
628                "\t\t",
629                "    ",
630                "\t// what are we editing??",
631                "\tif (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length  < 1) {",
632                "\t\treturn;",
633                "\t}",
634                "\t",
635                "\t// find the colon on the first line...",
636                "\t",
637                "\tif (_this.sourceview.editable_start_pos > -1) {",
638                "\t\t",
639                "\t\tvar buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();",
640                "\t\t",
641                "        //print(\"cursor changed : %d\\n\", buf.cursor_position);",
642                "        Gtk.TextIter spos,epos;",
643                "        buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);",
644                "        buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..",
645                "        ",
646                "        var gotit= false;",
647                "        var line = spos.get_line();",
648                "        var endline = buf.get_line_count();",
649                "        while (line < endline) {",
650                "    \t\tline++;",
651                "\t        buf.get_iter_at_line(out epos, line);",
652                "\t        if (buf.get_source_marks_at_line(line, \"grey\").length() > 0) {",
653                "\t\t        buf.get_iter_at_line(out epos, line);\t    \t\t",
654                "\t    \t\tgotit=true;",
655                "\t    \t\tbreak;",
656                "    \t\t}",
657                "\t\t}",
658                "        ",
659                " \t\tif (gotit) {",
660                "\t \t\tprint(\"End Offset = %d/%d\\n\", epos.get_line(), epos.get_offset());",
661                "\t\t\t// get the pos...",
662                "\t\t\t// in theory the last char will be '}' or '},' .. or ','",
663                "\t\t\t// we should chop the ',' of the end...",
664                "\t\t\tvar str = buf.get_text(spos, epos, false);",
665                "\t\t\tprint(\"got string\\n%s\\n\", str);",
666                "\t\t",
667                "\t\t}",
668                "\t}",
669                "    return ;",
670                "}",
671                "",
672                " ",
673                ""
674               ]
675              },
676              "xtype" : "Buffer",
677              "| bool highlightErrors" : [
678               "( Gee.HashMap<int,string> validate_res) {",
679               "         ",
680               "    this.error_line = validate_res.size;",
681               "\t",
682               "    if (this.error_line < 1) {",
683               "          return true;",
684               "    }",
685               "    var tlines = this.el.get_line_count ();",
686               "    Gtk.TextIter iter;",
687               "    var valiter = validate_res.map_iterator();",
688               "    while (valiter.next()) {",
689               "    ",
690               "//        print(\"get inter\\n\");",
691               "        var eline = valiter.get_key();",
692               "        if (eline > tlines) {",
693               "            continue;",
694               "        }",
695               "        this.el.get_iter_at_line( out iter, eline);",
696               "        //print(\"mark line\\n\");",
697               "        this.el.create_source_mark(valiter.get_value(), \"ERR\", iter);",
698               "    }   ",
699               "    return false;",
700               "}"
701              ],
702              "| string toString" : [
703               "  () {",
704               "    ",
705               "    Gtk.TextIter s;",
706               "    Gtk.TextIter e;",
707               "    this.el.get_start_iter(out s);",
708               "    this.el.get_end_iter(out e);",
709               "    var ret = this.el.get_text(s,e,true);",
710               "    //print(\"TO STRING? \" + ret);",
711               "    return ret;",
712               "}",
713               " "
714              ]
715             },
716             {
717              "$ xns" : "Gtk",
718              "* pack" : "add_controller",
719              "listeners" : {
720               "key_pressed" : [
721                "(keyval, keycode, state) => {",
722                "",
723                " ",
724                "    ",
725                "  \tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
726                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
727                "\t\t_this.forwardSearch(true);",
728                "\t    return false;",
729                "\t}",
730                "\tif (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
731                "\t    GLib.debug(\"SAVE: ctrl-f  pressed\");",
732                "\t\t_this.search_entry.el.grab_focus();",
733                "\t    return false ;",
734                "\t}",
735                "    ",
736                "\t//this.button_is_pressed = true;",
737                "\t//return false;",
738                "   // print(event.key.keyval)",
739                "    ",
740                "    return false;",
741                " ",
742                " ",
743                "}",
744                ""
745               ]
746              },
747              "xtype" : "EventControllerKey"
748             },
749             {
750              "$ xns" : "Gtk",
751              "listeners" : {
752               "released" : [
753                "(n_press, x, y) => {",
754                "",
755                "\tprint(\"BUTTON RELEASE EVENT\\n\");",
756                "\t_this.sourceview.onCursorChanged();",
757                "\t//this.button_is_pressed = false;",
758                "\t ",
759                "}",
760                ""
761               ]
762              },
763              "xtype" : "GestureClick"
764             }
765            ],
766            "listeners" : {
767             "query_tooltip" : [
768              "(x, y, keyboard_tooltip, tooltip) => {",
769              "\t",
770              "\t//GLib.debug(\"query tooltip\");",
771              "\tGtk.TextIter iter;",
772              "\tint trailing;",
773              "\t",
774              "\tvar yoff = (int) _this.sourceviewscroll.el.vadjustment.value;",
775              "\t",
776              "\tthis.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);",
777              "\t ",
778              "\tvar l = iter.get_line();",
779              "\t//GLib.debug(\"query tooltip line %d\", (int) l);",
780              "\tvar marks = _this.buffer.el.get_source_marks_at_line(l, null);",
781              "\t//GLib.debug(\"query tooltip line marks %d\", (int) marks.length());",
782              "\tvar str = \"\";",
783              "\tmarks.@foreach((m) => { ",
784              "\t\t//GLib.debug(\"got mark %s\", m.name);",
785              "\t\tstr += (str.length > 0 ? \"\\n\" : \"\") + m.name;",
786              "\t});",
787              "\t// true if there is a mark..",
788              "\tif (str.length > 0 ) {",
789              "\t\t\ttooltip.set_text( str);",
790              "\t}",
791              "\treturn str.length > 0 ? true : false;",
792              "",
793              "}"
794             ]
795            },
796            "string name" : "roo-view",
797            "xtype" : "View",
798            "| string toString" : [
799             "() {",
800             "   Gtk.TextIter s;",
801             "    Gtk.TextIter e;",
802             "    this.el.get_buffer().get_start_iter(out s);",
803             "    this.el.get_buffer().get_end_iter(out e);",
804             "    var ret = this.el.get_buffer().get_text(s,e,true);",
805             "    //print(\"TO STRING? \" + ret);",
806             "    return ret;",
807             "}",
808             ""
809            ],
810            "| void clearGreySelection" : [
811             "() {",
812             " // clear all the marks..",
813             "    var sbuf = (GtkSource.Buffer)this.el.buffer;",
814             "    ",
815             "    Gtk.TextIter start;",
816             "    Gtk.TextIter end;     ",
817             "        ",
818             "    sbuf.get_bounds (out start, out end);",
819             "    sbuf.remove_source_marks (start, end, \"grey\");",
820             "    ",
821             "    ",
822             "}",
823             ""
824            ],
825            "| void highlightErrorsJson" : [
826             " (string type, Json.Object obj) {",
827             "       // this is a hook for the vala code - it has no value in javascript ",
828             "       // as we only have one error ususally....",
829             "        return  ;",
830             "    ",
831             " ",
832             "",
833             "",
834             "}"
835            ],
836            "| void loadFile" : [
837             "( ) {",
838             "    this.loading = true;",
839             "    ",
840             "    ",
841             "    // get the cursor and scroll position....",
842             "    var buf = this.el.get_buffer();",
843             "\tvar cpos = buf.cursor_position;",
844             "    ",
845             "   print(\"BEFORE LOAD cursor = %d\\n\", cpos);",
846             "   ",
847             "    var vadj_pos = this.el.get_vadjustment().get_value();",
848             "   ",
849             "    ",
850             " ",
851             "    buf.set_text(\"\",0);",
852             "    var sbuf = (GtkSource.Buffer) buf;",
853             "",
854             "    ",
855             "",
856             "    if (_this.file == null || _this.file.xtype != \"Roo\") {",
857             "        print(\"xtype != Roo\");",
858             "        this.loading = false;",
859             "        return;",
860             "    }",
861             "    ",
862             "    // get the string from the rendered tree...",
863             "     ",
864             "     var str = _this.file.toSource();",
865             "     ",
866             "//    print(\"setting str %d\\n\", str.length);",
867             "    buf.set_text(str, str.length);",
868             "    var lm = GtkSource.LanguageManager.get_default();",
869             "     ",
870             "    //?? is javascript going to work as js?",
871             "    ",
872             "    ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));",
873             "  ",
874             "    ",
875             "    Gtk.TextIter start;",
876             "    Gtk.TextIter end;     ",
877             "        ",
878             "    sbuf.get_bounds (out start, out end);",
879             "    sbuf.remove_source_marks (start, end, null); // remove all marks..",
880             "    ",
881             "     GLib.Timeout.add(500, () => {",
882             "",
883             "        print(\"RESORTING cursor to = %d\\n\", cpos);",
884             "\t\tGtk.TextIter cpos_iter;",
885             "\t\tbuf.get_iter_at_offset(out cpos_iter, cpos);",
886             "\t\tbuf.place_cursor(cpos_iter); ",
887             "\t\t",
888             "\t\tthis.el.get_vadjustment().set_value(vadj_pos);;",
889             "\t\t",
890             "",
891             "\t\tthis.onCursorChanged();",
892             "\t\t",
893             "\t\t",
894             "\t\t//_this.buffer.checkSyntax();",
895             "\t\treturn false;",
896             "\t});",
897             "\t\t",
898             "    this.loading = false; ",
899             "    _this.buffer.dirty = false;",
900             "}",
901             ""
902            ],
903            "| void nodeSelected" : [
904             "(JsRender.Node? sel, bool scroll ) {",
905             "  ",
906             "    ",
907             "\t",
908             "    // this is connected in widnowstate",
909             "",
910             "",
911             "\t// not sure why....   ",
912             "  //  while(Gtk.events_pending()) {",
913             "   //     Gtk.main_iteration();",
914             " //   }",
915             "    ",
916             "    this.node_selected = sel;",
917             "    ",
918             "   // this.updateGreySelection(scroll);",
919             "    ",
920             "    ",
921             "    ",
922             "}",
923             "",
924             "   ",
925             ""
926            ],
927            "| void onCursorChanged" : [
928             "(/*ParamSpec ps*/) {",
929             "",
930             "\t\tif (!this.key_is_pressed && !this.button_is_pressed) {",
931             "\t\t\treturn;",
932             "\t\t}",
933             "",
934             "\t   if (this.loading) {",
935             "            return;",
936             "        }",
937             "       // if (ps.name != \"cursor-position\") {",
938             "       //     return;",
939             "       // }",
940             "",
941             "        var buf = this.el.get_buffer();",
942             "        //print(\"cursor changed : %d\\n\", buf.cursor_position);",
943             "        Gtk.TextIter cpos;",
944             "        buf.get_iter_at_offset(out cpos, buf.cursor_position);",
945             "        ",
946             "        var ln = cpos.get_line();",
947             "        ",
948             "        ",
949             "        // --- select node at line....",
950             "        ",
951             "        var node = _this.file.lineToNode(ln+1);",
952             " ",
953             "        if (node == null) {",
954             "            print(\"can not find node\\n\");",
955             "            return;",
956             "        }",
957             "        var prop = node.lineToProp(ln+1);",
958             "        print(\"prop : %s\", prop == null ? \"???\" : prop.name);",
959             "        ",
960             "        ",
961             "        // ---------- this selects the tree's node...",
962             "        ",
963             "        var ltree = _this.main_window.windowstate.left_tree;",
964             "         ltree.model.selectNode(node);",
965             "        ",
966             "\t       ",
967             "        //print(\"changing cursor on tree..\\n\");",
968             "       ",
969             "",
970             "        ",
971             "        // let's try allowing editing on the methods.",
972             "        // a little klunky at present..",
973             "        this.prop_selected = \"\";",
974             "        /*",
975             "        if (prop != null) {",
976             "    \t\t//see if we can find it..",
977             "    \t\tvar kv = prop.split(\":\");",
978             "    \t\tif (kv[0] == \"p\") {",
979             "    \t\t",
980             "        \t\t//var k = prop.get_key(kv[1]);",
981             "        \t\t// fixme -- need to determine if it's an editable property...",
982             "        \t\tthis.prop_selected = prop;",
983             "        \t\t",
984             "    \t\t} else if (kv[0] == \"l\") {",
985             "    \t\t\t this.prop_selected = prop;",
986             "    \t\t\t",
987             "    \t\t}",
988             "        }",
989             "       */",
990             "           // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
991             "           //this.nodeSelected(node,false);",
992             "            ",
993             "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
994             "           ",
995             "        ",
996             "        // highlight the node..",
997             "}",
998             " "
999            ],
1000            "| void updateGreySelection" : [
1001             "(bool scroll) { ",
1002             "\tvar sel = this.node_selected;",
1003             "\tprint(\"node selected\\n\");",
1004             "    var buf = this.el.get_buffer();",
1005             "    var sbuf = (GtkSource.Buffer) buf;",
1006             "",
1007             "   ",
1008             "   this.clearGreySelection();",
1009             "   ",
1010             "   ",
1011             "   ",
1012             "     if (sel == null) {",
1013             "\t     print(\"no selected node\\n\");",
1014             "        // no highlighting..",
1015             "        return;",
1016             "    }",
1017             "    ",
1018             "    print(\"highlight region %d to %d\\n\", sel.line_start,sel.line_end);",
1019             "    Gtk.TextIter iter;   ",
1020             "    sbuf.get_iter_at_line(out iter,  sel.line_start);",
1021             "    ",
1022             "    ",
1023             "    Gtk.TextIter cur_iter;",
1024             "    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
1025             "   ",
1026             "    var cursor_at_line = cur_iter.get_line();",
1027             "    ",
1028             "    ",
1029             "    //var cur_line = cur_iter.get_line();",
1030             "    //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
1031             "    ",
1032             "    //} else {",
1033             "    if (scroll) {",
1034             "\t\tprint(\"scrolling to node -- should occur on node picking.\\n\");",
1035             "    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1036             "\t}",
1037             "    ",
1038             "    var start_line = sel.line_start;",
1039             "    var end_line = sel.line_end;",
1040             "    ",
1041             "    ",
1042             "    this.el.editable = false;",
1043             "    ",
1044             "    //var colon_pos = 0;",
1045             "    ",
1046             "    this.editable_start_pos = -1;",
1047             "    ",
1048             "    // now if we have selected a property...",
1049             "    if (this.prop_selected.length> 0 ) {",
1050             "",
1051             "\t\tint nstart, nend;",
1052             "\t\tif (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {",
1053             "\t\t\tstart_line = nstart;",
1054             "\t\t\tend_line = nend;",
1055             "\t\t\t// this.el.editable = true; << cant do this!!?",
1056             "\t\t\tprint(\"start line = %d, end line = %d\\n\", start_line, end_line);",
1057             "\t\t\t",
1058             "\t\t\t\t// see if we are 'right of ':'",
1059             "\t\t\t\t// get an iter for the start of the line.",
1060             "\t\t\tGtk.TextIter start_first_line_iter,end_first_line_iter;",
1061             "\t\t\tthis.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);",
1062             "\t\t\tthis.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);",
1063             "\t\t\t ",
1064             "\t\t\t",
1065             "\t\t\t",
1066             "\t\t\t",
1067             "\t\t\tif (end_first_line_iter.forward_to_line_end()) {",
1068             "\t\t\t\tvar first_line  = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);",
1069             "\t\t\t\t",
1070             "\t\t\t\tprint(\"first line = %s\\n\", first_line);",
1071             "\t\t\t\tif (first_line.contains(\":\")) {",
1072             "\t\t\t\t\tthis.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(\":\") + 1;",
1073             "\t\t\t\t\tprint(\"colon_pos  = %d\\n\", this.editable_start_pos);",
1074             "\t\t\t\t}",
1075             "\t\t\t\t",
1076             "",
1077             "\t\t\t\t//Gtk.TextIter colon_iter;",
1078             "\t\t\t\t//sbuf.get_iter_at_offset (out colon_iter, colon_pos);",
1079             "\t\t\t\t//sbuf.create_source_mark(null, \"active_text\", colon_iter);",
1080             "\t\t\t}",
1081             "\t\t\t",
1082             "\t\t\t",
1083             "\t\t\t",
1084             "\t\t\t//print(\"is cursor at line? %d ?= %d\\n\", start_line -1 , cursor_at_line);",
1085             "\t\t\t//if (start_line - 1 == cursor_at_line) {",
1086             "\t\t\t// should be ok - current_posssion can not be less than '-1'...",
1087             "\t\t\tif (sbuf.cursor_position < this.editable_start_pos) {",
1088             "\t\t\t",
1089             "\t\t\t\tprint(\"cursor is before start pos.. - turn off editable...\\n\");",
1090             "\t\t\t\t//var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);",
1091             "\t\t\t\t//print(\"before cursor string =  %s\\n\", before_cursor_string);",
1092             "\t\t\t\t//if (!before_cursor_string.contains(\":\")) {",
1093             "\t\t\t\t\tthis.el.editable = false;",
1094             "\t\t\t\t//}",
1095             "\t\t\t\t",
1096             "\t\t\t}",
1097             "\t\t\t ",
1098             "\t\t\t ",
1099             "",
1100             "\t\t\t ",
1101             "\t\t}",
1102             "\t\tprint(\"propSelected = %s range  %d -> %d\\n\", this.prop_selected, start_line, end_line);\t\t",
1103             "\t\t",
1104             "\t\t",
1105             "    }",
1106             "    ",
1107             "\tprint(\"checking selection\\n\");",
1108             "    ",
1109             "    ",
1110             "    // check selection - if it's out of 'bounds'",
1111             "    if (this.el.editable && sbuf.get_has_selection()) {",
1112             "\t\tGtk.TextIter sel_start_iter, sel_end_iter;",
1113             "\t\tsbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);",
1114             "\t\t",
1115             "\t\tif (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||",
1116             "\t\t\tsel_start_iter.get_line() > end_line   || sel_end_iter.get_line() < start_line\t\t\t) {",
1117             "\t\t\t// save?",
1118             "\t\t\tthis.el.editable = false;",
1119             "\t\t}",
1120             "\t\tif (this.editable_start_pos > 0 &&",
1121             "\t\t\t(sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)",
1122             "\t\t\t",
1123             "\t\t) {",
1124             "\t\t\tthis.el.editable = false;",
1125             "\t\t}",
1126             "\t\t",
1127             "\t\t ",
1128             "    ",
1129             "    }",
1130             "    ",
1131             "    ",
1132             "    ",
1133             "    ",
1134             "    for (var i = 0; i < buf.get_line_count();i++) {",
1135             "        if (i < (start_line -1) || i > (end_line -1)) {",
1136             "           ",
1137             "            sbuf.get_iter_at_line(out iter, i);",
1138             "            sbuf.create_source_mark(null, \"grey\", iter);",
1139             "            ",
1140             "        }",
1141             "    ",
1142             "    }",
1143             "    if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {",
1144             "\t    Gtk.TextIter cpos_iter;",
1145             "\t\tbuf.get_iter_at_line(out cpos_iter, start_line);",
1146             "\t\t",
1147             "\t\tbuf.place_cursor(cpos_iter); ",
1148             "\t}",
1149             "",
1150             "",
1151             "}"
1152            ]
1153           }
1154          ],
1155          "xtype" : "ScrolledWindow"
1156         },
1157         {
1158          "$ xns" : "Gtk",
1159          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
1160          "bool homogeneous" : false,
1161          "bool vexpand" : false,
1162          "int spacing" : 0,
1163          "items" : [
1164           {
1165            "$ xns" : "Gtk",
1166            "* init" : [
1167             "this.css = new Gtk.CssProvider();",
1168             " ",
1169             "this.css.load_from_string(",
1170             "\t\"#roo-search-entry { background-color: #ccc; }\"",
1171             ");",
1172             " ",
1173             "Gtk.StyleContext.add_provider_for_display(",
1174             "\tthis.el.get_display(),",
1175             "\tthis.css,",
1176             "\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
1177             ");",
1178             "\t\t",
1179             "\t ",
1180             " ",
1181             ""
1182            ],
1183            "Gtk.CssProvider css" : "",
1184            "bool hexpand" : true,
1185            "id" : "search_entry",
1186            "items" : [
1187             {
1188              "$ xns" : "Gtk",
1189              "listeners" : {
1190               "key_pressed" : [
1191                "(keyval, keycode, state) => {",
1192                "",
1193                "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
1194                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
1195                "\t\t_this.forwardSearch(true);",
1196                "\t    return true;",
1197                "\t}",
1198                "    ",
1199                "  ",
1200                " \tif (keyval == Gdk.Key.Return) {",
1201                "\t\t_this.forwardSearch(true);",
1202                "\t\t",
1203                "\t\t",
1204                "\t    return true;",
1205                "",
1206                "\t}    ",
1207                "   // print(event.key.keyval)",
1208                "   ",
1209                "    return false;",
1210                "}",
1211                ""
1212               ]
1213              },
1214              "xtype" : "EventControllerKey"
1215             }
1216            ],
1217            "listeners" : {
1218             "search_changed" : [
1219              "( ) => {",
1220              "",
1221              "_this.search(_this.search_entry.el.text);",
1222              "\t _this.search_results.updateResults();",
1223              "",
1224              "\tGLib.Timeout.add_seconds(1,() => {",
1225              "\t\t _this.search_results.updateResults();",
1226              "\t\t return false;",
1227              "\t });",
1228              "}",
1229              ""
1230             ]
1231            },
1232            "string name" : "roo-search-entry",
1233            "string placeholder_text" : "Press enter to search",
1234            "xtype" : "SearchEntry",
1235            "| void forwardSearch" : [
1236             "(bool change_focus) {",
1237             "",
1238             "",
1239             "\t_this.forwardSearch(change_focus);",
1240             "",
1241             "/*",
1242             "",
1243             "\tswitch(_this.windowstate.state) {",
1244             "\t\tcase WindowState.State.CODEONLY:",
1245             "\t\t//case WindowState.State.CODE:",
1246             "\t\t\t// search the code being edited..",
1247             "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
1248             "\t\t\t ",
1249             "\t\t\tbreak;",
1250             "\t\tcase WindowState.State.PREVIEW:",
1251             "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
1252             "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
1253             "\t\t\t} else { ",
1254             "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
1255             "\t\t\t}",
1256             "\t\t",
1257             "\t\t\tbreak;",
1258             "\t}",
1259             "\t*/",
1260             "\t",
1261             "}",
1262             ""
1263            ]
1264           },
1265           {
1266            "$ xns" : "Gtk",
1267            "id" : "search_results",
1268            "int margin_end" : 4,
1269            "int margin_start" : 4,
1270            "string label" : "No Results",
1271            "xtype" : "Label",
1272            "| void updateResults" : [
1273             "() {",
1274             "\tthis.el.visible = true;",
1275             "\t",
1276             "\tvar res = _this.searchcontext.get_occurrences_count();",
1277             "\tif (res < 0) {",
1278             "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
1279             "\t\treturn;",
1280             "\t}",
1281             "",
1282             "\t_this.nextBtn.el.sensitive = false;",
1283             "\t_this.backBtn.el.sensitive = false;\t",
1284             "",
1285             "\tif (res > 0) {",
1286             "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
1287             "\t\t_this.nextBtn.el.sensitive = true;",
1288             "\t\t_this.backBtn.el.sensitive = true;",
1289             "\t\treturn;",
1290             "\t} ",
1291             "\t_this.search_results.el.label = \"No Matches\";",
1292             "\t",
1293             "}"
1294            ]
1295           },
1296           {
1297            "$ xns" : "Gtk",
1298            "bool always_show_image" : true,
1299            "bool sensitive" : false,
1300            "id" : "nextBtn",
1301            "listeners" : {
1302             "clicked" : [
1303              "(event) => {",
1304              "",
1305              "\t_this.forwardSearch(true);",
1306              "\t ",
1307              "}",
1308              ""
1309             ]
1310            },
1311            "string icon_name" : "go-down",
1312            "xtype" : "Button"
1313           },
1314           {
1315            "$ xns" : "Gtk",
1316            "bool always_show_image" : true,
1317            "bool sensitive" : false,
1318            "id" : "backBtn",
1319            "listeners" : {
1320             "clicked" : [
1321              "(event) => {",
1322              "",
1323              "\t_this.backSearch(true);",
1324              "\t",
1325              "\t ",
1326              "}",
1327              ""
1328             ]
1329            },
1330            "string icon_name" : "go-up",
1331            "xtype" : "Button"
1332           },
1333           {
1334            "$ xns" : "Gtk",
1335            "bool always_show_image" : true,
1336            "items" : [
1337             {
1338              "$ xns" : "Gtk",
1339              "* pack" : false,
1340              "* prop" : "popover",
1341              "id" : "search_settings",
1342              "items" : [
1343               {
1344                "$ xns" : "Gtk",
1345                "* prop" : "child",
1346                "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
1347                "int spacing" : 0,
1348                "items" : [
1349                 {
1350                  "$ xns" : "Gtk",
1351                  "* init" : [
1352                   "{",
1353                   "\tthis.el.show();",
1354                   "}",
1355                   ""
1356                  ],
1357                  "id" : "case_sensitive",
1358                  "string label" : "Case Sensitive",
1359                  "xtype" : "CheckButton"
1360                 },
1361                 {
1362                  "$ xns" : "Gtk",
1363                  "* init" : [
1364                   "{",
1365                   "\tthis.el.show();",
1366                   "}",
1367                   ""
1368                  ],
1369                  "id" : "regex",
1370                  "string label" : "Regex",
1371                  "xtype" : "CheckButton"
1372                 },
1373                 {
1374                  "$ xns" : "Gtk",
1375                  "* init" : [
1376                   "{",
1377                   "\tthis.el.show();",
1378                   "}",
1379                   ""
1380                  ],
1381                  "id" : "multiline",
1382                  "string label" : "Multi-line (add \\n)",
1383                  "xtype" : "CheckButton"
1384                 }
1385                ],
1386                "xtype" : "Box"
1387               }
1388              ],
1389              "xtype" : "Popover"
1390             }
1391            ],
1392            "string icon_name" : "emblem-system",
1393            "xtype" : "MenuButton"
1394           }
1395          ],
1396          "xtype" : "Box"
1397         }
1398        ],
1399        "xtype" : "Box"
1400       }
1401      ],
1402      "xtype" : "Notebook"
1403     }
1404    ],
1405    "xtype" : "Box",
1406    "| int search" : [
1407     "(string in_txt) {",
1408     "\tthis.notebook.el.page = 1;",
1409     "\t",
1410     " ",
1411     "   ",
1412     "\tvar s = new GtkSource.SearchSettings();",
1413     "\ts.case_sensitive = _this.case_sensitive.el.active;",
1414     "\ts.regex_enabled = _this.regex.el.active;\t",
1415     "\ts.wrap_around = false;",
1416     "\t",
1417     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
1418     "\tthis.searchcontext.set_highlight(true);",
1419     "\tvar txt = in_txt;",
1420     "\t",
1421     "\tif (_this.multiline.el.active) {",
1422     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
1423     "\t}",
1424     "\t",
1425     "\ts.set_search_text(txt);",
1426     "\tGtk.TextIter beg, st,en;",
1427     "\tbool has_wrapped_around;",
1428     "\tthis.buffer.el.get_start_iter(out beg);",
1429     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
1430     "\tthis.last_search_end = 0;",
1431     "\t",
1432     "\treturn this.searchcontext.get_occurrences_count();",
1433     "",
1434     " ",
1435     "    ",
1436     "",
1437     "}",
1438     ""
1439    ],
1440    "| void backSearch" : [
1441     "(bool change_focus) {",
1442     "",
1443     "\tif (this.searchcontext == null) {",
1444     "\t\treturn;",
1445     "\t} ",
1446     "\t",
1447     "\tGtk.TextIter beg, st,en;",
1448     "\tbool has_wrapped_around;",
1449     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
1450     "\t",
1451     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
1452     "\t",
1453     "\t\tthis.last_search_end = 0;",
1454     "\t\treturn;",
1455     "\t}",
1456     "\tthis.last_search_end = en.get_offset();",
1457     "\tif (change_focus) {",
1458     "\t\tthis.sourceview.el.grab_focus();",
1459     "\t}",
1460     "\tthis.buffer.el.place_cursor(st);",
1461     "\tthis.sourceview.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1462     "\tvar ln = st.get_line();",
1463     "\tthis.highlightNodeAtLine(ln);",
1464     "\t",
1465     " ",
1466     "}",
1467     ""
1468    ],
1469    "| void createThumb" : [
1470     "() {",
1471     "    ",
1472     "    ",
1473     "    if (this.file == null) {",
1474     "        return;",
1475     "    }",
1476     "    ",
1477     "\tif (this.notebook.el.page > 0 ) {",
1478     "        return;",
1479     "    }",
1480     "    ",
1481     " \tthis.file.widgetToIcon(this.view.el); ",
1482     "",
1483     "    ",
1484     "     ",
1485     "    ",
1486     "     ",
1487     "}",
1488     ""
1489    ],
1490    "| void forwardSearch" : [
1491     "(bool change_focus) {",
1492     "",
1493     "\tif (this.searchcontext == null) {",
1494     "\t\treturn;",
1495     "\t}",
1496     "\tthis.notebook.el.page = 1;",
1497     "\tGtk.TextIter beg, st,en;",
1498     "\tbool has_wrapped_around;",
1499     "\tvar buf = this.sourceview.el.get_buffer();",
1500     "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
1501     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
1502     "\t\tthis.last_search_end = 0;",
1503     "\t\treturn;",
1504     "\t}",
1505     "\tthis.last_search_end = en.get_offset();",
1506     "\tif (change_focus) {",
1507     "\t\tthis.sourceview.el.grab_focus();",
1508     "\t}",
1509     "\tbuf.place_cursor(st);",
1510     "\t",
1511     " ",
1512     "\t ",
1513     "\tthis.sourceview.el.scroll_to_iter(st,  0.0f, true, 0.0f, 0.5f);",
1514     "\t",
1515     "\t",
1516     "\tvar ln = st.get_line();",
1517     "\t",
1518     "\tthis.highlightNodeAtLine(ln);",
1519     "}\t",
1520     "  "
1521    ],
1522    "| void highlightNodeAtLine" : [
1523     "(int ln) {",
1524     "",
1525     "",
1526     "\t ",
1527     "\t// highlight node...",
1528     "\t",
1529     "\t\t",
1530     "    var node = _this.file.lineToNode(ln+1);",
1531     " ",
1532     "    if (node == null) {",
1533     "        //print(\"can not find node\\n\");",
1534     "        return;",
1535     "    }",
1536     "    var prop = node.lineToProp(ln+1);",
1537     "    print(\"prop : %s\", prop == null ? \"???\" : prop.name);",
1538     "        ",
1539     "        ",
1540     "    // ---------- this selects the tree's node...",
1541     "    ",
1542     "    var ltree = _this.main_window.windowstate.left_tree;",
1543     "   ltree.model.selectNode(node);",
1544     "        ",
1545     "    //_this.sourceview.allow_node_scroll = false; /// block node scrolling..",
1546     "\t       ",
1547     "   ",
1548     "    //print(\"changing cursor on tree..\\n\");",
1549     "   ",
1550     "",
1551     "    ",
1552     "    // let's try allowing editing on the methods.",
1553     "    // a little klunky at present..",
1554     "\t_this.sourceview.prop_selected = \"\";",
1555     "\t/*",
1556     "    if (prop != null) {",
1557     "\t\t//see if we can find it..",
1558     "\t\tvar kv = prop.split(\":\");",
1559     "\t\tif (kv[0] == \"p\") {",
1560     "\t\t",
1561     "    \t\t//var k = prop.get_key(kv[1]);",
1562     "    \t\t// fixme -- need to determine if it's an editable property...",
1563     "    \t\t_this.sourceview.prop_selected = prop;",
1564     "    \t\t",
1565     "\t\t} else if (kv[0] == \"l\") {",
1566     "\t\t\t _this.sourceview.prop_selected = prop;",
1567     "\t\t\t",
1568     "\t\t}",
1569     "    }",
1570     "    */",
1571     "   // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
1572     "   _this.sourceview.nodeSelected(node,false);",
1573     "    ",
1574     "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
1575     "      //      GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
1576     "\t  //          this.allow_node_scroll = true;",
1577     "\t  //          return false;",
1578     "      //      });",
1579     "      //  }",
1580     "\t\t",
1581     "\t\t",
1582     "\t\t",
1583     "\t\t",
1584     "\t\t",
1585     "\t\t",
1586     "\t\t",
1587     "\t\t",
1588     "\t\t",
1589     "\t\t ",
1590     "",
1591     "}",
1592     " "
1593    ],
1594    "| void loadFile" : [
1595     "",
1596     "(JsRender.JsRender file)",
1597     "{",
1598     "    this.file = file;",
1599     "    this.view.renderJS(true);",
1600     "    this.notebook.el.page = 0;// gtk preview ",
1601     "    this.sourceview.loadFile();   ",
1602     "}",
1603     " ",
1604     " "
1605    ],
1606    "| void requestRedraw" : [
1607     "() {",
1608     "    this.view.renderJS(false);",
1609     "    this.sourceview.loadFile();   ",
1610     "}"
1611    ],
1612    "| void scroll_to_line" : [
1613     "(int line) {",
1614     "   // code preview...",
1615     "   ",
1616     "   GLib.Timeout.add(100, () => {",
1617     "   ",
1618     "\t\tthis.notebook.el.set_current_page( 1 );",
1619     "\t   ",
1620     "\t   ",
1621     "\t\t  var buf = this.sourceview.el.get_buffer();",
1622     "\t ",
1623     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1624     "",
1625     "",
1626     "\t\tGtk.TextIter iter;   ",
1627     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1628     "\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1629     "\t\treturn false;",
1630     "\t});   ",
1631     "",
1632     "   ",
1633     "}",
1634     ""
1635    ]
1636   }
1637  ],
1638  "name" : "WindowRooView"
1639 }