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         
117         
118         
119         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
120         this.el.set_default_size( 500,200); // not sure why it grows..
121         GLib.debug("Loading tickets"); 
122          
123     
124         this.el.show_all();
125         this.el.set_keep_above(true);
126         _this.prmodel.loadProjects();
127         
128         var curproj = GitTicket.singleton().getProjectByRepo(repo);
129         if (curproject != null) {
130     //          _this.projectsel.selectProject(curproject);
131         }
132         
133         _this.dbmodel.loadTickets();
134         this.el.run();
135     
136     }
137     public class Xcls_VBox2 : Object
138     {
139         public Gtk.VBox el;
140         private NewBranch  _this;
141
142
143             // my vars (def)
144
145         // ctor
146         public Xcls_VBox2(NewBranch _owner )
147         {
148             _this = _owner;
149             this.el = new Gtk.VBox( true, 0 );
150
151             // my vars (dec)
152
153             // set gobject values
154             var child_0 = new Xcls_Table3( _this );
155             child_0.ref();
156             this.el.pack_start (  child_0.el , false,false,0 );
157         }
158
159         // user defined functions
160     }
161     public class Xcls_Table3 : Object
162     {
163         public Gtk.Table el;
164         private NewBranch  _this;
165
166
167             // my vars (def)
168
169         // ctor
170         public Xcls_Table3(NewBranch _owner )
171         {
172             _this = _owner;
173             this.el = new Gtk.Table( 5, 5, true );
174
175             // my vars (dec)
176
177             // set gobject values
178             this.el.expand = false;
179             this.el.margin = 2;
180             this.el.column_spacing = 4;
181             this.el.vexpand = false;
182             var child_0 = new Xcls_Label4( _this );
183             child_0.ref();
184             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
185             var child_1 = new Xcls_Label5( _this );
186             child_1.ref();
187             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
188             var child_2 = new Xcls_projectsel( _this );
189             child_2.ref();
190             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
191             var child_3 = new Xcls_ticketsel( _this );
192             child_3.ref();
193             this.el.attach_defaults (  child_3.el , 1,4,1,2 );
194             var child_4 = new Xcls_Button12( _this );
195             child_4.ref();
196             this.el.attach_defaults (  child_4.el , 4,5,1,2 );
197             var child_5 = new Xcls_Label13( _this );
198             child_5.ref();
199             this.el.attach_defaults (  child_5.el , 0,1,3,4 );
200             var child_6 = new Xcls_name( _this );
201             child_6.ref();
202             this.el.attach_defaults (  child_6.el , 0,4,4,5 );
203             var child_7 = new Xcls_Button15( _this );
204             child_7.ref();
205             this.el.attach_defaults (  child_7.el , 4,5,4,5 );
206             var child_8 = new Xcls_Box16( _this );
207             child_8.ref();
208             this.el.attach_defaults (  child_8.el , 0,5,2,3 );
209         }
210
211         // user defined functions
212     }
213     public class Xcls_Label4 : Object
214     {
215         public Gtk.Label el;
216         private NewBranch  _this;
217
218
219             // my vars (def)
220
221         // ctor
222         public Xcls_Label4(NewBranch _owner )
223         {
224             _this = _owner;
225             this.el = new Gtk.Label( "Project" );
226
227             // my vars (dec)
228
229             // set gobject values
230             this.el.halign = Gtk.Align.START;
231             this.el.justify = Gtk.Justification.RIGHT;
232             this.el.visible = true;
233         }
234
235         // user defined functions
236     }
237
238     public class Xcls_Label5 : Object
239     {
240         public Gtk.Label el;
241         private NewBranch  _this;
242
243
244             // my vars (def)
245
246         // ctor
247         public Xcls_Label5(NewBranch _owner )
248         {
249             _this = _owner;
250             this.el = new Gtk.Label( "Ticket" );
251
252             // my vars (dec)
253
254             // set gobject values
255             this.el.halign = Gtk.Align.START;
256             this.el.visible = true;
257         }
258
259         // user defined functions
260     }
261
262     public class Xcls_projectsel : Object
263     {
264         public Gtk.ComboBox el;
265         private NewBranch  _this;
266
267
268             // my vars (def)
269         public bool loading;
270
271         // ctor
272         public Xcls_projectsel(NewBranch _owner )
273         {
274             _this = _owner;
275             _this.projectsel = this;
276             this.el = new Gtk.ComboBox.with_entry();
277
278             // my vars (dec)
279             this.loading = false;
280
281             // set gobject values
282             var child_0 = new Xcls_prcellrenderer( _this );
283             child_0.ref();
284             this.el.pack_start (  child_0.el , true );
285             var child_1 = new Xcls_prmodel( _this );
286             child_1.ref();
287             this.el.set_model (  child_1.el  );
288
289             // init method
290
291             this.el.set_entry_text_column(1);
292
293             //listeners
294             this.el.changed.connect( () => {
295                 /*if (this.loading) {
296                         return;
297                 }
298                 var ticket_id = this.selectedTicketId();
299                 
300                 var name = RooTicket.singleton().usernameLocal();
301                 
302                 if (ticket_id == "" || ticket_id == null) {
303                 
304                         var dt = new  DateTime.now_local();
305                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
306                         return;
307                 }
308                 
309                 
310                 var ticket = RooTicket.singleton().getById(ticket_id);
311                
312                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
313                 
314                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
315                 */
316             });
317         }
318
319         // user defined functions
320         public string selectedTicketId () {
321         Gtk.TreeIter iter;
322                 Value val1;
323          
324          
325                 this.el.get_active_iter (out iter);
326                 _this.dbmodel.el.get_value (iter, 0, out val1);
327          
328         
329                 return  (string) val1;
330                 
331                 
332                 
333                 
334         }
335     }
336     public class Xcls_prcellrenderer : Object
337     {
338         public Gtk.CellRendererText el;
339         private NewBranch  _this;
340
341
342             // my vars (def)
343
344         // ctor
345         public Xcls_prcellrenderer(NewBranch _owner )
346         {
347             _this = _owner;
348             _this.prcellrenderer = this;
349             this.el = new Gtk.CellRendererText();
350
351             // my vars (dec)
352
353             // set gobject values
354         }
355
356         // user defined functions
357     }
358
359     public class Xcls_prmodel : Object
360     {
361         public Gtk.ListStore el;
362         private NewBranch  _this;
363
364
365             // my vars (def)
366
367         // ctor
368         public Xcls_prmodel(NewBranch _owner )
369         {
370             _this = _owner;
371             _this.prmodel = this;
372             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
373
374             // my vars (dec)
375
376             // set gobject values
377         }
378
379         // user defined functions
380         public void loadProjects () {
381         
382             var rt = RooTicket.singleton();
383             rt.loadProjects();
384             
385             _this.projectsel.loading = true;
386         
387             this.el.clear();                                    
388             Gtk.TreeIter iter;
389             var el = this.el;
390             
391             el.append(out iter);
392         
393             
394             el.set_value(iter, 0, "");
395             el.set_value(iter, 1, "-- select a project --");
396             
397             _this.projectsel.el.set_active_iter(iter);
398             var projects = rt.projects;
399             foreach(var project in projects) {
400             
401                 el.append(out iter);
402                 
403                 el.set_value(iter, 0, project.id);
404                 el.set_value(iter, 1,  project.name );
405                 
406                 
407             }
408             
409             _this.projectsel.loading = false;
410              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
411                                              
412         }
413     }
414
415
416     public class Xcls_ticketsel : Object
417     {
418         public Gtk.ComboBox el;
419         private NewBranch  _this;
420
421
422             // my vars (def)
423         public bool loading;
424
425         // ctor
426         public Xcls_ticketsel(NewBranch _owner )
427         {
428             _this = _owner;
429             _this.ticketsel = this;
430             this.el = new Gtk.ComboBox.with_entry();
431
432             // my vars (dec)
433             this.loading = false;
434
435             // set gobject values
436             var child_0 = new Xcls_dbcellrenderer( _this );
437             child_0.ref();
438             this.el.pack_start (  child_0.el , true );
439             var child_1 = new Xcls_dbmodel( _this );
440             child_1.ref();
441             this.el.set_model (  child_1.el  );
442
443             // init method
444
445             //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
446             this.el.set_entry_text_column(1);
447
448             //listeners
449             this.el.changed.connect( () => {
450                 if (this.loading) {
451                         return;
452                 }
453                 var ticket_id = this.selectedTicketId();
454                 
455                 var name = RooTicket.singleton().usernameLocal();
456                 
457                 if (ticket_id == "" || ticket_id == null) {
458                 
459                         var dt = new  DateTime.now_local();
460                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
461                         return;
462                 }
463                 
464                 
465                 var ticket = RooTicket.singleton().getById(ticket_id);
466                
467                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
468                 
469                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
470             });
471         }
472
473         // user defined functions
474         public string selectedTicketId () {
475         Gtk.TreeIter iter;
476                 Value val1;
477          
478          
479                 this.el.get_active_iter (out iter);
480                 _this.dbmodel.el.get_value (iter, 0, out val1);
481          
482         
483                 return  (string) val1;
484                 
485                 
486                 
487                 
488         }
489     }
490     public class Xcls_dbcellrenderer : Object
491     {
492         public Gtk.CellRendererText el;
493         private NewBranch  _this;
494
495
496             // my vars (def)
497
498         // ctor
499         public Xcls_dbcellrenderer(NewBranch _owner )
500         {
501             _this = _owner;
502             _this.dbcellrenderer = this;
503             this.el = new Gtk.CellRendererText();
504
505             // my vars (dec)
506
507             // set gobject values
508         }
509
510         // user defined functions
511     }
512
513     public class Xcls_dbmodel : Object
514     {
515         public Gtk.ListStore el;
516         private NewBranch  _this;
517
518
519             // my vars (def)
520
521         // ctor
522         public Xcls_dbmodel(NewBranch _owner )
523         {
524             _this = _owner;
525             _this.dbmodel = this;
526             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
527
528             // my vars (dec)
529
530             // set gobject values
531         }
532
533         // user defined functions
534         public void loadTickets () {
535         
536             RooTicket.singleton().loadTickets();
537             
538             _this.ticketsel.loading = true;
539         
540             this.el.clear();                                    
541             Gtk.TreeIter iter;
542             var el = this.el;
543             
544             el.append(out iter);
545         
546             
547             el.set_value(iter, 0, "");
548             el.set_value(iter, 1, "-- select a ticket --");
549             
550             _this.ticketsel.el.set_active_iter(iter);
551             var tickets = RooTicket.singleton().tickets;
552             foreach(var ticket in tickets) {
553             
554                 el.append(out iter);
555                 
556                 el.set_value(iter, 0, ticket.id);
557                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
558                 
559                 //if (data.get(i) == cur) {
560                  //   _this.build_module.el.set_active_iter(iter);
561                // }
562                 
563             }
564             
565             _this.ticketsel.loading = false;
566              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
567                                              
568         }
569     }
570
571
572     public class Xcls_Button12 : Object
573     {
574         public Gtk.Button el;
575         private NewBranch  _this;
576
577
578             // my vars (def)
579
580         // ctor
581         public Xcls_Button12(NewBranch _owner )
582         {
583             _this = _owner;
584             this.el = new Gtk.Button();
585
586             // my vars (dec)
587
588             // set gobject values
589             this.el.expand = false;
590             this.el.label = "New Ticket";
591         }
592
593         // user defined functions
594     }
595
596     public class Xcls_Label13 : Object
597     {
598         public Gtk.Label el;
599         private NewBranch  _this;
600
601
602             // my vars (def)
603
604         // ctor
605         public Xcls_Label13(NewBranch _owner )
606         {
607             _this = _owner;
608             this.el = new Gtk.Label( "Use this as branch name" );
609
610             // my vars (dec)
611
612             // set gobject values
613             this.el.halign = Gtk.Align.START;
614             this.el.justify = Gtk.Justification.RIGHT;
615             this.el.xalign = 0.900000f;
616         }
617
618         // user defined functions
619     }
620
621     public class Xcls_name : Object
622     {
623         public Gtk.Entry el;
624         private NewBranch  _this;
625
626
627             // my vars (def)
628
629         // ctor
630         public Xcls_name(NewBranch _owner )
631         {
632             _this = _owner;
633             _this.name = this;
634             this.el = new Gtk.Entry();
635
636             // my vars (dec)
637
638             // set gobject values
639             this.el.visible = true;
640         }
641
642         // user defined functions
643     }
644
645     public class Xcls_Button15 : Object
646     {
647         public Gtk.Button el;
648         private NewBranch  _this;
649
650
651             // my vars (def)
652
653         // ctor
654         public Xcls_Button15(NewBranch _owner )
655         {
656             _this = _owner;
657             this.el = new Gtk.Button();
658
659             // my vars (dec)
660
661             // set gobject values
662             this.el.label = "Create Branch";
663
664             // init method
665
666             {
667                this.el.get_style_context().add_class("suggested-action");
668             }
669
670             //listeners
671             this.el.activate.connect( () => {
672                 _this.el.response(1);
673             });
674         }
675
676         // user defined functions
677     }
678
679     public class Xcls_Box16 : Object
680     {
681         public Gtk.Box el;
682         private NewBranch  _this;
683
684
685             // my vars (def)
686
687         // ctor
688         public Xcls_Box16(NewBranch _owner )
689         {
690             _this = _owner;
691             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
692
693             // my vars (dec)
694
695             // set gobject values
696             var child_0 = new Xcls_CheckButton17( _this );
697             child_0.ref();
698             this.el.add (  child_0.el  );
699             var child_1 = new Xcls_CheckButton18( _this );
700             child_1.ref();
701             this.el.add (  child_1.el  );
702             var child_2 = new Xcls_Label19( _this );
703             child_2.ref();
704             this.el.add (  child_2.el  );
705         }
706
707         // user defined functions
708     }
709     public class Xcls_CheckButton17 : Object
710     {
711         public Gtk.CheckButton el;
712         private NewBranch  _this;
713
714
715             // my vars (def)
716
717         // ctor
718         public Xcls_CheckButton17(NewBranch _owner )
719         {
720             _this = _owner;
721             this.el = new Gtk.CheckButton();
722
723             // my vars (dec)
724
725             // set gobject values
726             this.el.label = "Show tickets not assigned to me";
727         }
728
729         // user defined functions
730     }
731
732     public class Xcls_CheckButton18 : Object
733     {
734         public Gtk.CheckButton el;
735         private NewBranch  _this;
736
737
738             // my vars (def)
739
740         // ctor
741         public Xcls_CheckButton18(NewBranch _owner )
742         {
743             _this = _owner;
744             this.el = new Gtk.CheckButton();
745
746             // my vars (dec)
747
748             // set gobject values
749             this.el.label = "Show closed Tickets";
750         }
751
752         // user defined functions
753     }
754
755     public class Xcls_Label19 : Object
756     {
757         public Gtk.Label el;
758         private NewBranch  _this;
759
760
761             // my vars (def)
762
763         // ctor
764         public Xcls_Label19(NewBranch _owner )
765         {
766             _this = _owner;
767             this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
768
769             // my vars (dec)
770
771             // set gobject values
772             this.el.halign = Gtk.Align.END;
773             this.el.hexpand = true;
774             this.el.use_markup = true;
775
776             //listeners
777             this.el.activate_link.connect( (uri) => {
778                 if (uri == "refresh") {
779                         _this.prmodel.loadProjects();
780                         _this.dbmodel.loadTickets();            
781                 }
782                 return true;
783             });
784         }
785
786         // user defined functions
787     }
788
789
790
791
792 }