resources/RooUsage.txt
[app.Builder.js] / src / Builder4 / DialogPluginWebkit.vala
index b278857..e4c46f4 100644 (file)
@@ -1,6 +1,6 @@
 static Xcls_DialogPluginWebkit  _DialogPluginWebkit;
 
-public class Xcls_DialogPluginWebkit : Object 
+public class Xcls_DialogPluginWebkit : Object
 {
     public Gtk.Dialog el;
     private Xcls_DialogPluginWebkit  _this;
@@ -16,8 +16,9 @@ public class Xcls_DialogPluginWebkit : Object
 
         // my vars (def)
     public string tmpjs;
+    public string result_json;
 
-    // ctor 
+    // ctor
     public Xcls_DialogPluginWebkit()
     {
         _this = this;
@@ -28,10 +29,10 @@ public class Xcls_DialogPluginWebkit : Object
         // set gobject values
         this.el.title = "Add / Edit Component";
         this.el.default_height = 500;
-        this.el.default_width = 500;
+        this.el.default_width = 750;
         this.el.deletable = true;
         this.el.modal = true;
-        var child_0 = new Xcls_VBox2( _this );
+        var child_0 = new Xcls_Box2( _this );
         child_0.ref();
         this.el.get_content_area().add (  child_0.el  );
         var child_1 = new Xcls_Button5( _this );
@@ -44,7 +45,7 @@ public class Xcls_DialogPluginWebkit : Object
         child_3.ref();
         this.el.add_action_widget (  child_3.el , 1 );
 
-        // listeners 
+        //listeners
         this.el.delete_event.connect( (self, event) => {
             this.el.hide();
             return true; 
@@ -52,30 +53,35 @@ public class Xcls_DialogPluginWebkit : Object
         });
     }
 
-    // user defined functions 
-    public string show (Gtk.Window ?parent, string text) {// JsRender.Node node) {
+    // user defined functions
+    public string show (Gtk.Window ?parent, Project.Project project, string cls, string tbl) {// JsRender.Node node) {
      
         if (parent  != null) {
             this.el.set_transient_for(parent);
             this.el.modal = true;
         }
-           var db = new JsRender.RooDatabase.from_cfg ("MySQL", "hydra", "root", "");
+        this.result_json = "";
+         var  db = project.roo_database;
          
         
          this.el.show_all();
          var   ret = "";
-        while (true) {
+         while (true) {
         
             var runhtml = "<script type=\"text/javascript\">\n" ;
             string builderhtml;
             
+            try {
+                GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
+            } catch (Error e) {
+                builderhtml = "";
+            }
             
-            GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
     
             runhtml += builderhtml + "\n";
             
             
-               runhtml += "\n" +
+            runhtml += "\n" +
                 "Builder.saveHTML = function() {};\n" + 
            "Roo.onReady(function() {\n" +
     
@@ -85,7 +91,7 @@ public class Xcls_DialogPluginWebkit : Object
        
             
     
-            var ar = db.readForeignKeys("Person");
+            var ar = db.readForeignKeys(tbl);
             var  generator = new Json.Generator ();
             var  root = new Json.Node(Json.NodeType.OBJECT);
             root.init_object(ar);
@@ -96,7 +102,7 @@ public class Xcls_DialogPluginWebkit : Object
             
             runhtml += "\n" +
             " Roo.XComponent.on('buildcomplete', function() {\n" +
-             "    Editor.Roo.grid.Grid.panel.loadData(" + generator.to_data (null) + "); " +
+             "    Editor." + cls + ".panel.loadData(" + generator.to_data (null) + "); " +
             "});\n";
     
             
@@ -111,22 +117,21 @@ public class Xcls_DialogPluginWebkit : Object
             // need to modify paths
     
             string inhtml;
+            try {
+                GLib.FileUtils.get_contents(
+                    BuilderApplication.configDirectory() + "/resources/roo.builder.html"
+                        , out inhtml);
             
-            GLib.FileUtils.get_contents(
-                BuilderApplication.configDirectory() + "/resources/roo.builder.html"
-                    , out inhtml);
-            
-            
+            } catch (Error e) {
+                inhtml = "";
+            }
             // fetch the json from the database...
             
             //print(runhtml);
             
             var html = inhtml.replace("</head>", runhtml + // + this.runhtml + 
-                "<script type=\"text/javascript\" src=\"xhttp://localhost/app.Builder.js/resources/Editors/Editor.Roo.grid.Grid.js\"></script>" + 
-          //      "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +   
-                  //  "<script type=\"text/javascript\">\n" +
-                  //  js_src + "\n" + 
-                  //  "</script>" + 
+                "<script type=\"text/javascript\" src=\"resources://localhost/Editors/Editor." + cls + ".js\"></script>" + 
+          
                             
             "</head>");
             //print("LOAD HTML " + html);
@@ -143,19 +148,34 @@ public class Xcls_DialogPluginWebkit : Object
             
         
        
-            var response_id = this.el.run();
+             var response_id = this.el.run();
             
-             if (response_id == 3) {
-                 this.webview.el.execute_script("Editor.Roo.grid.Grid.panel.toBJS()");
-                
-                 continue;
+             if (response_id == 1) { // OK...
+                 var loop = new MainLoop();
+                 // run toBJS to get the data... (calls back into alert handler)
+                    _this.result_json = "";
+                     this.webview.el.run_javascript.begin("Editor." + cls + ".panel.toBJS();", null, (obj, res) => {
+                         try {
+                            this.webview.el.run_javascript.end(res);
+                        } catch(Error e) {
+                    
+                         }
+                         loop.quit();
+                     });
+                     loop.run();
+                     ret = _this.result_json;
+                     
+                 
+        //           print("LOOP END?");
+                 // try and get the resopse...
+                break;
              }
             if (response_id < 1) {
                 this.el.hide();
                  return "";
             }
             // keep showing...?
-            break;
+            continue;
         }
         
         // now we save it..
@@ -166,31 +186,42 @@ public class Xcls_DialogPluginWebkit : Object
         
         
     }
-    public class Xcls_VBox2 : Object 
+    public bool has_plugin (string cls) {
+    
+         return GLib.FileUtils.test(
+                BuilderApplication.configDirectory() + "/resources/Editors/Editor." + cls + ".js",
+                GLib.FileTest.IS_REGULAR
+          );
+        
+    
+    
+    }
+    public class Xcls_Box2 : Object
     {
-        public Gtk.VBox el;
+        public Gtk.Box el;
         private Xcls_DialogPluginWebkit  _this;
 
 
             // my vars (def)
 
-        // ctor 
-        public Xcls_VBox2(Xcls_DialogPluginWebkit _owner )
+        // ctor
+        public Xcls_Box2(Xcls_DialogPluginWebkit _owner )
         {
             _this = _owner;
-            this.el = new Gtk.VBox( false, 0 );
+            this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
 
             // my vars (dec)
 
             // set gobject values
+            this.el.homogeneous = false;
             var child_0 = new Xcls_ScrolledWindow3( _this );
             child_0.ref();
             this.el.pack_start (  child_0.el , false,true,3 );
         }
 
-        // user defined functions 
+        // user defined functions
     }
-    public class Xcls_ScrolledWindow3 : Object 
+    public class Xcls_ScrolledWindow3 : Object
     {
         public Gtk.ScrolledWindow el;
         private Xcls_DialogPluginWebkit  _this;
@@ -198,7 +229,7 @@ public class Xcls_DialogPluginWebkit : Object
 
             // my vars (def)
 
-        // ctor 
+        // ctor
         public Xcls_ScrolledWindow3(Xcls_DialogPluginWebkit _owner )
         {
             _this = _owner;
@@ -212,14 +243,14 @@ public class Xcls_DialogPluginWebkit : Object
             child_0.ref();
             this.el.add (  child_0.el  );
 
-            // init method 
+            // init method
 
             this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
         }
 
-        // user defined functions 
+        // user defined functions
     }
-    public class Xcls_webview : Object 
+    public class Xcls_webview : Object
     {
         public WebKit.WebView el;
         private Xcls_DialogPluginWebkit  _this;
@@ -227,7 +258,7 @@ public class Xcls_DialogPluginWebkit : Object
 
             // my vars (def)
 
-        // ctor 
+        // ctor
         public Xcls_webview(Xcls_DialogPluginWebkit _owner )
         {
             _this = _owner;
@@ -238,7 +269,7 @@ public class Xcls_DialogPluginWebkit : Object
 
             // set gobject values
 
-            // init method 
+            // init method
 
             {
                 // this may not work!?
@@ -270,7 +301,7 @@ public class Xcls_DialogPluginWebkit : Object
                 
             }
 
-            // listeners 
+            //listeners
             this.el.script_dialog.connect( (dialog) => {
                 if (this.el == null) {
                     return true;
@@ -288,12 +319,18 @@ public class Xcls_DialogPluginWebkit : Object
                     return false;
                 }
                 print("CMD: %s\n",ar[1]);
-                    print("ARGS: %s\n",ar[2]);
+                print("ARGS: %s\n",ar[2]);
                 switch(ar[1]) {
+                
                     case "SAVEHTML":
-                      print("%sw",ar[2]);
-                      //  _this.file.saveHTML(ar[2]);
+                        // print("%sw",ar[2]);
+                        //  _this.file.saveHTML(ar[2]);
                         return true;
+                        
+                    case "OUT":
+                        _this.result_json = ar[2];
+                        return true;
+                        
                     default:
                         return true;
                 }
@@ -301,9 +338,12 @@ public class Xcls_DialogPluginWebkit : Object
             });
         }
 
-        // user defined functions 
+        // user defined functions
     }
-    public class Xcls_Button5 : Object 
+
+
+
+    public class Xcls_Button5 : Object
     {
         public Gtk.Button el;
         private Xcls_DialogPluginWebkit  _this;
@@ -311,7 +351,7 @@ public class Xcls_DialogPluginWebkit : Object
 
             // my vars (def)
 
-        // ctor 
+        // ctor
         public Xcls_Button5(Xcls_DialogPluginWebkit _owner )
         {
             _this = _owner;
@@ -323,9 +363,10 @@ public class Xcls_DialogPluginWebkit : Object
             this.el.label = "Reload";
         }
 
-        // user defined functions 
+        // user defined functions
     }
-    public class Xcls_Button6 : Object 
+
+    public class Xcls_Button6 : Object
     {
         public Gtk.Button el;
         private Xcls_DialogPluginWebkit  _this;
@@ -333,7 +374,7 @@ public class Xcls_DialogPluginWebkit : Object
 
             // my vars (def)
 
-        // ctor 
+        // ctor
         public Xcls_Button6(Xcls_DialogPluginWebkit _owner )
         {
             _this = _owner;
@@ -345,9 +386,10 @@ public class Xcls_DialogPluginWebkit : Object
             this.el.label = "Cancel";
         }
 
-        // user defined functions 
+        // user defined functions
     }
-    public class Xcls_Button7 : Object 
+
+    public class Xcls_Button7 : Object
     {
         public Gtk.Button el;
         private Xcls_DialogPluginWebkit  _this;
@@ -355,7 +397,7 @@ public class Xcls_DialogPluginWebkit : Object
 
             // my vars (def)
 
-        // ctor 
+        // ctor
         public Xcls_Button7(Xcls_DialogPluginWebkit _owner )
         {
             _this = _owner;
@@ -367,6 +409,7 @@ public class Xcls_DialogPluginWebkit : Object
             this.el.label = "OK";
         }
 
-        // user defined functions 
+        // user defined functions
     }
+
 }