fix line numbering issues with vala generator - hopefully fixes completion in node...
[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             "    _this.main_window.windowstate.updateErrorMarksAll();",
876             "    ",
877             "    // what does this do?",
878             "     GLib.Timeout.add(500, () => {",
879             "",
880             "        print(\"RESORTING cursor to = %d\\n\", cpos);",
881             "\t\tGtk.TextIter cpos_iter;",
882             "\t\tbuf.get_iter_at_offset(out cpos_iter, cpos);",
883             "\t\tbuf.place_cursor(cpos_iter); ",
884             "\t\t",
885             "\t\tthis.el.get_vadjustment().set_value(vadj_pos);;",
886             "\t\t",
887             "",
888             "\t\tthis.onCursorChanged();",
889             "\t\t",
890             "\t\t",
891             "\t\t//_this.buffer.checkSyntax();",
892             "\t\treturn false;",
893             "\t});",
894             "\t\t",
895             "    this.loading = false; ",
896             "    _this.buffer.dirty = false;",
897             "}",
898             ""
899            ],
900            "| void nodeSelected" : [
901             "(JsRender.Node? sel, bool scroll ) {",
902             "  ",
903             "    ",
904             "\t",
905             "    // this is connected in widnowstate",
906             "",
907             "",
908             "\t// not sure why....   ",
909             "  //  while(Gtk.events_pending()) {",
910             "   //     Gtk.main_iteration();",
911             " //   }",
912             "    ",
913             "    this.node_selected = sel;",
914             "    ",
915             "   // this.updateGreySelection(scroll);",
916             "    ",
917             "    ",
918             "    ",
919             "}",
920             "",
921             "   ",
922             ""
923            ],
924            "| void onCursorChanged" : [
925             "(/*ParamSpec ps*/) {",
926             "",
927             "\t\tif (!this.key_is_pressed && !this.button_is_pressed) {",
928             "\t\t\treturn;",
929             "\t\t}",
930             "",
931             "\t   if (this.loading) {",
932             "            return;",
933             "        }",
934             "       // if (ps.name != \"cursor-position\") {",
935             "       //     return;",
936             "       // }",
937             "",
938             "        var buf = this.el.get_buffer();",
939             "        //print(\"cursor changed : %d\\n\", buf.cursor_position);",
940             "        Gtk.TextIter cpos;",
941             "        buf.get_iter_at_offset(out cpos, buf.cursor_position);",
942             "        ",
943             "        var ln = cpos.get_line();",
944             "        ",
945             "        ",
946             "        // --- select node at line....",
947             "        ",
948             "        var node = _this.file.lineToNode(ln+1);",
949             " ",
950             "        if (node == null) {",
951             "            print(\"can not find node\\n\");",
952             "            return;",
953             "        }",
954             "        var prop = node.lineToProp(ln+1);",
955             "        print(\"prop : %s\", prop == null ? \"???\" : prop.name);",
956             "        ",
957             "        ",
958             "        // ---------- this selects the tree's node...",
959             "        ",
960             "        var ltree = _this.main_window.windowstate.left_tree;",
961             "         ltree.model.selectNode(node);",
962             "        ",
963             "\t       ",
964             "        //print(\"changing cursor on tree..\\n\");",
965             "       ",
966             "",
967             "        ",
968             "        // let's try allowing editing on the methods.",
969             "        // a little klunky at present..",
970             "        this.prop_selected = \"\";",
971             "        /*",
972             "        if (prop != null) {",
973             "    \t\t//see if we can find it..",
974             "    \t\tvar kv = prop.split(\":\");",
975             "    \t\tif (kv[0] == \"p\") {",
976             "    \t\t",
977             "        \t\t//var k = prop.get_key(kv[1]);",
978             "        \t\t// fixme -- need to determine if it's an editable property...",
979             "        \t\tthis.prop_selected = prop;",
980             "        \t\t",
981             "    \t\t} else if (kv[0] == \"l\") {",
982             "    \t\t\t this.prop_selected = prop;",
983             "    \t\t\t",
984             "    \t\t}",
985             "        }",
986             "       */",
987             "           // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
988             "           //this.nodeSelected(node,false);",
989             "            ",
990             "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
991             "           ",
992             "        ",
993             "        // highlight the node..",
994             "}",
995             " "
996            ],
997            "| void updateGreySelection" : [
998             "(bool scroll) { ",
999             "\tvar sel = this.node_selected;",
1000             "\tprint(\"node selected\\n\");",
1001             "    var buf = this.el.get_buffer();",
1002             "    var sbuf = (GtkSource.Buffer) buf;",
1003             "",
1004             "   ",
1005             "   this.clearGreySelection();",
1006             "   ",
1007             "   ",
1008             "   ",
1009             "     if (sel == null) {",
1010             "\t     print(\"no selected node\\n\");",
1011             "        // no highlighting..",
1012             "        return;",
1013             "    }",
1014             "    ",
1015             "    print(\"highlight region %d to %d\\n\", sel.line_start,sel.line_end);",
1016             "    Gtk.TextIter iter;   ",
1017             "    sbuf.get_iter_at_line(out iter,  sel.line_start);",
1018             "    ",
1019             "    ",
1020             "    Gtk.TextIter cur_iter;",
1021             "    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
1022             "   ",
1023             "    var cursor_at_line = cur_iter.get_line();",
1024             "    ",
1025             "    ",
1026             "    //var cur_line = cur_iter.get_line();",
1027             "    //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
1028             "    ",
1029             "    //} else {",
1030             "    if (scroll) {",
1031             "\t\tprint(\"scrolling to node -- should occur on node picking.\\n\");",
1032             "    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1033             "\t}",
1034             "    ",
1035             "    var start_line = sel.line_start;",
1036             "    var end_line = sel.line_end;",
1037             "    ",
1038             "    ",
1039             "    this.el.editable = false;",
1040             "    ",
1041             "    //var colon_pos = 0;",
1042             "    ",
1043             "    this.editable_start_pos = -1;",
1044             "    ",
1045             "    // now if we have selected a property...",
1046             "    if (this.prop_selected.length> 0 ) {",
1047             "",
1048             "\t\tint nstart, nend;",
1049             "\t\tif (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {",
1050             "\t\t\tstart_line = nstart;",
1051             "\t\t\tend_line = nend;",
1052             "\t\t\t// this.el.editable = true; << cant do this!!?",
1053             "\t\t\tprint(\"start line = %d, end line = %d\\n\", start_line, end_line);",
1054             "\t\t\t",
1055             "\t\t\t\t// see if we are 'right of ':'",
1056             "\t\t\t\t// get an iter for the start of the line.",
1057             "\t\t\tGtk.TextIter start_first_line_iter,end_first_line_iter;",
1058             "\t\t\tthis.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);",
1059             "\t\t\tthis.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);",
1060             "\t\t\t ",
1061             "\t\t\t",
1062             "\t\t\t",
1063             "\t\t\t",
1064             "\t\t\tif (end_first_line_iter.forward_to_line_end()) {",
1065             "\t\t\t\tvar first_line  = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);",
1066             "\t\t\t\t",
1067             "\t\t\t\tprint(\"first line = %s\\n\", first_line);",
1068             "\t\t\t\tif (first_line.contains(\":\")) {",
1069             "\t\t\t\t\tthis.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(\":\") + 1;",
1070             "\t\t\t\t\tprint(\"colon_pos  = %d\\n\", this.editable_start_pos);",
1071             "\t\t\t\t}",
1072             "\t\t\t\t",
1073             "",
1074             "\t\t\t\t//Gtk.TextIter colon_iter;",
1075             "\t\t\t\t//sbuf.get_iter_at_offset (out colon_iter, colon_pos);",
1076             "\t\t\t\t//sbuf.create_source_mark(null, \"active_text\", colon_iter);",
1077             "\t\t\t}",
1078             "\t\t\t",
1079             "\t\t\t",
1080             "\t\t\t",
1081             "\t\t\t//print(\"is cursor at line? %d ?= %d\\n\", start_line -1 , cursor_at_line);",
1082             "\t\t\t//if (start_line - 1 == cursor_at_line) {",
1083             "\t\t\t// should be ok - current_posssion can not be less than '-1'...",
1084             "\t\t\tif (sbuf.cursor_position < this.editable_start_pos) {",
1085             "\t\t\t",
1086             "\t\t\t\tprint(\"cursor is before start pos.. - turn off editable...\\n\");",
1087             "\t\t\t\t//var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);",
1088             "\t\t\t\t//print(\"before cursor string =  %s\\n\", before_cursor_string);",
1089             "\t\t\t\t//if (!before_cursor_string.contains(\":\")) {",
1090             "\t\t\t\t\tthis.el.editable = false;",
1091             "\t\t\t\t//}",
1092             "\t\t\t\t",
1093             "\t\t\t}",
1094             "\t\t\t ",
1095             "\t\t\t ",
1096             "",
1097             "\t\t\t ",
1098             "\t\t}",
1099             "\t\tprint(\"propSelected = %s range  %d -> %d\\n\", this.prop_selected, start_line, end_line);\t\t",
1100             "\t\t",
1101             "\t\t",
1102             "    }",
1103             "    ",
1104             "\tprint(\"checking selection\\n\");",
1105             "    ",
1106             "    ",
1107             "    // check selection - if it's out of 'bounds'",
1108             "    if (this.el.editable && sbuf.get_has_selection()) {",
1109             "\t\tGtk.TextIter sel_start_iter, sel_end_iter;",
1110             "\t\tsbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);",
1111             "\t\t",
1112             "\t\tif (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||",
1113             "\t\t\tsel_start_iter.get_line() > end_line   || sel_end_iter.get_line() < start_line\t\t\t) {",
1114             "\t\t\t// save?",
1115             "\t\t\tthis.el.editable = false;",
1116             "\t\t}",
1117             "\t\tif (this.editable_start_pos > 0 &&",
1118             "\t\t\t(sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)",
1119             "\t\t\t",
1120             "\t\t) {",
1121             "\t\t\tthis.el.editable = false;",
1122             "\t\t}",
1123             "\t\t",
1124             "\t\t ",
1125             "    ",
1126             "    }",
1127             "    ",
1128             "    ",
1129             "    ",
1130             "    ",
1131             "    for (var i = 0; i < buf.get_line_count();i++) {",
1132             "        if (i < (start_line -1) || i > (end_line -1)) {",
1133             "           ",
1134             "            sbuf.get_iter_at_line(out iter, i);",
1135             "            sbuf.create_source_mark(null, \"grey\", iter);",
1136             "            ",
1137             "        }",
1138             "    ",
1139             "    }",
1140             "    if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {",
1141             "\t    Gtk.TextIter cpos_iter;",
1142             "\t\tbuf.get_iter_at_line(out cpos_iter, start_line);",
1143             "\t\t",
1144             "\t\tbuf.place_cursor(cpos_iter); ",
1145             "\t}",
1146             "",
1147             "",
1148             "}"
1149            ]
1150           }
1151          ],
1152          "xtype" : "ScrolledWindow"
1153         },
1154         {
1155          "$ xns" : "Gtk",
1156          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
1157          "bool homogeneous" : false,
1158          "bool vexpand" : false,
1159          "int spacing" : 0,
1160          "items" : [
1161           {
1162            "$ xns" : "Gtk",
1163            "* init" : [
1164             "this.css = new Gtk.CssProvider();",
1165             " ",
1166             "this.css.load_from_string(",
1167             "\t\"#roo-search-entry { background-color: #ccc; }\"",
1168             ");",
1169             " ",
1170             "Gtk.StyleContext.add_provider_for_display(",
1171             "\tthis.el.get_display(),",
1172             "\tthis.css,",
1173             "\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
1174             ");",
1175             "\t\t",
1176             "\t ",
1177             " ",
1178             ""
1179            ],
1180            "Gtk.CssProvider css" : "",
1181            "bool hexpand" : true,
1182            "id" : "search_entry",
1183            "items" : [
1184             {
1185              "$ xns" : "Gtk",
1186              "listeners" : {
1187               "key_pressed" : [
1188                "(keyval, keycode, state) => {",
1189                "",
1190                "\tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
1191                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
1192                "\t\t_this.forwardSearch(true);",
1193                "\t    return true;",
1194                "\t}",
1195                "    ",
1196                "  ",
1197                " \tif (keyval == Gdk.Key.Return) {",
1198                "\t\t_this.forwardSearch(true);",
1199                "\t\t",
1200                "\t\t",
1201                "\t    return true;",
1202                "",
1203                "\t}    ",
1204                "   // print(event.key.keyval)",
1205                "   ",
1206                "    return false;",
1207                "}",
1208                ""
1209               ]
1210              },
1211              "xtype" : "EventControllerKey"
1212             }
1213            ],
1214            "listeners" : {
1215             "search_changed" : [
1216              "( ) => {",
1217              "",
1218              "_this.search(_this.search_entry.el.text);",
1219              "\t _this.search_results.updateResults();",
1220              "",
1221              "\tGLib.Timeout.add_seconds(1,() => {",
1222              "\t\t _this.search_results.updateResults();",
1223              "\t\t return false;",
1224              "\t });",
1225              "}",
1226              ""
1227             ]
1228            },
1229            "string name" : "roo-search-entry",
1230            "string placeholder_text" : "Press enter to search",
1231            "xtype" : "SearchEntry",
1232            "| void forwardSearch" : [
1233             "(bool change_focus) {",
1234             "",
1235             "",
1236             "\t_this.forwardSearch(change_focus);",
1237             "",
1238             "/*",
1239             "",
1240             "\tswitch(_this.windowstate.state) {",
1241             "\t\tcase WindowState.State.CODEONLY:",
1242             "\t\t//case WindowState.State.CODE:",
1243             "\t\t\t// search the code being edited..",
1244             "\t\t\t_this.windowstate.code_editor_tab.forwardSearch(change_focus);",
1245             "\t\t\t ",
1246             "\t\t\tbreak;",
1247             "\t\tcase WindowState.State.PREVIEW:",
1248             "\t\t\tif (_this.windowstate.file.xtype == \"Gtk\") {",
1249             "\t\t\t\t_this.windowstate.window_gladeview.forwardSearch(change_focus);",
1250             "\t\t\t} else { ",
1251             "\t\t\t\t _this.windowstate.window_rooview.forwardSearch(change_focus);",
1252             "\t\t\t}",
1253             "\t\t",
1254             "\t\t\tbreak;",
1255             "\t}",
1256             "\t*/",
1257             "\t",
1258             "}",
1259             ""
1260            ]
1261           },
1262           {
1263            "$ xns" : "Gtk",
1264            "id" : "search_results",
1265            "int margin_end" : 4,
1266            "int margin_start" : 4,
1267            "string label" : "No Results",
1268            "xtype" : "Label",
1269            "| void updateResults" : [
1270             "() {",
1271             "\tthis.el.visible = true;",
1272             "\t",
1273             "\tvar res = _this.searchcontext.get_occurrences_count();",
1274             "\tif (res < 0) {",
1275             "\t\t_this.search_results.el.label = \"??? Matches\";\t\t",
1276             "\t\treturn;",
1277             "\t}",
1278             "",
1279             "\t_this.nextBtn.el.sensitive = false;",
1280             "\t_this.backBtn.el.sensitive = false;\t",
1281             "",
1282             "\tif (res > 0) {",
1283             "\t\t_this.search_results.el.label = \"%d Matches\".printf(res);",
1284             "\t\t_this.nextBtn.el.sensitive = true;",
1285             "\t\t_this.backBtn.el.sensitive = true;",
1286             "\t\treturn;",
1287             "\t} ",
1288             "\t_this.search_results.el.label = \"No Matches\";",
1289             "\t",
1290             "}"
1291            ]
1292           },
1293           {
1294            "$ xns" : "Gtk",
1295            "bool always_show_image" : true,
1296            "bool sensitive" : false,
1297            "id" : "nextBtn",
1298            "listeners" : {
1299             "clicked" : [
1300              "(event) => {",
1301              "",
1302              "\t_this.forwardSearch(true);",
1303              "\t ",
1304              "}",
1305              ""
1306             ]
1307            },
1308            "string icon_name" : "go-down",
1309            "xtype" : "Button"
1310           },
1311           {
1312            "$ xns" : "Gtk",
1313            "bool always_show_image" : true,
1314            "bool sensitive" : false,
1315            "id" : "backBtn",
1316            "listeners" : {
1317             "clicked" : [
1318              "(event) => {",
1319              "",
1320              "\t_this.backSearch(true);",
1321              "\t",
1322              "\t ",
1323              "}",
1324              ""
1325             ]
1326            },
1327            "string icon_name" : "go-up",
1328            "xtype" : "Button"
1329           },
1330           {
1331            "$ xns" : "Gtk",
1332            "bool always_show_image" : true,
1333            "items" : [
1334             {
1335              "$ xns" : "Gtk",
1336              "* pack" : false,
1337              "* prop" : "popover",
1338              "id" : "search_settings",
1339              "items" : [
1340               {
1341                "$ xns" : "Gtk",
1342                "* prop" : "child",
1343                "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
1344                "int spacing" : 0,
1345                "items" : [
1346                 {
1347                  "$ xns" : "Gtk",
1348                  "* init" : [
1349                   "{",
1350                   "\tthis.el.show();",
1351                   "}",
1352                   ""
1353                  ],
1354                  "id" : "case_sensitive",
1355                  "string label" : "Case Sensitive",
1356                  "xtype" : "CheckButton"
1357                 },
1358                 {
1359                  "$ xns" : "Gtk",
1360                  "* init" : [
1361                   "{",
1362                   "\tthis.el.show();",
1363                   "}",
1364                   ""
1365                  ],
1366                  "id" : "regex",
1367                  "string label" : "Regex",
1368                  "xtype" : "CheckButton"
1369                 },
1370                 {
1371                  "$ xns" : "Gtk",
1372                  "* init" : [
1373                   "{",
1374                   "\tthis.el.show();",
1375                   "}",
1376                   ""
1377                  ],
1378                  "id" : "multiline",
1379                  "string label" : "Multi-line (add \\n)",
1380                  "xtype" : "CheckButton"
1381                 }
1382                ],
1383                "xtype" : "Box"
1384               }
1385              ],
1386              "xtype" : "Popover"
1387             }
1388            ],
1389            "string icon_name" : "emblem-system",
1390            "xtype" : "MenuButton"
1391           }
1392          ],
1393          "xtype" : "Box"
1394         }
1395        ],
1396        "xtype" : "Box"
1397       }
1398      ],
1399      "xtype" : "Notebook"
1400     }
1401    ],
1402    "xtype" : "Box",
1403    "| int search" : [
1404     "(string in_txt) {",
1405     "\tthis.notebook.el.page = 1;",
1406     "\t",
1407     " ",
1408     "   ",
1409     "\tvar s = new GtkSource.SearchSettings();",
1410     "\ts.case_sensitive = _this.case_sensitive.el.active;",
1411     "\ts.regex_enabled = _this.regex.el.active;\t",
1412     "\ts.wrap_around = false;",
1413     "\t",
1414     "\tthis.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);",
1415     "\tthis.searchcontext.set_highlight(true);",
1416     "\tvar txt = in_txt;",
1417     "\t",
1418     "\tif (_this.multiline.el.active) {",
1419     "\t\ttxt = in_txt.replace(\"\\\\n\", \"\\n\");",
1420     "\t}",
1421     "\t",
1422     "\ts.set_search_text(txt);",
1423     "\tGtk.TextIter beg, st,en;",
1424     "\tbool has_wrapped_around;",
1425     "\tthis.buffer.el.get_start_iter(out beg);",
1426     "\tthis.searchcontext.forward(beg, out st, out en, out has_wrapped_around);",
1427     "\tthis.last_search_end = 0;",
1428     "\t",
1429     "\treturn this.searchcontext.get_occurrences_count();",
1430     "",
1431     " ",
1432     "    ",
1433     "",
1434     "}",
1435     ""
1436    ],
1437    "| void backSearch" : [
1438     "(bool change_focus) {",
1439     "",
1440     "\tif (this.searchcontext == null) {",
1441     "\t\treturn;",
1442     "\t} ",
1443     "\t",
1444     "\tGtk.TextIter beg, st,en;",
1445     "\tbool has_wrapped_around;",
1446     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );",
1447     "\t",
1448     "\tif (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {",
1449     "\t",
1450     "\t\tthis.last_search_end = 0;",
1451     "\t\treturn;",
1452     "\t}",
1453     "\tthis.last_search_end = en.get_offset();",
1454     "\tif (change_focus) {",
1455     "\t\tthis.sourceview.el.grab_focus();",
1456     "\t}",
1457     "\tthis.buffer.el.place_cursor(st);",
1458     "\tthis.sourceview.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
1459     "\tvar ln = st.get_line();",
1460     "\tthis.highlightNodeAtLine(ln);",
1461     "\t",
1462     " ",
1463     "}",
1464     ""
1465    ],
1466    "| void createThumb" : [
1467     "() {",
1468     "    ",
1469     "    ",
1470     "    if (this.file == null) {",
1471     "        return;",
1472     "    }",
1473     "    ",
1474     "\tif (this.notebook.el.page > 0 ) {",
1475     "        return;",
1476     "    }",
1477     "    ",
1478     " \tthis.file.widgetToIcon(this.view.el); ",
1479     "",
1480     "    ",
1481     "     ",
1482     "    ",
1483     "     ",
1484     "}",
1485     ""
1486    ],
1487    "| void forwardSearch" : [
1488     "(bool change_focus) {",
1489     "",
1490     "\tif (this.searchcontext == null) {",
1491     "\t\treturn;",
1492     "\t}",
1493     "\tthis.notebook.el.page = 1;",
1494     "\tGtk.TextIter beg, st,en;",
1495     "\tbool has_wrapped_around;",
1496     "\tvar buf = this.sourceview.el.get_buffer();",
1497     "\tbuf.get_iter_at_offset(out beg, this.last_search_end);",
1498     "\tif (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {",
1499     "\t\tthis.last_search_end = 0;",
1500     "\t\treturn;",
1501     "\t}",
1502     "\tthis.last_search_end = en.get_offset();",
1503     "\tif (change_focus) {",
1504     "\t\tthis.sourceview.el.grab_focus();",
1505     "\t}",
1506     "\tbuf.place_cursor(st);",
1507     "\t",
1508     " ",
1509     "\t ",
1510     "\tthis.sourceview.el.scroll_to_iter(st,  0.0f, true, 0.0f, 0.5f);",
1511     "\t",
1512     "\t",
1513     "\tvar ln = st.get_line();",
1514     "\t",
1515     "\tthis.highlightNodeAtLine(ln);",
1516     "}\t",
1517     "  "
1518    ],
1519    "| void highlightNodeAtLine" : [
1520     "(int ln) {",
1521     "",
1522     "",
1523     "\t ",
1524     "\t// highlight node...",
1525     "\t",
1526     "\t\t",
1527     "    var node = _this.file.lineToNode(ln+1);",
1528     " ",
1529     "    if (node == null) {",
1530     "        //print(\"can not find node\\n\");",
1531     "        return;",
1532     "    }",
1533     "    var prop = node.lineToProp(ln+1);",
1534     "    print(\"prop : %s\", prop == null ? \"???\" : prop.name);",
1535     "        ",
1536     "        ",
1537     "    // ---------- this selects the tree's node...",
1538     "    ",
1539     "    var ltree = _this.main_window.windowstate.left_tree;",
1540     "   ltree.model.selectNode(node);",
1541     "        ",
1542     "    //_this.sourceview.allow_node_scroll = false; /// block node scrolling..",
1543     "\t       ",
1544     "   ",
1545     "    //print(\"changing cursor on tree..\\n\");",
1546     "   ",
1547     "",
1548     "    ",
1549     "    // let's try allowing editing on the methods.",
1550     "    // a little klunky at present..",
1551     "\t_this.sourceview.prop_selected = \"\";",
1552     "\t/*",
1553     "    if (prop != null) {",
1554     "\t\t//see if we can find it..",
1555     "\t\tvar kv = prop.split(\":\");",
1556     "\t\tif (kv[0] == \"p\") {",
1557     "\t\t",
1558     "    \t\t//var k = prop.get_key(kv[1]);",
1559     "    \t\t// fixme -- need to determine if it's an editable property...",
1560     "    \t\t_this.sourceview.prop_selected = prop;",
1561     "    \t\t",
1562     "\t\t} else if (kv[0] == \"l\") {",
1563     "\t\t\t _this.sourceview.prop_selected = prop;",
1564     "\t\t\t",
1565     "\t\t}",
1566     "    }",
1567     "    */",
1568     "   // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); ",
1569     "   _this.sourceview.nodeSelected(node,false);",
1570     "    ",
1571     "            // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
1572     "      //      GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
1573     "\t  //          this.allow_node_scroll = true;",
1574     "\t  //          return false;",
1575     "      //      });",
1576     "      //  }",
1577     "\t\t",
1578     "\t\t",
1579     "\t\t",
1580     "\t\t",
1581     "\t\t",
1582     "\t\t",
1583     "\t\t",
1584     "\t\t",
1585     "\t\t",
1586     "\t\t ",
1587     "",
1588     "}",
1589     " "
1590    ],
1591    "| void loadFile" : [
1592     "",
1593     "(JsRender.JsRender file)",
1594     "{",
1595     "    this.file = file;",
1596     "    this.view.renderJS(true);",
1597     "    this.notebook.el.page = 0;// gtk preview ",
1598     "    this.sourceview.loadFile();   ",
1599     "}",
1600     " ",
1601     " "
1602    ],
1603    "| void requestRedraw" : [
1604     "() {",
1605     "    this.view.renderJS(false);",
1606     "    this.sourceview.loadFile();   ",
1607     "}"
1608    ],
1609    "| void scroll_to_line" : [
1610     "(int line) {",
1611     "   // code preview...",
1612     "   ",
1613     "   GLib.Timeout.add(100, () => {",
1614     "   ",
1615     "\t\tthis.notebook.el.set_current_page( 1 );",
1616     "\t   ",
1617     "\t   ",
1618     "\t\t  var buf = this.sourceview.el.get_buffer();",
1619     "\t ",
1620     "\t\tvar sbuf = (GtkSource.Buffer) buf;",
1621     "",
1622     "",
1623     "\t\tGtk.TextIter iter;   ",
1624     "\t\tsbuf.get_iter_at_line(out iter,  line);",
1625     "\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
1626     "\t\treturn false;",
1627     "\t});   ",
1628     "",
1629     "   ",
1630     "}",
1631     ""
1632    ],
1633    "| void updateErrorMarks" : [
1634     "(string category) {",
1635     "\t",
1636     " ",
1637     "",
1638     "\tvar buf = _this.buffer.el;",
1639     "\tGtk.TextIter start;",
1640     "\tGtk.TextIter end;     ",
1641     "\tbuf.get_bounds (out start, out end);",
1642     "",
1643     "\tbuf.remove_source_marks (start, end, category);",
1644     " ",
1645     "\tGLib.debug(\"highlight errors\");\t\t ",
1646     "",
1647     "\t // we should highlight other types of errors..",
1648     "",
1649     " ",
1650     "",
1651     "\t ",
1652     "\tif (_this.file == null) {",
1653     "\t\tGLib.debug(\"file is null?\");",
1654     "\t\treturn;",
1655     "",
1656     "\t}",
1657     "\tvar ar = this.file.getErrors(category);",
1658     "\tif (ar == null || ar.get_n_items() < 1) {",
1659     "\t\tGLib.debug(\"higjlight %s has no errors\", category);",
1660     "\t\treturn;",
1661     "\t}",
1662     " ",
1663     "",
1664     " ",
1665     "\t",
1666     "\tvar offset = 0;",
1667     "\t ",
1668     "",
1669     "\tvar tlines = buf.get_line_count () +1;",
1670     "\t",
1671     " ",
1672     "\t ",
1673     "\tfor (var i = 0; i < ar.get_n_items();i++) {",
1674     "\t\tvar err = (Palete.CompileError) ar.get_item(i);",
1675     "\t\t",
1676     "\t     Gtk.TextIter iter;",
1677     "//        print(\"get inter\\n\");",
1678     "\t    var eline = err.line - offset;",
1679     "\t    GLib.debug(\"GOT ERROR on line %d -- converted to %d  (offset = %d)\",",
1680     "\t    \terr.line ,eline, offset);",
1681     "\t    ",
1682     "\t    ",
1683     "\t    if (eline > tlines || eline < 0) {",
1684     "\t        return;",
1685     "\t    }",
1686     "\t   ",
1687     "\t    ",
1688     "\t    buf.get_iter_at_line( out iter, eline);",
1689     "\t   ",
1690     "\t   ",
1691     "\t\tvar msg = \"Line: %d %s : %s\".printf(eline+1, err.category, err.msg);",
1692     "\t    buf.create_source_mark( msg, err.category, iter);",
1693     "\t    GLib.debug(\"set line %d to %s\", eline, msg);",
1694     "\t    //this.marks.set(eline, msg);",
1695     "\t}",
1696     "\treturn ;",
1697     "",
1698     "",
1699     "",
1700     " ",
1701     "",
1702     "}"
1703    ]
1704   }
1705  ],
1706  "name" : "WindowRooView"
1707 }