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_Button16( _this );
49         child_1.ref();
50         this.el.add_action_widget (  child_1.el , 0 );
51         var child_2 = new Xcls_Button17( _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,4,3,4 );
198             var child_7 = new Xcls_Button15( _this );
199             child_7.ref();
200             this.el.attach_defaults (  child_7.el , 4,5,1,2 );
201         }
202
203         // user defined functions
204     }
205     public class Xcls_Label4 : Object
206     {
207         public Gtk.Label el;
208         private NewBranch  _this;
209
210
211             // my vars (def)
212
213         // ctor
214         public Xcls_Label4(NewBranch _owner )
215         {
216             _this = _owner;
217             this.el = new Gtk.Label( "Project" );
218
219             // my vars (dec)
220
221             // set gobject values
222             this.el.halign = Gtk.Align.START;
223             this.el.justify = Gtk.Justification.RIGHT;
224             this.el.visible = true;
225         }
226
227         // user defined functions
228     }
229
230     public class Xcls_Label5 : Object
231     {
232         public Gtk.Label el;
233         private NewBranch  _this;
234
235
236             // my vars (def)
237
238         // ctor
239         public Xcls_Label5(NewBranch _owner )
240         {
241             _this = _owner;
242             this.el = new Gtk.Label( "Ticket" );
243
244             // my vars (dec)
245
246             // set gobject values
247             this.el.halign = Gtk.Align.START;
248             this.el.visible = true;
249         }
250
251         // user defined functions
252     }
253
254     public class Xcls_ticketsel : Object
255     {
256         public Gtk.ComboBox el;
257         private NewBranch  _this;
258
259
260             // my vars (def)
261         public bool loading;
262
263         // ctor
264         public Xcls_ticketsel(NewBranch _owner )
265         {
266             _this = _owner;
267             _this.ticketsel = this;
268             this.el = new Gtk.ComboBox();
269
270             // my vars (dec)
271             this.loading = false;
272
273             // set gobject values
274             var child_0 = new Xcls_dbcellrenderer( _this );
275             child_0.ref();
276             this.el.pack_start (  child_0.el , true );
277             var child_1 = new Xcls_dbmodel( _this );
278             child_1.ref();
279             this.el.set_model (  child_1.el  );
280
281             // init method
282
283             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
284
285             //listeners
286             this.el.changed.connect( () => {
287                 if (this.loading) {
288                         return;
289                 }
290                 var ticket_id = this.selectedTicketId();
291                 
292                 var name = RooTicket.singleton().usernameLocal();
293                 
294                 if (ticket_id == "" || ticket_id == null) {
295                 
296                         var dt = new  DateTime.now_local();
297                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
298                         return;
299                 }
300                 
301                 
302                 var ticket = RooTicket.singleton().getById(ticket_id);
303                
304                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
305                 
306                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
307             });
308         }
309
310         // user defined functions
311         public string selectedTicketId () {
312         Gtk.TreeIter iter;
313                 Value val1;
314          
315          
316                 this.el.get_active_iter (out iter);
317                 _this.dbmodel.el.get_value (iter, 0, out val1);
318          
319         
320                 return  (string) val1;
321                 
322                 
323                 
324                 
325         }
326     }
327     public class Xcls_dbcellrenderer : Object
328     {
329         public Gtk.CellRendererText el;
330         private NewBranch  _this;
331
332
333             // my vars (def)
334
335         // ctor
336         public Xcls_dbcellrenderer(NewBranch _owner )
337         {
338             _this = _owner;
339             _this.dbcellrenderer = this;
340             this.el = new Gtk.CellRendererText();
341
342             // my vars (dec)
343
344             // set gobject values
345         }
346
347         // user defined functions
348     }
349
350     public class Xcls_dbmodel : Object
351     {
352         public Gtk.ListStore el;
353         private NewBranch  _this;
354
355
356             // my vars (def)
357
358         // ctor
359         public Xcls_dbmodel(NewBranch _owner )
360         {
361             _this = _owner;
362             _this.dbmodel = this;
363             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
364
365             // my vars (dec)
366
367             // set gobject values
368         }
369
370         // user defined functions
371         public void loadTickets () {
372         
373             RooTicket.singleton().loadTickets();
374             
375             _this.ticketsel.loading = true;
376         
377             this.el.clear();                                    
378             Gtk.TreeIter iter;
379             var el = this.el;
380             
381             el.append(out iter);
382         
383             
384             el.set_value(iter, 0, "");
385             el.set_value(iter, 1, "-- select a ticket --");
386             
387             _this.ticketsel.el.set_active_iter(iter);
388             var tickets = RooTicket.singleton().tickets;
389             foreach(var ticket in tickets) {
390             
391                 el.append(out iter);
392                 
393                 el.set_value(iter, 0, ticket.id);
394                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
395                 
396                 //if (data.get(i) == cur) {
397                  //   _this.build_module.el.set_active_iter(iter);
398                // }
399                 
400             }
401             
402             _this.ticketsel.loading = false;
403              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
404                                              
405         }
406     }
407
408
409     public class Xcls_ticketsel : Object
410     {
411         public Gtk.ComboBox el;
412         private NewBranch  _this;
413
414
415             // my vars (def)
416         public bool loading;
417
418         // ctor
419         public Xcls_ticketsel(NewBranch _owner )
420         {
421             _this = _owner;
422             _this.ticketsel = this;
423             this.el = new Gtk.ComboBox();
424
425             // my vars (dec)
426             this.loading = false;
427
428             // set gobject values
429             var child_0 = new Xcls_dbcellrenderer( _this );
430             child_0.ref();
431             this.el.pack_start (  child_0.el , true );
432             var child_1 = new Xcls_dbmodel( _this );
433             child_1.ref();
434             this.el.set_model (  child_1.el  );
435
436             // init method
437
438             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
439
440             //listeners
441             this.el.changed.connect( () => {
442                 if (this.loading) {
443                         return;
444                 }
445                 var ticket_id = this.selectedTicketId();
446                 
447                 var name = RooTicket.singleton().usernameLocal();
448                 
449                 if (ticket_id == "" || ticket_id == null) {
450                 
451                         var dt = new  DateTime.now_local();
452                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
453                         return;
454                 }
455                 
456                 
457                 var ticket = RooTicket.singleton().getById(ticket_id);
458                
459                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
460                 
461                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
462             });
463         }
464
465         // user defined functions
466         public string selectedTicketId () {
467         Gtk.TreeIter iter;
468                 Value val1;
469          
470          
471                 this.el.get_active_iter (out iter);
472                 _this.dbmodel.el.get_value (iter, 0, out val1);
473          
474         
475                 return  (string) val1;
476                 
477                 
478                 
479                 
480         }
481     }
482     public class Xcls_dbcellrenderer : Object
483     {
484         public Gtk.CellRendererText el;
485         private NewBranch  _this;
486
487
488             // my vars (def)
489
490         // ctor
491         public Xcls_dbcellrenderer(NewBranch _owner )
492         {
493             _this = _owner;
494             _this.dbcellrenderer = this;
495             this.el = new Gtk.CellRendererText();
496
497             // my vars (dec)
498
499             // set gobject values
500         }
501
502         // user defined functions
503     }
504
505     public class Xcls_dbmodel : Object
506     {
507         public Gtk.ListStore el;
508         private NewBranch  _this;
509
510
511             // my vars (def)
512
513         // ctor
514         public Xcls_dbmodel(NewBranch _owner )
515         {
516             _this = _owner;
517             _this.dbmodel = this;
518             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
519
520             // my vars (dec)
521
522             // set gobject values
523         }
524
525         // user defined functions
526         public void loadTickets () {
527         
528             RooTicket.singleton().loadTickets();
529             
530             _this.ticketsel.loading = true;
531         
532             this.el.clear();                                    
533             Gtk.TreeIter iter;
534             var el = this.el;
535             
536             el.append(out iter);
537         
538             
539             el.set_value(iter, 0, "");
540             el.set_value(iter, 1, "-- select a ticket --");
541             
542             _this.ticketsel.el.set_active_iter(iter);
543             var tickets = RooTicket.singleton().tickets;
544             foreach(var ticket in tickets) {
545             
546                 el.append(out iter);
547                 
548                 el.set_value(iter, 0, ticket.id);
549                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
550                 
551                 //if (data.get(i) == cur) {
552                  //   _this.build_module.el.set_active_iter(iter);
553                // }
554                 
555             }
556             
557             _this.ticketsel.loading = false;
558              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
559                                              
560         }
561     }
562
563
564     public class Xcls_Button12 : Object
565     {
566         public Gtk.Button el;
567         private NewBranch  _this;
568
569
570             // my vars (def)
571
572         // ctor
573         public Xcls_Button12(NewBranch _owner )
574         {
575             _this = _owner;
576             this.el = new Gtk.Button();
577
578             // my vars (dec)
579
580             // set gobject values
581             this.el.expand = false;
582             this.el.label = "New Ticket";
583         }
584
585         // user defined functions
586     }
587
588     public class Xcls_Label13 : Object
589     {
590         public Gtk.Label el;
591         private NewBranch  _this;
592
593
594             // my vars (def)
595
596         // ctor
597         public Xcls_Label13(NewBranch _owner )
598         {
599             _this = _owner;
600             this.el = new Gtk.Label( "Use this as branch name" );
601
602             // my vars (dec)
603
604             // set gobject values
605             this.el.halign = Gtk.Align.START;
606             this.el.justify = Gtk.Justification.RIGHT;
607             this.el.xalign = 0.900000f;
608         }
609
610         // user defined functions
611     }
612
613     public class Xcls_name : Object
614     {
615         public Gtk.Entry el;
616         private NewBranch  _this;
617
618
619             // my vars (def)
620
621         // ctor
622         public Xcls_name(NewBranch _owner )
623         {
624             _this = _owner;
625             _this.name = this;
626             this.el = new Gtk.Entry();
627
628             // my vars (dec)
629
630             // set gobject values
631             this.el.visible = true;
632         }
633
634         // user defined functions
635     }
636
637     public class Xcls_Button15 : Object
638     {
639         public Gtk.Button el;
640         private NewBranch  _this;
641
642
643             // my vars (def)
644
645         // ctor
646         public Xcls_Button15(NewBranch _owner )
647         {
648             _this = _owner;
649             this.el = new Gtk.Button();
650
651             // my vars (dec)
652
653             // set gobject values
654             this.el.expand = false;
655             this.el.label = "New Ticket";
656         }
657
658         // user defined functions
659     }
660
661
662
663     public class Xcls_Button16 : Object
664     {
665         public Gtk.Button el;
666         private NewBranch  _this;
667
668
669             // my vars (def)
670
671         // ctor
672         public Xcls_Button16(NewBranch _owner )
673         {
674             _this = _owner;
675             this.el = new Gtk.Button();
676
677             // my vars (dec)
678
679             // set gobject values
680             this.el.relief = Gtk.ReliefStyle.NONE;
681             this.el.label = "Do not create Branch";
682         }
683
684         // user defined functions
685     }
686
687     public class Xcls_Button17 : Object
688     {
689         public Gtk.Button el;
690         private NewBranch  _this;
691
692
693             // my vars (def)
694
695         // ctor
696         public Xcls_Button17(NewBranch _owner )
697         {
698             _this = _owner;
699             this.el = new Gtk.Button();
700
701             // my vars (dec)
702
703             // set gobject values
704             this.el.label = "Create Branch";
705         }
706
707         // user defined functions
708     }
709
710 }