Builder3/Window.js
[app.Builder.js] / Builder / EditProject.js
old mode 100755 (executable)
new mode 100644 (file)
index 1301c69..5f772c5
-//<Script type="text/javascript">
-
-XN = imports.xnew;
 Gtk = imports.gi.Gtk;
+Gdk = imports.gi.Gdk;
+Pango = imports.gi.Pango;
+GLib = imports.gi.GLib;
+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;
-Builder = imports['Builder.js'];
-Roo = imports['Roo.js'];
-
-StandardErrorDialog = imports.Builder.StandardErrorDialog.StandardErrorDialog;
-ProjectManager =      imports.Builder.Provider.ProjectManager.ProjectManager;
-/**
- * add/edit project
- * 
- * project type: gtk or roo..
- * 
- * directory.
- * 
- * 
- * 
- */
-
-EditProject = new XObject({
-    
+XObject = imports.XObject.XObject;
+EditProject=new XObject({
+    xtype: Gtk.Dialog,
+    default_height : 500,
+    default_width : 600,
+    deletable : true,
+    modal : true,
+    border_width : 3,
+    title : "Project Properties",
+    show : function(c) {
+           c = c || { name : '' , xtype : '' };
+        this.project  = c;
+        if (!this.el) {
+            this.init();
+        }
+        var _this = this;
+        [ 'xtype'  ].forEach(function(k) {
+            _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
+        });
+       // shouild set path..
         
-        xtype : Gtk.Dialog,
-        type: Gtk.WindowType.TOPLEVEL,
-        deletable : false,
-        modal : true,
-        
-        project : {},
-        init : function()
-        {
-            XObject.prototype.init.call(this); 
-            this.el.add_button("OK",1 );
-            this.el.add_button("Cancel",0 );
-            
-        },
-        show : function (c) 
-        {
-            
-            c = c || { name : '' , xtype : '' };
-            this.project  = c;
-            
-            [ 'xtype' , 'name' ].forEach(function(k) {
-                this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
-            }
-            if (!this.el) {
-                this.init();
-            }
-            this.el.show_all();
-            this.success = c.success;
-            
-            
+        this.el.show_all();
+        this.success = c.success;
+    },
+    listeners : {
+        destroy_event : function (self, event) {
+             this.el.hide();
+                        return false;
         },
-        
-        listeners :  {
-            
-            'delete-event' : function (widget, event) {
-                this.el.hide();
-                return true;
-            },
-            
-            response : function (w, id) 
-            {
-                
-                if (id < 1) {
+        response : function (self, id) {
+         if (id < 1) {
                     this.el.hide();
                     return;
                 }
                 if (!this.get('xtype').getValue().length) {
-                    StandardErrorDialog.show("You have to set Project type");
-                     
+                    this.get('/StandardErrorDialog').show("You have to set Project type");             
                     return;
                 }
+                if (!this.get('dir').el.get_filename().length) {
+                    this.get('/StandardErrorDialog').show("You have to select a folder");             
+                    return;
+                }
+        
                 this.el.hide();
                 
                 
+                var fn = this.get('dir').el.get_filename();
                 
-                
-                this.project.name  = this.get('name').getValue();
+                this.project.name  = GLib.basename(fn);
                 this.project.xtype  = this.get('xtype').getValue();
+                this.project.paths = {};
+                this.project.paths[fn] =  'dir' ;
                 
-                
-                
-                
-                var pr = ProjectManager.update(this.project);
+                var pr = imports.Builder.Provider.ProjectManager.ProjectManager.update(this.project);
                 
                 this.success(pr);
                 Seed.print(id);
-            },
-            
-        
-            
-        },
-        
-        set : {
-            set_border_width : [ 0 ],
-            set_title : [ 'Project Properties' ],
-            set_default_size: [600, 400] //,
-            
-            //show_all : []
-        },
-     
-        items : [
-            {
-                
-                xtype : Gtk.VBox',
-                xns: 'Gtk',
-                
-                pack : function(p,e) {
-                    p.el.get_content_area().add(e.el)
-                },
-                items : [
-                    {
-                        xtype : Gtk.HBox',
-                        xns: 'Gtk',
-                        pack : [ 'pack_start', false, true , 0 ],
-                        
-                        items : [
-                            {
-                                xtype : Gtk.Label',
-                                pack : [ 'pack_start', false, true , 0 ],
-                                xns: 'Gtk',
-                                label : "Project Name:"
-                            },
-                            
-                            {
-                                xtype : Gtk.Entry',
-                                
-                                xns: 'Gtk',
-                                pack : [ 'pack_end', true, true , 0 ],
-                                listeners : {
-                                    _rendered  : function(self) {
-                                        
-                                        _form.name = this;
-                                    }
-                                },
-                                setValue : function(v) {
-                                    this.el.set_text(v);
-                                },
-                                getValue : function()
-                                {
-                                    return this.el.get_text();
-                                }
-                            }
-                         
-                        ]
-                        
+        }
+    },
+    items : [
+        {
+            xtype: Gtk.VBox,
+            pack : function(p,e) {
+                        p.el.get_content_area().add(e.el)
                     },
-                    {
-                        xtype : Gtk.HBox',
-                        xns: 'Gtk',
-                        pack : [ 'pack_start', false, true , 0 ],
-                        
-                        items : [
-                            {
-                                xtype : Gtk.Label',
-                                pack : [ 'pack_start', false, true , 0 ],
-                                xns: 'Gtk',
-                                label : "Project Type:"
+            items : [
+                {
+                    xtype: Gtk.HBox,
+                    pack : "pack_start,false,true,3",
+                    items : [
+                        {
+                            xtype: Gtk.Label,
+                            pack : "pack_start,false,true,3",
+                            label : "Project type :"
+                        },
+                        {
+                            xtype: Gtk.ComboBox,
+                            pack : "pack_end,true,true,3",
+                            id : "xtype",
+                            setValue : function(v)
+                                            {
+                                                var el = this.el;
+                                                el.set_active(-1);
+                                                this.get('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 this.get('model').data[ix].xtype;
                             },
-                            
-                            
-                            {
-                
-                                
-                                xtype : Gtk.ComboBox',
-                                pack : [ 'pack_end', true, true , 0 ],
-                                set : {
-                                 //   set_text_column : [1]
-                                   //set_size_request : [150,-1]
-                                },
-                                
-                            
-                                setValue : function(v)
+                            init : function() {
+                                XObject.prototype.init.call(this);
+                              this.el.add_attribute(this.items[0].el , 'markup', 1 );  
+                            },
+                            items : [
                                 {
-                                    var el = this.el;
-                                    el.set_active(-1);
-                                    Roo.each(this.model.data, function(n, ix) {
-                                        if (v == n.xtype) {
-                                            el.set_active(ix);
-                                            return false;
-                                        }
-                                    })
+                                    xtype: Gtk.CellRendererText,
+                                    pack : "pack_start"
                                 },
-                                getValue : function() 
                                 {
-                                    var ix = this.el.get_active();
-                                    if (ix < 0 ) {
-                                        return '';
-                                    }
-                                    return this.model.data[ix].xtype;
-                                    /*
-                                    var iter = new Gtk.TreeIter();
-                                    if (this.el.get_active_iter(iter)) {
-                                        return '';
-                                    }
-                                    var value = new GObject.Value('');
-                                    this.model.el.get_value(iter, 0, value);
-                                    return value.value;
-                                    */
-                                },
-                                
-                                
-                                listeners : {
-                                    
-                                    _new : function ()
-                                    {
-                                        _view = this;
-                                    },
+                                    xtype: Gtk.ListStore,
+                                    pack : "set_model",
+                                    init : function() {
+                                        XObject.prototype.init.call(this);
                                     
-                                    _rendered  : function ()
-                                    {
-                                        
-                                        _form.xtype = this;
-                                        this.el.add_attribute(this.items[0].el , 'markup', 1 );  
-                                        //this.el.add_attribute(this.items[0].el , 'popup', 2 );     
-                                         
-                                     
-                                  
-                                    }
-                                },
-                                items : [
-                                   {
-                                        
-                                        
-                                   
-                                        
-                                        xtype : Gtk.CellRendererText',
-                                        pack : ['pack_start'],
-                                        
-
-                                         
+                                                                this.el.set_column_types ( 2, [
+                                                                    GObject.TYPE_STRING,  // real key
+                                                                    GObject.TYPE_STRING // real type
+                                                                    
+                                                                    
+                                                                ] );
+                                                                
+                                                                this.data = [
+                                                                    { xtype: 'Roo', desc : "Roo Project" },
+                                                                    { xtype: 'Gtk', desc : "Gtk Project" },    
+                                                                    //{ xtype: 'JS', desc : "Javascript Class" }
+                                                                ]
+                                                                
+                                                                this.loadData(this.data);
+                                                                    
                                     },
-                                    {
-                                        
-                                        pack : [ 'set_model' ],
-                                        xtype : Gtk.ListStore',
-                                        
-                                        listeners : {
-                                            _new : function()
-                                            {
-                                                _view.model = this;
-                                            },
-                                            _rendered :  function ()
-                                            {
-                                             
-                                                this.el.set_column_types ( 2, [
-                                                    GObject.TYPE_STRING,  // real key
-                                                    GObject.TYPE_STRING // real type
+                                    loadData : function (data) {
+                                                                                
+                                                var iter = new Gtk.TreeIter();
+                                                var el = this.el;
+                                                data.forEach(function(p) {
                                                     
+                                                    el.append(iter);
                                                     
-                                                ] );
-                                                
-                                                this.data = [
-                                                    { xtype: 'Roo', desc : "Roo Project" },
-                                                    { xtype: 'Gtk', desc : "Gtk Project" },    
-                                                    //{ xtype: 'JS', desc : "Javascript Class" }
-                                                ]
-                                                
-                                                this.loadData(this.data);
-                                                
-                                                return;
-                                               
-                                            
-                                            
-                                            }
-                                        },
-                                       
-                                       
-                                        
-                                        loadData : function (data) {
-                                            
-                                            var iter = new Gtk.TreeIter();
-                                            var el = this.el;
-                                            Roo.each(data, function(p) {
-                                                
-                                                el.append(iter);
-                                                
-                                                 
-                                                el.set_value(iter, 0, p.xtype);
-                                                el.set_value(iter, 1, p.desc);
-                                                
-                                            });
-                                             
-                                            
-                                            
-                                        }
-                                         
-                                    }
-                                  
-                                         
-                                ]
-                            }
-                 
-                                
-                        ]
-                    },
-                    {
-                        xtype : Gtk.Label',
-                        pack : [ 'pack_end', true, true , 0 ],
-                        xns: 'Gtk',
-                        label : ""
-                    },
-                    
-                    
-                    
-                    
-                ]
-            }
-        ]
-    };
-    
-}
-//_win = XN.xnew(create());
\ No newline at end of file
+                                                     
+                                                    el.set_value(iter, 0, p.xtype);
+                                                    el.set_value(iter, 1, p.desc);
+                                                    
+                                                });
+                                                  
+                                                                         
+                                    },
+                                    id : "model"
+                                }
+                            ]
+                        }
+                    ]
+                },
+                {
+                    xtype: Gtk.FileChooserWidget,
+                    pack : "pack_end,true,true,5",
+                    action : Gtk.FileChooserAction.SELECT_FOLDER,
+                    id : "dir",
+                    select_multiple : false
+                }
+            ]
+        },
+        {
+            xtype: Gtk.Button,
+            pack : "add_action_widget,1",
+            label : "OK"
+        },
+        {
+            xtype: Gtk.Button,
+            pack : "add_action_widget,0",
+            label : "Cancel"
+        }
+    ]
+});
+EditProject.init();
+XObject.cache['/EditProject'] = EditProject;