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