Sample/Window.bjs
authorAlan Knowles <alan@akbkhome.com>
Wed, 1 Sep 2010 05:35:26 +0000 (13:35 +0800)
committerAlan Knowles <alan@akbkhome.com>
Wed, 1 Sep 2010 05:35:26 +0000 (13:35 +0800)
Sample/Window.bjs

index fd1d514..74a6368 100644 (file)
                                                                                             "xtype": "WebView",
                                                                                             "|init": "function() {\n    XObject.prototype.init.call(this);\n    // this may not work!?\n    var settings =  this.el.get_settings();\n    settings.enable_developer_extras = true;\n    \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    var _this = this;\n     \n     // init inspector..\n    this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {\n         _this.get('/BottomPane.inspector').el.show();\n         return _this.get('/BottomPane.inspector').el;\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_string( \"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,              /* widget that will accept a drop */\n            Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,\n            null,            /* lists of target to support */\n            0,              /* size of list */\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(0, 1, function() {\n        //    print(\"run refresh?\");\n         _this.runRefresh(); \n         return true;\n     });\n    \n    \n}\n",
                                                                                             "|renderJS": "function(data) {\n    this.refreshRequired  = true;\n}\n",
-                                                                                            "|runRefresh": "function() \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) {\n       // do not redraw if last redraw was less that 5 seconds ago.\n       if (((new Date()) -  this.lastRedraw) < 5000) {\n            return;\n        }\n    }\n    \n    \n    \n    \n     if (!this.get('/Window.LeftTree').getActiveFile()) {\n        return;\n     }\n     this.refreshRequired = false;\n   //  print(\"HTML RENDERING\");\n     \n     this.get('/BottomPane').el.show();\n     this.get('/BottomPane').el.set_current_page(2);// webkit inspector\n\n    \n    var js = this.get('/LeftTree.model').toJS();\n    if (!js || !js.length) {\n        print(\"no data\");\n        return;\n    }\n    var  data = js[0];\n    \n    \n     var project = this.get('/Window.LeftTree').getActiveFile().project;\n     //print (project.fn);\n     // set it to non-empty.\n     project.runhtml  =     project.runhtml  || '';\n     project.runhtml  = project.runhtml.length ?  project.runhtml : '<script type=\"text/javascript\"></script>'; \n    \n\n     this.runhtml  = this.runhtml || '';\n    \n     if (project.runhtml != this.runhtml) {\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         var runhtml = '<script type=\"text/javascript\">' + \"\\n\" ;\n         runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + \"\\n\";\n         runhtml += '</script>'+ \"\\n\" ;\n        \n        this.runhtml = project.runhtml;\n        // need to modify paths\n        \n        \n        \n        var html = imports.File.File.read(__script_path__ + '/../builder.html');\n        html = html.replace('</head>', runhtml + this.runhtml + '</head>');\n        print(\"LOAD HTML \" + html);\n        this.el.load_html_string( html , \n            //fixme - should be a config option!\n            'http://localhost/app.Builder/'\n        );\n        \n        // should trigger load_finished! - which in truns shoudl set refresh Required;\n        return;\n    \n    }\n    \n    \n    this.renderedData = data;\n    var str = JSON.stringify(data) ;\n    \n    if (!this.ready) {\n        console.log('not loaded yet');\n    }\n    this.lastRedraw = new Date();\n    print( \"start render\" +    this.lastRedraw);\n    this.el.execute_script(\"Builder.render(\" + JSON.stringify(data) + \");\");\n    print( \"start render\" +    this.lastRedraw);\n    \n}\n",
+                                                                                            "|runRefresh": "function() \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) {\n       // do not redraw if last redraw was less that 5 seconds ago.\n       if (((new Date()) -  this.lastRedraw) < 5000) {\n            return;\n        }\n    }\n    \n    \n    \n    \n     if (!this.get('/Window.LeftTree').getActiveFile()) {\n        return;\n     }\n     this.refreshRequired = false;\n   //  print(\"HTML RENDERING\");\n     \n     this.get('/BottomPane').el.show();\n     this.get('/BottomPane').el.set_current_page(2);// webkit inspector\n\n    \n    var js = this.get('/LeftTree.model').toJS();\n    if (!js || !js.length) {\n        print(\"no data\");\n        return;\n    }\n    var  data = js[0];\n    \n    \n     var project = this.get('/Window.LeftTree').getActiveFile().project;\n     //print (project.fn);\n     // set it to non-empty.\n     project.runhtml  =     project.runhtml  || '';\n     project.runhtml  = project.runhtml.length ?  project.runhtml : '<script type=\"text/javascript\"></script>'; \n    \n\n     this.runhtml  = this.runhtml || '';\n    \n     if (project.runhtml != this.runhtml) {\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         var runhtml = '<script type=\"text/javascript\">' + \"\\n\" ;\n         runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + \"\\n\";\n         runhtml += '</script>'+ \"\\n\" ;\n        \n        this.runhtml = project.runhtml;\n        // need to modify paths\n        \n        \n        \n        var html = imports.File.File.read(__script_path__ + '/../builder.html');\n        html = html.replace('</head>', runhtml + this.runhtml + '</head>');\n        print(\"LOAD HTML \" + html);\n        this.el.load_html_string( html , \n            //fixme - should be a config option!\n            'http://localhost/app.Builder/'\n        );\n        \n        // should trigger load_finished! - which in truns shoudl set refresh Required;\n        return;\n    \n    }\n    \n    \n    this.renderedData = data;\n    var str = JSON.stringify(data) ;\n    \n    if (!this.ready) {\n        console.log('not loaded yet');\n    }\n    this.lastRedraw = new Date();\n    print( \"start render\" +    this.lastRedraw);\n    this.el.execute_script(\"Builder.render(\" + JSON.stringify(data) + \");\");\n    print( \"after render\" +    (new Date()));\n    \n}\n",
                                                                                             "|xns": "WebKit"
                                                                                         }
                                                                                     ]