22823176df6a620c1189ef95cfea4557a7a97eb8
[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              "bool in_cursor_change" : false,
596              "id" : "buffer",
597              "int error_line" : "-1",
598              "int last_line" : "-1",
599              "listeners" : {
600               "changed" : [
601                " () => {",
602                "  ",
603                "    // check syntax??",
604                "    // ??needed..??",
605                "   // _this.save_button.el.sensitive = true;",
606                "    ///?? has changed occured during loading?",
607                "    ",
608                "    // only trigger this if ",
609                "    ",
610                "    ",
611                "    ",
612                "    ",
613                "    if (_this.sourceview.loading) {",
614                "\t\treturn;",
615                "\t}",
616                "\t",
617                "",
618                "\t",
619                "    print(\"- PREVIEW EDITOR CHANGED--\");",
620                "",
621                "    this.dirty = true;  ",
622                "   // this.checkSyntax(); // this calls backs and highlights errors.. in theory...  ",
623                "",
624                "",
625                "",
626                "\tif (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {",
627                "\t\tprint(\"button or key not pressed to generate change?!\\n\");",
628                "\t\treturn;",
629                "\t}",
630                "\t\t",
631                "    ",
632                "\t// what are we editing??",
633                "\tif (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length  < 1) {",
634                "\t\treturn;",
635                "\t}",
636                "\t",
637                "\t// find the colon on the first line...",
638                "\t",
639                "\tif (_this.sourceview.editable_start_pos > -1) {",
640                "\t\t",
641                "\t\tvar buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();",
642                "\t\t",
643                "        //print(\"cursor changed : %d\\n\", buf.cursor_position);",
644                "        Gtk.TextIter spos,epos;",
645                "        buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);",
646                "        buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..",
647                "        ",
648                "        var gotit= false;",
649                "        var line = spos.get_line();",
650                "        var endline = buf.get_line_count();",
651                "        while (line < endline) {",
652                "    \t\tline++;",
653                "\t        buf.get_iter_at_line(out epos, line);",
654                "\t        if (buf.get_source_marks_at_line(line, \"grey\").length() > 0) {",
655                "\t\t        buf.get_iter_at_line(out epos, line);\t    \t\t",
656                "\t    \t\tgotit=true;",
657                "\t    \t\tbreak;",
658                "    \t\t}",
659                "\t\t}",
660                "        ",
661                " \t\tif (gotit) {",
662                "\t \t\tprint(\"End Offset = %d/%d\\n\", epos.get_line(), epos.get_offset());",
663                "\t\t\t// get the pos...",
664                "\t\t\t// in theory the last char will be '}' or '},' .. or ','",
665                "\t\t\t// we should chop the ',' of the end...",
666                "\t\t\tvar str = buf.get_text(spos, epos, false);",
667                "\t\t\tprint(\"got string\\n%s\\n\", str);",
668                "\t\t",
669                "\t\t}",
670                "\t}",
671                "    return ;",
672                "}",
673                "",
674                " ",
675                ""
676               ],
677               "cursor_moved" : [
678                "( ) => {",
679                "GLib.debug(\"cursor moved called\");",
680                "",
681                "",
682                " \tif (this.in_cursor_change ) {",
683                "        GLib.debug(\"cursor changed : %d [ignoring nested call)\", this.el.cursor_position);",
684                "        return;",
685                "    }",
686                "   ",
687                "    GLib.debug(\"cursor changed : %d\", this.el.cursor_position);",
688                "    Gtk.TextIter cpos;",
689                "    this.el.get_iter_at_offset(out cpos, this.el.cursor_position);",
690                "    ",
691                "    var ln = cpos.get_line();",
692                "    if (this.last_line == ln ){",
693                "    \treturn;",
694                "\t}",
695                "\tthis.last_line = ln;",
696                "    var node = _this.file.lineToNode(ln);",
697                "",
698                "    if (node == null) {",
699                "        print(\"can not find node\\n\");",
700                "        return;",
701                "    }",
702                "    this.in_cursor_change  = true;",
703                "    var ltree = _this.main_window.windowstate.left_tree;",
704                "    ltree.model.selectNode(node);",
705                "    this.in_cursor_change  = false;",
706                "}",
707                ""
708               ]
709              },
710              "xtype" : "Buffer",
711              "| bool highlightErrors" : [
712               "( Gee.HashMap<int,string> validate_res) {",
713               "         ",
714               "    this.error_line = validate_res.size;",
715               "\t",
716               "    if (this.error_line < 1) {",
717               "          return true;",
718               "    }",
719               "    var tlines = this.el.get_line_count ();",
720               "    Gtk.TextIter iter;",
721               "    var valiter = validate_res.map_iterator();",
722               "    while (valiter.next()) {",
723               "    ",
724               "//        print(\"get inter\\n\");",
725               "        var eline = valiter.get_key();",
726               "        if (eline > tlines) {",
727               "            continue;",
728               "        }",
729               "        this.el.get_iter_at_line( out iter, eline);",
730               "        //print(\"mark line\\n\");",
731               "        this.el.create_source_mark(valiter.get_value(), \"ERR\", iter);",
732               "    }   ",
733               "    return false;",
734               "}"
735              ],
736              "| string toString" : [
737               "  () {",
738               "    ",
739               "    Gtk.TextIter s;",
740               "    Gtk.TextIter e;",
741               "    this.el.get_start_iter(out s);",
742               "    this.el.get_end_iter(out e);",
743               "    var ret = this.el.get_text(s,e,true);",
744               "    //print(\"TO STRING? \" + ret);",
745               "    return ret;",
746               "}",
747               " "
748              ]
749             },
750             {
751              "$ xns" : "Gtk",
752              "* pack" : "add_controller",
753              "listeners" : {
754               "key_pressed" : [
755                "(keyval, keycode, state) => {",
756                "",
757                " ",
758                "    ",
759                "  \tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
760                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
761                "\t\t_this.forwardSearch(true);",
762                "\t    return false;",
763                "\t}",
764                "\tif (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
765                "\t    GLib.debug(\"SAVE: ctrl-f  pressed\");",
766                "\t\t_this.search_entry.el.grab_focus();",
767                "\t    return false ;",
768                "\t}",
769                "    ",
770                "\t//this.button_is_pressed = true;",
771                "\t//return false;",
772                "   // print(event.key.keyval)",
773                "    ",
774                "    return false;",
775                " ",
776                " ",
777                "}",
778                ""
779               ]
780              },
781              "xtype" : "EventControllerKey"
782             }
783            ],
784            "listeners" : {
785             "query_tooltip" : [
786              "(x, y, keyboard_tooltip, tooltip) => {",
787              "\t",
788              "\t//GLib.debug(\"query tooltip\");",
789              "\tGtk.TextIter iter;",
790              "\tint trailing;",
791              "\t",
792              "\tvar yoff = (int) _this.sourceviewscroll.el.vadjustment.value;",
793              "\t",
794              "\tthis.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);",
795              "\t ",
796              "\tvar l = iter.get_line();",
797              "\t//GLib.debug(\"query tooltip line %d\", (int) l);",
798              "\tvar marks = _this.buffer.el.get_source_marks_at_line(l, null);",
799              "\t//GLib.debug(\"query tooltip line marks %d\", (int) marks.length());",
800              "\tvar str = \"\";",
801              "\tmarks.@foreach((m) => { ",
802              "\t\t//GLib.debug(\"got mark %s\", m.name);",
803              "\t\tstr += (str.length > 0 ? \"\\n\" : \"\") + m.name;",
804              "\t});",
805              "\t// true if there is a mark..",
806              "\tif (str.length > 0 ) {",
807              "\t\t\ttooltip.set_text( str);",
808              "\t}",
809              "\treturn str.length > 0 ? true : false;",
810              "",
811              "}"
812             ]
813            },
814            "string name" : "roo-view",
815            "xtype" : "View",
816            "| string toString" : [
817             "() {",
818             "   Gtk.TextIter s;",
819             "    Gtk.TextIter e;",
820             "    this.el.get_buffer().get_start_iter(out s);",
821             "    this.el.get_buffer().get_end_iter(out e);",
822             "    var ret = this.el.get_buffer().get_text(s,e,true);",
823             "    //print(\"TO STRING? \" + ret);",
824             "    return ret;",
825             "}",
826             ""
827            ],
828            "| void clearGreySelection" : [
829             "() {",
830             " // clear all the marks..",
831             "    var sbuf = (GtkSource.Buffer)this.el.buffer;",
832             "    ",
833             "    Gtk.TextIter start;",
834             "    Gtk.TextIter end;     ",
835             "        ",
836             "    sbuf.get_bounds (out start, out end);",
837             "    sbuf.remove_source_marks (start, end, \"grey\");",
838             "    ",
839             "    ",
840             "}",
841             ""
842            ],
843            "| void highlightErrorsJson" : [
844             " (string type, Json.Object obj) {",
845             "       // this is a hook for the vala code - it has no value in javascript ",
846             "       // as we only have one error ususally....",
847             "        return  ;",
848             "    ",
849             " ",
850             "",
851             "",
852             "}"
853            ],
854            "| void loadFile" : [
855             "( ) {",
856             "    this.loading = true;",
857             "    ",
858             "    ",
859             "    // get the cursor and scroll position....",
860             "    var buf = this.el.get_buffer();",
861             "\tvar cpos = buf.cursor_position;",
862             "    ",
863             "   print(\"BEFORE LOAD cursor = %d\\n\", cpos);",
864             "   ",
865             "    var vadj_pos = this.el.get_vadjustment().get_value();",
866             "   ",
867             "    ",
868             " ",
869             "    buf.set_text(\"\",0);",
870             "    var sbuf = (GtkSource.Buffer) buf;",
871             "",
872             "    ",
873             "",
874             "    if (_this.file == null || _this.file.xtype != \"Roo\") {",
875             "        print(\"xtype != Roo\");",
876             "        this.loading = false;",
877             "        return;",
878             "    }",
879             "    ",
880             "    // get the string from the rendered tree...",
881             "     ",
882             "     var str = _this.file.toSource();",
883             "     ",
884             "//    print(\"setting str %d\\n\", str.length);",
885             "    buf.set_text(str, str.length);",
886             "    var lm = GtkSource.LanguageManager.get_default();",
887             "     ",
888             "    //?? is javascript going to work as js?",
889             "    ",
890             "    ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));",
891             "  ",
892             "    ",
893             "    _this.main_window.windowstate.updateErrorMarksAll();",
894             "    ",
895             "    //  restore the cursor position?",
896             "    // after reloading the contents.",
897             "     GLib.Timeout.add(500, () => {",
898             "\t\t_this.buffer.in_cursor_change = true;",
899             "        print(\"RESORTING cursor to = %d\\n\", cpos);",
900             "\t\tGtk.TextIter cpos_iter;",
901             "\t\tbuf.get_iter_at_offset(out cpos_iter, cpos);",
902             "\t\tbuf.place_cursor(cpos_iter); ",
903             "\t\t",
904             "\t\tthis.el.get_vadjustment().set_value(vadj_pos);;",
905             "\t\t_this.buffer.in_cursor_change = false;",
906             " ",
907             "\t\t",
908             "\t\t",
909             "\t\t//_this.buffer.checkSyntax();",
910             "\t\treturn false;",
911             "\t});",
912             "\t\t",
913             "    this.loading = false; ",
914             "    _this.buffer.dirty = false;",
915             "}",
916             ""
917            ],
918            "| void nodeSelected" : [
919             "(JsRender.Node? sel, bool scroll) {",
920             "  ",
921             "    ",
922             "    if (this.loading) {",
923             "    \treturn;",
924             "\t}",
925             "    // this is connected in widnowstate",
926             "    print(\"Roo-view - node selected\\n\");",
927             "    var buf = this.el.get_buffer();",
928             " ",
929             "    var sbuf = (GtkSource.Buffer) buf;",
930             "",
931             "    ",
932             "    ",
933             "   ",
934             "    // clear all the marks..",
935             "     Gtk.TextIter start;",
936             "    Gtk.TextIter end;     ",
937             "        ",
938             "    sbuf.get_bounds (out start, out end);",
939             "    sbuf.remove_source_marks (start, end, \"grey\");",
940             "    ",
941             "        this.node_selected = sel;",
942             "     if (sel == null) {",
943             "        // no highlighting..",
944             "        return;",
945             "    }",
946             "    Gtk.TextIter iter;   ",
947             "    sbuf.get_iter_at_line(out iter,  sel.line_start);",
948             "    ",
949             "    ",
950             "    Gtk.TextIter cur_iter;",
951             "    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
952             "    ",
953             "    //var cur_line = cur_iter.get_line();",
954             "    //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
955             "    ",
956             "    //} else {",
957             "    if (! _this.buffer.in_cursor_change) {",
958             "    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
959             "\t}",
960             "    ",
961             "     ",
962             "    ",
963             "    for (var i = 0; i < buf.get_line_count();i++) {",
964             "        if (i < sel.line_start || i > sel.line_end) {",
965             "           ",
966             "            sbuf.get_iter_at_line(out iter, i);",
967             "            sbuf.create_source_mark(null, \"grey\", iter);",
968             "            ",
969             "        }",
970             "    ",
971             "    }",
972             "    ",
973             "",
974             "}",
975             ""
976            ],
977            "| void updateGreySelection" : [
978             "(bool scroll) { ",
979             "\tvar sel = this.node_selected;",
980             "\tprint(\"node selected\\n\");",
981             "    var buf = this.el.get_buffer();",
982             "    var sbuf = (GtkSource.Buffer) buf;",
983             "",
984             "   ",
985             "   this.clearGreySelection();",
986             "   ",
987             "   ",
988             "   ",
989             "     if (sel == null) {",
990             "\t     print(\"no selected node\\n\");",
991             "        // no highlighting..",
992             "        return;",
993             "    }",
994             "    ",
995             "    print(\"highlight region %d to %d\\n\", sel.line_start,sel.line_end);",
996             "    Gtk.TextIter iter;   ",
997             "    sbuf.get_iter_at_line(out iter,  sel.line_start);",
998             "    ",
999             "    ",
1000             "    Gtk.TextIter cur_iter;",
1001             "    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
1002             "   ",
1003             "    var cursor_at_line = cur_iter.get_line();",
1004             "    ",
1005             "    ",
1006             "    //var cur_line = cur_iter.get_line();",
1007             "    //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
1008             "    ",
1009             "    //} else {",
1010             "    if (scroll) {",
1011             "\t\tprint(\"scrolling to node -- should occur on node picking.\\n\");",
1012             "    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1013             "\t}",
1014             "    ",
1015             "    var start_line = sel.line_start;",
1016             "    var end_line = sel.line_end;",
1017             "    ",
1018             "    ",
1019             "    this.el.editable = false;",
1020             "    ",
1021             "    //var colon_pos = 0;",
1022             "    ",
1023             "    this.editable_start_pos = -1;",
1024             "    ",
1025             "    // now if we have selected a property...",
1026             "    if (this.prop_selected.length> 0 ) {",
1027             "",
1028             "\t\tint nstart, nend;",
1029             "\t\tif (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {",
1030             "\t\t\tstart_line = nstart;",
1031             "\t\t\tend_line = nend;",
1032             "\t\t\t// this.el.editable = true; << cant do this!!?",
1033             "\t\t\tprint(\"start line = %d, end line = %d\\n\", start_line, end_line);",
1034             "\t\t\t",
1035             "\t\t\t\t// see if we are 'right of ':'",
1036             "\t\t\t\t// get an iter for the start of the line.",
1037             "\t\t\tGtk.TextIter start_first_line_iter,end_first_line_iter;",
1038             "\t\t\tthis.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);",
1039             "\t\t\tthis.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);",
1040             "\t\t\t ",
1041             "\t\t\t",
1042             "\t\t\t",
1043             "\t\t\t",
1044             "\t\t\tif (end_first_line_iter.forward_to_line_end()) {",
1045             "\t\t\t\tvar first_line  = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);",
1046             "\t\t\t\t",
1047             "\t\t\t\tprint(\"first line = %s\\n\", first_line);",
1048             "\t\t\t\tif (first_line.contains(\":\")) {",
1049             "\t\t\t\t\tthis.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(\":\") + 1;",
1050             "\t\t\t\t\tprint(\"colon_pos  = %d\\n\", this.editable_start_pos);",
1051             "\t\t\t\t}",
1052             "\t\t\t\t",
1053             "",
1054             "\t\t\t\t//Gtk.TextIter colon_iter;",
1055             "\t\t\t\t//sbuf.get_iter_at_offset (out colon_iter, colon_pos);",
1056             "\t\t\t\t//sbuf.create_source_mark(null, \"active_text\", colon_iter);",
1057             "\t\t\t}",
1058             "\t\t\t",
1059             "\t\t\t",
1060             "\t\t\t",
1061             "\t\t\t//print(\"is cursor at line? %d ?= %d\\n\", start_line -1 , cursor_at_line);",
1062             "\t\t\t//if (start_line - 1 == cursor_at_line) {",
1063             "\t\t\t// should be ok - current_posssion can not be less than '-1'...",
1064             "\t\t\tif (sbuf.cursor_position < this.editable_start_pos) {",
1065             "\t\t\t",
1066             "\t\t\t\tprint(\"cursor is before start pos.. - turn off editable...\\n\");",
1067             "\t\t\t\t//var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);",
1068             "\t\t\t\t//print(\"before cursor string =  %s\\n\", before_cursor_string);",
1069             "\t\t\t\t//if (!before_cursor_string.contains(\":\")) {",
1070             "\t\t\t\t\tthis.el.editable = false;",
1071             "\t\t\t\t//}",
1072             "\t\t\t\t",
1073             "\t\t\t}",
1074             "\t\t\t ",
1075             "\t\t\t ",
1076             "",
1077             "\t\t\t ",
1078             "\t\t}",
1079             "\t\tprint(\"propSelected = %s range  %d -> %d\\n\", this.prop_selected, start_line, end_line);\t\t",
1080             "\t\t",
1081             "\t\t",
1082             "    }",
1083             "    ",
1084             "\tprint(\"checking selection\\n\");",
1085             "    ",
1086             "    ",
1087             "    // check selection - if it's out of 'bounds'",
1088             "    if (this.el.editable && sbuf.get_has_selection()) {",
1089             "\t\tGtk.TextIter sel_start_iter, sel_end_iter;",
1090             "\t\tsbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);",
1091             "\t\t",
1092             "\t\tif (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||",
1093             "\t\t\tsel_start_iter.get_line() > end_line   || sel_end_iter.get_line() < start_line\t\t\t) {",
1094             "\t\t\t// save?",
1095             "\t\t\tthis.el.editable = false;",
1096             "\t\t}",
1097             "\t\tif (this.editable_start_pos > 0 &&",
1098             "\t\t\t(sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)",
1099             "\t\t\t",
1100             "\t\t) {",
1101             "\t\t\tthis.el.editable = false;",
1102             "\t\t}",
1103             "\t\t",
1104             "\t\t ",
1105             "    ",
1106             "    }",
1107             "    ",
1108             "    ",
1109             "    ",
1110             "    ",
1111             "    for (var i = 0; i < buf.get_line_count();i++) {",
1112             "        if (i < (start_line -1) || i > (end_line -1)) {",
1113             "           ",
1114             "            sbuf.get_iter_at_line(out iter, i);",
1115             "            sbuf.create_source_mark(null, \"grey\", iter);",
1116             "            ",
1117             "        }",
1118             "    ",
1119             "    }",
1120             "    if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {",
1121             "\t    Gtk.TextIter cpos_iter;",
1122             "\t\tbuf.get_iter_at_line(out cpos_iter, start_line);",
1123             "\t\t",
1124             "\t\tbuf.place_cursor(cpos_iter); ",
1125             "\t}",
1126             "",
1127             "",
1128             "}"
1129            ]
1130           }
1131          ],
1132          "xtype" : "ScrolledWindow"
1133         },
1134         {
1135          "$ xns" : "Gtk",
1136          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
1137          "bool homogeneous" : false,
1138          "bool vexpand" : false,
1139          "int spacing" : 0,
1140          "items" : [
1141           {
1142            "$ xns" : "Gtk",
1143            "* init" : [
1144             "this.css = new Gtk.CssProvider();",
1145             " ",
1146             "this.css.load_from_string(",
1147             "\t\"#roo-search-entry { background-color: #ccc; }\"",
1148             ");",
1149             " ",
1150             "Gtk.StyleContext.add_provider_for_display(",
1151             "\tthis.el.get_display(),",
1152             "\tthis.css,",
1153             "\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
1154             ");",
1155             "\t\t",
1156             "\t ",
1157             " ",
1158             ""
1159            ],
1160            "Gtk.CssProvider css" : "",
1161            "bool hexpand" : true,
1162            "id" : "search_entry",
1163            "items" : [
1164             {
1165              "$ xns" : "Gtk",
1166              "listeners" : {
1167               "key_pressed" : [
1168                "(keyval, keycode, state) => {",
1169                "",
1170                "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
1171                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
1172                "\t\t_this.forwardSearch(true);",
1173                "\t    return true;",
1174                "\t}",
1175                "    ",
1176                "  ",
1177                " \tif (keyval == Gdk.Key.Return) {",
1178                "\t\t_this.forwardSearch(true);",
1179                "\t\t",
1180                "\t\t",
1181                "\t    return true;",
1182                "",
1183                "\t}    ",
1184                "   // print(event.key.keyval)",
1185                "   ",
1186                "    return false;",
1187                "}",
1188                ""
1189               ]
1190              },
1191              "xtype" : "EventControllerKey"
1192             }
1193            ],
1194            "listeners" : {
1195             "search_changed" : [
1196              "( ) => {",
1197              "",
1198              "_this.search(_this.search_entry.el.text);",
1199              "\t _this.search_results.updateResults();",
1200              "",
1201              "\tGLib.Timeout.add_seconds(1,() => {",
1202              "\t\t _this.search_results.updateResults();",
1203              "\t\t return false;",
1204              "\t });",
1205              "}",
1206              ""
1207             ]
1208            },
1209            "string name" : "roo-search-entry",
1210            "string placeholder_text" : "Press enter to search",
1211            "xtype" : "SearchEntry",
1212            "| void forwardSearch" : [
1213             "(bool change_focus) {",
1214             "",
1215             "",
1216             "\t_this.forwardSearch(change_focus);",
1217             "",
1218             "/*",
1219             "",
1220             "\tswitch(_this.windowstate.state) {",
1221             "\t\tcase WindowState.State.CODEONLY:",
1222             "\t\t//case WindowState.State.CODE:",
1223             "\t\t\t// search the code being edited..",
1224             "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
1225             "\t\t\t ",
1226             "\t\t\tbreak;",
1227             "\t\tcase WindowState.State.PREVIEW:",
1228             "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
1229             "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
1230             "\t\t\t} else { ",
1231             "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
1232             "\t\t\t}",
1233             "\t\t",
1234             "\t\t\tbreak;",
1235             "\t}",
1236             "\t*/",
1237             "\t",
1238             "}",
1239             ""
1240            ]
1241           },
1242           {
1243            "$ xns" : "Gtk",
1244            "id" : "search_results",
1245            "int margin_end" : 4,
1246            "int margin_start" : 4,
1247            "string label" : "No Results",
1248            "xtype" : "Label",
1249            "| void updateResults" : [
1250             "() {",
1251             "\tthis.el.visible = true;",
1252             "\t",
1253             "\tvar res = _this.searchcontext.get_occurrences_count();",
1254             "\tif (res < 0) {",
1255             "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
1256             "\t\treturn;",
1257             "\t}",
1258             "",
1259             "\t_this.nextBtn.el.sensitive = false;",
1260             "\t_this.backBtn.el.sensitive = false;\t",
1261             "",
1262             "\tif (res > 0) {",
1263             "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
1264             "\t\t_this.nextBtn.el.sensitive = true;",
1265             "\t\t_this.backBtn.el.sensitive = true;",
1266             "\t\treturn;",
1267             "\t} ",
1268             "\t_this.search_results.el.label = \"No Matches\";",
1269             "\t",
1270             "}"
1271            ]
1272           },
1273           {
1274            "$ xns" : "Gtk",
1275            "bool always_show_image" : true,
1276            "bool sensitive" : false,
1277            "id" : "nextBtn",
1278            "listeners" : {
1279             "clicked" : [
1280              "(event) => {",
1281              "",
1282              "\t_this.forwardSearch(true);",
1283              "\t ",
1284              "}",
1285              ""
1286             ]
1287            },
1288            "string icon_name" : "go-down",
1289            "xtype" : "Button"
1290           },
1291           {
1292            "$ xns" : "Gtk",
1293            "bool always_show_image" : true,
1294            "bool sensitive" : false,
1295            "id" : "backBtn",
1296            "listeners" : {
1297             "clicked" : [
1298              "(event) => {",
1299              "",
1300              "\t_this.backSearch(true);",
1301              "\t",
1302              "\t ",
1303              "}",
1304              ""
1305             ]
1306            },
1307            "string icon_name" : "go-up",
1308            "xtype" : "Button"
1309           },
1310           {
1311            "$ xns" : "Gtk",
1312            "bool always_show_image" : true,
1313            "items" : [
1314             {
1315              "$ xns" : "Gtk",
1316              "* pack" : false,
1317              "* prop" : "popover",
1318              "id" : "search_settings",
1319              "items" : [
1320               {
1321                "$ xns" : "Gtk",
1322                "* prop" : "child",
1323                "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
1324                "int spacing" : 0,
1325                "items" : [
1326                 {
1327                  "$ xns" : "Gtk",
1328                  "* init" : [
1329                   "{",
1330                   "\tthis.el.show();",
1331                   "}",
1332                   ""
1333                  ],
1334                  "id" : "case_sensitive",
1335                  "string label" : "Case Sensitive",
1336                  "xtype" : "CheckButton"
1337                 },
1338                 {
1339                  "$ xns" : "Gtk",
1340                  "* init" : [
1341                   "{",
1342                   "\tthis.el.show();",
1343                   "}",
1344                   ""
1345                  ],
1346                  "id" : "regex",
1347                  "string label" : "Regex",
1348                  "xtype" : "CheckButton"
1349                 },
1350                 {
1351                  "$ xns" : "Gtk",
1352                  "* init" : [
1353                   "{",
1354                   "\tthis.el.show();",
1355                   "}",
1356                   ""
1357                  ],
1358                  "id" : "multiline",
1359                  "string label" : "Multi-line (add \\n)",
1360                  "xtype" : "CheckButton"
1361                 }
1362                ],
1363                "xtype" : "Box"
1364               }
1365              ],
1366              "xtype" : "Popover"
1367             }
1368            ],
1369            "string icon_name" : "emblem-system",
1370            "xtype" : "MenuButton"
1371           }
1372          ],
1373          "xtype" : "Box"
1374         }
1375        ],
1376        "xtype" : "Box"
1377       }
1378      ],
1379      "xtype" : "Notebook"
1380     }
1381    ],
1382    "xtype" : "Box",
1383    "| int search" : [
1384     "(string in_txt) {",
1385     "\tthis.notebook.el.page = 1;",
1386     "\t",
1387     " ",
1388     "   ",
1389     "\tvar s = new GtkSource.SearchSettings();",
1390     "\ts.case_sensitive = _this.case_sensitive.el.active;",
1391     "\ts.regex_enabled = _this.regex.el.active;\t",
1392     "\ts.wrap_around = false;",
1393     "\t",
1394     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
1395     "\tthis.searchcontext.set_highlight(true);",
1396     "\tvar txt = in_txt;",
1397     "\t",
1398     "\tif (_this.multiline.el.active) {",
1399     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
1400     "\t}",
1401     "\t",
1402     "\ts.set_search_text(txt);",
1403     "\tGtk.TextIter beg, st,en;",
1404     "\tbool has_wrapped_around;",
1405     "\tthis.buffer.el.get_start_iter(out beg);",
1406     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
1407     "\tthis.last_search_end = 0;",
1408     "\t",
1409     "\treturn this.searchcontext.get_occurrences_count();",
1410     "",
1411     " ",
1412     "    ",
1413     "",
1414     "}",
1415     ""
1416    ],
1417    "| void backSearch" : [
1418     "(bool change_focus) {",
1419     "",
1420     "\tif (this.searchcontext == null) {",
1421     "\t\treturn;",
1422     "\t} ",
1423     "\t",
1424     "\tGtk.TextIter beg, st,en;",
1425     "\tbool has_wrapped_around;",
1426     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
1427     "\t",
1428     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
1429     "\t",
1430     "\t\tthis.last_search_end = 0;",
1431     "\t\treturn;",
1432     "\t}",
1433     "\tthis.last_search_end = en.get_offset();",
1434     "\tif (change_focus) {",
1435     "\t\tthis.sourceview.el.grab_focus();",
1436     "\t}",
1437     "\tthis.buffer.el.place_cursor(st);",
1438     "\tthis.sourceview.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1439     "\tvar ln = st.get_line();",
1440     "\tthis.highlightNodeAtLine(ln);",
1441     "\t",
1442     " ",
1443     "}",
1444     ""
1445    ],
1446    "| void createThumb" : [
1447     "() {",
1448     "    ",
1449     "    ",
1450     "    if (this.file == null) {",
1451     "        return;",
1452     "    }",
1453     "    ",
1454     "\tif (this.notebook.el.page > 0 ) {",
1455     "        return;",
1456     "    }",
1457     "    ",
1458     " \tthis.file.widgetToIcon(this.view.el); ",
1459     "",
1460     "    ",
1461     "     ",
1462     "    ",
1463     "     ",
1464     "}",
1465     ""
1466    ],
1467    "| void forwardSearch" : [
1468     "(bool change_focus) {",
1469     "",
1470     "\tif (this.searchcontext == null) {",
1471     "\t\treturn;",
1472     "\t}",
1473     "\tthis.notebook.el.page = 1;",
1474     "\tGtk.TextIter beg, st,en;",
1475     "\tbool has_wrapped_around;",
1476     "\tvar buf = this.sourceview.el.get_buffer();",
1477     "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
1478     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
1479     "\t\tthis.last_search_end = 0;",
1480     "\t\treturn;",
1481     "\t}",
1482     "\tthis.last_search_end = en.get_offset();",
1483     "\tif (change_focus) {",
1484     "\t\tthis.sourceview.el.grab_focus();",
1485     "\t}",
1486     "\tbuf.place_cursor(st);",
1487     "\t",
1488     " ",
1489     "\t ",
1490     "\tthis.sourceview.el.scroll_to_iter(st,  0.0f, true, 0.0f, 0.5f);",
1491     "\t",
1492     "\t",
1493     "\tvar ln = st.get_line();",
1494     "\t",
1495     "\tthis.highlightNodeAtLine(ln);",
1496     "}\t",
1497     "  "
1498    ],
1499    "| void highlightNodeAtLine" : [
1500     "(int ln) {",
1501     "",
1502     "",
1503     "\t ",
1504     "\t// highlight node...",
1505     "\t",
1506     "\t\t",
1507     "    var node = _this.file.lineToNode(ln+1);",
1508     " ",
1509     "    if (node == null) {",
1510     "        //print(\"can not find node\\n\");",
1511     "        return;",
1512     "    }",
1513     "    var prop = node.lineToProp(ln+1);",
1514     "    print(\"prop : %s\", prop == null ? \"???\" : prop.name);",
1515     "        ",
1516     "        ",
1517     "    // ---------- this selects the tree's node...",
1518     "    ",
1519     "    var ltree = _this.main_window.windowstate.left_tree;",
1520     "   ltree.model.selectNode(node);",
1521     "        ",
1522     "    //_this.sourceview.allow_node_scroll = false; /// block node scrolling..",
1523     "\t       ",
1524     "   ",
1525     "    //print(\"changing cursor on tree..\\n\");",
1526     "   ",
1527     "",
1528     "    ",
1529     "    // let's try allowing editing on the methods.",
1530     "    // a little klunky at present..",
1531     "\t_this.sourceview.prop_selected = \"\";",
1532     "\t/*",
1533     "    if (prop != null) {",
1534     "\t\t//see if we can find it..",
1535     "\t\tvar kv = prop.split(\":\");",
1536     "\t\tif (kv[0] == \"p\") {",
1537     "\t\t",
1538     "    \t\t//var k = prop.get_key(kv[1]);",
1539     "    \t\t// fixme -- need to determine if it's an editable property...",
1540     "    \t\t_this.sourceview.prop_selected = prop;",
1541     "    \t\t",
1542     "\t\t} else if (kv[0] == \"l\") {",
1543     "\t\t\t _this.sourceview.prop_selected = prop;",
1544     "\t\t\t",
1545     "\t\t}",
1546     "    }",
1547     "    */",
1548     "   // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
1549     "   _this.sourceview.nodeSelected(node,false);",
1550     "    ",
1551     "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
1552     "      //      GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
1553     "\t  //          this.allow_node_scroll = true;",
1554     "\t  //          return false;",
1555     "      //      });",
1556     "      //  }",
1557     "\t\t",
1558     "\t\t",
1559     "\t\t",
1560     "\t\t",
1561     "\t\t",
1562     "\t\t",
1563     "\t\t",
1564     "\t\t",
1565     "\t\t",
1566     "\t\t ",
1567     "",
1568     "}",
1569     " "
1570    ],
1571    "| void loadFile" : [
1572     "",
1573     "(JsRender.JsRender file)",
1574     "{",
1575     "    this.file = file;",
1576     "    this.view.renderJS(true);",
1577     "    this.notebook.el.page = 0;// gtk preview ",
1578     "    this.sourceview.loadFile();   ",
1579     "}",
1580     " ",
1581     " "
1582    ],
1583    "| void requestRedraw" : [
1584     "() {",
1585     "    this.view.renderJS(false);",
1586     "    this.sourceview.loadFile();   ",
1587     "}"
1588    ],
1589    "| void scroll_to_line" : [
1590     "(int line) {",
1591     "   // code preview...",
1592     "   ",
1593     "   GLib.Timeout.add(100, () => {",
1594     "   ",
1595     "\t\tthis.notebook.el.set_current_page( 1 );",
1596     "\t   ",
1597     "\t   ",
1598     "\t\t  var buf = this.sourceview.el.get_buffer();",
1599     "\t ",
1600     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1601     "",
1602     "",
1603     "\t\tGtk.TextIter iter;   ",
1604     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1605     "\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1606     "\t\treturn false;",
1607     "\t});   ",
1608     "",
1609     "   ",
1610     "}",
1611     ""
1612    ],
1613    "| void updateErrorMarks" : [
1614     "(string category) {",
1615     "\t",
1616     " ",
1617     "",
1618     "\tvar buf = _this.buffer.el;",
1619     "\tGtk.TextIter start;",
1620     "\tGtk.TextIter end;     ",
1621     "\tbuf.get_bounds (out start, out end);",
1622     "",
1623     "\tbuf.remove_source_marks (start, end, category);",
1624     " ",
1625     "\tGLib.debug(\"highlight errors\");\t\t ",
1626     "",
1627     "\t // we should highlight other types of errors..",
1628     "",
1629     " ",
1630     "",
1631     "\t ",
1632     "\tif (_this.file == null) {",
1633     "\t\tGLib.debug(\"file is null?\");",
1634     "\t\treturn;",
1635     "",
1636     "\t}",
1637     "\tvar ar = this.file.getErrors(category);",
1638     "\tif (ar == null || ar.get_n_items() < 1) {",
1639     "\t\tGLib.debug(\"higjlight %s has no errors\", category);",
1640     "\t\treturn;",
1641     "\t}",
1642     " ",
1643     "",
1644     " ",
1645     "\t",
1646     "\tvar offset = 0;",
1647     "\t ",
1648     "",
1649     "\tvar tlines = buf.get_line_count () +1;",
1650     "\t",
1651     " ",
1652     "\t ",
1653     "\tfor (var i = 0; i < ar.get_n_items();i++) {",
1654     "\t\tvar err = (Palete.CompileError) ar.get_item(i);",
1655     "\t\t",
1656     "\t     Gtk.TextIter iter;",
1657     "//        print(\"get inter\\n\");",
1658     "\t    var eline = err.line - offset;",
1659     "\t    GLib.debug(\"GOT ERROR on line %d -- converted to %d  (offset = %d)\",",
1660     "\t    \terr.line ,eline, offset);",
1661     "\t    ",
1662     "\t    ",
1663     "\t    if (eline > tlines || eline < 0) {",
1664     "\t        return;",
1665     "\t    }",
1666     "\t   ",
1667     "\t    ",
1668     "\t    buf.get_iter_at_line( out iter, eline);",
1669     "\t   ",
1670     "\t   ",
1671     "\t\tvar msg = \"Line: %d %s : %s\".printf(eline+1, err.category, err.msg);",
1672     "\t    buf.create_source_mark( msg, err.category, iter);",
1673     "\t    GLib.debug(\"set line %d to %s\", eline, msg);",
1674     "\t    //this.marks.set(eline, msg);",
1675     "\t}",
1676     "\treturn ;",
1677     "",
1678     "",
1679     "",
1680     " ",
1681     "",
1682     "}"
1683    ]
1684   }
1685  ],
1686  "name" : "WindowRooView"
1687 }