handling of old branches
[gitlive] / NewBranch.vala
1 static NewBranch  _NewBranch;
2
3 public class NewBranch : Object
4 {
5     public Gtk.Dialog el;
6     private NewBranch  _this;
7
8     public static NewBranch singleton()
9     {
10         if (_NewBranch == null) {
11             _NewBranch= new NewBranch();
12         }
13         return _NewBranch;
14     }
15     public Xcls_ticketsel ticketsel;
16     public Xcls_dbcellrenderer dbcellrenderer;
17     public Xcls_dbmodel dbmodel;
18     public Xcls_name name;
19
20         // my vars (def)
21     public GitRepo? repo;
22     public bool running;
23     public Gee.ArrayList<GitMonitorQueue> queue;
24
25     // ctor
26     public NewBranch()
27     {
28         _this = this;
29         this.el = new Gtk.Dialog();
30
31         // my vars (dec)
32         this.repo = null;
33         this.running = false;
34         this.queue = null;
35
36         // set gobject values
37         this.el.title = "Create a working branch ";
38         this.el.default_height = 200;
39         this.el.default_width = 500;
40         this.el.deletable = true;
41         this.el.modal = true;
42         var child_0 = new Xcls_VBox2( _this );
43         child_0.ref();
44         this.el.get_content_area().add (  child_0.el  );
45         var child_1 = new Xcls_Button10( _this );
46         child_1.ref();
47         this.el.add_action_widget (  child_1.el , 0 );
48         var child_2 = new Xcls_Button11( _this );
49         child_2.ref();
50         this.el.add_action_widget (  child_2.el , 1 );
51
52         //listeners
53         this.el.delete_event.connect( (self, event) => {
54             this.el.hide();
55             this.running = false;
56             return true; 
57             //test  
58         });
59         this.el.response.connect( (self, response_id) =>  { 
60           
61                 GLib.debug("got %d", (int) response_id);
62                 if (response_id == 0) {
63                     _this.el.hide();    
64                     this.running = false; 
65                         GitMonitor.gitmonitor.start();      
66                         return;
67                 }
68                  
69                 // have they selected a ticket..
70                 // make that the current active ticket?
71                 // we really need to store locally what ticket is being worked on..
72                 // in theory we could be working on multiple project and not merging..
73                 // -- each repo would have their active ticket (only one per repo)
74                 // -- so we could just store that in there
75                 // -- initial load can check the contents of the ticket files on first scan.
76                 var ticket_id = _this.ticketsel.selectedTicketId();
77                 
78                 var success = true;
79             if (this.repo != null) {
80                 var bn = _this.name.el.get_text();
81                 if (ticket_id != "" ) {
82                                 success = this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
83                         } else {
84                                 success = this.repo.createBranchNamed(bn);
85                         }
86             }
87         
88                             this.running = false; 
89         
90                  
91                  
92                  
93         
94                  
95         });
96         this.el.show.connect( (self)  => {
97          
98         
99           //test
100         });
101     }
102
103     // user defined functions
104     public   void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue ) 
105     {
106          // this.el.set_gravity(Gdk.Gravity.NORTH);
107         if (this.running) { // should not happen!!
108                 GLib.error("new branch show called, when already being displayed?");
109         }
110         this.queue = queue;
111         
112         this.running  = true;
113         GitMonitor.gitmonitor.stop();
114         
115         this.repo = repo;
116         
117         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
118                 GLib.debug("Loading tickets"); 
119     
120     
121         this.el.show_all();
122         _this.dbmodel.loadTickets();
123     
124     }
125     public class Xcls_VBox2 : Object
126     {
127         public Gtk.VBox el;
128         private NewBranch  _this;
129
130
131             // my vars (def)
132
133         // ctor
134         public Xcls_VBox2(NewBranch _owner )
135         {
136             _this = _owner;
137             this.el = new Gtk.VBox( true, 0 );
138
139             // my vars (dec)
140
141             // set gobject values
142             var child_0 = new Xcls_Table3( _this );
143             child_0.ref();
144             this.el.pack_start (  child_0.el , false,false,0 );
145         }
146
147         // user defined functions
148     }
149     public class Xcls_Table3 : Object
150     {
151         public Gtk.Table el;
152         private NewBranch  _this;
153
154
155             // my vars (def)
156
157         // ctor
158         public Xcls_Table3(NewBranch _owner )
159         {
160             _this = _owner;
161             this.el = new Gtk.Table( 2, 2, false );
162
163             // my vars (dec)
164
165             // set gobject values
166             this.el.margin = 2;
167             this.el.column_spacing = 2;
168             var child_0 = new Xcls_Label4( _this );
169             child_0.ref();
170             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
171             var child_1 = new Xcls_ticketsel( _this );
172             child_1.ref();
173             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
174             var child_2 = new Xcls_Label8( _this );
175             child_2.ref();
176             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
177             var child_3 = new Xcls_name( _this );
178             child_3.ref();
179             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
180         }
181
182         // user defined functions
183     }
184     public class Xcls_Label4 : Object
185     {
186         public Gtk.Label el;
187         private NewBranch  _this;
188
189
190             // my vars (def)
191
192         // ctor
193         public Xcls_Label4(NewBranch _owner )
194         {
195             _this = _owner;
196             this.el = new Gtk.Label( "Select Ticket" );
197
198             // my vars (dec)
199
200             // set gobject values
201             this.el.justify = Gtk.Justification.RIGHT;
202             this.el.xalign = 0.900000f;
203             this.el.visible = true;
204         }
205
206         // user defined functions
207     }
208
209     public class Xcls_ticketsel : Object
210     {
211         public Gtk.ComboBox el;
212         private NewBranch  _this;
213
214
215             // my vars (def)
216         public bool loading;
217
218         // ctor
219         public Xcls_ticketsel(NewBranch _owner )
220         {
221             _this = _owner;
222             _this.ticketsel = this;
223             this.el = new Gtk.ComboBox();
224
225             // my vars (dec)
226             this.loading = false;
227
228             // set gobject values
229             var child_0 = new Xcls_dbcellrenderer( _this );
230             child_0.ref();
231             this.el.pack_start (  child_0.el , true );
232             var child_1 = new Xcls_dbmodel( _this );
233             child_1.ref();
234             this.el.set_model (  child_1.el  );
235
236             // init method
237
238             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
239
240             //listeners
241             this.el.changed.connect( () => {
242                 if (this.loading) {
243                         return;
244                 }
245                 var ticket_id = this.selectedTicketId();
246                 
247                 var name = RooTicket.singleton().usernameLocal();
248                 
249                 if (ticket_id == "" || ticket_id == null) {
250                 
251                         var dt = new  DateTime.now_local();
252                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
253                         return;
254                 }
255                 
256                 
257                 var ticket = RooTicket.singleton().getById(ticket_id);
258                
259                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
260                 
261                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
262             });
263         }
264
265         // user defined functions
266         public string selectedTicketId () {
267         Gtk.TreeIter iter;
268                 Value val1;
269          
270          
271                 this.el.get_active_iter (out iter);
272                 _this.dbmodel.el.get_value (iter, 0, out val1);
273          
274         
275                 return  (string) val1;
276                 
277                 
278                 
279                 
280         }
281     }
282     public class Xcls_dbcellrenderer : Object
283     {
284         public Gtk.CellRendererText el;
285         private NewBranch  _this;
286
287
288             // my vars (def)
289
290         // ctor
291         public Xcls_dbcellrenderer(NewBranch _owner )
292         {
293             _this = _owner;
294             _this.dbcellrenderer = this;
295             this.el = new Gtk.CellRendererText();
296
297             // my vars (dec)
298
299             // set gobject values
300         }
301
302         // user defined functions
303     }
304
305     public class Xcls_dbmodel : Object
306     {
307         public Gtk.ListStore el;
308         private NewBranch  _this;
309
310
311             // my vars (def)
312
313         // ctor
314         public Xcls_dbmodel(NewBranch _owner )
315         {
316             _this = _owner;
317             _this.dbmodel = this;
318             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
319
320             // my vars (dec)
321
322             // set gobject values
323         }
324
325         // user defined functions
326         public void loadTickets () {
327         
328             RooTicket.singleton().loadTickets();
329             
330             _this.ticketsel.loading = true;
331         
332             this.el.clear();                                    
333             Gtk.TreeIter iter;
334             var el = this.el;
335             
336             el.append(out iter);
337         
338             
339             el.set_value(iter, 0, "");
340             el.set_value(iter, 1, "-- select a ticket --");
341             
342             _this.ticketsel.el.set_active_iter(iter);
343             var tickets = RooTicket.singleton().tickets;
344             foreach(var ticket in tickets) {
345             
346                 el.append(out iter);
347                 
348                 el.set_value(iter, 0, ticket.id);
349                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
350                 
351                 //if (data.get(i) == cur) {
352                  //   _this.build_module.el.set_active_iter(iter);
353                // }
354                 
355             }
356             
357             _this.ticketsel.loading = false;
358              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
359                                              
360         }
361     }
362
363
364     public class Xcls_Label8 : Object
365     {
366         public Gtk.Label el;
367         private NewBranch  _this;
368
369
370             // my vars (def)
371
372         // ctor
373         public Xcls_Label8(NewBranch _owner )
374         {
375             _this = _owner;
376             this.el = new Gtk.Label( "or use this as branch name" );
377
378             // my vars (dec)
379
380             // set gobject values
381             this.el.justify = Gtk.Justification.RIGHT;
382             this.el.xalign = 0.900000f;
383         }
384
385         // user defined functions
386     }
387
388     public class Xcls_name : Object
389     {
390         public Gtk.Entry el;
391         private NewBranch  _this;
392
393
394             // my vars (def)
395
396         // ctor
397         public Xcls_name(NewBranch _owner )
398         {
399             _this = _owner;
400             _this.name = this;
401             this.el = new Gtk.Entry();
402
403             // my vars (dec)
404
405             // set gobject values
406             this.el.visible = true;
407         }
408
409         // user defined functions
410     }
411
412
413
414     public class Xcls_Button10 : Object
415     {
416         public Gtk.Button el;
417         private NewBranch  _this;
418
419
420             // my vars (def)
421
422         // ctor
423         public Xcls_Button10(NewBranch _owner )
424         {
425             _this = _owner;
426             this.el = new Gtk.Button();
427
428             // my vars (dec)
429
430             // set gobject values
431             this.el.relief = Gtk.ReliefStyle.NONE;
432             this.el.label = "Do not create Branch";
433         }
434
435         // user defined functions
436     }
437
438     public class Xcls_Button11 : Object
439     {
440         public Gtk.Button el;
441         private NewBranch  _this;
442
443
444             // my vars (def)
445
446         // ctor
447         public Xcls_Button11(NewBranch _owner )
448         {
449             _this = _owner;
450             this.el = new Gtk.Button();
451
452             // my vars (dec)
453
454             // set gobject values
455             this.el.label = "Create Branch";
456         }
457
458         // user defined functions
459     }
460
461 }