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                 this.running = false; 
87         
88                  
89                 _this.el.hide();        
90          
91         
92                  
93         });
94         this.el.show.connect( (self)  => {
95          
96         
97           //test
98         });
99     }
100
101     // user defined functions
102     public   void show (  RooTicket ticket ) 
103     {
104          // this.el.set_gravity(Gdk.Gravity.NORTH);
105         if (this.running) {
106                 return;
107         }
108         this.ticket = ticket;
109         
110         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
111                 GLib.debug("Loading tickets"); 
112     
113     
114         this.el.show_all();
115         _this.dbmodel.loadTickets();
116         _this.actionmodel.loadActions();
117     
118     }
119     public class Xcls_VBox2 : Object
120     {
121         public Gtk.VBox el;
122         private MergeBranch  _this;
123
124
125             // my vars (def)
126
127         // ctor
128         public Xcls_VBox2(MergeBranch _owner )
129         {
130             _this = _owner;
131             this.el = new Gtk.VBox( true, 0 );
132
133             // my vars (dec)
134
135             // set gobject values
136             var child_0 = new Xcls_Table3( _this );
137             child_0.ref();
138             this.el.pack_start (  child_0.el , false,false,0 );
139         }
140
141         // user defined functions
142     }
143     public class Xcls_Table3 : Object
144     {
145         public Gtk.Table el;
146         private MergeBranch  _this;
147
148
149             // my vars (def)
150
151         // ctor
152         public Xcls_Table3(MergeBranch _owner )
153         {
154             _this = _owner;
155             this.el = new Gtk.Table( 2, 2, false );
156
157             // my vars (dec)
158
159             // set gobject values
160             this.el.margin = 2;
161             this.el.column_spacing = 2;
162             var child_0 = new Xcls_Label4( _this );
163             child_0.ref();
164             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
165             var child_1 = new Xcls_actionsel( _this );
166             child_1.ref();
167             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
168             var child_2 = new Xcls_Label8( _this );
169             child_2.ref();
170             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
171             var child_3 = new Xcls_ticketsel( _this );
172             child_3.ref();
173             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
174             var child_4 = new Xcls_Label12( _this );
175             child_4.ref();
176             this.el.attach_defaults (  child_4.el , 0,1,2,3 );
177             var child_5 = new Xcls_name( _this );
178             child_5.ref();
179             this.el.attach_defaults (  child_5.el , 1,2,2,3 );
180         }
181
182         // user defined functions
183     }
184     public class Xcls_Label4 : Object
185     {
186         public Gtk.Label el;
187         private MergeBranch  _this;
188
189
190             // my vars (def)
191
192         // ctor
193         public Xcls_Label4(MergeBranch _owner )
194         {
195             _this = _owner;
196             this.el = new Gtk.Label( "Do what?" );
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_actionsel : Object
210     {
211         public Gtk.ComboBox el;
212         private MergeBranch  _this;
213
214
215             // my vars (def)
216         public bool loading;
217
218         // ctor
219         public Xcls_actionsel(MergeBranch _owner )
220         {
221             _this = _owner;
222             _this.actionsel = 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_actioncellrenderer( _this );
230             child_0.ref();
231             this.el.pack_start (  child_0.el , true );
232             var child_1 = new Xcls_actionmodel( _this );
233             child_1.ref();
234             this.el.set_model (  child_1.el  );
235
236             // init method
237
238             this.el.add_attribute(_this.actioncellrenderer.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     }
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.action.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                 var ticket_id = this.selectedTicketId();
417                 
418                 var name = RooTicket.singleton().usernameLocal();
419                 
420                 if (ticket_id == "" || ticket_id == null) {
421                 
422                         var dt = new  DateTime.now_local();
423             //          _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
424                         return;
425                 }
426                  
427                 _this.ticket = RooTicket.singleton().getById(ticket_id);
428                 _this.name.updateText();
429                 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
430                 
431                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
432             });
433         }
434
435         // user defined functions
436         public string selectedTicketId () {
437         Gtk.TreeIter iter;
438                 Value val1;
439          
440          
441                 this.el.get_active_iter (out iter);
442                 _this.dbmodel.el.get_value (iter, 0, out val1);
443          
444         
445                 return  (string) val1;
446                 
447                 
448                 
449                 
450         }
451     }
452     public class Xcls_dbcellrenderer : Object
453     {
454         public Gtk.CellRendererText el;
455         private MergeBranch  _this;
456
457
458             // my vars (def)
459
460         // ctor
461         public Xcls_dbcellrenderer(MergeBranch _owner )
462         {
463             _this = _owner;
464             _this.dbcellrenderer = this;
465             this.el = new Gtk.CellRendererText();
466
467             // my vars (dec)
468
469             // set gobject values
470         }
471
472         // user defined functions
473     }
474
475     public class Xcls_dbmodel : Object
476     {
477         public Gtk.ListStore el;
478         private MergeBranch  _this;
479
480
481             // my vars (def)
482
483         // ctor
484         public Xcls_dbmodel(MergeBranch _owner )
485         {
486             _this = _owner;
487             _this.dbmodel = this;
488             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
489
490             // my vars (dec)
491
492             // set gobject values
493         }
494
495         // user defined functions
496         public void loadTickets () {
497         
498             RooTicket.singleton().loadTickets();
499             
500             _this.ticketsel.loading = true;
501         
502             this.el.clear();                                    
503             Gtk.TreeIter iter;
504             var el = this.el;
505             
506             el.append(out iter);
507         
508             
509             el.set_value(iter, 0, "");
510             el.set_value(iter, 1, "-- select a ticket --");
511             
512             _this.ticketsel.el.set_active_iter(iter);
513             var tickets = RooTicket.singleton().tickets;
514             foreach(var ticket in tickets) {
515             
516                 el.append(out iter);
517         
518                 el.set_value(iter, 0, ticket.id);
519                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
520                         if (_this.ticket.id == ticket.id) {
521                             _this.ticketsel.el.set_active_iter(iter);
522                     }
523                 
524             }
525             
526             _this.ticketsel.loading = false;
527              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
528                                              
529         }
530     }
531
532
533     public class Xcls_Label12 : Object
534     {
535         public Gtk.Label el;
536         private MergeBranch  _this;
537
538
539             // my vars (def)
540
541         // ctor
542         public Xcls_Label12(MergeBranch _owner )
543         {
544             _this = _owner;
545             this.el = new Gtk.Label( "Use this commit message" );
546
547             // my vars (dec)
548
549             // set gobject values
550             this.el.justify = Gtk.Justification.RIGHT;
551             this.el.xalign = 0.900000f;
552         }
553
554         // user defined functions
555     }
556
557     public class Xcls_name : Object
558     {
559         public Gtk.Entry el;
560         private MergeBranch  _this;
561
562
563             // my vars (def)
564
565         // ctor
566         public Xcls_name(MergeBranch _owner )
567         {
568             _this = _owner;
569             _this.name = this;
570             this.el = new Gtk.Entry();
571
572             // my vars (dec)
573
574             // set gobject values
575             this.el.visible = true;
576         }
577
578         // user defined functions
579     }
580
581
582
583     public class Xcls_Button14 : Object
584     {
585         public Gtk.Button el;
586         private MergeBranch  _this;
587
588
589             // my vars (def)
590
591         // ctor
592         public Xcls_Button14(MergeBranch _owner )
593         {
594             _this = _owner;
595             this.el = new Gtk.Button();
596
597             // my vars (dec)
598
599             // set gobject values
600             this.el.relief = Gtk.ReliefStyle.NONE;
601             this.el.label = "Cancel";
602         }
603
604         // user defined functions
605     }
606
607     public class Xcls_Button15 : Object
608     {
609         public Gtk.Button el;
610         private MergeBranch  _this;
611
612
613             // my vars (def)
614
615         // ctor
616         public Xcls_Button15(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.label = "Do Merge";
625         }
626
627         // user defined functions
628     }
629
630 }