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