1 //<Script type="text/javascript">
4 GObject = imports.gi.GObject;
6 GLib = imports.gi.GLib;
8 console = imports.console.console;
9 XObject = imports.XObject.XObject;
12 StandardErrorDialog = imports.Builder.StandardErrorDialog.StandardErrorDialog;
16 * basically uses a standard template ? pulled from the web?
18 * you have to pick which template, and give it a name..
20 * and pick which directory to put it in?
24 DialogNewComponent = new XObject({
27 // type: Gtk.WindowType.TOPLEVEL,
30 title : "New Component",
35 XObject.prototype.init.call(this);
36 this.el.add_button("OK",1 );
37 this.el.add_button("Cancel",0 );
41 this.el.set_default_size (600, 400);
51 c = c || { name : '' , xtype : '' };
52 // check whic project we are adding to..
53 XObject.extend(this, c);
54 var Window = imports.Builder.Window.Window;
55 this.el.set_screen(Window.el.get_screen());
58 for (var i in this.project.paths) {
66 this.get('directory_model').loadData(paths);
71 this.success = c.success;
73 var tm = this.get('template_model');
78 var dir = __script_path__ + '/templates/';
80 var f = Gio.file_new_for_path(dir);
81 f.enumerate_children_async ("*", Gio.FileQueryInfoFlags.NONE,
82 GLib.PRIORITY_DEFAULT, null, function(o,ar) {
84 var fe = f.enumerate_children_finish(ar);
86 while (ch = fe.next_file(null)) {
87 var add = dir + '/' + ch.get_name();
88 if (!add.match(/\.js$/)) {
91 tm.templates.push(add);
102 'delete-event' : function (widget, event) {
107 response : function (w, id)
109 if (id < 1) { // cancel!
118 if (!DialogNewComponent.get('xnsid').el.get_text().length ||
119 // DialogNewComponent.get('template').getValue().length ||
120 !DialogNewComponent.get('directory').getValue().length
122 StandardErrorDialog.show(
123 "You have to set Project name ,template and directory"
129 var dir = DialogNewComponent.get('template').getValue();
130 var xidns = DialogNewComponent.get('xnsid').el.get_text();
133 if (GLib.file_test (GLib.dir + '/' + xidns + '.bjs', GLib.FileTest.EXISTS)) {
134 StandardErrorDialog.show(
135 "That file already exists"
142 //var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());
145 var nf = _this.project.create(dir + '/' + xidns + '.bjs');
146 this.success(_this.project, nf);
147 //tmpl.copyTo(dir + '/' + xidns + '.bjs', function() {
148 // tmpl.setNSID(xidns);
149 /// _this.project.addFile(tmpl);
150 // this.success(_this.project, tmpl);
169 pack: function(p,e) {
170 p.el.get_content_area().add(e.el)
175 pack : [ 'pack_start', false, true , 0 ],
180 label : "Component Name:",
181 pack : [ 'pack_start', false, true , 0 ]
188 pack : [ 'pack_end', true, true , 0 ],
189 setValue : function(v)
193 getValue : function()
195 return this.el.get_text();
204 pack : [ 'pack_start', false, true , 0 ],
209 label : "Using Template:",
210 pack : [ 'pack_start', false, true , 0 ],
217 xtype : Gtk.ComboBox,
218 pack : [ 'pack_end', true, true , 0 ],
221 XObject.prototype.init.call(this);
222 this.el.add_attribute(this.items[0].el , 'markup', 1 );
226 setValue : function(v)
230 DialogNewComponent.get('template_model').templates.forEach(
239 getValue : function()
241 var ix = this.el.get_active();
245 return DialogNewComponent.get('template_model').templates[ix];
253 xtype : Gtk.CellRendererText,
254 pack : ['pack_start'],
258 id : 'template_model',
259 pack : [ 'set_model' ],
260 xtype : Gtk.ListStore,
264 XObject.prototype.init.call(this);
265 this.el.set_column_types ( 2, [
266 GObject.TYPE_STRING, // real key
267 GObject.TYPE_STRING // real type
276 loadData : function () {
278 var iter = new Gtk.TreeIter();
280 this.templates.forEach(function(p) {
284 el.set_value(iter, 0, p);
285 el.set_value(iter, 1, p);
305 pack : [ 'pack_start', false, true , 0 ],
310 pack : [ 'pack_start', false, true , 0 ],
311 label : "In Directory:"
317 xtype : Gtk.ComboBox,
318 pack : [ 'pack_end', true, true , 0 ],
322 XObject.prototype.init.call(this);
323 this.el.add_attribute(this.items[0].el , 'markup', 1 );
327 setValue : function(v)
331 DialogNewComponent.get('directory_model').data.forEach(
340 getValue : function()
342 var ix = this.el.get_active();
346 var data = DialogNewComponent.get('directory_model').data;
348 return data[ix].desc;
355 xtype : Gtk.CellRendererText,
356 pack : ['pack_start'],
360 xtype : Gtk.ListStore,
361 pack : [ 'set_model' ],
362 id: 'directory_model',
365 XObject.prototype.init.call(this);
366 this.el.set_column_types ( 2, [
367 GObject.TYPE_STRING, // real key
368 GObject.TYPE_STRING // real type
375 loadData : function (data) {
378 var iter = new Gtk.TreeIter();
380 data.forEach( function(p) {
385 el.set_value(iter, 0, p.id);
386 el.set_value(iter, 1, p.desc);
403 pack : [ 'pack_end', true, true , 0 ],
417 //_win = XN.xnew(create());