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_ticketsel ticketsel;
16     public Xcls_dbcellrenderer dbcellrenderer;
17     public Xcls_dbmodel dbmodel;
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 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.repo = 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 ( GitRepo repo ) 
103     {
104          // this.el.set_gravity(Gdk.Gravity.NORTH);
105         if (this.running) {
106                 return;
107         }
108         this.repo = repo;
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     
117     }
118     public class Xcls_VBox2 : Object
119     {
120         public Gtk.VBox el;
121         private MergeBranch  _this;
122
123
124             // my vars (def)
125
126         // ctor
127         public Xcls_VBox2(MergeBranch _owner )
128         {
129             _this = _owner;
130             this.el = new Gtk.VBox( true, 0 );
131
132             // my vars (dec)
133
134             // set gobject values
135             var child_0 = new Xcls_Table3( _this );
136             child_0.ref();
137             this.el.pack_start (  child_0.el , false,false,0 );
138         }
139
140         // user defined functions
141     }
142     public class Xcls_Table3 : Object
143     {
144         public Gtk.Table el;
145         private MergeBranch  _this;
146
147
148             // my vars (def)
149
150         // ctor
151         public Xcls_Table3(MergeBranch _owner )
152         {
153             _this = _owner;
154             this.el = new Gtk.Table( 2, 2, false );
155
156             // my vars (dec)
157
158             // set gobject values
159             this.el.margin = 2;
160             this.el.column_spacing = 2;
161             var child_0 = new Xcls_Label4( _this );
162             child_0.ref();
163             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
164             var child_1 = new Xcls_ticketsel( _this );
165             child_1.ref();
166             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
167             var child_2 = new Xcls_Label8( _this );
168             child_2.ref();
169             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
170             var child_3 = new Xcls_ticketsel( _this );
171             child_3.ref();
172             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
173             var child_4 = new Xcls_Label12( _this );
174             child_4.ref();
175             this.el.attach_defaults (  child_4.el , 0,1,1,2 );
176             var child_5 = new Xcls_name( _this );
177             child_5.ref();
178             this.el.attach_defaults (  child_5.el , 1,2,1,2 );
179         }
180
181         // user defined functions
182     }
183     public class Xcls_Label4 : Object
184     {
185         public Gtk.Label el;
186         private MergeBranch  _this;
187
188
189             // my vars (def)
190
191         // ctor
192         public Xcls_Label4(MergeBranch _owner )
193         {
194             _this = _owner;
195             this.el = new Gtk.Label( "Select Ticket" );
196
197             // my vars (dec)
198
199             // set gobject values
200             this.el.justify = Gtk.Justification.RIGHT;
201             this.el.xalign = 0.900000f;
202             this.el.visible = true;
203         }
204
205         // user defined functions
206     }
207
208     public class Xcls_ticketsel : Object
209     {
210         public Gtk.ComboBox el;
211         private MergeBranch  _this;
212
213
214             // my vars (def)
215         public bool loading;
216
217         // ctor
218         public Xcls_ticketsel(MergeBranch _owner )
219         {
220             _this = _owner;
221             _this.ticketsel = this;
222             this.el = new Gtk.ComboBox();
223
224             // my vars (dec)
225             this.loading = false;
226
227             // set gobject values
228             var child_0 = new Xcls_dbcellrenderer( _this );
229             child_0.ref();
230             this.el.pack_start (  child_0.el , true );
231             var child_1 = new Xcls_dbmodel( _this );
232             child_1.ref();
233             this.el.set_model (  child_1.el  );
234
235             // init method
236
237             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
238
239             //listeners
240             this.el.changed.connect( () => {
241                 if (this.loading) {
242                         return;
243                 }
244                 var ticket_id = this.selectedTicketId();
245                 
246                 var name = RooTicket.singleton().usernameLocal();
247                 
248                 if (ticket_id == "" || ticket_id == null) {
249                 
250                         var dt = new  DateTime.now_local();
251                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
252                         return;
253                 }
254                 
255                 
256                 var ticket = RooTicket.singleton().getById(ticket_id);
257                
258                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
259                 
260                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
261             });
262         }
263
264         // user defined functions
265         public string selectedTicketId () {
266         Gtk.TreeIter iter;
267                 Value val1;
268          
269          
270                 this.el.get_active_iter (out iter);
271                 _this.dbmodel.el.get_value (iter, 0, out val1);
272          
273         
274                 return  (string) val1;
275                 
276                 
277                 
278                 
279         }
280     }
281     public class Xcls_dbcellrenderer : Object
282     {
283         public Gtk.CellRendererText el;
284         private MergeBranch  _this;
285
286
287             // my vars (def)
288
289         // ctor
290         public Xcls_dbcellrenderer(MergeBranch _owner )
291         {
292             _this = _owner;
293             _this.dbcellrenderer = this;
294             this.el = new Gtk.CellRendererText();
295
296             // my vars (dec)
297
298             // set gobject values
299         }
300
301         // user defined functions
302     }
303
304     public class Xcls_dbmodel : Object
305     {
306         public Gtk.ListStore el;
307         private MergeBranch  _this;
308
309
310             // my vars (def)
311
312         // ctor
313         public Xcls_dbmodel(MergeBranch _owner )
314         {
315             _this = _owner;
316             _this.dbmodel = this;
317             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
318
319             // my vars (dec)
320
321             // set gobject values
322         }
323
324         // user defined functions
325         public void loadTickets () {
326         
327             RooTicket.singleton().loadTickets();
328             
329             _this.ticketsel.loading = true;
330         
331             this.el.clear();                                    
332             Gtk.TreeIter iter;
333             var el = this.el;
334             
335             el.append(out iter);
336         
337             
338             el.set_value(iter, 0, "");
339             el.set_value(iter, 1, "-- select a ticket --");
340             
341             _this.ticketsel.el.set_active_iter(iter);
342             var tickets = RooTicket.singleton().tickets;
343             foreach(var ticket in tickets) {
344             
345                 el.append(out iter);
346                 
347                 el.set_value(iter, 0, ticket.id);
348                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
349                 
350                 //if (data.get(i) == cur) {
351                  //   _this.build_module.el.set_active_iter(iter);
352                // }
353                 
354             }
355             
356             _this.ticketsel.loading = false;
357              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
358                                              
359         }
360     }
361
362
363     public class Xcls_Label8 : Object
364     {
365         public Gtk.Label el;
366         private MergeBranch  _this;
367
368
369             // my vars (def)
370
371         // ctor
372         public Xcls_Label8(MergeBranch _owner )
373         {
374             _this = _owner;
375             this.el = new Gtk.Label( "Select Ticket" );
376
377             // my vars (dec)
378
379             // set gobject values
380             this.el.justify = Gtk.Justification.RIGHT;
381             this.el.xalign = 0.900000f;
382             this.el.visible = true;
383         }
384
385         // user defined functions
386     }
387
388     public class Xcls_ticketsel : Object
389     {
390         public Gtk.ComboBox el;
391         private MergeBranch  _this;
392
393
394             // my vars (def)
395         public bool loading;
396
397         // ctor
398         public Xcls_ticketsel(MergeBranch _owner )
399         {
400             _this = _owner;
401             _this.ticketsel = this;
402             this.el = new Gtk.ComboBox();
403
404             // my vars (dec)
405             this.loading = false;
406
407             // set gobject values
408             var child_0 = new Xcls_dbcellrenderer( _this );
409             child_0.ref();
410             this.el.pack_start (  child_0.el , true );
411             var child_1 = new Xcls_dbmodel( _this );
412             child_1.ref();
413             this.el.set_model (  child_1.el  );
414
415             // init method
416
417             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
418
419             //listeners
420             this.el.changed.connect( () => {
421                 if (this.loading) {
422                         return;
423                 }
424                 var ticket_id = this.selectedTicketId();
425                 
426                 var name = RooTicket.singleton().usernameLocal();
427                 
428                 if (ticket_id == "" || ticket_id == null) {
429                 
430                         var dt = new  DateTime.now_local();
431                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
432                         return;
433                 }
434                 
435                 
436                 var ticket = RooTicket.singleton().getById(ticket_id);
437                
438                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
439                 
440                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
441             });
442         }
443
444         // user defined functions
445         public string selectedTicketId () {
446         Gtk.TreeIter iter;
447                 Value val1;
448          
449          
450                 this.el.get_active_iter (out iter);
451                 _this.dbmodel.el.get_value (iter, 0, out val1);
452          
453         
454                 return  (string) val1;
455                 
456                 
457                 
458                 
459         }
460     }
461     public class Xcls_dbcellrenderer : Object
462     {
463         public Gtk.CellRendererText el;
464         private MergeBranch  _this;
465
466
467             // my vars (def)
468
469         // ctor
470         public Xcls_dbcellrenderer(MergeBranch _owner )
471         {
472             _this = _owner;
473             _this.dbcellrenderer = this;
474             this.el = new Gtk.CellRendererText();
475
476             // my vars (dec)
477
478             // set gobject values
479         }
480
481         // user defined functions
482     }
483
484     public class Xcls_dbmodel : Object
485     {
486         public Gtk.ListStore el;
487         private MergeBranch  _this;
488
489
490             // my vars (def)
491
492         // ctor
493         public Xcls_dbmodel(MergeBranch _owner )
494         {
495             _this = _owner;
496             _this.dbmodel = this;
497             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
498
499             // my vars (dec)
500
501             // set gobject values
502         }
503
504         // user defined functions
505         public void loadTickets () {
506         
507             RooTicket.singleton().loadTickets();
508             
509             _this.ticketsel.loading = true;
510         
511             this.el.clear();                                    
512             Gtk.TreeIter iter;
513             var el = this.el;
514             
515             el.append(out iter);
516         
517             
518             el.set_value(iter, 0, "");
519             el.set_value(iter, 1, "-- select a ticket --");
520             
521             _this.ticketsel.el.set_active_iter(iter);
522             var tickets = RooTicket.singleton().tickets;
523             foreach(var ticket in tickets) {
524             
525                 el.append(out iter);
526                 
527                 el.set_value(iter, 0, ticket.id);
528                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
529                 
530                 //if (data.get(i) == cur) {
531                  //   _this.build_module.el.set_active_iter(iter);
532                // }
533                 
534             }
535             
536             _this.ticketsel.loading = false;
537              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
538                                              
539         }
540     }
541
542
543     public class Xcls_Label12 : Object
544     {
545         public Gtk.Label el;
546         private MergeBranch  _this;
547
548
549             // my vars (def)
550
551         // ctor
552         public Xcls_Label12(MergeBranch _owner )
553         {
554             _this = _owner;
555             this.el = new Gtk.Label( "or use this as branch name" );
556
557             // my vars (dec)
558
559             // set gobject values
560             this.el.justify = Gtk.Justification.RIGHT;
561             this.el.xalign = 0.900000f;
562         }
563
564         // user defined functions
565     }
566
567     public class Xcls_name : Object
568     {
569         public Gtk.Entry el;
570         private MergeBranch  _this;
571
572
573             // my vars (def)
574
575         // ctor
576         public Xcls_name(MergeBranch _owner )
577         {
578             _this = _owner;
579             _this.name = this;
580             this.el = new Gtk.Entry();
581
582             // my vars (dec)
583
584             // set gobject values
585             this.el.visible = true;
586         }
587
588         // user defined functions
589     }
590
591
592
593     public class Xcls_Button14 : Object
594     {
595         public Gtk.Button el;
596         private MergeBranch  _this;
597
598
599             // my vars (def)
600
601         // ctor
602         public Xcls_Button14(MergeBranch _owner )
603         {
604             _this = _owner;
605             this.el = new Gtk.Button();
606
607             // my vars (dec)
608
609             // set gobject values
610             this.el.relief = Gtk.ReliefStyle.NONE;
611             this.el.label = "Do not create Branch";
612         }
613
614         // user defined functions
615     }
616
617     public class Xcls_Button15 : Object
618     {
619         public Gtk.Button el;
620         private MergeBranch  _this;
621
622
623             // my vars (def)
624
625         // ctor
626         public Xcls_Button15(MergeBranch _owner )
627         {
628             _this = _owner;
629             this.el = new Gtk.Button();
630
631             // my vars (dec)
632
633             // set gobject values
634             this.el.label = "Create Branch";
635         }
636
637         // user defined functions
638     }
639
640 }