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