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 : 3,
155                     n_rows : 2,
156                     pack : "add",
157                     listeners : {
158                         
159                     },
160                     items : [
161                         {
162                             xtype: Gtk.Label,
163                             'bottom-attach' : 1,
164                             label : "parent",
165                             'left-attach' : 0,
166                             pack : "add",
167                             'right-attach' : 1,
168                             top_attach : 0,
169                             visible : true
170                         },
171                         {
172                             xtype: Gtk.Label,
173                             'bottom-attach' : 2,
174                             label : "title",
175                             'left-attach' : 0,
176                             pack : "add",
177                             'right-attach' : 1,
178                             'top-attach' : 1,
179                             visible : true
180                         },
181                         {
182                             xtype: Gtk.Entry,
183                             bottom_attach_parent : 1,
184                             label : "test",
185                             left_attach_parent : 1,
186                             pack : "add",
187                             right_attach_parent : 2,
188                             'top-attach_parent' : 0,
189                             visible : true
190                         }
191                     ]
192                 }
193             ]
194         },
195         {
196             xtype: Gtk.Button,
197             pack : "add_action_widget,0",
198             label : "Cancel"
199         },
200         {
201             xtype: Gtk.Button,
202             pack : "add_action_widget,1",
203             label : "OK"
204         }
205     ]
206 });
207 DialogNewComponent.init();
208 XObject.cache['/DialogNewComponent'] = DialogNewComponent;