22f2feceb00cdf50b8800316870f68a1c66ae9a7
[app.Builder.js] / Builder / 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()) {
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                     this.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         if (c.name) {
110             this.el.set_title("Edit File Details - " + c.name);
111         } else {
112             this.el.set_title("Create New File");
113         }
114          
115         this.file = c;
116         console.log('show all');
117         this.el.show_all();
118         this.success = c.success;
119         
120         
121     },
122     items : [
123         {
124             xtype: Gtk.VBox,
125             pack : function(p,e) {
126                                 p.el.get_content_area().add(e.el)
127                             },
128             items : [
129                 {
130                     xtype: Gtk.Table,
131                     n_columns : 2,
132                     n_rows : 3,
133                     pack : "pack_start,false,false,0",
134                     homogeneous : false,
135                     items : [
136                         {
137                             xtype: Gtk.Label,
138                             label : "Component Name",
139                             pack : "add",
140                             x_options : 4,
141                             xalign : 0.9,
142                             justify : Gtk.Justification.RIGHT
143                         },
144                         {
145                             xtype: Gtk.Entry,
146                             id : "name",
147                             pack : "add",
148                             visible : true
149                         },
150                         {
151                             xtype: Gtk.Label,
152                             label : "Title",
153                             pack : "add",
154                             x_options : 4,
155                             xalign : 0.9,
156                             justify : Gtk.Justification.RIGHT,
157                             visible : true
158                         },
159                         {
160                             xtype: Gtk.Entry,
161                             id : "title",
162                             pack : "add",
163                             visible : true
164                         },
165                         {
166                             xtype: Gtk.Label,
167                             label : "Region",
168                             pack : "add",
169                             tooltip_text : "center, north, south, east, west",
170                             x_options : 4,
171                             xalign : 0.9,
172                             justify : Gtk.Justification.RIGHT,
173                             visible : true
174                         },
175                         {
176                             xtype: Gtk.Entry,
177                             id : "region",
178                             pack : "add",
179                             visible : true
180                         },
181                         {
182                             xtype: Gtk.Label,
183                             label : "Parent Name",
184                             pack : "add",
185                             x_options : 4,
186                             xalign : 0.9,
187                             justify : Gtk.Justification.RIGHT,
188                             visible : true
189                         },
190                         {
191                             xtype: Gtk.Entry,
192                             id : "parent",
193                             pack : "add",
194                             visible : true
195                         },
196                         {
197                             xtype: Gtk.Label,
198                             label : "Disable method",
199                             pack : "add",
200                             x_options : 4,
201                             xalign : 0.9,
202                             justify : Gtk.Justification.RIGHT,
203                             visible : true
204                         },
205                         {
206                             xtype: Gtk.Entry,
207                             id : "disable",
208                             pack : "add",
209                             visible : true
210                         },
211                         {
212                             xtype: Gtk.Label,
213                             label : "Order (for tabs)",
214                             pack : "add",
215                             x_options : 4,
216                             xalign : 0.9,
217                             justify : Gtk.Justification.RIGHT,
218                             visible : true
219                         },
220                         {
221                             xtype: Gtk.Entry,
222                             id : "modOrder",
223                             pack : "add",
224                             visible : true
225                         }
226                     ]
227                 }
228             ]
229         },
230         {
231             xtype: Gtk.Button,
232             pack : "add_action_widget,0",
233             label : "Cancel"
234         },
235         {
236             xtype: Gtk.Button,
237             pack : "add_action_widget,1",
238             label : "OK"
239         }
240     ]
241 });
242 DialogNewComponent.init();
243 XObject.cache['/DialogNewComponent'] = DialogNewComponent;