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 , 1 );
43
44         // listeners 
45         this.el.delete_event.connect( (self, event) => {
46             this.el.hide();
47             return true; 
48             //test  
49         });
50     }
51
52     // user defined functions 
53     public string show (Gtk.Window ?parent, string text) {// JsRender.Node node) {
54      
55         if (parent  != null) {
56             this.el.set_transient_for(parent);
57             this.el.modal = true;
58         }
59         
60         
61         var runhtml = "<script type=\"text/javascript\">\n" ;
62         string builderhtml;
63         
64         
65         GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
66     
67         runhtml += builderhtml + "\n";
68         runhtml += "</script>\n" ;
69     
70         // fix to make sure they are the same..
71         
72         // need to modify paths
73     
74         string inhtml;
75         
76         GLib.FileUtils.get_contents(
77             BuilderApplication.configDirectory() + "/resources/roo.builder.html"
78                 , out inhtml);
79         
80         
81     /*
82         string js_src = js + "\n" +
83         "Roo.onReady(function() {\n" +
84         "if (" + _this.file.name +".show) " +  _this.file.name +".show({});\n" +
85         "Roo.XComponent.build();\n" +
86         "});\n";
87     */  
88       
89         var fc =    FakeServerCache.factory_with_data(js_src);
90         this.tmpjs = fc.fname;
91         print(runhtml);
92         
93             var html = inhtml.replace("</head>", runhtml + // + this.runhtml + 
94     
95           //      "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +   
96                   //  "<script type=\"text/javascript\">\n" +
97                   //  js_src + "\n" + 
98                   //  "</script>" + 
99                             
100             "</head>");
101             //print("LOAD HTML " + html);
102             
103              //var rootURL = _this.file.project.rootURL;
104        
105             
106             
107             this.webview.el.load_html( html , 
108                 //fixme - should be a config option!
109                 "xhttp://localhost/app.Builder.js/"
110             );
111         
112             
113         
114         this.el.show_all();
115          var   ret = "";
116         while (true) {
117             var response_id = this.el.run();
118             if (response_id < 1) {
119                 this.el.hide();
120                  return "";
121             }
122             // keep showing...?
123             break;
124         }
125         
126         // now we save it..
127         this.el.hide();
128         
129         return ret;
130         
131         
132         
133     }
134     public class Xcls_VBox2 : Object 
135     {
136         public Gtk.VBox el;
137         private Xcls_DialogPluginWebkit  _this;
138
139
140             // my vars (def)
141
142         // ctor 
143         public Xcls_VBox2(Xcls_DialogPluginWebkit _owner )
144         {
145             _this = _owner;
146             this.el = new Gtk.VBox( false, 0 );
147
148             // my vars (dec)
149
150             // set gobject values
151             var child_0 = new Xcls_ScrolledWindow3( _this );
152             child_0.ref();
153             this.el.pack_start (  child_0.el , false,true,3 );
154         }
155
156         // user defined functions 
157     }
158     public class Xcls_ScrolledWindow3 : Object 
159     {
160         public Gtk.ScrolledWindow el;
161         private Xcls_DialogPluginWebkit  _this;
162
163
164             // my vars (def)
165
166         // ctor 
167         public Xcls_ScrolledWindow3(Xcls_DialogPluginWebkit _owner )
168         {
169             _this = _owner;
170             this.el = new Gtk.ScrolledWindow( null, null );
171
172             // my vars (dec)
173
174             // set gobject values
175             this.el.expand = true;
176             var child_0 = new Xcls_webview( _this );
177             child_0.ref();
178             this.el.add (  child_0.el  );
179
180             // init method 
181
182             this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
183         }
184
185         // user defined functions 
186     }
187     public class Xcls_webview : Object 
188     {
189         public WebKit.WebView el;
190         private Xcls_DialogPluginWebkit  _this;
191
192
193             // my vars (def)
194
195         // ctor 
196         public Xcls_webview(Xcls_DialogPluginWebkit _owner )
197         {
198             _this = _owner;
199             _this.webview = this;
200             this.el = new WebKit.WebView();
201
202             // my vars (dec)
203
204             // set gobject values
205
206             // init method 
207
208             {
209                 // this may not work!?
210                 var settings =  this.el.get_settings();
211                 
212                  
213                 //var fs= new FakeServer(this.el);
214                 //fs.ref();
215                 // this was an attempt to change the url perms.. did not work..
216                 // settings.enable_file_access_from_file_uris = true;
217                 // settings.enable_offline_web_application_cache - true;
218                 // settings.enable_universal_access_from_file_uris = true;
219                
220                  
221                 
222                 
223                 
224             
225                  // FIXME - base url of script..
226                  // we need it so some of the database features work.
227                 this.el.load_html( "Render not ready" , 
228                         //fixme - should be a config option!
229                         // or should we catch stuff and fix it up..
230                         "xhttp://localhost/app.Builder/"
231                 );
232                     
233                     
234                 
235                 
236             }
237
238             // listeners 
239             this.el.load_changed.connect( (le) => {
240                 if (le != WebKit.LoadEvent.FINISHED) {
241                     return;
242                 }
243                 if (this.runjs.length < 1) {
244                     return;
245                 }
246               //  this.el.run_javascript(this.runjs, null);
247                  FakeServerCache.remove(    this.runjs);
248                 this.runjs = "";
249             });
250         }
251
252         // user defined functions 
253     }
254     public class Xcls_Button5 : Object 
255     {
256         public Gtk.Button el;
257         private Xcls_DialogPluginWebkit  _this;
258
259
260             // my vars (def)
261
262         // ctor 
263         public Xcls_Button5(Xcls_DialogPluginWebkit _owner )
264         {
265             _this = _owner;
266             this.el = new Gtk.Button();
267
268             // my vars (dec)
269
270             // set gobject values
271             this.el.label = "Cancel";
272         }
273
274         // user defined functions 
275     }
276     public class Xcls_Button6 : Object 
277     {
278         public Gtk.Button el;
279         private Xcls_DialogPluginWebkit  _this;
280
281
282             // my vars (def)
283
284         // ctor 
285         public Xcls_Button6(Xcls_DialogPluginWebkit _owner )
286         {
287             _this = _owner;
288             this.el = new Gtk.Button();
289
290             // my vars (dec)
291
292             // set gobject values
293             this.el.label = "OK";
294         }
295
296         // user defined functions 
297     }
298 }