Sample/DialogNewComponent.js
[app.Builder.js] / Sample / 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     deletable : false,
15     modal : true,
16     title : "New Component",
17     id : "DialogNewComponent",
18     default_width : 500,
19     default_height : 200,
20     show : function (c) 
21             {
22                 if (!this.el) {
23                     this.init();
24                 }
25                 c = c || { name : '' , xtype : '' };
26                 // check whic project we are adding to..
27                 XObject.extend(this, c);
28                 // causes problems.. get_screen?? not transfer ownership?
29                /// var Window                = imports.Builder.Window.Window;
30                 //this.el.set_screen(Window.el.get_screen());
31                 
32                 //var paths = [];
33                 //for (var i in this.project.paths) {
34                  //   paths.push({
35                  //       id : i,
36                  //       desc : i
37                  //   });
38                // }
39                  //console.log('load paths');
40                  
41                 // load the paths.
42                // this.get('directory_model').loadData(paths);
43                     
44                 
45                 console.log('show all');
46                 this.el.show_all();
47                 this.success = c.success;
48                 /*
49                 var tm = this.get('template_model');
50                 if (tm.templates) {
51                     return;
52                 }
53                 tm.templates = [];
54                 var dir = __script_path__ + '/templates/';
55                 
56                 var f = Gio.file_new_for_path(dir);
57                 f.enumerate_children_async ("*",  Gio.FileQueryInfoFlags.NONE, 
58                         GLib.PRIORITY_DEFAULT, null, function(o,ar) {
59                     // enum completed..
60                     var fe = f.enumerate_children_finish(ar);
61                     var ch = '';
62                     while (ch = fe.next_file(null)) {
63                         var add = dir + '/' + ch.get_name();
64                         if (!add.match(/\.js$/)) {
65                             continue;
66                         }
67                         tm.templates.push(add);
68                         
69                     }
70                     tm.loadData();
71                     
72                 }, null);
73                 */
74                 
75             },
76     listeners : {
77         delete_event : function (self, event) {
78             this.el.hide();
79             return true;
80         },
81         response : function (self, response_id) {
82                 if (response_id < 1) { // cancel!
83                     this.el.hide();
84                     return;
85                 }
86         
87         
88                     
89                    
90             
91                 if (!this.get('xnsid').el.get_text().length ) {
92                     this.get('/StandardErrorDialog').show(
93                         "You have to set Project name "
94                     );
95                      
96                     return;
97                 }
98                 var dir ='';
99                 for (var i in this.project.paths) {
100                         dir = i;
101                         break;
102                 }
103         
104                 var xidns = DialogNewComponent.get('xnsid').el.get_text();
105                 
106                 // what about .js ?
107                  if (GLib.file_test (GLib.dir + '/' + xidns + '.bjs', GLib.FileTest.EXISTS)) {
108                     StandardErrorDialog.show(
109                         "That file already exists"
110                     ); 
111                     return;
112                 }
113                 this.el.hide();
114                 
115                 
116                 //var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());
117                 
118                 var _this = this;
119                 var nf = _this.project.create(dir + '/' + xidns + '.bjs');
120                 if (this.get('/DialogNewComponent').success) {
121                     this.get('/DialogNewComponent').success(_this.project, nf);
122                 }
123         },
124         show : function (self) {
125           this.el.show_all();
126         }
127     },
128     items : [
129         {
130             xtype: Gtk.VBox,
131             pack : function(p,e) {
132                                 p.el.get_content_area().add(e.el)
133                             },
134             items : [
135                 {
136                     xtype: Gtk.HBox,
137                     pack : "pack_start,false,true,0",
138                     items : [
139                         {
140                             xtype: Gtk.Label,
141                             pack : "pack_start,false,true,0",
142                             label : "Component Name",
143                             xpad : 10
144                         },
145                         {
146                             xtype: Gtk.Entry,
147                             pack : "pack_end,true,true,0",
148                             id : "xnsid"
149                         }
150                     ]
151                 },
152                 {
153                     xtype: Gtk.Table,
154                     n_columns : 2,
155                     n_rows : 3,
156                     pack : "pack_start,false,false,0",
157                     homogeneous : false,
158                     items : [
159                         {
160                             xtype: Gtk.Label,
161                             label : "parent",
162                             pack : "add",
163                             xalign : 0.9,
164                             justify : Gtk.Justification.RIGHT,
165                             visible : true
166                         },
167                         {
168                             xtype: Gtk.Entry,
169                             pack : "add",
170                             visible : true,
171                             listeners : {
172                                 
173                             }
174                         },
175                         {
176                             xtype: Gtk.Label,
177                             label : "title",
178                             pack : "add",
179                             xalign : 0.9,
180                             justify : Gtk.Justification.RIGHT,
181                             visible : true
182                         },
183                         {
184                             xtype: Gtk.Entry,
185                             pack : "add",
186                             visible : true,
187                             listeners : {
188                                 
189                             }
190                         },
191                         {
192                             xtype: Gtk.Label,
193                             label : "parent",
194                             pack : "add",
195                             xalign : 1,
196                             justify : Gtk.Justification.RIGHT,
197                             visible : true
198                         },
199                         {
200                             xtype: Gtk.Entry,
201                             pack : "add",
202                             visible : true,
203                             listeners : {
204                                 
205                             }
206                         }
207                     ]
208                 }
209             ]
210         },
211         {
212             xtype: Gtk.Button,
213             pack : "add_action_widget,0",
214             label : "Cancel"
215         },
216         {
217             xtype: Gtk.Button,
218             pack : "add_action_widget,1",
219             label : "OK"
220         }
221     ]
222 });
223 DialogNewComponent.init();
224 XObject.cache['/DialogNewComponent'] = DialogNewComponent;