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