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