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