src/Builder4/DialogPluginWebkit.bjs
[app.Builder.js] / src / Builder4 / DialogPluginWebkit.vala
1 static Xcls_DialogPluginWebkit  _DialogPluginWebkit;
2
3 public class Xcls_DialogPluginWebkit : Object 
4 {
5     public Gtk.Dialog el;
6     private Xcls_DialogPluginWebkit  _this;
7
8     public static Xcls_DialogPluginWebkit singleton()
9     {
10         if (_DialogPluginWebkit == null) {
11             _DialogPluginWebkit= new Xcls_DialogPluginWebkit();
12         }
13         return _DialogPluginWebkit;
14     }
15     public Xcls_webview webview;
16
17         // my vars (def)
18     public string tmpjs;
19
20     // ctor 
21     public Xcls_DialogPluginWebkit()
22     {
23         _this = this;
24         this.el = new Gtk.Dialog();
25
26         // my vars (dec)
27
28         // set gobject values
29         this.el.title = "Add / Edit Component";
30         this.el.default_height = 500;
31         this.el.default_width = 500;
32         this.el.deletable = true;
33         this.el.modal = true;
34         var child_0 = new Xcls_VBox2( _this );
35         child_0.ref();
36         this.el.get_content_area().add (  child_0.el  );
37         var child_1 = new Xcls_Button5( _this );
38         child_1.ref();
39         this.el.add_action_widget (  child_1.el , 0 );
40         var child_2 = new Xcls_Button6( _this );
41         child_2.ref();
42         this.el.add_action_widget (  child_2.el , 0 );
43         var child_3 = new Xcls_Button7( _this );
44         child_3.ref();
45         this.el.add_action_widget (  child_3.el , 1 );
46
47         // listeners 
48         this.el.delete_event.connect( (self, event) => {
49             this.el.hide();
50             return true; 
51             //test  
52         });
53     }
54
55     // user defined functions 
56     public string show (Gtk.Window ?parent, string text) {// JsRender.Node node) {
57      
58         if (parent  != null) {
59             this.el.set_transient_for(parent);
60             this.el.modal = true;
61         }
62         
63         
64         var runhtml = "<script type=\"text/javascript\">\n" ;
65         string builderhtml;
66         
67         
68         GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
69     
70         runhtml += builderhtml + "\n";
71         
72         
73            runhtml += "\n" +
74             "Builder.saveHTML = function() {};\n" + 
75         "Roo.onReady(function() {\n" +
76     
77         "Roo.XComponent.build();\n" +
78         "});\n";
79         
80         
81         var db = new JsRender.RooDatabase.from_cfg ("MySQL", "hydra", "root", "");
82         
83     
84         var ar = db.readForeignKeys("Person");
85         var  generator = new Json.Generator ();
86         var  root = new Json.Node(Json.NodeType.OBJECT);
87         root.init_object(ar);
88         generator.set_root (root);
89         
90         generator.pretty = true;
91         generator.indent = 4;
92         
93      runhtml += "\n" +
94         " Roo.XComponent.on('buildcomplete', function() {\n" +
95          "    Editor.Roo.grid.Grid.panel.loadData(" + generator.to_data (null) + "); " +
96         "});\n";
97     
98         
99         
100         
101     
102         runhtml += "</script>\n" ;
103     
104     print(runhtml);
105         // fix to make sure they are the same..
106         
107         // need to modify paths
108     
109         string inhtml;
110         
111         GLib.FileUtils.get_contents(
112             BuilderApplication.configDirectory() + "/resources/roo.builder.html"
113                 , out inhtml);
114         
115         
116         // fetch the json from the database...
117         
118         //print(runhtml);
119         
120             var html = inhtml.replace("</head>", runhtml + // + this.runhtml + 
121                 "<script type=\"text/javascript\" src=\"xhttp://localhost/app.Builder.js/resources/Editors/Editor.Roo.grid.Grid.js\"></script>" + 
122           //      "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +   
123                   //  "<script type=\"text/javascript\">\n" +
124                   //  js_src + "\n" + 
125                   //  "</script>" + 
126                             
127             "</head>");
128             //print("LOAD HTML " + html);
129             
130              //var rootURL = _this.file.project.rootURL;
131        
132             
133             
134             this.webview.el.load_html( html , 
135                 //fixme - should be a config option!
136                 "xhttp://localhost/app.Builder.js/"
137             );
138         
139             
140         
141         this.el.show_all();
142          var   ret = "";
143         while (true) {
144             var response_id = this.el.run();
145             if (response_id < 1) {
146                 this.el.hide();
147                  return "";
148             }
149             // keep showing...?
150             break;
151         }
152         
153         // now we save it..
154         this.el.hide();
155         
156         return ret;
157         
158         
159         
160     }
161     public class Xcls_VBox2 : Object 
162     {
163         public Gtk.VBox el;
164         private Xcls_DialogPluginWebkit  _this;
165
166
167             // my vars (def)
168
169         // ctor 
170         public Xcls_VBox2(Xcls_DialogPluginWebkit _owner )
171         {
172             _this = _owner;
173             this.el = new Gtk.VBox( false, 0 );
174
175             // my vars (dec)
176
177             // set gobject values
178             var child_0 = new Xcls_ScrolledWindow3( _this );
179             child_0.ref();
180             this.el.pack_start (  child_0.el , false,true,3 );
181         }
182
183         // user defined functions 
184     }
185     public class Xcls_ScrolledWindow3 : Object 
186     {
187         public Gtk.ScrolledWindow el;
188         private Xcls_DialogPluginWebkit  _this;
189
190
191             // my vars (def)
192
193         // ctor 
194         public Xcls_ScrolledWindow3(Xcls_DialogPluginWebkit _owner )
195         {
196             _this = _owner;
197             this.el = new Gtk.ScrolledWindow( null, null );
198
199             // my vars (dec)
200
201             // set gobject values
202             this.el.expand = true;
203             var child_0 = new Xcls_webview( _this );
204             child_0.ref();
205             this.el.add (  child_0.el  );
206
207             // init method 
208
209             this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
210         }
211
212         // user defined functions 
213     }
214     public class Xcls_webview : Object 
215     {
216         public WebKit.WebView el;
217         private Xcls_DialogPluginWebkit  _this;
218
219
220             // my vars (def)
221
222         // ctor 
223         public Xcls_webview(Xcls_DialogPluginWebkit _owner )
224         {
225             _this = _owner;
226             _this.webview = this;
227             this.el = new WebKit.WebView();
228
229             // my vars (dec)
230
231             // set gobject values
232
233             // init method 
234
235             {
236                 // this may not work!?
237                 var settings =  this.el.get_settings();
238                 settings.enable_write_console_messages_to_stdout = true;
239                  
240                 var fs= new FakeServer(this.el);
241                 fs.ref();
242                 // this was an attempt to change the url perms.. did not work..
243                 // settings.enable_file_access_from_file_uris = true;
244                 // settings.enable_offline_web_application_cache - true;
245                 // settings.enable_universal_access_from_file_uris = true;
246                
247                  
248                 
249                 
250                 
251             
252                  // FIXME - base url of script..
253                  // we need it so some of the database features work.
254                 this.el.load_html( "Render not ready" , 
255                         //fixme - should be a config option!
256                         // or should we catch stuff and fix it up..
257                         "xhttp://localhost/app.Builder/"
258                 );
259                     
260                     
261                 
262                 
263             }
264
265             // listeners 
266             this.el.script_dialog.connect( (dialog) => {
267                 if (this.el == null) {
268                     return true;
269                 }
270                 
271                  var msg = dialog.get_message();
272                  if (msg.length < 4) {
273                     return false;
274                  }
275                  if (msg.substring(0,4) != "IPC:") {
276                      return false;
277                  }
278                  var ar = msg.split(":", 3);
279                 if (ar.length < 3) {
280                     return false;
281                 }
282                 print("CMD: %s\n",ar[1]);
283                     print("ARGS: %s\n",ar[2]);
284                 switch(ar[1]) {
285                     case "SAVEHTML":
286                       print("%sw",ar[2]);
287                       //  _this.file.saveHTML(ar[2]);
288                         return true;
289                     default:
290                         return true;
291                 }
292                 
293             });
294         }
295
296         // user defined functions 
297     }
298     public class Xcls_Button5 : Object 
299     {
300         public Gtk.Button el;
301         private Xcls_DialogPluginWebkit  _this;
302
303
304             // my vars (def)
305
306         // ctor 
307         public Xcls_Button5(Xcls_DialogPluginWebkit _owner )
308         {
309             _this = _owner;
310             this.el = new Gtk.Button();
311
312             // my vars (dec)
313
314             // set gobject values
315             this.el.label = "Cancel";
316         }
317
318         // user defined functions 
319     }
320     public class Xcls_Button6 : Object 
321     {
322         public Gtk.Button el;
323         private Xcls_DialogPluginWebkit  _this;
324
325
326             // my vars (def)
327
328         // ctor 
329         public Xcls_Button6(Xcls_DialogPluginWebkit _owner )
330         {
331             _this = _owner;
332             this.el = new Gtk.Button();
333
334             // my vars (dec)
335
336             // set gobject values
337             this.el.label = "Cancel";
338         }
339
340         // user defined functions 
341     }
342     public class Xcls_Button7 : Object 
343     {
344         public Gtk.Button el;
345         private Xcls_DialogPluginWebkit  _this;
346
347
348             // my vars (def)
349
350         // ctor 
351         public Xcls_Button7(Xcls_DialogPluginWebkit _owner )
352         {
353             _this = _owner;
354             this.el = new Gtk.Button();
355
356             // my vars (dec)
357
358             // set gobject values
359             this.el.label = "OK";
360         }
361
362         // user defined functions 
363     }
364 }