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 // causes problems.. get_screen?? not transfer ownership?
54 /// var Window = imports.Builder.Window.Window;
55 //this.el.set_screen(Window.el.get_screen());
58 for (var i in this.project.paths) {
64 console.log('load paths');
67 this.get('directory_model').loadData(paths);
70 console.log('show all');
72 this.success = c.success;
74 var tm = this.get('template_model');
79 var dir = __script_path__ + '/templates/';
81 var f = Gio.file_new_for_path(dir);
82 f.enumerate_children_async ("*", Gio.FileQueryInfoFlags.NONE,
83 GLib.PRIORITY_DEFAULT, null, function(o,ar) {
85 var fe = f.enumerate_children_finish(ar);
87 while (ch = fe.next_file(null)) {
88 var add = dir + '/' + ch.get_name();
89 if (!add.match(/\.js$/)) {
92 tm.templates.push(add);
104 'delete-event' : function (widget, event) {
109 response : function (w, id)
111 if (id < 1) { // cancel!
120 if (!DialogNewComponent.get('xnsid').el.get_text().length ||
121 // DialogNewComponent.get('template').getValue().length ||
122 !DialogNewComponent.get('directory').getValue().length
124 StandardErrorDialog.show(
125 "You have to set Project name ,template and directory"
131 var dir = DialogNewComponent.get('directory').getValue();
132 var xidns = DialogNewComponent.get('xnsid').el.get_text();
135 if (GLib.file_test (GLib.dir + '/' + xidns + '.bjs', GLib.FileTest.EXISTS)) {
136 StandardErrorDialog.show(
137 "That file already exists"
144 //var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());
147 var nf = _this.project.create(dir + '/' + xidns + '.bjs');
148 if (DialogNewComponent.success) {
149 DialogNewComponent.success(_this.project, nf);
152 //tmpl.copyTo(dir + '/' + xidns + '.bjs', function() {
153 // tmpl.setNSID(xidns);
154 /// _this.project.addFile(tmpl);
155 // this.success(_this.project, tmpl);
174 pack: function(p,e) {
175 p.el.get_content_area().add(e.el)
180 pack : [ 'pack_start', false, true , 0 ],
185 label : "Component Name:",
186 pack : [ 'pack_start', false, true , 0 ]
193 pack : [ 'pack_end', true, true , 0 ],
194 setValue : function(v)
198 getValue : function()
200 return this.el.get_text();
209 pack : [ 'pack_start', false, true , 0 ],
214 label : "Using Template:",
215 pack : [ 'pack_start', false, true , 0 ],
222 xtype : Gtk.ComboBox,
223 pack : [ 'pack_end', true, true , 0 ],
226 XObject.prototype.init.call(this);
227 this.el.add_attribute(this.items[0].el , 'markup', 1 );
231 setValue : function(v)
235 DialogNewComponent.get('template_model').templates.forEach(
244 getValue : function()
246 var ix = this.el.get_active();
250 return DialogNewComponent.get('template_model').templates[ix];
258 xtype : Gtk.CellRendererText,
259 pack : ['pack_start'],
263 id : 'template_model',
264 pack : [ 'set_model' ],
265 xtype : Gtk.ListStore,
269 XObject.prototype.init.call(this);
270 this.el.set_column_types ( 2, [
271 GObject.TYPE_STRING, // real key
272 GObject.TYPE_STRING // real type
281 loadData : function () {
283 var iter = new Gtk.TreeIter();
285 this.templates.forEach(function(p) {
289 el.set_value(iter, 0, p);
290 el.set_value(iter, 1, p);
310 pack : [ 'pack_start', false, true , 0 ],
315 pack : [ 'pack_start', false, true , 0 ],
316 label : "In Directory:"
322 xtype : Gtk.ComboBox,
323 pack : [ 'pack_end', true, true , 0 ],
327 XObject.prototype.init.call(this);
328 this.el.add_attribute(this.items[0].el , 'markup', 1 );
332 setValue : function(v)
336 this.get('directory_model').data.forEach(
345 getValue : function()
347 var ix = this.el.get_active();
351 var data = this.get('directory_model').data;
353 return data[ix].desc;
360 xtype : Gtk.CellRendererText,
361 pack : ['pack_start'],
365 xtype : Gtk.ListStore,
366 pack : [ 'set_model' ],
367 id: 'directory_model',
370 XObject.prototype.init.call(this);
371 this.el.set_column_types ( 2, [
372 GObject.TYPE_STRING, // real key
373 GObject.TYPE_STRING // real type
380 loadData : function (data) {
383 var iter = new Gtk.TreeIter();
385 data.forEach( function(p) {
390 el.set_value(iter, 0, p.id);
391 el.set_value(iter, 1, p.desc);
408 pack : [ 'pack_end', true, true , 0 ],
422 //_win = XN.xnew(create());