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_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_projectsel( _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,3,4 );
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_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.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_dbmodel : Object
352     {
353         public Gtk.ListStore el;
354         private NewBranch  _this;
355
356
357             // my vars (def)
358
359         // ctor
360         public Xcls_dbmodel(NewBranch _owner )
361         {
362             _this = _owner;
363             _this.dbmodel = 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.get_style_contect().add_class("suggested-action");
661             }
662         }
663
664         // user defined functions
665     }
666
667
668
669     public class Xcls_Button16 : Object
670     {
671         public Gtk.Button el;
672         private NewBranch  _this;
673
674
675             // my vars (def)
676
677         // ctor
678         public Xcls_Button16(NewBranch _owner )
679         {
680             _this = _owner;
681             this.el = new Gtk.Button();
682
683             // my vars (dec)
684
685             // set gobject values
686             this.el.relief = Gtk.ReliefStyle.NONE;
687             this.el.label = "Do not create Branch";
688         }
689
690         // user defined functions
691     }
692
693     public class Xcls_Button17 : Object
694     {
695         public Gtk.Button el;
696         private NewBranch  _this;
697
698
699             // my vars (def)
700
701         // ctor
702         public Xcls_Button17(NewBranch _owner )
703         {
704             _this = _owner;
705             this.el = new Gtk.Button();
706
707             // my vars (dec)
708
709             // set gobject values
710             this.el.label = "Create Branch";
711         }
712
713         // user defined functions
714     }
715
716 }