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