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_projectsel projectsel;
16     public Xcls_prcellrenderer prcellrenderer;
17     public Xcls_prmodel prmodel;
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
49         //listeners
50         this.el.delete_event.connect( (self, event) => {
51             this.el.hide();
52             return true; 
53             //test  
54         });
55         this.el.response.connect( (self, response_id) =>  { 
56           
57                 GLib.debug("got %d", (int) response_id);
58                 if (response_id < 1) {
59                     _this.el.hide();    
60                     this.running = false; 
61                         return;
62                 }
63                  
64                 // have they selected a ticket..
65                 // make that the current active ticket?
66                 // we really need to store locally what ticket is being worked on..
67                 // in theory we could be working on multiple project and not merging..
68                 // -- each repo would have their active ticket (only one per repo)
69                 // -- so we could just store that in there
70                 // -- initial load can check the contents of the ticket files on first scan.
71                 var ticket_id = _this.ticketsel.selectedTicketId();
72                 
73             if (this.repo != null) {
74                 var bn = _this.name.el.get_text();
75         
76                         var res = this.repo.setActiveTicket(                    
77                                  RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
78                          );
79                          if (res) {
80                                 // start the monitoring..
81                                  GitMonitor.gitmonitor.start();
82                                  
83                          }
84             }
85             
86         
87             this.running = false; 
88         
89                 this.el.hide();
90                  
91                  
92         
93                  
94         });
95         this.el.show.connect( (self)  => {
96          
97         
98           //test
99         });
100     }
101
102     // user defined functions
103     public   void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue ) 
104     {
105          // this.el.set_gravity(Gdk.Gravity.NORTH);
106         if (this.running) { // should not happen!!
107                 GLib.error("new branch show called, when already being displayed?");
108         }
109         this.queue = queue;
110         
111         this.running  = true;
112         GitMonitor.gitmonitor.stop();
113         
114         this.repo = repo;
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.el.set_keep_above(true);
122         _this.dbmodel.loadTickets();
123         this.el.run();
124     
125     }
126     public class Xcls_VBox2 : Object
127     {
128         public Gtk.VBox el;
129         private NewBranch  _this;
130
131
132             // my vars (def)
133
134         // ctor
135         public Xcls_VBox2(NewBranch _owner )
136         {
137             _this = _owner;
138             this.el = new Gtk.VBox( true, 0 );
139
140             // my vars (dec)
141
142             // set gobject values
143             var child_0 = new Xcls_Table3( _this );
144             child_0.ref();
145             this.el.pack_start (  child_0.el , false,false,0 );
146         }
147
148         // user defined functions
149     }
150     public class Xcls_Table3 : Object
151     {
152         public Gtk.Table el;
153         private NewBranch  _this;
154
155
156             // my vars (def)
157
158         // ctor
159         public Xcls_Table3(NewBranch _owner )
160         {
161             _this = _owner;
162             this.el = new Gtk.Table( 5, 5, true );
163
164             // my vars (dec)
165
166             // set gobject values
167             this.el.expand = true;
168             this.el.margin = 2;
169             this.el.column_spacing = 4;
170             this.el.vexpand = false;
171             var child_0 = new Xcls_Label4( _this );
172             child_0.ref();
173             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
174             var child_1 = new Xcls_Label5( _this );
175             child_1.ref();
176             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
177             var child_2 = new Xcls_projectsel( _this );
178             child_2.ref();
179             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
180             var child_3 = new Xcls_ticketsel( _this );
181             child_3.ref();
182             this.el.attach_defaults (  child_3.el , 1,4,1,2 );
183             var child_4 = new Xcls_Button12( _this );
184             child_4.ref();
185             this.el.attach_defaults (  child_4.el , 4,5,1,2 );
186             var child_5 = new Xcls_Label13( _this );
187             child_5.ref();
188             this.el.attach_defaults (  child_5.el , 0,1,3,4 );
189             var child_6 = new Xcls_name( _this );
190             child_6.ref();
191             this.el.attach_defaults (  child_6.el , 0,4,4,5 );
192             var child_7 = new Xcls_Button15( _this );
193             child_7.ref();
194             this.el.attach_defaults (  child_7.el , 4,5,4,5 );
195             var child_8 = new Xcls_CheckButton16( _this );
196             child_8.ref();
197             this.el.attach_defaults (  child_8.el , 0,2,2,3 );
198             var child_9 = new Xcls_CheckButton17( _this );
199             child_9.ref();
200             this.el.attach_defaults (  child_9.el , 2,4,2,3 );
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_projectsel : 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_projectsel(NewBranch _owner )
265         {
266             _this = _owner;
267             _this.projectsel = 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_prcellrenderer( _this );
275             child_0.ref();
276             this.el.pack_start (  child_0.el , true );
277             var child_1 = new Xcls_prmodel( _this );
278             child_1.ref();
279             this.el.set_model (  child_1.el  );
280
281             // init method
282
283             this.el.add_attribute(_this.prcellrenderer.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
311         // user defined functions
312         public string selectedTicketId () {
313         Gtk.TreeIter iter;
314                 Value val1;
315          
316          
317                 this.el.get_active_iter (out iter);
318                 _this.dbmodel.el.get_value (iter, 0, out val1);
319          
320         
321                 return  (string) val1;
322                 
323                 
324                 
325                 
326         }
327     }
328     public class Xcls_prcellrenderer : Object
329     {
330         public Gtk.CellRendererText el;
331         private NewBranch  _this;
332
333
334             // my vars (def)
335
336         // ctor
337         public Xcls_prcellrenderer(NewBranch _owner )
338         {
339             _this = _owner;
340             _this.prcellrenderer = this;
341             this.el = new Gtk.CellRendererText();
342
343             // my vars (dec)
344
345             // set gobject values
346         }
347
348         // user defined functions
349     }
350
351     public class Xcls_prmodel : Object
352     {
353         public Gtk.ListStore el;
354         private NewBranch  _this;
355
356
357             // my vars (def)
358
359         // ctor
360         public Xcls_prmodel(NewBranch _owner )
361         {
362             _this = _owner;
363             _this.prmodel = this;
364             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
365
366             // my vars (dec)
367
368             // set gobject values
369         }
370
371         // user defined functions
372         public void loadTickets () {
373         
374             RooTicket.singleton().loadTickets();
375             
376             _this.ticketsel.loading = true;
377         
378             this.el.clear();                                    
379             Gtk.TreeIter iter;
380             var el = this.el;
381             
382             el.append(out iter);
383         
384             
385             el.set_value(iter, 0, "");
386             el.set_value(iter, 1, "-- select a ticket --");
387             
388             _this.ticketsel.el.set_active_iter(iter);
389             var tickets = RooTicket.singleton().tickets;
390             foreach(var ticket in tickets) {
391             
392                 el.append(out iter);
393                 
394                 el.set_value(iter, 0, ticket.id);
395                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
396                 
397                 //if (data.get(i) == cur) {
398                  //   _this.build_module.el.set_active_iter(iter);
399                // }
400                 
401             }
402             
403             _this.ticketsel.loading = false;
404              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
405                                              
406         }
407     }
408
409
410     public class Xcls_ticketsel : Object
411     {
412         public Gtk.ComboBox el;
413         private NewBranch  _this;
414
415
416             // my vars (def)
417         public bool loading;
418
419         // ctor
420         public Xcls_ticketsel(NewBranch _owner )
421         {
422             _this = _owner;
423             _this.ticketsel = this;
424             this.el = new Gtk.ComboBox();
425
426             // my vars (dec)
427             this.loading = false;
428
429             // set gobject values
430             var child_0 = new Xcls_dbcellrenderer( _this );
431             child_0.ref();
432             this.el.pack_start (  child_0.el , true );
433             var child_1 = new Xcls_dbmodel( _this );
434             child_1.ref();
435             this.el.set_model (  child_1.el  );
436
437             // init method
438
439             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
440
441             //listeners
442             this.el.changed.connect( () => {
443                 if (this.loading) {
444                         return;
445                 }
446                 var ticket_id = this.selectedTicketId();
447                 
448                 var name = RooTicket.singleton().usernameLocal();
449                 
450                 if (ticket_id == "" || ticket_id == null) {
451                 
452                         var dt = new  DateTime.now_local();
453                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
454                         return;
455                 }
456                 
457                 
458                 var ticket = RooTicket.singleton().getById(ticket_id);
459                
460                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
461                 
462                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
463             });
464         }
465
466         // user defined functions
467         public string selectedTicketId () {
468         Gtk.TreeIter iter;
469                 Value val1;
470          
471          
472                 this.el.get_active_iter (out iter);
473                 _this.dbmodel.el.get_value (iter, 0, out val1);
474          
475         
476                 return  (string) val1;
477                 
478                 
479                 
480                 
481         }
482     }
483     public class Xcls_dbcellrenderer : Object
484     {
485         public Gtk.CellRendererText el;
486         private NewBranch  _this;
487
488
489             // my vars (def)
490
491         // ctor
492         public Xcls_dbcellrenderer(NewBranch _owner )
493         {
494             _this = _owner;
495             _this.dbcellrenderer = this;
496             this.el = new Gtk.CellRendererText();
497
498             // my vars (dec)
499
500             // set gobject values
501         }
502
503         // user defined functions
504     }
505
506     public class Xcls_dbmodel : Object
507     {
508         public Gtk.ListStore el;
509         private NewBranch  _this;
510
511
512             // my vars (def)
513
514         // ctor
515         public Xcls_dbmodel(NewBranch _owner )
516         {
517             _this = _owner;
518             _this.dbmodel = this;
519             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
520
521             // my vars (dec)
522
523             // set gobject values
524         }
525
526         // user defined functions
527         public void loadTickets () {
528         
529             RooTicket.singleton().loadTickets();
530             
531             _this.ticketsel.loading = true;
532         
533             this.el.clear();                                    
534             Gtk.TreeIter iter;
535             var el = this.el;
536             
537             el.append(out iter);
538         
539             
540             el.set_value(iter, 0, "");
541             el.set_value(iter, 1, "-- select a ticket --");
542             
543             _this.ticketsel.el.set_active_iter(iter);
544             var tickets = RooTicket.singleton().tickets;
545             foreach(var ticket in tickets) {
546             
547                 el.append(out iter);
548                 
549                 el.set_value(iter, 0, ticket.id);
550                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
551                 
552                 //if (data.get(i) == cur) {
553                  //   _this.build_module.el.set_active_iter(iter);
554                // }
555                 
556             }
557             
558             _this.ticketsel.loading = false;
559              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
560                                              
561         }
562     }
563
564
565     public class Xcls_Button12 : Object
566     {
567         public Gtk.Button el;
568         private NewBranch  _this;
569
570
571             // my vars (def)
572
573         // ctor
574         public Xcls_Button12(NewBranch _owner )
575         {
576             _this = _owner;
577             this.el = new Gtk.Button();
578
579             // my vars (dec)
580
581             // set gobject values
582             this.el.expand = false;
583             this.el.label = "New Ticket";
584         }
585
586         // user defined functions
587     }
588
589     public class Xcls_Label13 : Object
590     {
591         public Gtk.Label el;
592         private NewBranch  _this;
593
594
595             // my vars (def)
596
597         // ctor
598         public Xcls_Label13(NewBranch _owner )
599         {
600             _this = _owner;
601             this.el = new Gtk.Label( "Use this as branch name" );
602
603             // my vars (dec)
604
605             // set gobject values
606             this.el.halign = Gtk.Align.START;
607             this.el.justify = Gtk.Justification.RIGHT;
608             this.el.xalign = 0.900000f;
609         }
610
611         // user defined functions
612     }
613
614     public class Xcls_name : Object
615     {
616         public Gtk.Entry el;
617         private NewBranch  _this;
618
619
620             // my vars (def)
621
622         // ctor
623         public Xcls_name(NewBranch _owner )
624         {
625             _this = _owner;
626             _this.name = this;
627             this.el = new Gtk.Entry();
628
629             // my vars (dec)
630
631             // set gobject values
632             this.el.visible = true;
633         }
634
635         // user defined functions
636     }
637
638     public class Xcls_Button15 : Object
639     {
640         public Gtk.Button el;
641         private NewBranch  _this;
642
643
644             // my vars (def)
645
646         // ctor
647         public Xcls_Button15(NewBranch _owner )
648         {
649             _this = _owner;
650             this.el = new Gtk.Button();
651
652             // my vars (dec)
653
654             // set gobject values
655             this.el.label = "Create Branch";
656
657             // init method
658
659             {
660                this.el.get_style_context().add_class("suggested-action");
661             }
662
663             //listeners
664             this.el.activate.connect( () => {
665                 _this.el.response(1);
666             });
667         }
668
669         // user defined functions
670     }
671
672     public class Xcls_CheckButton16 : Object
673     {
674         public Gtk.CheckButton el;
675         private NewBranch  _this;
676
677
678             // my vars (def)
679
680         // ctor
681         public Xcls_CheckButton16(NewBranch _owner )
682         {
683             _this = _owner;
684             this.el = new Gtk.CheckButton();
685
686             // my vars (dec)
687
688             // set gobject values
689             this.el.label = "Show tickets not assigned to me";
690         }
691
692         // user defined functions
693     }
694
695     public class Xcls_CheckButton17 : Object
696     {
697         public Gtk.CheckButton el;
698         private NewBranch  _this;
699
700
701             // my vars (def)
702
703         // ctor
704         public Xcls_CheckButton17(NewBranch _owner )
705         {
706             _this = _owner;
707             this.el = new Gtk.CheckButton();
708
709             // my vars (dec)
710
711             // set gobject values
712             this.el.label = "Show closed Tickets";
713         }
714
715         // user defined functions
716     }
717
718
719
720 }