Fix #5560 - Gitlive - branching wip
[gitlive] / MergeBranch.vala
1 static MergeBranch  _MergeBranch;
2
3 public class MergeBranch : Object
4 {
5     public Gtk.Dialog el;
6     private MergeBranch  _this;
7
8     public static MergeBranch singleton()
9     {
10         if (_MergeBranch == null) {
11             _MergeBranch= new MergeBranch();
12         }
13         return _MergeBranch;
14     }
15     public Xcls_actionsel actionsel;
16     public Xcls_actioncellrenderer actioncellrenderer;
17     public Xcls_actionmodel actionmodel;
18     public Xcls_ticketsel ticketsel;
19     public Xcls_dbcellrenderer dbcellrenderer;
20     public Xcls_dbmodel dbmodel;
21     public Xcls_name name;
22
23         // my vars (def)
24     public RooTicket? ticket;
25     public bool running;
26
27     // ctor
28     public MergeBranch()
29     {
30         _this = this;
31         this.el = new Gtk.Dialog();
32
33         // my vars (dec)
34         this.ticket = null;
35         this.running = false;
36
37         // set gobject values
38         this.el.title = "Merge Branch";
39         this.el.default_height = 200;
40         this.el.default_width = 500;
41         this.el.deletable = true;
42         this.el.modal = true;
43         var child_0 = new Xcls_VBox2( _this );
44         child_0.ref();
45         this.el.get_content_area().add (  child_0.el  );
46         var child_1 = new Xcls_Button14( _this );
47         child_1.ref();
48         this.el.add_action_widget (  child_1.el , 0 );
49         var child_2 = new Xcls_Button15( _this );
50         child_2.ref();
51         this.el.add_action_widget (  child_2.el , 1 );
52
53         //listeners
54         this.el.delete_event.connect( (self, event) => {
55             this.el.hide();
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             if (this.repo != null) {
79                 var bn = _this.name.el.get_text();
80                 if (ticket_id != "" ) {
81                                 this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
82                         } else {
83                                 this.repo.createBranchNamed(bn);
84                         }
85             }
86                 */
87                 
88                 GitRepo.doMerges(
89                         _this.actionsel.selectedAction(), 
90                         _this.ticketsel.selectedTicketId(),
91                         _this.name.el.get_text()
92                 );
93                 
94                 this.running = false; 
95         
96                  
97                 _this.el.hide();        
98                 GitMonitor.gitmonitor.start();
99         
100                  
101         });
102         this.el.show.connect( (self)  => {
103          
104         
105           //test
106         });
107     }
108
109     // user defined functions
110     public   void show (  RooTicket ticket ) 
111     {
112          // this.el.set_gravity(Gdk.Gravity.NORTH);
113         if (this.running) {
114                 return;
115         }
116         GitMonitor.gitmonitor.stop();
117         
118         this.ticket = ticket;
119         
120         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
121                 GLib.debug("Loading tickets"); 
122     
123     
124         this.el.show_all();
125         _this.dbmodel.loadTickets();
126         _this.actionmodel.loadActions();
127     
128     
129     }
130     public class Xcls_VBox2 : Object
131     {
132         public Gtk.VBox el;
133         private MergeBranch  _this;
134
135
136             // my vars (def)
137
138         // ctor
139         public Xcls_VBox2(MergeBranch _owner )
140         {
141             _this = _owner;
142             this.el = new Gtk.VBox( true, 0 );
143
144             // my vars (dec)
145
146             // set gobject values
147             var child_0 = new Xcls_Table3( _this );
148             child_0.ref();
149             this.el.pack_start (  child_0.el , false,false,0 );
150         }
151
152         // user defined functions
153     }
154     public class Xcls_Table3 : Object
155     {
156         public Gtk.Table el;
157         private MergeBranch  _this;
158
159
160             // my vars (def)
161
162         // ctor
163         public Xcls_Table3(MergeBranch _owner )
164         {
165             _this = _owner;
166             this.el = new Gtk.Table( 2, 2, false );
167
168             // my vars (dec)
169
170             // set gobject values
171             this.el.margin = 2;
172             this.el.column_spacing = 2;
173             var child_0 = new Xcls_Label4( _this );
174             child_0.ref();
175             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
176             var child_1 = new Xcls_actionsel( _this );
177             child_1.ref();
178             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
179             var child_2 = new Xcls_Label8( _this );
180             child_2.ref();
181             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
182             var child_3 = new Xcls_ticketsel( _this );
183             child_3.ref();
184             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
185             var child_4 = new Xcls_Label12( _this );
186             child_4.ref();
187             this.el.attach_defaults (  child_4.el , 0,1,2,3 );
188             var child_5 = new Xcls_name( _this );
189             child_5.ref();
190             this.el.attach_defaults (  child_5.el , 1,2,2,3 );
191         }
192
193         // user defined functions
194     }
195     public class Xcls_Label4 : Object
196     {
197         public Gtk.Label el;
198         private MergeBranch  _this;
199
200
201             // my vars (def)
202
203         // ctor
204         public Xcls_Label4(MergeBranch _owner )
205         {
206             _this = _owner;
207             this.el = new Gtk.Label( "Do what?" );
208
209             // my vars (dec)
210
211             // set gobject values
212             this.el.justify = Gtk.Justification.RIGHT;
213             this.el.xalign = 0.900000f;
214             this.el.visible = true;
215         }
216
217         // user defined functions
218     }
219
220     public class Xcls_actionsel : Object
221     {
222         public Gtk.ComboBox el;
223         private MergeBranch  _this;
224
225
226             // my vars (def)
227         public bool loading;
228
229         // ctor
230         public Xcls_actionsel(MergeBranch _owner )
231         {
232             _this = _owner;
233             _this.actionsel = this;
234             this.el = new Gtk.ComboBox();
235
236             // my vars (dec)
237             this.loading = false;
238
239             // set gobject values
240             var child_0 = new Xcls_actioncellrenderer( _this );
241             child_0.ref();
242             this.el.pack_start (  child_0.el , true );
243             var child_1 = new Xcls_actionmodel( _this );
244             child_1.ref();
245             this.el.set_model (  child_1.el  );
246
247             // init method
248
249             this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
250
251             //listeners
252             this.el.changed.connect( () => {
253                 if (this.loading) {
254                         return;
255                 }
256                 _this.name.updateText();
257                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
258             });
259         }
260
261         // user defined functions
262         public string selectedAction () {
263                 Gtk.TreeIter iter;
264                 Value val1;
265          
266                 this.el.get_active_iter (out iter);
267                 _this.actionmodel.el.get_value (iter, 0, out val1);
268         
269                 return  (string) val1;
270         }
271     }
272     public class Xcls_actioncellrenderer : Object
273     {
274         public Gtk.CellRendererText el;
275         private MergeBranch  _this;
276
277
278             // my vars (def)
279
280         // ctor
281         public Xcls_actioncellrenderer(MergeBranch _owner )
282         {
283             _this = _owner;
284             _this.actioncellrenderer = this;
285             this.el = new Gtk.CellRendererText();
286
287             // my vars (dec)
288
289             // set gobject values
290         }
291
292         // user defined functions
293     }
294
295     public class Xcls_actionmodel : Object
296     {
297         public Gtk.ListStore el;
298         private MergeBranch  _this;
299
300
301             // my vars (def)
302
303         // ctor
304         public Xcls_actionmodel(MergeBranch _owner )
305         {
306             _this = _owner;
307             _this.actionmodel = this;
308             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
309
310             // my vars (dec)
311
312             // set gobject values
313         }
314
315         // user defined functions
316         public void loadActions () {
317         
318          
319             
320             _this.actionsel.loading = true;
321         
322             this.el.clear();                                    
323             Gtk.TreeIter iter;
324             var el = this.el;
325             
326             el.append(out iter);
327         
328             
329             el.set_value(iter, 0, "");
330             el.set_value(iter, 1, "-- select action  --");
331             
332             _this.actionsel.el.set_active_iter(iter);
333         
334             el.append(out iter);    
335             el.set_value(iter, 0, "CLOSE");
336             el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
337                 
338                 
339             el.append(out iter);    
340             el.set_value(iter, 0, "LEAVE");
341             el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
342         
343             el.append(out iter);    
344             el.set_value(iter, 0, "MASTER");
345             el.set_value(iter, 1, "Merge changes FROM master into this branch");    
346             
347             el.append(out iter);    
348             el.set_value(iter, 0, "EXIT");
349             el.set_value(iter, 1, "Switch back to MASTER branch - no merge");    
350             
351             
352             
353             _this.actionsel.loading = false;
354              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
355                                              
356         }
357     }
358
359
360     public class Xcls_Label8 : Object
361     {
362         public Gtk.Label el;
363         private MergeBranch  _this;
364
365
366             // my vars (def)
367
368         // ctor
369         public Xcls_Label8(MergeBranch _owner )
370         {
371             _this = _owner;
372             this.el = new Gtk.Label( "Select Ticket" );
373
374             // my vars (dec)
375
376             // set gobject values
377             this.el.justify = Gtk.Justification.RIGHT;
378             this.el.xalign = 0.900000f;
379             this.el.visible = true;
380         }
381
382         // user defined functions
383     }
384
385     public class Xcls_ticketsel : Object
386     {
387         public Gtk.ComboBox el;
388         private MergeBranch  _this;
389
390
391             // my vars (def)
392         public bool loading;
393
394         // ctor
395         public Xcls_ticketsel(MergeBranch _owner )
396         {
397             _this = _owner;
398             _this.ticketsel = this;
399             this.el = new Gtk.ComboBox();
400
401             // my vars (dec)
402             this.loading = false;
403
404             // set gobject values
405             var child_0 = new Xcls_dbcellrenderer( _this );
406             child_0.ref();
407             this.el.pack_start (  child_0.el , true );
408             var child_1 = new Xcls_dbmodel( _this );
409             child_1.ref();
410             this.el.set_model (  child_1.el  );
411
412             // init method
413
414             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
415
416             //listeners
417             this.el.changed.connect( () => {
418                 if (this.loading) {
419                         return;
420                 }
421                 
422                  
423                 _this.name.updateText();
424                 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
425                 
426                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
427             });
428         }
429
430         // user defined functions
431         public string selectedTicketId () {
432         Gtk.TreeIter iter;
433                 Value val1;
434          
435          
436                 this.el.get_active_iter (out iter);
437                 _this.dbmodel.el.get_value (iter, 0, out val1);
438          
439         
440                 return  (string) val1;
441                 
442                 
443                 
444                 
445         }
446     }
447     public class Xcls_dbcellrenderer : Object
448     {
449         public Gtk.CellRendererText el;
450         private MergeBranch  _this;
451
452
453             // my vars (def)
454
455         // ctor
456         public Xcls_dbcellrenderer(MergeBranch _owner )
457         {
458             _this = _owner;
459             _this.dbcellrenderer = this;
460             this.el = new Gtk.CellRendererText();
461
462             // my vars (dec)
463
464             // set gobject values
465         }
466
467         // user defined functions
468     }
469
470     public class Xcls_dbmodel : Object
471     {
472         public Gtk.ListStore el;
473         private MergeBranch  _this;
474
475
476             // my vars (def)
477
478         // ctor
479         public Xcls_dbmodel(MergeBranch _owner )
480         {
481             _this = _owner;
482             _this.dbmodel = this;
483             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
484
485             // my vars (dec)
486
487             // set gobject values
488         }
489
490         // user defined functions
491         public void loadTickets () {
492         
493             RooTicket.singleton().loadTickets();
494             
495             _this.ticketsel.loading = true;
496         
497             this.el.clear();                                    
498             Gtk.TreeIter iter;
499             var el = this.el;
500             
501             el.append(out iter);
502         
503             
504             el.set_value(iter, 0, "");
505             el.set_value(iter, 1, "-- select a ticket --");
506             
507             _this.ticketsel.el.set_active_iter(iter);
508             var tickets = RooTicket.singleton().tickets;
509             foreach(var ticket in tickets) {
510             
511                 el.append(out iter);
512         
513                 el.set_value(iter, 0, ticket.id);
514                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
515                         if (_this.ticket.id == ticket.id) {
516                             _this.ticketsel.el.set_active_iter(iter);
517                     }
518                 
519             }
520             
521             _this.ticketsel.loading = false;
522              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
523                                              
524         }
525     }
526
527
528     public class Xcls_Label12 : Object
529     {
530         public Gtk.Label el;
531         private MergeBranch  _this;
532
533
534             // my vars (def)
535
536         // ctor
537         public Xcls_Label12(MergeBranch _owner )
538         {
539             _this = _owner;
540             this.el = new Gtk.Label( "Use this commit message" );
541
542             // my vars (dec)
543
544             // set gobject values
545             this.el.justify = Gtk.Justification.RIGHT;
546             this.el.xalign = 0.900000f;
547         }
548
549         // user defined functions
550     }
551
552     public class Xcls_name : Object
553     {
554         public Gtk.Entry el;
555         private MergeBranch  _this;
556
557
558             // my vars (def)
559
560         // ctor
561         public Xcls_name(MergeBranch _owner )
562         {
563             _this = _owner;
564             _this.name = this;
565             this.el = new Gtk.Entry();
566
567             // my vars (dec)
568
569             // set gobject values
570             this.el.visible = true;
571         }
572
573         // user defined functions
574         public void updateText () {
575                 var ticket_id = _this.ticketsel.selectedTicketId();
576                 
577                 RooTicket ticket = null;
578                 if (ticket_id.length > 0){
579                         ticket = RooTicket.singleton().getById(ticket_id);
580                 }
581                 
582                 var name = RooTicket.singleton().usernameLocal();
583                 var action = _this.actionsel.selectedAction();
584                 this.el.set_editable(true); 
585                 switch (action) {
586                         case "CLOSE": // merge changes and close..
587                                 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
588                                 break;
589                         case "LEAVE": // partial fix    
590                                 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id,   ticket != null ? ticket.summary : ""));
591                                 break;
592                         case "MASTER": // merge master
593                         case "EXIT": // just switch back...             
594                                 this.el.set_editable(false);
595                                 this.el.set_text(""); // not relivant..                         
596                                 break;
597                         default:
598                         
599                                 break; /// don't fix the text value.
600                 }
601            
602         }
603     }
604
605
606
607     public class Xcls_Button14 : Object
608     {
609         public Gtk.Button el;
610         private MergeBranch  _this;
611
612
613             // my vars (def)
614
615         // ctor
616         public Xcls_Button14(MergeBranch _owner )
617         {
618             _this = _owner;
619             this.el = new Gtk.Button();
620
621             // my vars (dec)
622
623             // set gobject values
624             this.el.relief = Gtk.ReliefStyle.NONE;
625             this.el.label = "Cancel";
626         }
627
628         // user defined functions
629     }
630
631     public class Xcls_Button15 : Object
632     {
633         public Gtk.Button el;
634         private MergeBranch  _this;
635
636
637             // my vars (def)
638
639         // ctor
640         public Xcls_Button15(MergeBranch _owner )
641         {
642             _this = _owner;
643             this.el = new Gtk.Button();
644
645             // my vars (dec)
646
647             // set gobject values
648             this.el.label = "Do Merge";
649         }
650
651         // user defined functions
652     }
653
654 }