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) {
63 console.log('load paths');
66 this.get('directory_model').loadData(paths);
69 console.log('show all');
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);
103 'delete-event' : function (widget, event) {
108 response : function (w, id)
110 if (id < 1) { // cancel!
119 if (!DialogNewComponent.get('xnsid').el.get_text().length ||
120 // DialogNewComponent.get('template').getValue().length ||
121 !DialogNewComponent.get('directory').getValue().length
123 StandardErrorDialog.show(
124 "You have to set Project name ,template and directory"
130 var dir = DialogNewComponent.get('directory').getValue();
131 var xidns = DialogNewComponent.get('xnsid').el.get_text();
134 if (GLib.file_test (GLib.dir + '/' + xidns + '.bjs', GLib.FileTest.EXISTS)) {
135 StandardErrorDialog.show(
136 "That file already exists"
143 //var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());
146 var nf = _this.project.create(dir + '/' + xidns + '.bjs');
147 if (DialogNewComponent.success) {
148 DialogNewComponent.success(_this.project, nf);
151 //tmpl.copyTo(dir + '/' + xidns + '.bjs', function() {
152 // tmpl.setNSID(xidns);
153 /// _this.project.addFile(tmpl);
154 // this.success(_this.project, tmpl);
173 pack: function(p,e) {
174 p.el.get_content_area().add(e.el)
179 pack : [ 'pack_start', false, true , 0 ],
184 label : "Component Name:",
185 pack : [ 'pack_start', false, true , 0 ]
192 pack : [ 'pack_end', true, true , 0 ],
193 setValue : function(v)
197 getValue : function()
199 return this.el.get_text();
208 pack : [ 'pack_start', false, true , 0 ],
213 label : "Using Template:",
214 pack : [ 'pack_start', false, true , 0 ],
221 xtype : Gtk.ComboBox,
222 pack : [ 'pack_end', true, true , 0 ],
225 XObject.prototype.init.call(this);
226 this.el.add_attribute(this.items[0].el , 'markup', 1 );
230 setValue : function(v)
234 DialogNewComponent.get('template_model').templates.forEach(
243 getValue : function()
245 var ix = this.el.get_active();
249 return DialogNewComponent.get('template_model').templates[ix];
257 xtype : Gtk.CellRendererText,
258 pack : ['pack_start'],
262 id : 'template_model',
263 pack : [ 'set_model' ],
264 xtype : Gtk.ListStore,
268 XObject.prototype.init.call(this);
269 this.el.set_column_types ( 2, [
270 GObject.TYPE_STRING, // real key
271 GObject.TYPE_STRING // real type
280 loadData : function () {
282 var iter = new Gtk.TreeIter();
284 this.templates.forEach(function(p) {
288 el.set_value(iter, 0, p);
289 el.set_value(iter, 1, p);
309 pack : [ 'pack_start', false, true , 0 ],
314 pack : [ 'pack_start', false, true , 0 ],
315 label : "In Directory:"
321 xtype : Gtk.ComboBox,
322 pack : [ 'pack_end', true, true , 0 ],
326 XObject.prototype.init.call(this);
327 this.el.add_attribute(this.items[0].el , 'markup', 1 );
331 setValue : function(v)
335 this.get('directory_model').data.forEach(
344 getValue : function()
346 var ix = this.el.get_active();
350 var data = this.get('directory_model').data;
352 return data[ix].desc;
359 xtype : Gtk.CellRendererText,
360 pack : ['pack_start'],
364 xtype : Gtk.ListStore,
365 pack : [ 'set_model' ],
366 id: 'directory_model',
369 XObject.prototype.init.call(this);
370 this.el.set_column_types ( 2, [
371 GObject.TYPE_STRING, // real key
372 GObject.TYPE_STRING // real type
379 loadData : function (data) {
382 var iter = new Gtk.TreeIter();
384 data.forEach( function(p) {
389 el.set_value(iter, 0, p.id);
390 el.set_value(iter, 1, p.desc);
407 pack : [ 'pack_end', true, true , 0 ],
421 //_win = XN.xnew(create());