1 //<Script type="text/javascript">
4 GObject = imports.gi.GObject;
6 GLib = imports.gi.GLib;
8 console = imports.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",
36 XObject.prototype.init.call(this);
37 this.el.add_button("OK",1 );
38 this.el.add_button("Cancel",0 );
40 this.el.set_default_size (600, 400);
41 console.log('shown all');
50 c = c || { name : '' , xtype : '' };
51 // check whic project we are adding to..
52 XObject.extend(this, c);
53 var Window = imports.Builder.Window.Window;
54 this.el.set_screen(Window.el.get_screen());
57 for (var i in this.project.paths) {
65 this.get('directory_model').loadData(paths);
70 this.success = c.success;
72 var tm = this.get('template_model');
77 var dir = __script_path__ + '/templates/';
79 var f = Gio.file_new_for_path(dir);
80 f.enumerate_children_async ("*", Gio.FileQueryInfoFlags.NONE,
81 GLib.PRIORITY_DEFAULT, null, function(o,ar) {
83 var fe = f.enumerate_children_finish(ar);
85 while (ch = fe.next_file(null)) {
86 var add = dir + '/' + ch.get_name();
87 if (!add.match(/\.js$/)) {
90 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('directory').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 if (DialogNewComponent.success) {
147 DialogNewComponent.success(_this.project, nf);
150 //tmpl.copyTo(dir + '/' + xidns + '.bjs', function() {
151 // tmpl.setNSID(xidns);
152 /// _this.project.addFile(tmpl);
153 // this.success(_this.project, tmpl);
172 pack: function(p,e) {
173 p.el.get_content_area().add(e.el)
178 pack : [ 'pack_start', false, true , 0 ],
183 label : "Component Name:",
184 pack : [ 'pack_start', false, true , 0 ]
191 pack : [ 'pack_end', true, true , 0 ],
192 setValue : function(v)
196 getValue : function()
198 return this.el.get_text();
207 pack : [ 'pack_start', false, true , 0 ],
212 label : "Using Template:",
213 pack : [ 'pack_start', false, true , 0 ],
220 xtype : Gtk.ComboBox,
221 pack : [ 'pack_end', true, true , 0 ],
224 XObject.prototype.init.call(this);
225 this.el.add_attribute(this.items[0].el , 'markup', 1 );
229 setValue : function(v)
233 DialogNewComponent.get('template_model').templates.forEach(
242 getValue : function()
244 var ix = this.el.get_active();
248 return DialogNewComponent.get('template_model').templates[ix];
256 xtype : Gtk.CellRendererText,
257 pack : ['pack_start'],
261 id : 'template_model',
262 pack : [ 'set_model' ],
263 xtype : Gtk.ListStore,
267 XObject.prototype.init.call(this);
268 this.el.set_column_types ( 2, [
269 GObject.TYPE_STRING, // real key
270 GObject.TYPE_STRING // real type
279 loadData : function () {
281 var iter = new Gtk.TreeIter();
283 this.templates.forEach(function(p) {
287 el.set_value(iter, 0, p);
288 el.set_value(iter, 1, p);
308 pack : [ 'pack_start', false, true , 0 ],
313 pack : [ 'pack_start', false, true , 0 ],
314 label : "In Directory:"
320 xtype : Gtk.ComboBox,
321 pack : [ 'pack_end', true, true , 0 ],
325 XObject.prototype.init.call(this);
326 this.el.add_attribute(this.items[0].el , 'markup', 1 );
330 setValue : function(v)
334 this.get('directory_model').data.forEach(
343 getValue : function()
345 var ix = this.el.get_active();
349 var data = this.get('directory_model').data;
351 return data[ix].desc;
358 xtype : Gtk.CellRendererText,
359 pack : ['pack_start'],
363 xtype : Gtk.ListStore,
364 pack : [ 'set_model' ],
365 id: 'directory_model',
368 XObject.prototype.init.call(this);
369 this.el.set_column_types ( 2, [
370 GObject.TYPE_STRING, // real key
371 GObject.TYPE_STRING // real type
378 loadData : function (data) {
381 var iter = new Gtk.TreeIter();
383 data.forEach( function(p) {
388 el.set_value(iter, 0, p.id);
389 el.set_value(iter, 1, p.desc);
406 pack : [ 'pack_end', true, true , 0 ],
420 //_win = XN.xnew(create());