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