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