1 //<Script type="text/javascript">
5 GObject = imports.gi.GObject;
7 GLib = imports.gi.GLib;
8 console = imports.console;
9 Builder = imports['Builder.js'];
10 Roo = imports['Roo.js'];
15 * basically uses a standard template ? pulled from the web?
17 * you have to pick which template, and give it a name..
19 * and pick which directory to put it in?
26 xnsid : 'Builder.DialogNewComponent',
30 // type: Gtk.WindowType.TOPLEVEL,
33 title : "New Component",
40 c = c || { name : '' , xtype : '' };
41 // check whic project we are adding to..
44 this.el.set_screen(XN.get('Builder.Window').window.el.get_screen());
47 for (var i in this.project.paths) {
55 XN.get(this).directory_model.loadData(paths);
60 this.success = c.success;
62 var tm = XN.get(this).template_model;
67 var dir = __script_path__ + '/templates/';
69 var f = Gio.file_new_for_path(dir);
70 f.enumerate_children_async ("*", Gio.FileQueryInfoFlags.NONE,
71 GLib.PRIORITY_DEFAULT, null, function(o,ar) {
73 var fe = f.enumerate_children_finish(ar);
75 while (ch = fe.next_file(null)) {
76 var add = dir + '/' + ch.get_name();
77 if (!add.match(/\.js$/)) {
80 tm.templates.push(add);
91 'delete-event' : function (widget, event) {
96 response : function (w, id)
98 if (id < 1) { // cancel!
107 if (!XN.get(this).xnsid.el.get_text().length ||
108 XN.get(this).template.getValue().length ||
109 XN.get(this).directory.getValue().length
111 XN.get('Builder.StandardErrorDialog').dialog.show(
112 "You have to set Project name ,template and directory"
118 var dir = XN.get(this).template.getValue();
119 var xidns = XN.get(this).xnsid.get_text();
122 if (GLib.file_test (GLib.dir + '/' + xidns + '.js', GLib.FileTest.EXISTS)) {
123 XN.get('Builder.StandardErrorDialog').dialog.show(
124 "That file already exists"
131 var tmpl = this.project.loadFileOnly(XN.get(this).template.getValue());
134 tmpl.copyTo(dir + '/' + xidns + '.js', function() {
136 _this.project.addFile(tmpl);
137 this.success(_this.project, tmpl);
145 _new : function(self) {
149 _rendered : function()
151 this.el.add_button("OK",1 );
152 this.el.add_button("Cancel",0 );
159 set_border_width : [ 0 ],
160 // set_title : [ 'Project Properties' ],
161 set_default_size: [600, 400] //,
172 packing : function(p,e) {
173 p.el.get_content_area().add(e.el)
179 packing : [ 'pack_start', false, true , 0 ],
184 packing : [ 'pack_start', false, true , 0 ],
186 label : "Component Name:"
194 packing : [ 'pack_end', true, true , 0 ],
196 setValue : function(v) {
199 getValue : function()
201 return this.el.get_text();
211 packing : [ 'pack_start', false, true , 0 ],
216 packing : [ 'pack_start', false, true , 0 ],
218 label : "Using Template:"
226 packing : [ 'pack_end', true, true , 0 ],
228 // set_text_column : [1]
229 //set_size_request : [150,-1]
233 setValue : function(v)
237 Roo.each(XN.get(this).template_model.templates, function(n) {
244 getValue : function()
246 var ix = this.el.get_active();
250 return XN.get(this).template_model.templates[ix];
252 var iter = new Gtk.TreeIter();
253 if (this.el.get_active_iter(iter)) {
256 var value = new GObject.Value('');
257 this.model.el.get_value(iter, 0, value);
266 _rendered : function ()
269 // _form.xtype = this;
270 this.el.add_attribute(this.items[0].el , 'markup', 1 );
271 //this.el.add_attribute(this.items[0].el , 'popup', 2 );
283 xtype : 'CellRendererText',
284 packing : ['pack_start'],
290 xid : 'template_model',
292 packing : [ 'set_model' ],
297 _rendered : function ()
300 this.el.set_column_types ( 2, [
301 GObject.TYPE_STRING, // real key
302 GObject.TYPE_STRING // real type
316 loadData : function () {
318 var iter = new Gtk.TreeIter();
320 Roo.each(this.templates, function(p) {
324 el.set_value(iter, 0, p);
325 el.set_value(iter, 1, p);
345 packing : [ 'pack_start', false, true , 0 ],
350 packing : [ 'pack_start', false, true , 0 ],
352 label : "In Directory:"
360 packing : [ 'pack_end', true, true , 0 ],
362 // set_text_column : [1]
363 //set_size_request : [150,-1]
367 setValue : function(v)
371 Roo.each(XN.get(this).directory_model.data, function(n, ix) {
378 getValue : function()
380 var ix = this.el.get_active();
384 return XN.get(this).directory_model.data[ix].xtype;
386 var iter = new Gtk.TreeIter();
387 if (this.el.get_active_iter(iter)) {
390 var value = new GObject.Value('');
391 this.model.el.get_value(iter, 0, value);
400 _rendered : function ()
403 // _form.xtype = this;
404 this.el.add_attribute(this.items[0].el , 'markup', 1 );
405 //this.el.add_attribute(this.items[0].el , 'popup', 2 );
417 xtype : 'CellRendererText',
418 packing : ['pack_start'],
425 packing : [ 'set_model' ],
427 xid: 'directory_model',
430 _rendered : function ()
433 this.el.set_column_types ( 2, [
434 GObject.TYPE_STRING, // real key
435 GObject.TYPE_STRING // real type
449 loadData : function (data) {
451 var iter = new Gtk.TreeIter();
453 Roo.each(data, function(p) {
458 el.set_value(iter, 0, p.id);
459 el.set_value(iter, 1, p.desc);
478 packing : [ 'pack_end', true, true , 0 ],
495 //_win = XN.xnew(create());