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