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