Builder3/Window.js
[app.Builder.js] / Builder / DialogNewComponent.js
old mode 100755 (executable)
new mode 100644 (file)
index 4831f00..3bf308d
-//<Script type="text/javascript">
-
 Gtk = imports.gi.Gtk;
-GObject = imports.gi.GObject;
-Gio = imports.gi.Gio;
+Gdk = imports.gi.Gdk;
+Pango = imports.gi.Pango;
 GLib = imports.gi.GLib;
-
-console = imports.console.console;
+Gio = imports.gi.Gio;
+GObject = imports.gi.GObject;
+GtkSource = imports.gi.GtkSource;
+WebKit = imports.gi.WebKit;
+Vte = imports.gi.Vte;
+GtkClutter = imports.gi.GtkClutter;
+console = imports.console;
 XObject = imports.XObject.XObject;
-
-Window                = imports.Builder.Window.Window;
-StandardErrorDialog = imports.Builder.StandardErrorDialog.StandardErrorDialog;
-/**
- * add a component
- * 
- * basically uses a standard template ? pulled from the web?
- * 
- * you have to pick which template, and give it a name..
- * 
- * and pick which directory to put it in?
- * 
- */
-
-DialogNewComponent = new XObject({
-        
-        xns : Gtk.Dialog,
-      //  type: Gtk.WindowType.TOPLEVEL,
-        deletable : false,
-        modal : true,
-        title  : "New Component",
-        border_width : 0,
-        project : false,
-        init : function()
-        {
-            XObject.prototype.init.call(this); 
-            this.el.add_button("OK",1 );
-            this.el.add_button("Cancel",0 );
-           
-        
-           
-            this.el.set_default_size (600, 400);
-            
-            //show_all : []
+DialogNewComponent=new XObject({
+    xtype: Gtk.Dialog,
+    listeners : {
+        delete_event : function (self, event) {
+            this.el.hide();
+            return true;
         },
-       
-        show : function (c) 
-        {
-            if (!this.el) {
-                this.init();
-            }
-            c = c || { name : '' , xtype : '' };
-            // check whic project we are adding to..
-            XObject.extend(this, c);
-            
-            this.el.set_screen(Window.el.get_screen());
-            
-            var paths = [];
-            for (var i in this.project.paths) {
-                paths.push({
-                    id : i,
-                    desc : i
-                });
-            }
-            
-            // load the paths.
-            this.get('directory_model').loadData(paths);
-                
-            
-            
-            this.el.show_all();
-            this.success = c.success;
-            
-            var tm = this.get('template_model');
-            if (tm.templates) {
-                return;
-            }
-            tm.templates = [];
-            var dir = __script_path__ + '/templates/';
-            
-            var f = Gio.file_new_for_path(dir);
-            f.enumerate_children_async ("*",  Gio.FileQueryInfoFlags.NONE, 
-                    GLib.PRIORITY_DEFAULT, null, function(o,ar) {
-                // enum completed..
-                var fe = f.enumerate_children_finish(ar);
-                var ch = '';
-                while (ch = fe.next_file(null)) {
-                    var add = dir + '/' + ch.get_name();
-                    if (!add.match(/\.js$/)) {
-                        continue;
-                    }
-                    tm.templates.push(add);
-                    
+        response : function (self, response_id) {
+               if (response_id < 1) { // cancel!
+                    this.el.hide();
+                    return;
                 }
-                tm.loadData();
-                
-            }, null);
-            
-        },
         
-        listeners : 
-        {
-            'delete-event' : function (widget, event) {
-                this.el.hide();
-                return true;
-            },
-            
-            response : function (w, id) 
-            {
-                if (id < 1) { // cancel!
-                    this.el.hide();
+                if (!this.get('name').el.get_text().length ) {
+                    this.get('/StandardErrorDialog').show(
+                        "You have to set Project name "
+                    );
+                     
                     return;
                 }
+                var isNew = this.file.name.length ? false : true;
                 
-                
-                    
-                   
-            
-                if (!DialogNewComponent.get(xnsid).el.get_text().length || 
-                   DialogNewComponent.get('template').getValue().length ||
-                   DialogNewComponent.get('directory').getValue().length 
-                ) {
-                    StandardErrorDialog.show(
-                        "You have to set Project name ,template and directory"
+                if (this.file.name.length && this.file.name != this.get('name').el.get_text()) {
+                    this.get('/StandardErrorDialog').show(
+                        "Sorry changing names does not work yet. "
                     );
                      
                     return;
                 }
+                for (var i in this.def) {
+                    this.file[i] =  this.get(i).el.get_text();
+                }
+               
+                if (!isNew) {
+                    this.file.save();
+                    this.el.hide();
+                    return;
+                }
+               
+            
+               var dir ='';
+                for (var i in this.project.paths) {
+                       dir = i;
+                       break;
+               }
+        
+         
                 
-                var dir = DialogNewComponent.get('template').getValue();
-                var xidns = DialogNewComponent.get('xnsid').get_text();
-                
-                
-                 if (GLib.file_test (GLib.dir + '/' + xidns + '.js', GLib.FileTest.EXISTS)) {
+                // what about .js ?
+                 if (GLib.file_test (GLib.dir + '/' + this.file.name + '.bjs', GLib.FileTest.EXISTS)) {
                     StandardErrorDialog.show(
                         "That file already exists"
                     ); 
@@ -139,275 +68,178 @@ DialogNewComponent = new XObject({
                 this.el.hide();
                 
                 
-                var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());
+                //var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());
                 
                 var _this = this;
-                tmpl.copyTo(dir + '/' + xidns + '.js', function() {
-                    tmpl.setNSID(xidns);
-                    _this.project.addFile(tmpl);
-                    this.success(_this.project, tmpl);
-                });
-                
-                
-                
-                
-            }
-            
-            
-            
+                var nf = _this.project.create(dir + '/' + this.file.name + '.bjs');
+                for (var i in this.file) {
+                    nf[i] = this.file[i];
+                }
+                if (this.get('/DialogNewComponent').success) {
+                    this.get('/DialogNewComponent').success(_this.project, nf);
+                }
         },
+        show : function (self) {
+          this.el.show_all();
+        }
+    },
+    default_height : 200,
+    default_width : 500,
+    id : "DialogNewComponent",
+    title : "New Component",
+    deletable : false,
+    modal : true,
+    show : function (c) 
+    {
+        this.project = c.project;
+        if (!this.el) {
+            this.init();
+        }
+        this.def =  { 
+            name : '' , 
+            title : '' ,
+            region : '' ,
+            parent: '',
+          //  disable: '',
+            modOrder : '0',
+            permname : ''
+        };
+        for (var i in this.def) {
+            c[i] = c[i] || this.def[i];
+            this.get(i).el.set_text(c[i]);
+        }
+        if (c.name) {
+            this.el.set_title("Edit File Details - " + c.name);
+        } else {
+            this.el.set_title("Create New File");
+        }
+         
+        this.file = c;
+        console.log('show all');
+        this.el.show_all();
+        this.success = c.success;
         
-       
-     
-        items : [
-            {
-                
-                xtype : Gtk.VBox,
-                
-                pack: function(p,e) {
-                    p.el.get_content_area().add(e.el)
-                },
-                items : [
-                    {
-                        xtype : Gtk.HBox,
-                        pack : [ 'pack_start', false, true , 0 ],
-                        
-                        items : [
-                            {
-                                xtype : Gtk.Label,
-                                label : "Component Name:",
-                                pack : [ 'pack_start', false, true , 0 ]
-                                
-                            },
-                            
-                            {
-                                id : 'xnsid',
-                                xtype : Gtk.Entry,
-                                pack : [ 'pack_end', true, true , 0 ],
-                                setValue : function(v) 
-                                {
-                                    this.el.set_text(v);
-                                },
-                                getValue : function()
-                                {
-                                    return this.el.get_text();
-                                }
-                            }
-                         
-                        ]
-                        
-                    },
-                    {
-                        xtype : Gtk.HBox,
-                        pack : [ 'pack_start', false, true , 0 ],
-                        
-                        items : [
-                            {
-                                xtype : Gtk.Label,
-                                label : "Using Template:"
-                                pack : [ 'pack_start', false, true , 0 ],
-                                
-                            },
-                            
-                            
-                            {
-                                id : 'template',
-                                xtype : Gtk.ComboBox,
-                                pack : [ 'pack_end', true, true , 0 ],
-                                init : function()
-                                {
-                                    XObject.prototype.init.call(this); 
-                                    this.el.add_attribute(this.items[0].el , 'markup', 1 );  
-                                       
-                                },
-                            
-                                setValue : function(v)
-                                {
-                                    var el = this.el;
-                                    el.set_active(-1);
-                                    DialogNewComponent.get('template_model').templates.forEach(
-                                        function(n, ix) {
-                                            if (v == n ) {
-                                                el.set_active(ix);
-                                                return false;
-                                            }
-                                        }
-                                    );
-                                },
-                                getValue : function() 
-                                {
-                                    var ix = this.el.get_active();
-                                    if (ix < 0 ) {
-                                        return '';
-                                    }
-                                    return DialogNewComponent.get('template_model').templates[ix];
-                                  
-                                },
-                                
-                                 
-                                items : [
-                                    {
-                                        
-                                        xtype : Gtk.CellRendererText,
-                                        pack : ['pack_start'],
-                                        
-                                    },
-                                    {
-                                        id : 'template_model',
-                                        pack : [ 'set_model' ],
-                                        xtype : Gtk.ListStore,
-                                        
-                                        init : 
-                                        listeners :  function ()
-                                        {
-                                            XObject.prototype.init.call(this); 
-                                            this.el.set_column_types ( 2, [
-                                                    GObject.TYPE_STRING,  // real key
-                                                    GObject.TYPE_STRING // real type
-                                            ] );
-                                             
-                                            
-                                        
-                                        },
-                                       
-                                        templates : false,
-                                        
-                                        loadData : function () {
-                                            this.el.clear();
-                                            var iter = new Gtk.TreeIter();
-                                            var el = this.el;
-                                            this.templates.forEach(function(p) {
-                                                
-                                                el.append(iter);
-                                                
-                                                el.set_value(iter, 0, p);
-                                                el.set_value(iter, 1, p);
-                                                
-                                            });
-                                             
-                                            
-                                            
-                                        }
-                                         
-                                    }
-                                  
-                                         
-                                ]
-                            }
-                 
-                                
-                        ]
-                    },
-                    {
-                        xtype : Gtk.HBox,
-                        
-                        pack : [ 'pack_start', false, true , 0 ],
-                        
-                        items : [
-                            {
-                                xtype : Gtk.Label,
-                                pack : [ 'pack_start', false, true , 0 ],
-                                label : "In Directory:"
+        
+    },
+    items : [
+        {
+            xtype: Gtk.VBox,
+            pack : function(p,e) {
+                                p.el.get_content_area().add(e.el)
                             },
-                            
-                            {
-                                id : 'directory',
-                                
-                                xtype : Gtk.ComboBox,
-                                pack : [ 'pack_end', true, true , 0 ],
-                            
-                                 init : function()
-                                {
-                                    XObject.prototype.init.call(this); 
-                                   this.el.add_attribute(this.items[0].el , 'markup', 1 );  
-                                       
-                                },
-                            
-                                setValue : function(v)
-                                {
-                                    var el = this.el;
-                                    el.set_active(-1);
-                                    DialogNewComponent.get('directory_model').data.forEach(
-                                        function(n,ix) {
-                                            if (v == n.xtype) {
-                                                el.set_active(ix);
-                                                return false;
-                                            }
-                                        }
-                                    );
-                                },
-                                getValue : function() 
-                                {
-                                    var ix = this.el.get_active();
-                                    if (ix < 0 ) {
-                                        return '';
-                                    }
-                                    return  DialogNewComponent.get('directory_model').data[ix].xtype;
-                                    
-                                },
-                                
-                                 
-                                items : [
-                                    {
-                                        xtype : Gtk.CellRendererText,
-                                        pack : ['pack_start'],
-                                    },
-                                    {
-                                        
-                                        xtype : Gtk.ListStore,
-                                        pack : [ 'set_model' ],
-                                        id: 'directory_model',
-                                        init : function()
-                                        {
-                                            XObject.prototype.init.call(this); 
-                                            this.el.set_column_types ( 2, [
-                                                GObject.TYPE_STRING,  // real key
-                                                GObject.TYPE_STRING // real type
-                                            ]); 
-                                        },
-                                     
-                                       
-                                       
-                                        
-                                        loadData : function (data) {
-                                            this.el.clear();
-                                            var iter = new Gtk.TreeIter();
-                                            var el = this.el;
-                                            data.forEach( function(p) {
-                                                
-                                                el.append(iter);
-                                                
-                                                 
-                                                el.set_value(iter, 0, p.id);
-                                                el.set_value(iter, 1, p.desc);
-                                                
-                                            });
-                                             
-                                        }
-                                         
-                                    }
-                                  
-                                         
-                                ]
-                            }
-                 
-                                
-                        ]
-                    },
-                    {
-                        xtype : Gtk.Label,
-                        pack : [ 'pack_end', true, true , 0 ],
-                        label : ""
-                    }
-                    
-                    
-                ]
-            }
-        ]
-    }
-);
-    
-
-
-//XN.xnew(create());
-//_win = XN.xnew(create());
\ No newline at end of file
+            items : [
+                {
+                    xtype: Gtk.Table,
+                    n_columns : 2,
+                    n_rows : 3,
+                    pack : "pack_start,false,false,0",
+                    homogeneous : false,
+                    items : [
+                        {
+                            xtype: Gtk.Label,
+                            label : "Component Name",
+                            pack : "add",
+                            x_options : 4,
+                            xalign : 0.9,
+                            justify : Gtk.Justification.RIGHT
+                        },
+                        {
+                            xtype: Gtk.Entry,
+                            id : "name",
+                            pack : "add",
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Label,
+                            label : "Title",
+                            pack : "add",
+                            x_options : 4,
+                            xalign : 0.9,
+                            justify : Gtk.Justification.RIGHT,
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Entry,
+                            id : "title",
+                            pack : "add",
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Label,
+                            label : "Region",
+                            pack : "add",
+                            tooltip_text : "center, north, south, east, west",
+                            x_options : 4,
+                            xalign : 0.9,
+                            justify : Gtk.Justification.RIGHT,
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Entry,
+                            id : "region",
+                            pack : "add",
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Label,
+                            label : "Parent Name",
+                            pack : "add",
+                            x_options : 4,
+                            xalign : 0.9,
+                            justify : Gtk.Justification.RIGHT,
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Entry,
+                            id : "parent",
+                            pack : "add",
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Label,
+                            label : "Permission Name",
+                            pack : "add",
+                            x_options : 4,
+                            xalign : 0.9,
+                            justify : Gtk.Justification.RIGHT,
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Entry,
+                            id : "permname",
+                            pack : "add",
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Label,
+                            label : "Order (for tabs)",
+                            pack : "add",
+                            x_options : 4,
+                            xalign : 0.9,
+                            justify : Gtk.Justification.RIGHT,
+                            visible : true
+                        },
+                        {
+                            xtype: Gtk.Entry,
+                            id : "modOrder",
+                            pack : "add",
+                            visible : true
+                        }
+                    ]
+                }
+            ]
+        },
+        {
+            xtype: Gtk.Button,
+            pack : "add_action_widget,0",
+            label : "Cancel"
+        },
+        {
+            xtype: Gtk.Button,
+            pack : "add_action_widget,1",
+            label : "OK"
+        }
+    ]
+});
+DialogNewComponent.init();
+XObject.cache['/DialogNewComponent'] = DialogNewComponent;