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