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