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').get_text();
133 if (GLib.file_test (GLib.dir + '/' + xidns + '.js', GLib.FileTest.EXISTS)) {
134 StandardErrorDialog.show(
135 "That file already exists"
142 var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());
145 tmpl.copyTo(dir + '/' + xidns + '.js', function() {
147 _this.project.addFile(tmpl);
148 this.success(_this.project, tmpl);
167 pack: function(p,e) {
168 p.el.get_content_area().add(e.el)
173 pack : [ 'pack_start', false, true , 0 ],
178 label : "Component Name:",
179 pack : [ 'pack_start', false, true , 0 ]
186 pack : [ 'pack_end', true, true , 0 ],
187 setValue : function(v)
191 getValue : function()
193 return this.el.get_text();
202 pack : [ 'pack_start', false, true , 0 ],
207 label : "Using Template:",
208 pack : [ 'pack_start', false, true , 0 ],
215 xtype : Gtk.ComboBox,
216 pack : [ 'pack_end', true, true , 0 ],
219 XObject.prototype.init.call(this);
220 this.el.add_attribute(this.items[0].el , 'markup', 1 );
224 setValue : function(v)
228 DialogNewComponent.get('template_model').templates.forEach(
237 getValue : function()
239 var ix = this.el.get_active();
243 return DialogNewComponent.get('template_model').templates[ix];
251 xtype : Gtk.CellRendererText,
252 pack : ['pack_start'],
256 id : 'template_model',
257 pack : [ 'set_model' ],
258 xtype : Gtk.ListStore,
262 XObject.prototype.init.call(this);
263 this.el.set_column_types ( 2, [
264 GObject.TYPE_STRING, // real key
265 GObject.TYPE_STRING // real type
274 loadData : function () {
276 var iter = new Gtk.TreeIter();
278 this.templates.forEach(function(p) {
282 el.set_value(iter, 0, p);
283 el.set_value(iter, 1, p);
303 pack : [ 'pack_start', false, true , 0 ],
308 pack : [ 'pack_start', false, true , 0 ],
309 label : "In Directory:"
315 xtype : Gtk.ComboBox,
316 pack : [ 'pack_end', true, true , 0 ],
320 XObject.prototype.init.call(this);
321 this.el.add_attribute(this.items[0].el , 'markup', 1 );
325 setValue : function(v)
329 DialogNewComponent.get('directory_model').data.forEach(
338 getValue : function()
340 var ix = this.el.get_active();
344 return DialogNewComponent.get('directory_model').data[ix].xtype;
351 xtype : Gtk.CellRendererText,
352 pack : ['pack_start'],
356 xtype : Gtk.ListStore,
357 pack : [ 'set_model' ],
358 id: 'directory_model',
361 XObject.prototype.init.call(this);
362 this.el.set_column_types ( 2, [
363 GObject.TYPE_STRING, // real key
364 GObject.TYPE_STRING // real type
371 loadData : function (data) {
374 var iter = new Gtk.TreeIter();
376 data.forEach( function(p) {
381 el.set_value(iter, 0, p.id);
382 el.set_value(iter, 1, p.desc);
399 pack : [ 'pack_end', true, true , 0 ],
413 //_win = XN.xnew(create());