Builder/EditProject.js
[app.Builder.js] / Builder / EditProject.js
1 //<Script type="text/javascript">
2
3 XN = imports.xnew;
4 Gtk = imports.gi.Gtk;
5 GObject = imports.gi.GObject;
6 console = imports.console;
7 Builder = imports['Builder.js'];
8 Roo = imports['Roo.js'];
9
10 StandardErrorDialog = imports.Builder.StandardErrorDialog.StandardErrorDialog;
11 ProjectManager =      imports.Builder.Provider.ProjectManager.ProjectManager;
12 /**
13  * add/edit project
14  * 
15  * project type: gtk or roo..
16  * 
17  * directory.
18  * 
19  * 
20  * 
21  */
22
23  
24 EditProject = new XObject({
25     
26         
27         xtype : Gtk.Dialog,
28         type: Gtk.WindowType.TOPLEVEL,
29         deletable : false,
30         modal : true,
31         border_width : 0,
32         title "Project Properties",
33         project : {},
34         init : function()
35         {
36             XObject.prototype.init.call(this); 
37             this.el.add_button("OK",1 );
38             this.el.add_button("Cancel",0 );
39              
40             this.el.set_default_size(600, 400);
41         },
42         show : function (c) 
43         {
44             
45             c = c || { name : '' , xtype : '' };
46             this.project  = c;
47             
48             [ 'xtype' , 'name' ].forEach(function(k) {
49                 this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
50             }
51             if (!this.el) {
52                 this.init();
53             }
54             this.el.show_all();
55             this.success = c.success;
56             
57             
58         },
59         
60         listeners :  {
61             
62             'delete-event' : function (widget, event) {
63                 this.el.hide();
64                 return true;
65             },
66             
67             response : function (w, id) 
68             {
69                 
70                 if (id < 1) {
71                     this.el.hide();
72                     return;
73                 }
74                 if (!this.get('xtype').getValue().length) {
75                     StandardErrorDialog.show("You have to set Project type");
76                      
77                     return;
78                 }
79                 this.el.hide();
80                 
81                 
82                 
83                 
84                 this.project.name  = this.get('name').getValue();
85                 this.project.xtype  = this.get('xtype').getValue();
86                 
87                 
88                 
89                 
90                 var pr = ProjectManager.update(this.project);
91                 
92                 this.success(pr);
93                 Seed.print(id);
94             },
95             
96         
97             
98         },
99         
100       
101         items : [
102             {
103                 
104                 xtype : Gtk.VBox,
105                 pack : function(p,e) {
106                     p.el.get_content_area().add(e.el)
107                 },
108                 items : [
109                     {
110                         xtype : Gtk.HBox,
111                         pack : [ 'pack_start', false, true , 0 ],
112                         items : [
113                             {
114                                 xtype : Gtk.Label,
115                                 pack : [ 'pack_start', false, true , 0 ],
116                                 label : "Project Name:"
117                             },
118                             
119                             {
120                                 xtype : Gtk.Entry,
121                                 id : 'name',
122                                 pack : [ 'pack_end', true, true , 0 ],
123                                 
124                                 setValue : function(v) 
125                                 {
126                                     this.el.set_text(v);
127                                 },
128                                 getValue : function()
129                                 {
130                                     return this.el.get_text();
131                                 }
132                             }
133                          
134                         ]
135                         
136                     },
137                     {
138                         xtype : Gtk.HBox',
139                         pack : [ 'pack_start', false, true , 0 ],
140                         items : [
141                             {
142                                 xtype : Gtk.Label,
143                                 pack : [ 'pack_start', false, true , 0 ],
144                                 label : "Project Type:"
145                             },
146                             {
147                                 xtype : Gtk.ComboBox,
148                                 id : 'xtype',
149                                 pack : [ 'pack_end', true, true , 0 ],
150                                 init : function() {
151                                     XObject.prototype.init.call(this); 
152                                     this.el.add_attribute(this.items[0].el , 'markup', 1 );  
153                                 }
154                                 setValue : function(v)
155                                 {
156                                     var el = this.el;
157                                     el.set_active(-1);
158                                     this.get('model').data.forEach(function(n, ix) {
159                                         if (v == n.xtype) {
160                                             el.set_active(ix);
161                                             return false;
162                                         }
163                                     });
164                                 },
165                                 getValue : function() 
166                                 {
167                                     var ix = this.el.get_active();
168                                     if (ix < 0 ) {
169                                         return '';
170                                     }
171                                     return this.get('model').data[ix].xtype;
172                                     /*
173                                     var iter = new Gtk.TreeIter();
174                                     if (this.el.get_active_iter(iter)) {
175                                         return '';
176                                     }
177                                     var value = new GObject.Value('');
178                                     this.model.el.get_value(iter, 0, value);
179                                     return value.value;
180                                     */
181                                 },
182                                 
183                                 
184                                 items : [
185                                     {
186                                         xtype : Gtk.CellRendererText,
187                                         pack : ['pack_start'],
188                                     },
189                                     {
190                                         id : 'model',
191                                         pack : [ 'set_model' ],
192                                         xtype : Gtk.ListStore',
193                                         init : function ()
194                                         {
195                                             XObject.prototype.init.call(this); 
196                              
197                                      
198                                             this.el.set_column_types ( 2, [
199                                                 GObject.TYPE_STRING,  // real key
200                                                 GObject.TYPE_STRING // real type
201                                                 
202                                                 
203                                             ] );
204                                             
205                                             this.data = [
206                                                 { xtype: 'Roo', desc : "Roo Project" },
207                                                 { xtype: 'Gtk', desc : "Gtk Project" },    
208                                                 //{ xtype: 'JS', desc : "Javascript Class" }
209                                             ]
210                                             
211                                             this.loadData(this.data);
212                                                 
213                                             
214                                             
215                                         },
216                                        
217                                        
218                                         
219                                         loadData : function (data) {
220                                             
221                                             var iter = new Gtk.TreeIter();
222                                             var el = this.el;
223                                             data.forEach(function(p) {
224                                                 
225                                                 el.append(iter);
226                                                 
227                                                  
228                                                 el.set_value(iter, 0, p.xtype);
229                                                 el.set_value(iter, 1, p.desc);
230                                                 
231                                             });
232                                              
233                                             
234                                             
235                                         }
236                                          
237                                     }
238                                   
239                                          
240                                 ]
241                             }
242                  
243                                 
244                         ]
245                     },
246                     {
247                         xtype : Gtk.Label,
248                         pack : [ 'pack_end', true, true , 0 ],
249                         
250                         label : ""
251                     }
252                     
253                     
254                     
255                     
256                 ]
257             }
258         ]
259     };
260     
261 }
262 //_win = XN.xnew(create());