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