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