Partial Fix #5560 - Gitlive - branching wip
[gitlive] / Clone.vala
diff --git a/Clone.vala b/Clone.vala
new file mode 100644 (file)
index 0000000..afad682
--- /dev/null
@@ -0,0 +1,283 @@
+static Clone  _Clone;
+
+public class Clone : Object
+{
+    public Gtk.Popover el;
+    private Clone  _this;
+
+    public static Clone singleton()
+    {
+        if (_Clone == null) {
+            _Clone= new Clone();
+        }
+        return _Clone;
+    }
+    public Xcls_reposel reposel;
+    public Xcls_prcellrenderer prcellrenderer;
+    public Xcls_repomodel repomodel;
+
+        // my vars (def)
+
+    // ctor
+    public Clone()
+    {
+        _this = this;
+        this.el = new Gtk.Popover( null );
+
+        // my vars (dec)
+
+        // set gobject values
+        this.el.border_width = 0;
+        this.el.modal = true;
+        this.el.position = Gtk.PositionType.RIGHT;
+        var child_0 = new Xcls_Box2( _this );
+        child_0.ref();
+        this.el.add (  child_0.el  );
+    }
+
+    // user defined functions
+    public void show (Gtk.Widget btn) {
+     
+               //console.log('show all');
+       this.el.set_modal(true);
+       this.el.set_relative_to(btn);
+       this.repomodel.loadRepos();
+       //this.el.set_position(Gtk.PositionType.RIGHT);
+    
+       // window + header?
+        GLib.debug("SHOWALL - POPIP\n");
+       this.el.show_all();
+    ;
+    }
+    public class Xcls_Box2 : Object
+    {
+        public Gtk.Box el;
+        private Clone  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_Box2(Clone _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
+
+            // my vars (dec)
+
+            // set gobject values
+            this.el.expand = false;
+            this.el.vexpand = false;
+            var child_0 = new Xcls_reposel( _this );
+            child_0.ref();
+            this.el.add (  child_0.el  );
+            var child_1 = new Xcls_Button6( _this );
+            child_1.ref();
+            this.el.add (  child_1.el  );
+        }
+
+        // user defined functions
+    }
+    public class Xcls_reposel : Object
+    {
+        public Gtk.ComboBox el;
+        private Clone  _this;
+
+
+            // my vars (def)
+        public bool loading;
+
+        // ctor
+        public Xcls_reposel(Clone _owner )
+        {
+            _this = _owner;
+            _this.reposel = this;
+            this.el = new Gtk.ComboBox.with_entry();
+
+            // my vars (dec)
+            this.loading = false;
+
+            // set gobject values
+            this.el.hexpand = true;
+            var child_0 = new Xcls_prcellrenderer( _this );
+            child_0.ref();
+            this.el.pack_start (  child_0.el , true );
+            var child_1 = new Xcls_repomodel( _this );
+            child_1.ref();
+            this.el.set_model (  child_1.el  );
+
+            // init method
+
+            this.el.set_entry_text_column(1);
+        }
+
+        // user defined functions
+        public string selectedRepo () {
+               Gtk.TreeIter iter;
+               Value val1;
+         
+         
+               this.el.get_active_iter (out iter);
+               _this.repomodel.el.get_value (iter, 0, out val1);
+         
+        
+               return  (string) val1;
+               
+               
+               
+               
+        }
+    }
+    public class Xcls_prcellrenderer : Object
+    {
+        public Gtk.CellRendererText el;
+        private Clone  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_prcellrenderer(Clone _owner )
+        {
+            _this = _owner;
+            _this.prcellrenderer = this;
+            this.el = new Gtk.CellRendererText();
+
+            // my vars (dec)
+
+            // set gobject values
+        }
+
+        // user defined functions
+    }
+
+    public class Xcls_repomodel : Object
+    {
+        public Gtk.ListStore el;
+        private Clone  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_repomodel(Clone _owner )
+        {
+            _this = _owner;
+            _this.repomodel = this;
+            this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
+
+            // my vars (dec)
+
+            // set gobject values
+        }
+
+        // user defined functions
+        public void loadRepos () {
+        
+            var rt = RooTicket.singleton();
+            var gr = GitRepo.singleton();
+            _this.reposel.loading = true;
+        
+            this.el.clear();                                    
+            Gtk.TreeIter iter;
+            var el = this.el;
+            
+            el.append(out iter);
+        
+            
+            el.set_value(iter, 0, "");
+            el.set_value(iter, 1, "-- select a repo --");
+         
+               _this.reposel.el.set_active_iter(iter);
+            
+            var projects = rt.projects;
+            foreach(var newrepo in rt.repos) {
+               var has_repo = false;
+               foreach(var repo in gr.cache.values) {
+                       if (newrepo.shortname == repo.name) {
+                               has_repo = true;
+                       }
+               }
+               if (has_repo) {
+                       continue;
+                       }
+                el.append(out iter);
+                
+                el.set_value(iter, 0, newrepo.shortname);
+                el.set_value(iter, 1, newrepo.shortname); // "%s : %s".printf(newrepo.shortname, newrepo.description) );
+               
+                
+            }
+            
+            _this.reposel.loading = false;
+             //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
+                                             
+        }
+    }
+
+
+    public class Xcls_Button6 : Object
+    {
+        public Gtk.Button el;
+        private Clone  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_Button6(Clone _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.Button();
+
+            // my vars (dec)
+
+            // set gobject values
+            this.el.label = "Checkout";
+
+            //listeners
+            this.el.button_press_event.connect( () => {
+                  _this.el.hide();
+                  Clones.singleton().el.hide();
+                 var repo = _this.reposel.selectedRepo();
+                    GitMonitor.gitmonitor.stop();
+                    
+                
+                    string[]  args = { "git" , "--no-pager" , "clone" };
+                
+                    args +=  ("http://git.roojs.com/" + repo );
+             
+                
+            
+                    string[]   env = {};
+                    string  home = "HOME=" + Environment.get_home_dir() ;
+                    env +=  home ;
+                               //v.push("GITPATH=" + this.repo );
+                    //}
+                      
+                    var cfg = new SpawnConfig(Environment.get_home_dir() + "/gitlive" , args , env);
+                    //cfg.debug = true;
+            
+                   // may throw error...
+                    var sp = new Spawn(cfg);
+                  
+                        GLib.debug("Spawn: %s", sp.output);
+               
+                    
+                    
+                    
+                    
+                    
+                    GitMonitor.gitmonitor.start();
+            
+                     GitRepo.updateAll("show_clones");
+                  
+                    return false;
+            });
+        }
+
+        // user defined functions
+    }
+
+
+}