Fix #5725 - disable create branch until ticket selected
[gitlive] / NewBranch.vala
index 9183007..fbf036d 100644 (file)
@@ -19,6 +19,7 @@ public class NewBranch : Object
     public Xcls_dbcellrenderer dbcellrenderer;
     public Xcls_dbmodel dbmodel;
     public Xcls_name name;
+    public Xcls_createbtn createbtn;
     public Xcls_btn_not_me btn_not_me;
     public Xcls_btn_closed btn_closed;
     public Xcls_scrolled_window scrolled_window;
@@ -59,11 +60,9 @@ public class NewBranch : Object
         this.el.response.connect( (self, response_id) =>  { 
           
                GLib.debug("got %d", (int) response_id);
-               if (response_id < 1) {
-                   _this.el.hide();    
-                   this.running = false; 
-                       return;
-               }
+               
+                
+               
                 
                // have they selected a ticket..
                // make that the current active ticket?
@@ -72,6 +71,14 @@ public class NewBranch : Object
                // -- each repo would have their active ticket (only one per repo)
                // -- so we could just store that in there
                // -- initial load can check the contents of the ticket files on first scan.
+        
+                
+               if (response_id < 1) {
+                   _this.el.hide();    
+                   this.running = false; 
+                       return;
+               }
+               
                var ticket_id = _this.ticketsel.selectedTicketId();
                
             if (this.repo != null) {
@@ -86,7 +93,7 @@ public class NewBranch : Object
                                 
                         }
             }
-            
+             
         
             this.running = false; 
         
@@ -123,17 +130,19 @@ public class NewBranch : Object
         this.el.set_keep_above(true);
        
         
-        var curproj = RooTicket.singleton().getProjectByRepo(this.repo);
+        var curproj = RooProject.getProjectByRepo(this.repo);
          _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
         
        _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
-    
-       if (tid != "") {
+       _this.createbtn.updateState();
+       
+       _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
+       if (tid != "") { 
                var name = RooTicket.singleton().usernameLocal();
                var ticket = RooTicket.singleton().getById(tid);
                _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
-    
-    
+       } else {
+               _this.ticketsel.el.get_child().get_style_context().add_class("warning");
        }
         _this.view.loadTicket(tid);
        this.el.run();
@@ -208,7 +217,7 @@ public class NewBranch : Object
             var child_6 = new Xcls_name( _this );
             child_6.ref();
             this.el.attach_defaults (  child_6.el , 0,4,4,5 );
-            var child_7 = new Xcls_Button15( _this );
+            var child_7 = new Xcls_createbtn( _this );
             child_7.ref();
             this.el.attach_defaults (  child_7.el , 4,5,4,5 );
             var child_8 = new Xcls_Box16( _this );
@@ -394,8 +403,7 @@ public class NewBranch : Object
         // user defined functions
         public void loadProjects (string id) {
         
-            var rt = RooTicket.singleton();
-            rt.loadProjects();
+        
             
             _this.projectsel.loading = true;
         
@@ -411,8 +419,8 @@ public class NewBranch : Object
             if (id == "") {
                    _this.projectsel.el.set_active_iter(iter);
             }
-            var projects = rt.projects;
-            foreach(var project in projects) {
+          
+            foreach(var project in RooProject.projects()) {
             
                 el.append(out iter);
                 
@@ -462,6 +470,7 @@ public class NewBranch : Object
 
             //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
             this.el.set_entry_text_column(1);
+            this.el.get_child().set_sensitive(false);
 
             //listeners
             this.el.changed.connect( () => {
@@ -472,11 +481,15 @@ public class NewBranch : Object
                
                var name = RooTicket.singleton().usernameLocal();
                
+               this.el.get_child().get_style_context().remove_class("warning");
                if (ticket_id == "" || ticket_id == null) {
                
                        var dt = new  DateTime.now_local();
                        _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
                        _this.view.loadTicket("");              
+                       
+                       this.el.get_child().get_style_context().add_class("warning");
+                       _this.createbtn.updateState();
                        return;
                }
                
@@ -487,6 +500,8 @@ public class NewBranch : Object
                _this.scrolled_window.el.show();
                 
                _this.view.loadTicket(ticket.id);
+               _this.createbtn.updateState();
+               
                //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
             });
         }
@@ -583,7 +598,7 @@ public class NewBranch : Object
                 el.append(out iter);
                 
                 el.set_value(iter, 0, ticket.id);
-                el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
+                el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
                 
                 if (ticket.id == tid) {
                            _this.ticketsel.el.set_active_iter(iter);
@@ -678,7 +693,7 @@ public class NewBranch : Object
         // user defined functions
     }
 
-    public class Xcls_Button15 : Object
+    public class Xcls_createbtn : Object
     {
         public Gtk.Button el;
         private NewBranch  _this;
@@ -687,9 +702,10 @@ public class NewBranch : Object
             // my vars (def)
 
         // ctor
-        public Xcls_Button15(NewBranch _owner )
+        public Xcls_createbtn(NewBranch _owner )
         {
             _this = _owner;
+            _this.createbtn = this;
             this.el = new Gtk.Button();
 
             // my vars (dec)
@@ -705,12 +721,33 @@ public class NewBranch : Object
 
             //listeners
             this.el.clicked.connect( () => {
+            
                GLib.debug("fire response = 1");
+               
+               var ticket_id = _this.ticketsel.selectedTicketId();
+               
+               if (ticket_id == "") {
+                       _this.ticketsel.el.get_child().get_style_context().add_class("warning");
+                       return;
+               }
+                
                _this.el.response(1);
             });
         }
 
         // user defined functions
+        public void updateState () {
+        
+               var ticket_id = _this.ticketsel.selectedTicketId();
+               
+               if (ticket_id == "") {
+                       this.el.set_sensitive(false);
+                       return;
+               }
+         
+               this.el.set_sensitive(true);
+         
+        }
     }
 
     public class Xcls_Box16 : Object
@@ -828,7 +865,8 @@ public class NewBranch : Object
             //listeners
             this.el.activate_link.connect( (uri) => {
                if (uri == "refresh") {
-                       var curproj = RooTicket.singleton().getProjectByRepo(_this.repo);
+                       RooProject.reload();
+                       var curproj = RooProject.getProjectByRepo(_this.repo);
                         _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
             
                        _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);