NewBranch.bjs
[gitlive] / NewBranch.vala
1 static NewBranch  _NewBranch;
2
3 public class NewBranch : Object
4 {
5     public Gtk.Dialog el;
6     private NewBranch  _this;
7
8     public static NewBranch singleton()
9     {
10         if (_NewBranch == null) {
11             _NewBranch= new NewBranch();
12         }
13         return _NewBranch;
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     public Gee.ArrayList<GitMonitorQueue> queue;
27
28     // ctor
29     public NewBranch()
30     {
31         _this = this;
32         this.el = new Gtk.Dialog();
33
34         // my vars (dec)
35         this.repo = null;
36         this.running = false;
37         this.queue = null;
38
39         // set gobject values
40         this.el.title = "Create a working branch ";
41         this.el.default_height = 200;
42         this.el.default_width = 500;
43         this.el.deletable = true;
44         this.el.modal = true;
45         var child_0 = new Xcls_VBox2( _this );
46         child_0.ref();
47         this.el.get_content_area().add (  child_0.el  );
48         var child_1 = new Xcls_Button15( _this );
49         child_1.ref();
50         this.el.add_action_widget (  child_1.el , 0 );
51         var child_2 = new Xcls_Button16( _this );
52         child_2.ref();
53         this.el.add_action_widget (  child_2.el , 1 );
54
55         //listeners
56         this.el.delete_event.connect( (self, event) => {
57             this.el.hide();
58             return true; 
59             //test  
60         });
61         this.el.response.connect( (self, response_id) =>  { 
62           
63                 GLib.debug("got %d", (int) response_id);
64                 if (response_id == 0) {
65                     _this.el.hide();    
66                     this.running = false; 
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         
82                         var res = this.repo.setActiveTicket(                    
83                                  RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
84                          );
85                          if (res) {
86                                 // start the monitoring..
87                                  GitMonitor.gitmonitor.start();
88                                  
89                          }
90             }
91             
92         
93             this.running = false; 
94         
95                 this.el.hide();
96                  
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 ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue ) 
110     {
111          // this.el.set_gravity(Gdk.Gravity.NORTH);
112         if (this.running) { // should not happen!!
113                 GLib.error("new branch show called, when already being displayed?");
114         }
115         this.queue = queue;
116         
117         this.running  = true;
118         GitMonitor.gitmonitor.stop();
119         
120         this.repo = repo;
121         
122         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
123                 GLib.debug("Loading tickets"); 
124     
125     
126         this.el.show_all();
127             this.el.set_keep_above(true);
128         _this.dbmodel.loadTickets();
129         this.el.run();
130     
131     }
132     public class Xcls_VBox2 : Object
133     {
134         public Gtk.VBox el;
135         private NewBranch  _this;
136
137
138             // my vars (def)
139
140         // ctor
141         public Xcls_VBox2(NewBranch _owner )
142         {
143             _this = _owner;
144             this.el = new Gtk.VBox( true, 0 );
145
146             // my vars (dec)
147
148             // set gobject values
149             var child_0 = new Xcls_Table3( _this );
150             child_0.ref();
151             this.el.pack_start (  child_0.el , false,false,0 );
152         }
153
154         // user defined functions
155     }
156     public class Xcls_Table3 : Object
157     {
158         public Gtk.Table el;
159         private NewBranch  _this;
160
161
162             // my vars (def)
163
164         // ctor
165         public Xcls_Table3(NewBranch _owner )
166         {
167             _this = _owner;
168             this.el = new Gtk.Table( 5, 6, true );
169
170             // my vars (dec)
171
172             // set gobject values
173             this.el.expand = true;
174             this.el.margin = 2;
175             this.el.column_spacing = 4;
176             this.el.vexpand = false;
177             var child_0 = new Xcls_Label4( _this );
178             child_0.ref();
179             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
180             var child_1 = new Xcls_Label5( _this );
181             child_1.ref();
182             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
183             var child_2 = new Xcls_ticketsel( _this );
184             child_2.ref();
185             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
186             var child_3 = new Xcls_ticketsel( _this );
187             child_3.ref();
188             this.el.attach_defaults (  child_3.el , 1,4,1,2 );
189             var child_4 = new Xcls_Button12( _this );
190             child_4.ref();
191             this.el.attach_defaults (  child_4.el , 4,5,1,2 );
192             var child_5 = new Xcls_Label13( _this );
193             child_5.ref();
194             this.el.attach_defaults (  child_5.el , 0,1,2,3 );
195             var child_6 = new Xcls_name( _this );
196             child_6.ref();
197             this.el.attach_defaults (  child_6.el , 0,5,3,4 );
198         }
199
200         // user defined functions
201     }
202     public class Xcls_Label4 : Object
203     {
204         public Gtk.Label el;
205         private NewBranch  _this;
206
207
208             // my vars (def)
209
210         // ctor
211         public Xcls_Label4(NewBranch _owner )
212         {
213             _this = _owner;
214             this.el = new Gtk.Label( "Project" );
215
216             // my vars (dec)
217
218             // set gobject values
219             this.el.halign = Gtk.Align.START;
220             this.el.justify = Gtk.Justification.RIGHT;
221             this.el.visible = true;
222         }
223
224         // user defined functions
225     }
226
227     public class Xcls_Label5 : Object
228     {
229         public Gtk.Label el;
230         private NewBranch  _this;
231
232
233             // my vars (def)
234
235         // ctor
236         public Xcls_Label5(NewBranch _owner )
237         {
238             _this = _owner;
239             this.el = new Gtk.Label( "Ticket" );
240
241             // my vars (dec)
242
243             // set gobject values
244             this.el.halign = Gtk.Align.START;
245             this.el.visible = true;
246         }
247
248         // user defined functions
249     }
250
251     public class Xcls_ticketsel : Object
252     {
253         public Gtk.ComboBox el;
254         private NewBranch  _this;
255
256
257             // my vars (def)
258         public bool loading;
259
260         // ctor
261         public Xcls_ticketsel(NewBranch _owner )
262         {
263             _this = _owner;
264             _this.ticketsel = this;
265             this.el = new Gtk.ComboBox();
266
267             // my vars (dec)
268             this.loading = false;
269
270             // set gobject values
271             var child_0 = new Xcls_dbcellrenderer( _this );
272             child_0.ref();
273             this.el.pack_start (  child_0.el , true );
274             var child_1 = new Xcls_dbmodel( _this );
275             child_1.ref();
276             this.el.set_model (  child_1.el  );
277
278             // init method
279
280             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
281
282             //listeners
283             this.el.changed.connect( () => {
284                 if (this.loading) {
285                         return;
286                 }
287                 var ticket_id = this.selectedTicketId();
288                 
289                 var name = RooTicket.singleton().usernameLocal();
290                 
291                 if (ticket_id == "" || ticket_id == null) {
292                 
293                         var dt = new  DateTime.now_local();
294                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
295                         return;
296                 }
297                 
298                 
299                 var ticket = RooTicket.singleton().getById(ticket_id);
300                
301                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
302                 
303                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
304             });
305         }
306
307         // user defined functions
308         public string selectedTicketId () {
309         Gtk.TreeIter iter;
310                 Value val1;
311          
312          
313                 this.el.get_active_iter (out iter);
314                 _this.dbmodel.el.get_value (iter, 0, out val1);
315          
316         
317                 return  (string) val1;
318                 
319                 
320                 
321                 
322         }
323     }
324     public class Xcls_dbcellrenderer : Object
325     {
326         public Gtk.CellRendererText el;
327         private NewBranch  _this;
328
329
330             // my vars (def)
331
332         // ctor
333         public Xcls_dbcellrenderer(NewBranch _owner )
334         {
335             _this = _owner;
336             _this.dbcellrenderer = this;
337             this.el = new Gtk.CellRendererText();
338
339             // my vars (dec)
340
341             // set gobject values
342         }
343
344         // user defined functions
345     }
346
347     public class Xcls_dbmodel : Object
348     {
349         public Gtk.ListStore el;
350         private NewBranch  _this;
351
352
353             // my vars (def)
354
355         // ctor
356         public Xcls_dbmodel(NewBranch _owner )
357         {
358             _this = _owner;
359             _this.dbmodel = this;
360             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
361
362             // my vars (dec)
363
364             // set gobject values
365         }
366
367         // user defined functions
368         public void loadTickets () {
369         
370             RooTicket.singleton().loadTickets();
371             
372             _this.ticketsel.loading = true;
373         
374             this.el.clear();                                    
375             Gtk.TreeIter iter;
376             var el = this.el;
377             
378             el.append(out iter);
379         
380             
381             el.set_value(iter, 0, "");
382             el.set_value(iter, 1, "-- select a ticket --");
383             
384             _this.ticketsel.el.set_active_iter(iter);
385             var tickets = RooTicket.singleton().tickets;
386             foreach(var ticket in tickets) {
387             
388                 el.append(out iter);
389                 
390                 el.set_value(iter, 0, ticket.id);
391                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
392                 
393                 //if (data.get(i) == cur) {
394                  //   _this.build_module.el.set_active_iter(iter);
395                // }
396                 
397             }
398             
399             _this.ticketsel.loading = false;
400              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
401                                              
402         }
403     }
404
405
406     public class Xcls_ticketsel : Object
407     {
408         public Gtk.ComboBox el;
409         private NewBranch  _this;
410
411
412             // my vars (def)
413         public bool loading;
414
415         // ctor
416         public Xcls_ticketsel(NewBranch _owner )
417         {
418             _this = _owner;
419             _this.ticketsel = this;
420             this.el = new Gtk.ComboBox();
421
422             // my vars (dec)
423             this.loading = false;
424
425             // set gobject values
426             var child_0 = new Xcls_dbcellrenderer( _this );
427             child_0.ref();
428             this.el.pack_start (  child_0.el , true );
429             var child_1 = new Xcls_dbmodel( _this );
430             child_1.ref();
431             this.el.set_model (  child_1.el  );
432
433             // init method
434
435             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
436
437             //listeners
438             this.el.changed.connect( () => {
439                 if (this.loading) {
440                         return;
441                 }
442                 var ticket_id = this.selectedTicketId();
443                 
444                 var name = RooTicket.singleton().usernameLocal();
445                 
446                 if (ticket_id == "" || ticket_id == null) {
447                 
448                         var dt = new  DateTime.now_local();
449                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
450                         return;
451                 }
452                 
453                 
454                 var ticket = RooTicket.singleton().getById(ticket_id);
455                
456                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
457                 
458                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
459             });
460         }
461
462         // user defined functions
463         public string selectedTicketId () {
464         Gtk.TreeIter iter;
465                 Value val1;
466          
467          
468                 this.el.get_active_iter (out iter);
469                 _this.dbmodel.el.get_value (iter, 0, out val1);
470          
471         
472                 return  (string) val1;
473                 
474                 
475                 
476                 
477         }
478     }
479     public class Xcls_dbcellrenderer : Object
480     {
481         public Gtk.CellRendererText el;
482         private NewBranch  _this;
483
484
485             // my vars (def)
486
487         // ctor
488         public Xcls_dbcellrenderer(NewBranch _owner )
489         {
490             _this = _owner;
491             _this.dbcellrenderer = this;
492             this.el = new Gtk.CellRendererText();
493
494             // my vars (dec)
495
496             // set gobject values
497         }
498
499         // user defined functions
500     }
501
502     public class Xcls_dbmodel : Object
503     {
504         public Gtk.ListStore el;
505         private NewBranch  _this;
506
507
508             // my vars (def)
509
510         // ctor
511         public Xcls_dbmodel(NewBranch _owner )
512         {
513             _this = _owner;
514             _this.dbmodel = this;
515             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
516
517             // my vars (dec)
518
519             // set gobject values
520         }
521
522         // user defined functions
523         public void loadTickets () {
524         
525             RooTicket.singleton().loadTickets();
526             
527             _this.ticketsel.loading = true;
528         
529             this.el.clear();                                    
530             Gtk.TreeIter iter;
531             var el = this.el;
532             
533             el.append(out iter);
534         
535             
536             el.set_value(iter, 0, "");
537             el.set_value(iter, 1, "-- select a ticket --");
538             
539             _this.ticketsel.el.set_active_iter(iter);
540             var tickets = RooTicket.singleton().tickets;
541             foreach(var ticket in tickets) {
542             
543                 el.append(out iter);
544                 
545                 el.set_value(iter, 0, ticket.id);
546                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
547                 
548                 //if (data.get(i) == cur) {
549                  //   _this.build_module.el.set_active_iter(iter);
550                // }
551                 
552             }
553             
554             _this.ticketsel.loading = false;
555              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
556                                              
557         }
558     }
559
560
561     public class Xcls_Button12 : Object
562     {
563         public Gtk.Button el;
564         private NewBranch  _this;
565
566
567             // my vars (def)
568
569         // ctor
570         public Xcls_Button12(NewBranch _owner )
571         {
572             _this = _owner;
573             this.el = new Gtk.Button();
574
575             // my vars (dec)
576
577             // set gobject values
578             this.el.expand = false;
579             this.el.label = "New Ticket";
580         }
581
582         // user defined functions
583     }
584
585     public class Xcls_Label13 : Object
586     {
587         public Gtk.Label el;
588         private NewBranch  _this;
589
590
591             // my vars (def)
592
593         // ctor
594         public Xcls_Label13(NewBranch _owner )
595         {
596             _this = _owner;
597             this.el = new Gtk.Label( "Use this as branch name" );
598
599             // my vars (dec)
600
601             // set gobject values
602             this.el.halign = Gtk.Align.START;
603             this.el.justify = Gtk.Justification.RIGHT;
604             this.el.xalign = 0.900000f;
605         }
606
607         // user defined functions
608     }
609
610     public class Xcls_name : Object
611     {
612         public Gtk.Entry el;
613         private NewBranch  _this;
614
615
616             // my vars (def)
617
618         // ctor
619         public Xcls_name(NewBranch _owner )
620         {
621             _this = _owner;
622             _this.name = this;
623             this.el = new Gtk.Entry();
624
625             // my vars (dec)
626
627             // set gobject values
628             this.el.visible = true;
629         }
630
631         // user defined functions
632     }
633
634
635
636     public class Xcls_Button15 : Object
637     {
638         public Gtk.Button el;
639         private NewBranch  _this;
640
641
642             // my vars (def)
643
644         // ctor
645         public Xcls_Button15(NewBranch _owner )
646         {
647             _this = _owner;
648             this.el = new Gtk.Button();
649
650             // my vars (dec)
651
652             // set gobject values
653             this.el.relief = Gtk.ReliefStyle.NONE;
654             this.el.label = "Do not create Branch";
655         }
656
657         // user defined functions
658     }
659
660     public class Xcls_Button16 : Object
661     {
662         public Gtk.Button el;
663         private NewBranch  _this;
664
665
666             // my vars (def)
667
668         // ctor
669         public Xcls_Button16(NewBranch _owner )
670         {
671             _this = _owner;
672             this.el = new Gtk.Button();
673
674             // my vars (dec)
675
676             // set gobject values
677             this.el.label = "Create Branch";
678         }
679
680         // user defined functions
681     }
682
683 }