1 //<Script type="text/javascript">
4 GObject = imports.gi.GObject;
6 GLib = imports.gi.GLib;
8 console = imports.console;
9 XObject = imports.XObject.XObject;
11 Window = imports.Builder.Window.Window;
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);
49 c = c || { name : '' , xtype : '' };
50 // check whic project we are adding to..
51 XObject.extend(this, c);
53 this.el.set_screen(Window.el.get_screen());
56 for (var i in this.project.paths) {
64 this.get('directory_model').loadData(paths);
69 this.success = c.success;
71 var tm = this.get('template_model');
76 var dir = __script_path__ + '/templates/';
78 var f = Gio.file_new_for_path(dir);
79 f.enumerate_children_async ("*", Gio.FileQueryInfoFlags.NONE,
80 GLib.PRIORITY_DEFAULT, null, function(o,ar) {
82 var fe = f.enumerate_children_finish(ar);
84 while (ch = fe.next_file(null)) {
85 var add = dir + '/' + ch.get_name();
86 if (!add.match(/\.js$/)) {
89 tm.templates.push(add);
100 'delete-event' : function (widget, event) {
105 response : function (w, id)
107 if (id < 1) { // cancel!
116 if (!DialogNewComponent.get(xnsid).el.get_text().length ||
117 DialogNewComponent.get('template').getValue().length ||
118 DialogNewComponent.get('directory').getValue().length
120 StandardErrorDialog.show(
121 "You have to set Project name ,template and directory"
127 var dir = DialogNewComponent.get('template').getValue();
128 var xidns = DialogNewComponent.get('xnsid').get_text();
131 if (GLib.file_test (GLib.dir + '/' + xidns + '.js', GLib.FileTest.EXISTS)) {
132 StandardErrorDialog.show(
133 "That file already exists"
140 var tmpl = this.project.loadFileOnlyDialogNewComponent.get('template').getValue());
143 tmpl.copyTo(dir + '/' + xidns + '.js', function() {
145 _this.project.addFile(tmpl);
146 this.success(_this.project, tmpl);
165 pack: function(p,e) {
166 p.el.get_content_area().add(e.el)
171 pack : [ 'pack_start', false, true , 0 ],
176 label : "Component Name:"
177 pack : [ 'pack_start', false, true , 0 ],
184 pack : [ 'pack_end', true, true , 0 ],
185 setValue : function(v)
189 getValue : function()
191 return this.el.get_text();
200 pack : [ 'pack_start', false, true , 0 ],
205 label : "Using Template:"
206 pack : [ 'pack_start', false, true , 0 ],
213 xtype : Gtk.ComboBox,
214 pack : [ 'pack_end', true, true , 0 ],
217 XObject.prototype.init.call(this);
218 this.el.add_attribute(this.items[0].el , 'markup', 1 );
222 setValue : function(v)
226 DialogNewComponent.get('template_model').templates.forEach(
235 getValue : function()
237 var ix = this.el.get_active();
241 return DialogNewComponent.get('template_model').templates[ix];
249 xtype : Gtk.CellRendererText,
250 pack : ['pack_start'],
254 id : 'template_model',
255 pack : [ 'set_model' ],
256 xtype : Gtk.ListStore,
259 listeners : function ()
261 XObject.prototype.init.call(this);
262 this.el.set_column_types ( 2, [
263 GObject.TYPE_STRING, // real key
264 GObject.TYPE_STRING // real type
273 loadData : function () {
275 var iter = new Gtk.TreeIter();
277 this.templates.forEach(function(p) {
281 el.set_value(iter, 0, p);
282 el.set_value(iter, 1, p);
302 pack : [ 'pack_start', false, true , 0 ],
307 pack : [ 'pack_start', false, true , 0 ],
308 label : "In Directory:"
314 xtype : Gtk.ComboBox,
315 pack : [ 'pack_end', true, true , 0 ],
319 XObject.prototype.init.call(this);
320 this.el.add_attribute(this.items[0].el , 'markup', 1 );
324 setValue : function(v)
328 DialogNewComponent.get('directory_model').data.forEach(
337 getValue : function()
339 var ix = this.el.get_active();
343 return DialogNewComponent.get('directory_model').data[ix].xtype;
350 xtype : Gtk.CellRendererText,
351 pack : ['pack_start'],
355 xtype : Gtk.ListStore,
356 pack : [ 'set_model' ],
357 id: 'directory_model',
360 XObject.prototype.init.call(this);
361 this.el.set_column_types ( 2, [
362 GObject.TYPE_STRING, // real key
363 GObject.TYPE_STRING // real type
370 loadData : function (data) {
372 var iter = new Gtk.TreeIter();
374 data.forEach( function(p) {
379 el.set_value(iter, 0, p.id);
380 el.set_value(iter, 1, p.desc);
399 pack : [ 'pack_end', true, true , 0 ],
413 //_win = XN.xnew(create());