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