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