Sample/DialogConfirm.js
[app.Builder.js] / Sample / DialogNewComponent.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 GtkClutter = imports.gi.GtkClutter;
11 console = imports.console;
12 XObject = imports.XObject.XObject;
13 DialogNewComponent=new XObject({
14     xtype: Gtk.Dialog,
15     listeners : {
16         delete_event : function (self, event) {
17             this.el.hide();
18             return true;
19         },
20         response : function (self, response_id) {
21                 if (response_id < 1) { // cancel!
22                     this.el.hide();
23                     return;
24                 }
25         
26                 if (!this.get('name').el.get_text().length ) {
27                     this.get('/StandardErrorDialog').show(
28                         "You have to set Project name "
29                     );
30                      
31                     return;
32                 }
33                 var isNew = this.file.name.length ? false : true;
34                 
35                 if (this.file.name.length && this.file.name != this.get('name').el.get_text()) {
36                     this.get('/StandardErrorDialog').show(
37                         "Sorry changing names does not work yet. "
38                     );
39                      
40                     return;
41                 }
42                 for (var i in this.def) {
43                     this.file[i] =  this.get(i).el.get_text();
44                 }
45                
46                 if (!isNew) {
47                     this.file.save();
48                     this.el.hide();
49                     return;
50                 }
51                
52             
53                 var dir ='';
54                 for (var i in this.project.paths) {
55                         dir = i;
56                         break;
57                 }
58         
59          
60                 
61                 // what about .js ?
62                  if (GLib.file_test (GLib.dir + '/' + this.file.name + '.bjs', GLib.FileTest.EXISTS)) {
63                     StandardErrorDialog.show(
64                         "That file already exists"
65                     ); 
66                     return;
67                 }
68                 this.el.hide();
69                 
70                 
71                 //var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());
72                 
73                 var _this = this;
74                 var nf = _this.project.create(dir + '/' + this.file.name + '.bjs');
75                 for (var i in this.file) {
76                     nf[i] = this.file[i];
77                 }
78                 if (this.get('/DialogNewComponent').success) {
79                     this.get('/DialogNewComponent').success(_this.project, nf);
80                 }
81         },
82         show : function (self) {
83           this.el.show_all();
84         }
85     },
86     default_height : 200,
87     default_width : 500,
88     id : "DialogNewComponent",
89     title : "New Component",
90     deletable : false,
91     modal : true,
92     show : function (c) 
93     {
94         this.project = c.project;
95         if (!this.el) {
96             this.init();
97         }
98         this.def =  { 
99             name : '' , 
100             title : '' ,
101             region : '' ,
102             parent: '',
103           //  disable: '',
104             modOrder : '0',
105             permname : ''
106         };
107         for (var i in this.def) {
108             c[i] = c[i] || this.def[i];
109             this.get(i).el.set_text(c[i]);
110         }
111         if (c.name) {
112             this.el.set_title("Edit File Details - " + c.name);
113         } else {
114             this.el.set_title("Create New File");
115         }
116          
117         this.file = c;
118         console.log('show all');
119         this.el.show_all();
120         this.success = c.success;
121         
122         
123     },
124     items : [
125         {
126             xtype: Gtk.VBox,
127             pack : function(p,e) {
128                                 p.el.get_content_area().add(e.el)
129                             },
130             items : [
131                 {
132                     xtype: Gtk.Table,
133                     n_columns : 2,
134                     n_rows : 3,
135                     pack : "pack_start,false,false,0",
136                     homogeneous : false,
137                     items : [
138                         {
139                             xtype: Gtk.Label,
140                             label : "Component Name",
141                             pack : "add",
142                             x_options : 4,
143                             xalign : 0.9,
144                             justify : Gtk.Justification.RIGHT
145                         },
146                         {
147                             xtype: Gtk.Entry,
148                             id : "name",
149                             pack : "add",
150                             visible : true
151                         },
152                         {
153                             xtype: Gtk.Label,
154                             label : "Title",
155                             pack : "add",
156                             x_options : 4,
157                             xalign : 0.9,
158                             justify : Gtk.Justification.RIGHT,
159                             visible : true
160                         },
161                         {
162                             xtype: Gtk.Entry,
163                             id : "title",
164                             pack : "add",
165                             visible : true
166                         },
167                         {
168                             xtype: Gtk.Label,
169                             label : "Region",
170                             pack : "add",
171                             tooltip_text : "center, north, south, east, west",
172                             x_options : 4,
173                             xalign : 0.9,
174                             justify : Gtk.Justification.RIGHT,
175                             visible : true
176                         },
177                         {
178                             xtype: Gtk.Entry,
179                             id : "region",
180                             pack : "add",
181                             visible : true
182                         },
183                         {
184                             xtype: Gtk.Label,
185                             label : "Parent Name",
186                             pack : "add",
187                             x_options : 4,
188                             xalign : 0.9,
189                             justify : Gtk.Justification.RIGHT,
190                             visible : true
191                         },
192                         {
193                             xtype: Gtk.Entry,
194                             id : "parent",
195                             pack : "add",
196                             visible : true
197                         },
198                         {
199                             xtype: Gtk.Label,
200                             label : "Permission Name",
201                             pack : "add",
202                             x_options : 4,
203                             xalign : 0.9,
204                             justify : Gtk.Justification.RIGHT,
205                             visible : true
206                         },
207                         {
208                             xtype: Gtk.Entry,
209                             id : "permname",
210                             pack : "add",
211                             visible : true
212                         },
213                         {
214                             xtype: Gtk.Label,
215                             label : "Order (for tabs)",
216                             pack : "add",
217                             x_options : 4,
218                             xalign : 0.9,
219                             justify : Gtk.Justification.RIGHT,
220                             visible : true
221                         },
222                         {
223                             xtype: Gtk.Entry,
224                             id : "modOrder",
225                             pack : "add",
226                             visible : true
227                         }
228                     ]
229                 }
230             ]
231         },
232         {
233             xtype: Gtk.Button,
234             pack : "add_action_widget,0",
235             label : "Cancel"
236         },
237         {
238             xtype: Gtk.Button,
239             pack : "add_action_widget,1",
240             label : "OK"
241         }
242     ]
243 });
244 DialogNewComponent.init();
245 XObject.cache['/DialogNewComponent'] = DialogNewComponent;