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