Sample/EditProject.js
[app.Builder.js] / Sample / EditProject.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
12 EditProject=new XObject({
13     xtype: Gtk.Dialog,
14     default_height : 300,
15     default_width : 600,
16     deletable : true,
17     modal : true,
18     border_width : 0,
19     title : "Project Properties",
20     show : function(c) {
21            c = c || { name : '' , xtype : '' };
22         this.project  = c;
23         if (!this.el) {
24             this.init();
25         }
26         var _this = this;
27         [ 'xtype' , 'name' ].forEach(function(k) {
28             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
29         });
30         
31         this.el.show_all();
32         this.success = c.success;
33     },
34     listeners : {
35         "destroy_event":function (self, event) {
36              this.el.hide();
37                         return false;
38         },
39         "response":function (self, id) {
40          if (id < 1) {
41                     this.el.hide();
42                     return;
43                 }
44                 if (!this.get('xtype').getValue().length) {
45                     this.get('/StandardErrorDialog').show("You have to set Project type");
46                      
47                     return;
48                 }
49                 this.el.hide();
50                 
51                 
52                 
53                 
54                 this.project.name  = this.get('name').getValue();
55                 this.project.xtype  = this.get('xtype').getValue();
56                 
57                 
58                 var pr = imports.Builder.Provider.ProjectManager.ProjectManager.update(this.project);
59                 
60                 this.success(pr);
61                 Seed.print(id);
62         }
63     },
64     items : [
65         {
66             xtype: Gtk.VBox,
67             pack : function(p,e) {
68                                 p.el.get_content_area().add(e.el)
69                             },
70             items : [
71                 {
72                     xtype: Gtk.HBox,
73                     pack : "pack_start,false,true,3",
74                     items : [
75                         {
76                             xtype: Gtk.Label,
77                             pack : "pack_start,false,true,3",
78                             label : "Project Name :"
79                         },
80                         {
81                             xtype: Gtk.Entry,
82                             pack : "pack_end,true,true,0",
83                             id : "name",
84                             getValue : function() {
85                                 return this.el.get_text();
86                             },
87                             setValue : function(v) 
88                                                             {
89                                                                 this.el.set_text(v);
90                                                             }
91                         }
92                     ]
93                 },
94                 {
95                     xtype: Gtk.HBox,
96                     pack : "pack_start,false,true,3",
97                     items : [
98                         {
99                             xtype: Gtk.Label,
100                             pack : "pack_start,false,true,0",
101                             label : "Project type :"
102                         },
103                         {
104                             xtype: Gtk.ComboBox,
105                             pack : "pack_end,true,true,0",
106                             id : "xtype",
107                             setValue : function(v)
108                                             {
109                                                 var el = this.el;
110                                                 el.set_active(-1);
111                                                 this.get('model').data.forEach(function(n, ix) {
112                                                     if (v == n.xtype) {
113                                                         el.set_active(ix);
114                                                         return false;
115                                                     }
116                                                 });
117                                             },
118                             getValue : function() {
119                                  var ix = this.el.get_active();
120                                         if (ix < 0 ) {
121                                             return '';
122                                         }
123                                         return this.get('model').data[ix].xtype;
124                             },
125                             init : function() {
126                                 XObject.prototype.init.call(this);
127                               this.el.add_attribute(this.items[0].el , 'markup', 1 );  
128                             },
129                             items : [
130                                 {
131                                     xtype: Gtk.CellRendererText,
132                                     pack : "pack_start"
133                                 },
134                                 {
135                                     xtype: Gtk.ListStore,
136                                     pack : "set_model",
137                                     init : function() {
138                                         XObject.prototype.init.call(this);
139                                     
140                                                                 this.el.set_column_types ( 2, [
141                                                                     GObject.TYPE_STRING,  // real key
142                                                                     GObject.TYPE_STRING // real type
143                                                                     
144                                                                     
145                                                                 ] );
146                                                                 
147                                                                 this.data = [
148                                                                     { xtype: 'Roo', desc : "Roo Project" },
149                                                                     { xtype: 'Gtk', desc : "Gtk Project" },    
150                                                                     //{ xtype: 'JS', desc : "Javascript Class" }
151                                                                 ]
152                                                                 
153                                                                 this.loadData(this.data);
154                                                                     
155                                     },
156                                     loadData : function (data) {
157                                                                                 
158                                                 var iter = new Gtk.TreeIter();
159                                                 var el = this.el;
160                                                 data.forEach(function(p) {
161                                                     
162                                                     el.append(iter);
163                                                     
164                                                      
165                                                     el.set_value(iter, 0, p.xtype);
166                                                     el.set_value(iter, 1, p.desc);
167                                                     
168                                                 });
169                                                   
170                                                                          
171                                     },
172                                     id : "model"
173                                 }
174                             ]
175                         }
176                     ]
177                 },
178                 {
179                     xtype: Gtk.FileChooserWidget,
180                     pack : "pack_end,true,true,3",
181                     action : Gtk.FileChooserAction.SELECT_FOLDER
182                 }
183             ]
184         },
185         {
186             xtype: Gtk.Button,
187             pack : "add_action_widget,1",
188             label : "OK"
189         },
190         {
191             xtype: Gtk.Button,
192             pack : "add_action_widget,0",
193             label : "Cancel"
194         }
195     ]
196 });
197 EditProject.init();
198 XObject.cache['/EditProject'] = EditProject;