src/Builder4/WindowRooView.bjs
authorAlan Knowles <alan@roojs.com>
Wed, 3 Jun 2015 03:38:48 +0000 (11:38 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 3 Jun 2015 03:38:48 +0000 (11:38 +0800)
src/Builder4/WindowRooView.vala

src/Builder4/WindowRooView.bjs
src/Builder4/WindowRooView.vala

index 7a76cba..7e436ad 100644 (file)
  "build_module" : "builder",
  "items" : [
   {
-   "id" : "WindowRooView",
-   "| void loadFile" : "(JsRender.JsRender file)\n{\n    this.file = file;\n    this.view.renderJS(true);\n}",
-   "| void createThumb" : "() {\n    \n    \n    if (this.file == null) {\n        return;\n    }\n    var filename = this.file.getIconFileName(false);\n    \n    var  win = this.el.get_parent_window();\n    var width = win.get_width();\n  //  var height = win.get_height();\n    try { \n        Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.el.position);\n        screenshot.save(filename,\"png\");\n    } catch(Error e) {\n        //noop\n    }\n\n    \n    \n    \n\n\n    \n     \n}\n",
-   "* pack" : "add",
-   "xtype" : "Paned",
-   "# JsRender.JsRender file" : "",
-   "| void requestRedraw" : "() {\n    this.view.renderJS(false);\n}",
+   "listeners" : {
+    "size_allocate" : "(aloc) => {\n\n    this.width = aloc.width;\n    this.height =aloc.height;\n}\n "
+   },
+   "| void scroll_to_line" : "(int line) {\n   this.notebook.el.page = 1;// code preview...\n   \n   GLib.Timeout.add(500, () => {\n   \n   \n\t   \n\t   \n\t\t  var buf = this.sourceview.el.get_buffer();\n\t \n\t\tvar sbuf = (Gtk.SourceBuffer) buf;\n\n\n\t\tGtk.TextIter iter;   \n\t\tsbuf.get_iter_at_line(out iter,  line);\n\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);\n\t\treturn false;\n\t});   \n\n   \n}\n",
+   "id" : "GtkView",
+   "# Gtk.Widget lastObj" : "null",
+   "| void createThumb" : "() {\n    \n    \n    if (this.file == null) {\n        return;\n    }\n    // only screenshot the gtk preview..\n    if (this.notebook.el.page > 0 ) {\n        return;\n    }\n    \n    \n    var filename = this.file.getIconFileName(false);\n    \n    var  win = this.el.get_parent_window();\n    var width = win.get_width();\n    var height = win.get_height();\n    try {\n         Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?\n         screenshot.save(filename,\"png\");\n    } catch (Error e) {\n        \n    }\n\n   \n    return;\n    \n    \n     \n     \n    \n    // should we hold until it's printed...\n    \n      \n\n    \n    \n\n\n    \n     \n}\n",
+   "| void loadFile" : "(JsRender.JsRender file) \n{\n        this.file = null;\n        \n        if (file.tree == null) {\n            return;\n        }\n        this.notebook.el.page = 0;// gtk preview \n   \n  \n        \n       this.file = file;     \n        this.sourceview.loadFile();\n        this.searchcontext = null;\n        \n\n        if (this.lastObj != null) {\n            this.container.el.remove(this.lastObj);\n        }\n        \n        // hide the compile view at present..\n          \n        \n        var w = this.width;\n        var h = this.height;\n        \n        print(\"ALLOC SET SIZES %d, %d\\n\", w,h); \n        \n        // set the container size min to 500/500 or 20 px less than max..\n        w = int.max (w-20, 500);\n        h = int.max (h-20, 500); \n        \n        print(\"SET SIZES %d, %d\\n\", w,h);       \n        _this.container.el.set_size_request(w,h);\n        \n        _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.\n        var rgba = Gdk.RGBA ();\n        rgba.parse (\"#ccc\");\n        _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);\n        \n        \n\tvar x = new JsRender.NodeToGtk(file.tree);\n        var obj = x.munge() as Gtk.Widget;\n        this.lastObj = null;\n\tif (obj == null) {\n        \treturn;\n\t}\n\tthis.lastObj = obj;\n        \n        this.container.el.add(obj);\n        obj.show_all();\n        \n         \n        \n}\n ",
+   "int width" : 0,
+   "bool hexpand" : true,
+   "| int search" : "(string txt) {\n\tthis.notebook.el.page = 1;\n \tvar s = new Gtk.SourceSearchSettings();\n\tvar buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();\n\tthis.searchcontext = new Gtk.SourceSearchContext(buf,s);\n\tthis.searchcontext.set_highlight(true);\n\ts.set_search_text(txt);\n\t\n\tGtk.TextIter beg, st,en;\n\t \n\tbuf.get_start_iter(out beg);\n\tthis.searchcontext.forward(beg, out st, out en);\n\tthis.last_search_end  = 0;\n\treturn this.searchcontext.get_occurrences_count();\n\n   \n}\n",
+   "int last_search_end" : 0,
+   "xtype" : "Box",
+   "Gtk.SourceSearchContext searchcontext" : "",
+   "# JsRender.JsRender file" : "null",
+   "int height" : 0,
    "$ xns" : "Gtk",
    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
+   "# Xcls_MainWindow main_window" : "",
+   "| void forwardSearch" : "() {\n\n\tif (this.searchcontext == null) {\n\t\treturn;\n\t}\n\tthis.notebook.el.page = 1;\n\tGtk.TextIter beg, st,en, stl;\n\t\n\tvar buf = this.sourceview.el.get_buffer();\n\tbuf.get_iter_at_offset(out beg, this.last_search_end);\n\tif (!this.searchcontext.forward(beg, out st, out en)) {\n\t\tthis.last_search_end = 0;\n\t} else { \n\t\tthis.last_search_end = en.get_offset();\n\t\n\t\tthis.sourceview.el.grab_focus();\n\t \n\t\tbuf.place_cursor(st);\n\t\tvar ln = st.get_line();\n\t\tbuf.get_iter_at_line(out stl,ln);\n\t\t \n\t\tthis.sourceview.el.scroll_to_iter(stl,  0.0f, true, 0.0f, 0.5f);\n\t}\n\n}\n",
    "items" : [
     {
-     "id" : "viewbox",
-     "xtype" : "Box",
-     "* pack" : "pack1,true,true",
+     "id" : "notebook",
+     "* pack" : "pack_start,true,true,0",
+     "xtype" : "Notebook",
      "$ xns" : "Gtk",
-     "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
-     "$ homogeneous" : false,
      "items" : [
       {
-       "$ vexpand" : false,
-       "* pack" : "pack_start,false,true,0",
-       "$ height_request" : 20,
-       "xtype" : "Box",
+       "id" : "label_preview",
+       "* pack" : false,
+       "xtype" : "Label",
+       "$ xns" : "Gtk",
+       "utf8 label" : "Preview"
+      },
+      {
+       "id" : "label_code",
+       "xtype" : "Label",
+       "* pack" : false,
+       "$ xns" : "Gtk",
+       "utf8 label" : "Preview Generated Code"
+      },
+      {
+       "* pack" : "append_page,_this.label_preview.el",
+       "xtype" : "ScrolledWindow",
        "$ xns" : "Gtk",
-       "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
-       "$ homogeneous" : true,
        "items" : [
         {
-         "listeners" : {
-          "clicked" : "( ) => {\n    _this.view.renderJS(  true);\n}"
-         },
-         "label" : "Redraw",
-         "* pack" : "pack_start,false,false,0",
-         "xtype" : "Button",
-         "$ xns" : "Gtk"
-        },
-        {
-         "listeners" : {
-          "toggled" : " (state) => {\n    this.el.set_label(this.el.active  ? \"Auto Redraw On\" : \"Auto Redraw Off\");\n}"
-         },
-         "label" : "Auto Redraw On",
-         "id" : "AutoRedraw",
-         "$ active" : true,
-         "* pack" : "pack_start,false,false,0",
-         "xtype" : "CheckButton",
-         "$ xns" : "Gtk"
-        },
-        {
-         "listeners" : {
-          "clicked" : " () => {\n  _this.view.redraws = 99;\n    _this.view.el.web_context.clear_cache();  \n  //_this.view.renderJS(true);\n  FakeServerCache.clear();\n  _this.view.reInit();\n\n}"
-         },
-         "label" : "Full Redraw",
-         "* pack" : "pack_start,false,false,0",
-         "xtype" : "Button",
-         "$ xns" : "Gtk"
+         "id" : "view_layout",
+         "xtype" : "Layout",
+         "* pack" : "add",
+         "$ xns" : "Gtk",
+         "items" : [
+          {
+           "id" : "container",
+           "* pack" : "put,10,10",
+           "xtype" : "Box",
+           "$ xns" : "Gtk",
+           "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL"
+          }
+         ]
         }
        ]
       },
       {
-       "id" : "viewcontainer",
-       "$ shadow_type" : "Gtk.ShadowType.IN",
-       "* init" : "  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);\n \n",
-       "* pack" : "pack_end,true,true,0",
        "xtype" : "ScrolledWindow",
+       "* pack" : "append_page,_this.label_code.el",
        "$ xns" : "Gtk",
        "items" : [
         {
-         "listeners" : {
-          "script_dialog" : " (dialog) => {\n    if (this.el == null) {\n        return true;\n    }\n    \n     var msg = dialog.get_message();\n     if (msg.length < 4) {\n        return false;\n     }\n     if (msg.substring(0,4) != \"IPC:\") {\n         return false;\n     }\n     var ar = msg.split(\":\", 3);\n    if (ar.length < 3) {\n        return false;\n    }\n    switch(ar[1]) {\n        case \"SAVEHTML\":\n            _this.file.saveHTML(ar[2]);\n            return true;\n        default:\n            return false;\n    }\n    \n}",
-          "show" : "  ( ) => {\n    this.initInspector();;\n}",
-          "drag_drop" : "  ( ctx, x, y,time, ud) => {\n    return false;\n    /*\n\tprint(\"TARGET: drag-drop\");\n        var is_valid_drop_site = true;\n        \n         \n        Gtk.drag_get_data\n        (\n                w,         // will receive 'drag-data-received' signal \n                ctx,        /* represents the current state of the DnD \n                this.get('/Window').atoms[\"STRING\"],    /* the target type we want \n                time            /* time stamp \n        );\n                        \n                        \n                        /* No target offered by source => error \n                       \n\n\treturn  is_valid_drop_site;\n\t*/\n}",
-          "load_changed" : "(le) => {\n    if (le != WebKit.LoadEvent.FINISHED) {\n        return;\n    }\n    if (this.runjs.length < 1) {\n        return;\n    }\n  //  this.el.run_javascript(this.runjs, null);\n     FakeServerCache.remove(    this.runjs);\n    this.runjs = \"\";\n}"
-         },
-         "# string renderedData" : "\"\"",
-         "id" : "view",
-         "# bool refreshRequired" : false,
-         "* init" : " {\n    // this may not work!?\n    var settings =  this.el.get_settings();\n    settings.enable_developer_extras = true;\n    \n    \n    var fs= new FakeServer(this.el);\n    fs.ref();\n    // this was an attempt to change the url perms.. did not work..\n    // settings.enable_file_access_from_file_uris = true;\n    // settings.enable_offline_web_application_cache - true;\n    // settings.enable_universal_access_from_file_uris = true;\n   \n     \n    \n    \n    \n\n     // FIXME - base url of script..\n     // we need it so some of the database features work.\n    this.el.load_html( \"Render not ready\" , \n            //fixme - should be a config option!\n            // or should we catch stuff and fix it up..\n            \"http://localhost/app.Builder/\"\n    );\n        \n        \n   //this.el.open('file:///' + __script_path__ + '/../builder.html');\n    /*\n    Gtk.drag_dest_set\n    (\n            this.el,              //\n            Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,\n            null,            // list of targets\n            Gdk.DragAction.COPY         // what to do with data after dropped \n    );\n                            \n   // print(\"RB: TARGETS : \" + LeftTree.atoms[\"STRING\"]);\n    Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);\n    */\n    GLib.Timeout.add_seconds(1,  ()  =>{\n         //print(\"run refresh?\");\n         if (this.el == null) {\n            return false;\n         }\n         this.runRefresh(); \n         return true;\n     });\n    \n    \n}\n",
-         "| void reInit" : "() {\n   print(\"reInit?\");\n         // if this happens destroy the webkit..\n         // recreate it..\n     this.el.stop_loading();\n         \n     if (_this.viewbox.el.get_parent() == null) {\n        return;\n     }\n         \n         \n    _this.viewbox.el.remove(_this.viewcontainer.el);\n    _this.el.remove(_this.inspectorcontainer.el);        \n         \n         // destory seems to cause problems.\n         //this.el.destroy();\n        //_this.viewcontainer.el.destroy();\n         //_this.inspectorcontainer.el.destroy();\n     var  inv =new Xcls_inspectorcontainer(_this);\n      inv.ref();\n      _this.el.pack2(inv.el,true,true);\n      \n      \n     this.el = null;         \n     var nv =new Xcls_viewcontainer(_this);\n     nv.ref();\n     _this.viewbox.el.pack_end(nv.el,true,true,0);\n         \n         \n     inv.el.show_all();\n     nv.el.show_all();\n         //while(Gtk.events_pending ()) Gtk.main_iteration ();\n         //_this.view.renderJS(true); \n     _this.view.refreshRequired  = true;\n}\n",
+         "gboolean show_line_marks" : true,
+         "id" : "sourceview",
+         "* init" : "{\n   \n    var description =   Pango.FontDescription.from_string(\"monospace\");\n    description.set_size(8000);\n    this.el.override_font(description);\n\n    this.loading = true;\n    var buf = this.el.get_buffer();\n    buf.notify.connect((ps) => {\n        if (this.loading) {\n            return;\n        }\n        if (ps.name != \"cursor-position\") {\n            return;\n        }\n        print(\"cursor changed : %d\\n\", buf.cursor_position);\n        Gtk.TextIter cpos;\n        buf.get_iter_at_offset(out cpos, buf.cursor_position);\n        \n        var ln = cpos.get_line();\n \n        var node = _this.file.lineToNode(ln);\n \n        if (node == null) {\n            print(\"can not find node\\n\");\n            return;\n        }\n        var ltree = _this.main_window.windowstate.left_tree;\n        var tp = ltree.model.treePathFromNode(node);\n        print(\"got tree path %s\\n\", tp);\n        if (tp != \"\") {\n\t       this.allow_node_scroll = false;        \n\t       print(\"changing cursor on tree..\\n\");\n            ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);\n            // scrolling is disabled... as node selection calls scroll 10ms after it changes.\n            GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {\n\t            this.allow_node_scroll = true;\n\t            return false;\n            });\n        }\n        \n        // highlight the node..\n        \n    });\n  \n  \n  \n    var attrs = new Gtk.SourceMarkAttributes();\n    var  pink =   Gdk.RGBA();\n    pink.parse ( \"pink\");\n    attrs.set_background ( pink);\n    attrs.set_icon_name ( \"process-stop\");    \n    attrs.query_tooltip_text.connect(( mark) => {\n        //print(\"tooltip query? %s\\n\", mark.name);\n        return mark.name;\n    });\n    \n    this.el.set_mark_attributes (\"ERR\", attrs, 1);\n    \n     var wattrs = new Gtk.SourceMarkAttributes();\n    var  blue =   Gdk.RGBA();\n    blue.parse ( \"#ABF4EB\");\n    wattrs.set_background ( blue);\n    wattrs.set_icon_name ( \"process-stop\");    \n    wattrs.query_tooltip_text.connect(( mark) => {\n        //print(\"tooltip query? %s\\n\", mark.name);\n        return mark.name;\n    });\n    \n    this.el.set_mark_attributes (\"WARN\", wattrs, 1);\n    \n \n    \n     var dattrs = new Gtk.SourceMarkAttributes();\n    var  purple =   Gdk.RGBA();\n    purple.parse ( \"#EEA9FF\");\n    dattrs.set_background ( purple);\n    dattrs.set_icon_name ( \"process-stop\");    \n    dattrs.query_tooltip_text.connect(( mark) => {\n        //print(\"tooltip query? %s\\n\", mark.name);\n        return mark.name;\n    });\n    \n    this.el.set_mark_attributes (\"DEPR\", dattrs, 1);\n    \n    \n    var gattrs = new Gtk.SourceMarkAttributes();\n    var  grey =   Gdk.RGBA();\n    grey.parse ( \"#ccc\");\n    gattrs.set_background ( grey);\n \n    \n    this.el.set_mark_attributes (\"grey\", gattrs, 1);\n    \n    \n    \n    \n    \n    \n}\n ",
+         "| void nodeSelected" : "(JsRender.Node? sel) {\n  \n    \n  \n    // this is connected in widnowstate\n    print(\"node selected\\n\");\n    var buf = this.el.get_buffer();\n \n    var sbuf = (Gtk.SourceBuffer) buf;\n\n   \n    while(Gtk.events_pending()) {\n        Gtk.main_iteration();\n    }\n    \n   \n    // clear all the marks..\n     Gtk.TextIter start;\n    Gtk.TextIter end;     \n        \n    sbuf.get_bounds (out start, out end);\n    sbuf.remove_source_marks (start, end, \"grey\");\n    \n    \n     if (sel == null) {\n        // no highlighting..\n        return;\n    }\n    Gtk.TextIter iter;   \n    sbuf.get_iter_at_line(out iter,  sel.line_start);\n    \n    \n    Gtk.TextIter cur_iter;\n    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);\n    \n    //var cur_line = cur_iter.get_line();\n    //if (cur_line > sel.line_start && cur_line < sel.line_end) {\n    \n    //} else {\n    if (this.allow_node_scroll) {\n\t\t \n    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);\n\t}\n    \n     \n    \n    for (var i = 0; i < buf.get_line_count();i++) {\n        if (i < sel.line_start || i > sel.line_end) {\n           \n            sbuf.get_iter_at_line(out iter, i);\n            sbuf.create_source_mark(null, \"grey\", iter);\n            \n        }\n    \n    }\n    \n\n}\n",
+         "bool loading" : true,
+         "| string toString" : "() {\n   Gtk.TextIter s;\n    Gtk.TextIter e;\n    this.el.get_buffer().get_start_iter(out s);\n    this.el.get_buffer().get_end_iter(out e);\n    var ret = this.el.get_buffer().get_text(s,e,true);\n    //print(\"TO STRING? \" + ret);\n    return ret;\n}\n",
+         "| void loadFile" : "( ) {\n    this.loading = true;\n    var buf = this.el.get_buffer();\n    buf.set_text(\"\",0);\n    var sbuf = (Gtk.SourceBuffer) buf;\n\n    \n\n    if (_this.file == null || _this.file.xtype != \"Gtk\") {\n        print(\"xtype != Gtk\");\n        this.loading = false;\n        return;\n    }\n    \n    var valafn = \"\";\n      try {             \n           var  regex = new Regex(\"\\\\.bjs$\");\n        \n         \n            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");\n         } catch (GLib.RegexError e) {\n             this.loading = false;\n            return;\n        }   \n    \n\n   if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {\n        print(\"File path has no errors\\n\");\n        this.loading = false;\n        return  ;\n    }\n    \n    string str;\n    try {\n    \n        GLib.FileUtils.get_contents (valafn, out str);\n    } catch (Error e) {\n        this.loading = false;\n        return  ;\n    }\n\n//    print(\"setting str %d\\n\", str.length);\n    buf.set_text(str, str.length);\n    var lm = Gtk.SourceLanguageManager.get_default();\n     \n    //?? is javascript going to work as js?\n    \n    ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));\n  \n    \n    Gtk.TextIter start;\n    Gtk.TextIter end;     \n        \n    sbuf.get_bounds (out start, out end);\n    sbuf.remove_source_marks (start, end, null); // remove all marks..\n    \n    \n    if (_this.main_window.windowstate.last_compile_result != null) {\n        var obj = _this.main_window.windowstate.last_compile_result;\n        this.highlightErrorsJson(\"ERR\", obj);\n        this.highlightErrorsJson(\"WARN\", obj);\n        this.highlightErrorsJson(\"DEPR\", obj);\t\t\t\n    }\n    //while (Gtk.events_pending()) {\n     //   Gtk.main_iteration();\n   // }\n    \n    this.loading = false; \n}\n",
          "* pack" : "add",
-         "redraws" : 0,
-         "xtype" : "WebView",
-         "# WebKit.WebInspector inspector" : "",
-         "# string runjs" : "\"\"",
-         "# int redraws" : 0,
-         "| void runRefresh" : " () \n{\n    // this is run every 2 seconds from the init..\n\n  \n    \n    if (!this.refreshRequired) {\n       // print(\"no refresh required\");\n        return;\n    }\n\n    if (this.lastRedraw != null) {\n       // do not redraw if last redraw was less that 5 seconds ago.\n       if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {\n            return;\n        }\n    }\n    \n    if (_this.file == null) {\n        return;\n    }\n    \n    \n     this.refreshRequired = false;\n   //  print(\"HTML RENDERING\");\n     \n     \n     //this.get('/BottomPane').el.show();\n     //this.get('/BottomPane').el.set_current_page(2);// webkit inspector\n    _this.file.webkit_page_id  = this.el.get_page_id();\n    \n    var js = _this.file.toSourcePreview();\n\n    if (js.length < 1) {\n        print(\"no data\");\n        return;\n    }\n//    var  data = js[0];\n    this.redraws++;\n  \n    var project = _this.file.project;  \n\n     //print (project.fn);\n     // set it to non-empty.\n     \n//     runhtml = runhtml.length ?  runhtml : '<script type=\"text/javascript\"></script>'; \n\n\n//   this.runhtml  = this.runhtml || '';\n \n \n    // then we need to reload the browser using\n    // load_html_string..\n\n    // then trigger a redraw once it's loaded..\n    this.pendingRedraw = true;\n\n    var runhtml = \"<script type=\\\"text/javascript\\\">\\n\" ;\n    string builderhtml;\n    \n    try {\n        GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + \"/resources/roo.builder.js\", out builderhtml);\n    } catch (Error e) {\n        builderhtml = \"\";\n    }\n\n    runhtml += builderhtml + \"\\n\";\n    runhtml += \"</script>\\n\" ;\n\n    // fix to make sure they are the same..\n    this.runhtml = project.runhtml;\n    // need to modify paths\n\n    string inhtml;\n    var base_template = _this.file.project.base_template;\n    \n    if (base_template.length > 0 && !FileUtils.test(\n        BuilderApplication.configDirectory() + \"/resources/\" +  base_template, FileTest.EXISTS)  \n        ) {\n           print(\"invalid base_template name - using default:  %s\\n\", base_template);\n           base_template = \"\";\n    \n    }\n    try {\n        GLib.FileUtils.get_contents(\n            BuilderApplication.configDirectory() + \"/resources/\" + \n                (base_template.length > 0 ? base_template :  \"roo.builder.html\")\n                , out inhtml);\n    \n    } catch (Error e) {\n        inhtml = \"\";\n    }    \n    this.renderedData = js;\n\n\n    string js_src = js + \"\\n\" +\n\t\"Roo.onReady(function() {\\n\" +\n\t\"if (\" + _this.file.name +\".show) \" +  _this.file.name +\".show({});\\n\" +\n\t\"Roo.XComponent.build();\\n\" +\n\t\"});\\n\";\n\t\n   // print(\"render js: \" + js);\n    //if (!this.ready) {\n  //      console.log('not loaded yet');\n    //}\n    this.lastRedraw = new DateTime.now_local();\n\n\n    //this.runjs = js_src;\n    var fc =    FakeServerCache.factory_with_data(js_src);\n    this.runjs = fc.fname;\n    \n        var html = inhtml.replace(\"</head>\", runhtml + this.runhtml + \n            \"<script type=\\\"text/javascript\\\" src=\\\"xhttp://localhost\" + fc.fname + \"\\\"></script>\" +   \n              //  \"<script type=\\\"text/javascript\\\">\\n\" +\n              //  js_src + \"\\n\" + \n              //  \"</script>\" + \n                        \n        \"</head>\");\n        //print(\"LOAD HTML \" + html);\n        \n         var rootURL = _this.file.project.rootURL;\n   \n        \n        \n        this.el.load_html( html , \n            //fixme - should be a config option!\n            (rootURL.length > 0 ? rootURL : \"xhttp://localhost/app.Builder.js/\")\n        );\n        \n    // force the inspector...        \n       //   this.initInspector();\n        \n        // - no need for this, the builder javascript will call it when build is complete\n        //GLib.Timeout.add_seconds(1, () => {\n        //    this.el.run_javascript(\"Builder.saveHTML()\",null);\n        //    return false;\n        //});\n//     print( \"before render\" +    this.lastRedraw);\n//    print( \"after render\" +    (new Date()));\n    \n}\n                                                                                                                                                                                                                        ",
-         "$ xns" : "WebKit",
-         "| void initInspector" : "() {\n    \n   /* if (this.inspector == this.el.get_inspector()) {\n        this.inspector.show();\n        this.inspector.open_window();        \n        print(\"init inspecter called, and inspector is the same as existing\\n\");\n        return;\n    }\n    print(\"new inspector?\\n\");\n*/\n    this.inspector = this.el.get_inspector();\n    this.inspector.ref();\n    \n    // got a new inspector...\n        \n    this.inspector.open_window.connect(() => {\n         this.inspector = this.el.get_inspector();\n        print(\"inspector attach\\n\");\n        var wv = this.inspector.get_web_view();\n        if (wv != null) {\n            print(\"got inspector web view\\n\");\n            \n            var cn = _this.inspectorcontainer.el.get_child();\n            if (cn != null) {\n                 _this.inspectorcontainer.el.remove(cn);\n             }\n            \n            _this.inspectorcontainer.el.add(wv);\n            wv.show();\n        } else {\n            //this.inspector.close();\n            \n            //this.inspector = null;\n           \n \n        }\n        return true;\n       \n    });\n    /*\n    this.inspector.closed.connect(() => {\n         print(\"inspector closed?!?\");\n         // if this happens destroy the webkit..\n         // recreate it..\n         this.el.stop_loading();\n         \n         if (_this.viewbox.el.get_parent() == null) {\n            return;\n         }\n         \n         \n        _this.viewbox.el.remove(_this.viewcontainer.el);\n        _this.el.remove(_this.inspectorcontainer.el);        \n         \n         // destory seems to cause problems.\n         //this.el.destroy();\n        //_this.viewcontainer.el.destroy();\n         //_this.inspectorcontainer.el.destroy();\n\n         this.el = null;         \n         var nv =new Xcls_viewcontainer(_this);\n         nv.ref();\n         _this.viewbox.el.pack_end(nv.el,true,true,0);\n         \n          var  inv =new Xcls_inspectorcontainer(_this);\n          inv.ref();\n          _this.el.pack2(inv.el,true,true);\n         \n         inv.el.show_all();\n         nv.el.show_all();\n         //while(Gtk.events_pending ()) Gtk.main_iteration ();\n         //_this.view.renderJS(true); \n         _this.view.refreshRequired  = true;\n       \n    }); \n    */\n    \n    this.inspector.show();\n}\n",
-         "# GLib.DateTime lastRedraw" : "null",
-         "# string runhtml" : "\"\"",
-         "# bool pendingRedraw" : false,
-         "| void renderJS" : "(bool force) {\n\n    // this is the public redraw call..\n    // we refresh in a loop privately..\n    var autodraw = _this.AutoRedraw.el.active;\n    if (!autodraw && !force) {\n        print(\"Skipping redraw - no force, and autodraw off\");\n        return;\n    }\n     \n    this.refreshRequired  = true;\n}\n"
+         "xtype" : "SourceView",
+         "bool allow_node_scroll" : true,
+         "| void highlightErrorsJson" : " (string type, Json.Object obj) {\n      Gtk.TextIter start;\n     Gtk.TextIter end;   \n     \n     var buf =  this.el.get_buffer();\n       var sbuf = (Gtk.SourceBuffer)buf;\n        buf.get_bounds (out start, out end);\n        \n        sbuf.remove_source_marks (start, end, type);\n                 \n     \n     // we should highlight other types of errors..\n    \n    if (!obj.has_member(type)) {\n        print(\"Return has no errors\\n\");\n        return  ;\n    }\n    var err = obj.get_object_member(type);\n    \n    if (_this.file == null) { \n        return; // just in case the file has not loaded yet?\n    }\n \n\n    var valafn = \"\";\n      try {             \n           var  regex = new Regex(\"\\\\.bjs$\");\n        \n         \n            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");\n         } catch (GLib.RegexError e) {\n            return;\n        }   \n\n   if (!err.has_member(valafn)) {\n        print(\"File path has no errors\\n\");\n        return  ;\n    }\n    var lines = err.get_object_member(valafn);\n    \n   \n    \n    var tlines = buf.get_line_count () +1;\n    \n    lines.foreach_member((obj, line, node) => {\n        \n             Gtk.TextIter iter;\n    //        print(\"get inter\\n\");\n            var eline = int.parse(line) -1  ;\n            print(\"GOT ERROR on line %s -- converted to %d\\n\", line,eline);\n            \n            \n            if (eline > tlines || eline < 0) {\n                return;\n            }\n            sbuf.get_iter_at_line( out iter, eline);\n            //print(\"mark line\\n\");\n            var msg  = type + \" on line: %d - %s\".printf(eline+1, valafn);\n            var ar = lines.get_array_member(line);\n            for (var i = 0 ; i < ar.get_length(); i++) {\n\t\t    msg += (msg.length > 0) ? \"\\n\" : \"\";\n\t\t    msg += ar.get_string_element(i);\n\t    }\n            \n            \n            sbuf.create_source_mark(msg, type, iter);\n        } );\n        return  ;\n    \n \n\n\n}",
+         "$ xns" : "Gtk",
+         "gboolean show_line_numbers" : true,
+         "gboolean editable" : false
         }
        ]
       }
      ]
-    },
-    {
-     "id" : "inspectorcontainer",
-     "$ shadow_type" : "Gtk.ShadowType.IN",
-     "* init" : "  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);\n \n",
-     "xtype" : "ScrolledWindow",
-     "* pack" : "pack2,true,true",
-     "$ xns" : "Gtk"
     }
    ]
   }
index 3abbc0c..527cf9e 100644 (file)
@@ -52,7 +52,7 @@ public class Xcls_GtkView : Object
         
             this.width = aloc.width;
             this.height =aloc.height;
-            });
+        });
     }
 
     // user defined functions
@@ -111,7 +111,9 @@ public class Xcls_GtkView : Object
         // should we hold until it's printed...
         
           
-     
+    
+        
+