src/Builder4/EditProject.bjs
[app.Builder.js] / src / Builder4 / EditProject.vala
1 static EditProject  _EditProject;
2
3 public class EditProject : Object
4 {
5     public Gtk.Dialog el;
6     private EditProject  _this;
7
8     public static EditProject singleton()
9     {
10         if (_EditProject == null) {
11             _EditProject= new EditProject();
12         }
13         return _EditProject;
14     }
15     public Xcls_xtype xtype;
16     public Xcls_cellrender cellrender;
17     public Xcls_model model;
18     public Xcls_dir dir;
19
20         // my vars (def)
21
22     // ctor
23     public EditProject()
24     {
25         _this = this;
26         this.el = new Gtk.Dialog();
27
28         // my vars (dec)
29
30         // set gobject values
31         this.el.title = "Project Properties";
32         this.el.name = "EditProject";
33         this.el.border_width = 3;
34         this.el.default_height = 500;
35         this.el.default_width = 600;
36         this.el.deletable = true;
37         this.el.modal = true;
38         var child_0 = new Xcls_VBox2( _this );
39         child_0.ref();
40         this.el.get_content_area().add (  child_0.el  );
41         var child_1 = new Xcls_Button9( _this );
42         child_1.ref();
43         this.el.add_action_widget (  child_1.el , 1 );
44         var child_2 = new Xcls_Button10( _this );
45         child_2.ref();
46         this.el.add_action_widget (  child_2.el , 0 );
47
48         //listeners
49         this.el.destroy_event.connect( (self, event) => {
50           this.el.response(0);
51         //     this.el.hide();
52             return false;
53         });
54     }
55
56     // user defined functions
57     public Project.Project? show () {
58           
59     
60         //[ 'xtype'  ].forEach(function(k) {
61         //    _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
62         //});
63         // shouild set path..
64         _this.model.loadData();
65         this.el.show_all();
66         
67         var err_dialog = StandardErrorDialog.singleton();
68     
69         var id = -1;
70         while (id < 0) {
71              id =  this.el.run();
72              if (id < 1) {
73                     this.el.hide();
74                     return null;
75             }
76      
77              
78               if (_this.xtype.getValue().length < 1) {
79                    
80                     err_dialog.show(_this.el,"You have to set Project type");             
81                     id = -1;
82                     continue;
83                 }
84                 if (_this.dir.el.get_filename().length < 1) {
85      
86                     err_dialog.show(_this.el,"You have to select a folder");             
87                     id = -1;
88                     continue;
89                 }
90                
91         }
92         
93         this.el.hide();
94         
95         
96         
97      
98         var fn = _this.dir.el.get_filename();
99         print("add %s\n" , fn);
100         
101         var project = Project.Project.factory(_this.xtype.getValue(), fn);
102         project.save();
103         Project.projects.set(project.name,project);
104         
105         //var pr = imports.Builder.Provider.ProjectManager.ProjectManager.update(this.project);
106         
107         return project;
108     
109         
110         //this.success = c.success;
111     }
112     public class Xcls_VBox2 : Object
113     {
114         public Gtk.VBox el;
115         private EditProject  _this;
116
117
118             // my vars (def)
119
120         // ctor
121         public Xcls_VBox2(EditProject _owner )
122         {
123             _this = _owner;
124             this.el = new Gtk.VBox( false, 0 );
125
126             // my vars (dec)
127
128             // set gobject values
129             var child_0 = new Xcls_HBox3( _this );
130             child_0.ref();
131             this.el.pack_start (  child_0.el , false,true,3 );
132             var child_1 = new Xcls_dir( _this );
133             child_1.ref();
134             this.el.pack_end (  child_1.el , true,true,5 );
135         }
136
137         // user defined functions
138     }
139     public class Xcls_HBox3 : Object
140     {
141         public Gtk.HBox el;
142         private EditProject  _this;
143
144
145             // my vars (def)
146
147         // ctor
148         public Xcls_HBox3(EditProject _owner )
149         {
150             _this = _owner;
151             this.el = new Gtk.HBox( false, 0 );
152
153             // my vars (dec)
154
155             // set gobject values
156             var child_0 = new Xcls_Label4( _this );
157             child_0.ref();
158             this.el.pack_start (  child_0.el , false,true,3 );
159             var child_1 = new Xcls_xtype( _this );
160             child_1.ref();
161             this.el.pack_end (  child_1.el , true,true,3 );
162         }
163
164         // user defined functions
165     }
166     public class Xcls_Label4 : Object
167     {
168         public Gtk.Label el;
169         private EditProject  _this;
170
171
172             // my vars (def)
173
174         // ctor
175         public Xcls_Label4(EditProject _owner )
176         {
177             _this = _owner;
178             this.el = new Gtk.Label( "Project type :" );
179
180             // my vars (dec)
181
182             // set gobject values
183         }
184
185         // user defined functions
186     }
187
188     public class Xcls_xtype : Object
189     {
190         public Gtk.ComboBox el;
191         private EditProject  _this;
192
193
194             // my vars (def)
195
196         // ctor
197         public Xcls_xtype(EditProject _owner )
198         {
199             _this = _owner;
200             _this.xtype = this;
201             this.el = new Gtk.ComboBox();
202
203             // my vars (dec)
204
205             // set gobject values
206             var child_0 = new Xcls_cellrender( _this );
207             child_0.ref();
208             this.el.pack_start (  child_0.el , true );
209             var child_1 = new Xcls_model( _this );
210             child_1.ref();
211             this.el.set_model (  child_1.el  );
212
213             // init method
214
215             this.el.add_attribute(_this.cellrender.el , "markup", 1 );
216         }
217
218         // user defined functions
219         public string getValue () {
220              var ix = this.el.get_active();
221                 if (ix < 0 ) {
222                     return "";
223                 }
224                 switch(ix) {
225                     case 0:
226                         return "Roo";
227                     case 1:
228                         return "Gtk";
229                 }
230                 return "";
231         }
232         public void setValue (v)    {
233                 var el = this.el;
234                 el.set_active(-1);
235                 
236                 for (var i =0;i < this.data.length; i++ ) {
237                     if (v == this.data.nth_datA(i)) {
238                         el.set_active(ix);
239                         return false;
240                     }
241                 }
242             }
243     }
244     public class Xcls_cellrender : Object
245     {
246         public Gtk.CellRendererText el;
247         private EditProject  _this;
248
249
250             // my vars (def)
251
252         // ctor
253         public Xcls_cellrender(EditProject _owner )
254         {
255             _this = _owner;
256             _this.cellrender = this;
257             this.el = new Gtk.CellRendererText();
258
259             // my vars (dec)
260
261             // set gobject values
262         }
263
264         // user defined functions
265     }
266
267     public class Xcls_model : Object
268     {
269         public Gtk.ListStore el;
270         private EditProject  _this;
271
272
273             // my vars (def)
274
275         // ctor
276         public Xcls_model(EditProject _owner )
277         {
278             _this = _owner;
279             _this.model = this;
280             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
281
282             // my vars (dec)
283
284             // set gobject values
285         }
286
287         // user defined functions
288         public void loadData ( ) {
289                 this.el.clear();
290                               
291                 Gtk.TreeIter iter;
292                         
293                 el.append(out iter);
294                 
295                 el.set_value(iter, 0, "Roo");
296                 el.set_value(iter, 1, "Roo Project");
297                  el.append(out iter);
298                 
299                 el.set_value(iter, 0, "Gtk");
300                 el.set_value(iter, 1, "Gtk Project");
301                  
302                       
303                                              
304         }
305     }
306
307
308
309     public class Xcls_dir : Object
310     {
311         public Gtk.FileChooserWidget el;
312         private EditProject  _this;
313
314
315             // my vars (def)
316
317         // ctor
318         public Xcls_dir(EditProject _owner )
319         {
320             _this = _owner;
321             _this.dir = this;
322             this.el = new Gtk.FileChooserWidget( Gtk.FileChooserAction.SELECT_FOLDER );
323
324             // my vars (dec)
325
326             // set gobject values
327             this.el.create_folders = false;
328             this.el.select_multiple = false;
329         }
330
331         // user defined functions
332     }
333
334
335     public class Xcls_Button9 : Object
336     {
337         public Gtk.Button el;
338         private EditProject  _this;
339
340
341             // my vars (def)
342
343         // ctor
344         public Xcls_Button9(EditProject _owner )
345         {
346             _this = _owner;
347             this.el = new Gtk.Button();
348
349             // my vars (dec)
350
351             // set gobject values
352             this.el.label = "OK";
353         }
354
355         // user defined functions
356     }
357
358     public class Xcls_Button10 : Object
359     {
360         public Gtk.Button el;
361         private EditProject  _this;
362
363
364             // my vars (def)
365
366         // ctor
367         public Xcls_Button10(EditProject _owner )
368         {
369             _this = _owner;
370             this.el = new Gtk.Button();
371
372             // my vars (dec)
373
374             // set gobject values
375             this.el.label = "Cancel";
376         }
377
378         // user defined functions
379     }
380
381 }