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