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     public Xcls_btn_not_me btn_not_me;
23     public Xcls_btn_closed btn_closed;
24     public Xcls_scrolled_window scrolled_window;
25
26         // my vars (def)
27     public GitRepo? repo;
28     public bool running;
29     public Gee.ArrayList<GitMonitorQueue> queue;
30
31     // ctor
32     public NewBranch()
33     {
34         _this = this;
35         this.el = new Gtk.Dialog();
36
37         // my vars (dec)
38         this.repo = null;
39         this.running = false;
40         this.queue = null;
41
42         // set gobject values
43         this.el.title = "Create a working branch ";
44         this.el.default_height = 200;
45         this.el.default_width = 500;
46         this.el.deletable = true;
47         this.el.modal = true;
48         var child_0 = new Xcls_Box2( _this );
49         child_0.ref();
50         this.el.get_content_area().add (  child_0.el  );
51
52         //listeners
53         this.el.delete_event.connect( (self, event) => {
54             this.el.hide();
55             return true; 
56             //test  
57         });
58         this.el.response.connect( (self, response_id) =>  { 
59           
60                 GLib.debug("got %d", (int) response_id);
61                 if (response_id < 1) {
62                     _this.el.hide();    
63                     this.running = false; 
64                         return;
65                 }
66                  
67                 // have they selected a ticket..
68                 // make that the current active ticket?
69                 // we really need to store locally what ticket is being worked on..
70                 // in theory we could be working on multiple project and not merging..
71                 // -- each repo would have their active ticket (only one per repo)
72                 // -- so we could just store that in there
73                 // -- initial load can check the contents of the ticket files on first scan.
74                 var ticket_id = _this.ticketsel.selectedTicketId();
75                 
76             if (this.repo != null) {
77                 var bn = _this.name.el.get_text();
78         
79                         var res = this.repo.setActiveTicket(                    
80                                  RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
81                          );
82                          if (res) {
83                                 // start the monitoring..
84                                  GitMonitor.gitmonitor.start();
85                                  
86                          }
87             }
88             
89         
90             this.running = false; 
91         
92                 this.el.hide();
93                  
94                  
95         
96                  
97         });
98     }
99
100     // user defined functions
101     public   void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" ) 
102     {
103          // this.el.set_gravity(Gdk.Gravity.NORTH);
104         if (this.running) { // should not happen!!
105                 GLib.error("new branch show called, when already being displayed?");
106         }
107         this.queue = queue;
108         
109         this.running  = true;
110         GitMonitor.gitmonitor.stop();
111         
112         this.repo = repo;
113         
114          
115         
116         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
117         this.el.set_default_size( 500,200); // not sure why it grows..
118         GLib.debug("Loading tickets"); 
119          
120     
121         this.el.show_all();
122         this.el.set_keep_above(true);
123        
124         
125         var curproj = RooTicket.singleton().getProjectByRepo(this.repo);
126          _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
127         
128         _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
129         if (tid != "") {
130                 var name = RooTicket.singleton().usernameLocal();
131                 var ticket = RooTicket.singleton().getById(tid);
132                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
133         }
134     
135         this.el.run();
136     
137     }
138     public class Xcls_Box2 : Object
139     {
140         public Gtk.Box el;
141         private NewBranch  _this;
142
143
144             // my vars (def)
145
146         // ctor
147         public Xcls_Box2(NewBranch _owner )
148         {
149             _this = _owner;
150             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
151
152             // my vars (dec)
153
154             // set gobject values
155             var child_0 = new Xcls_Table3( _this );
156             child_0.ref();
157             this.el.pack_start (  child_0.el , false,false,0 );
158             var child_1 = new Xcls_scrolled_window( _this );
159             child_1.ref();
160             this.el.add (  child_1.el  );
161         }
162
163         // user defined functions
164     }
165     public class Xcls_Table3 : Object
166     {
167         public Gtk.Table el;
168         private NewBranch  _this;
169
170
171             // my vars (def)
172
173         // ctor
174         public Xcls_Table3(NewBranch _owner )
175         {
176             _this = _owner;
177             this.el = new Gtk.Table( 5, 5, true );
178
179             // my vars (dec)
180
181             // set gobject values
182             this.el.expand = false;
183             this.el.margin = 2;
184             this.el.column_spacing = 4;
185             this.el.vexpand = false;
186             var child_0 = new Xcls_Label4( _this );
187             child_0.ref();
188             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
189             var child_1 = new Xcls_Label5( _this );
190             child_1.ref();
191             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
192             var child_2 = new Xcls_projectsel( _this );
193             child_2.ref();
194             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
195             var child_3 = new Xcls_ticketsel( _this );
196             child_3.ref();
197             this.el.attach_defaults (  child_3.el , 1,4,1,2 );
198             var child_4 = new Xcls_Button12( _this );
199             child_4.ref();
200             this.el.attach_defaults (  child_4.el , 4,5,1,2 );
201             var child_5 = new Xcls_Label13( _this );
202             child_5.ref();
203             this.el.attach_defaults (  child_5.el , 0,1,3,4 );
204             var child_6 = new Xcls_name( _this );
205             child_6.ref();
206             this.el.attach_defaults (  child_6.el , 0,4,4,5 );
207             var child_7 = new Xcls_Button15( _this );
208             child_7.ref();
209             this.el.attach_defaults (  child_7.el , 4,5,4,5 );
210             var child_8 = new Xcls_Box16( _this );
211             child_8.ref();
212             this.el.attach_defaults (  child_8.el , 0,5,2,3 );
213         }
214
215         // user defined functions
216     }
217     public class Xcls_Label4 : Object
218     {
219         public Gtk.Label el;
220         private NewBranch  _this;
221
222
223             // my vars (def)
224
225         // ctor
226         public Xcls_Label4(NewBranch _owner )
227         {
228             _this = _owner;
229             this.el = new Gtk.Label( "Project" );
230
231             // my vars (dec)
232
233             // set gobject values
234             this.el.halign = Gtk.Align.START;
235             this.el.justify = Gtk.Justification.RIGHT;
236             this.el.visible = true;
237         }
238
239         // user defined functions
240     }
241
242     public class Xcls_Label5 : Object
243     {
244         public Gtk.Label el;
245         private NewBranch  _this;
246
247
248             // my vars (def)
249
250         // ctor
251         public Xcls_Label5(NewBranch _owner )
252         {
253             _this = _owner;
254             this.el = new Gtk.Label( "Ticket" );
255
256             // my vars (dec)
257
258             // set gobject values
259             this.el.halign = Gtk.Align.START;
260             this.el.visible = true;
261         }
262
263         // user defined functions
264     }
265
266     public class Xcls_projectsel : Object
267     {
268         public Gtk.ComboBox el;
269         private NewBranch  _this;
270
271
272             // my vars (def)
273         public bool loading;
274
275         // ctor
276         public Xcls_projectsel(NewBranch _owner )
277         {
278             _this = _owner;
279             _this.projectsel = this;
280             this.el = new Gtk.ComboBox.with_entry();
281
282             // my vars (dec)
283             this.loading = false;
284
285             // set gobject values
286             var child_0 = new Xcls_prcellrenderer( _this );
287             child_0.ref();
288             this.el.pack_start (  child_0.el , true );
289             var child_1 = new Xcls_prmodel( _this );
290             child_1.ref();
291             this.el.set_model (  child_1.el  );
292
293             // init method
294
295             this.el.set_entry_text_column(1);
296
297             //listeners
298             this.el.changed.connect( () => {
299                 if (this.loading) {
300                         return;
301                 }
302                 var project_id = this.selectedProjectId();
303                 _this.dbmodel.loadTickets(project_id);
304                 
305                 
306                 /*if (this.loading) {
307                         return;
308                 }
309                 var ticket_id = this.selectedTicketId();
310                 
311                 var name = RooTicket.singleton().usernameLocal();
312                 
313                 if (ticket_id == "" || ticket_id == null) {
314                 
315                         var dt = new  DateTime.now_local();
316                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
317                         return;
318                 }
319                 
320                 
321                 var ticket = RooTicket.singleton().getById(ticket_id);
322                
323                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
324                 
325                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
326                 */
327             });
328         }
329
330         // user defined functions
331         public string selectedProjectId () {
332                 Gtk.TreeIter iter;
333                 Value val1;
334          
335          
336                 this.el.get_active_iter (out iter);
337                 _this.prmodel.el.get_value (iter, 0, out val1);
338          
339         
340                 return  (string) val1;
341                 
342                 
343                 
344                 
345         }
346     }
347     public class Xcls_prcellrenderer : Object
348     {
349         public Gtk.CellRendererText el;
350         private NewBranch  _this;
351
352
353             // my vars (def)
354
355         // ctor
356         public Xcls_prcellrenderer(NewBranch _owner )
357         {
358             _this = _owner;
359             _this.prcellrenderer = this;
360             this.el = new Gtk.CellRendererText();
361
362             // my vars (dec)
363
364             // set gobject values
365         }
366
367         // user defined functions
368     }
369
370     public class Xcls_prmodel : Object
371     {
372         public Gtk.ListStore el;
373         private NewBranch  _this;
374
375
376             // my vars (def)
377
378         // ctor
379         public Xcls_prmodel(NewBranch _owner )
380         {
381             _this = _owner;
382             _this.prmodel = this;
383             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
384
385             // my vars (dec)
386
387             // set gobject values
388         }
389
390         // user defined functions
391         public void loadProjects (string id) {
392         
393             var rt = RooTicket.singleton();
394             rt.loadProjects();
395             
396             _this.projectsel.loading = true;
397         
398             this.el.clear();                                    
399             Gtk.TreeIter iter;
400             var el = this.el;
401             
402             el.append(out iter);
403         
404             
405             el.set_value(iter, 0, "");
406             el.set_value(iter, 1, "-- select a project --");
407             if (id == "") {
408                     _this.projectsel.el.set_active_iter(iter);
409             }
410             var projects = rt.projects;
411             foreach(var project in projects) {
412             
413                 el.append(out iter);
414                 
415                 el.set_value(iter, 0, project.id);
416                 el.set_value(iter, 1,  project.name );
417                 if (id == project.id) {
418                            _this.projectsel.el.set_active_iter(iter);
419                     }   
420                 
421             }
422             
423             _this.projectsel.loading = false;
424              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
425                                              
426         }
427     }
428
429
430     public class Xcls_ticketsel : Object
431     {
432         public Gtk.ComboBox el;
433         private NewBranch  _this;
434
435
436             // my vars (def)
437         public bool loading;
438
439         // ctor
440         public Xcls_ticketsel(NewBranch _owner )
441         {
442             _this = _owner;
443             _this.ticketsel = this;
444             this.el = new Gtk.ComboBox.with_entry();
445
446             // my vars (dec)
447             this.loading = false;
448
449             // set gobject values
450             var child_0 = new Xcls_dbcellrenderer( _this );
451             child_0.ref();
452             this.el.pack_start (  child_0.el , true );
453             var child_1 = new Xcls_dbmodel( _this );
454             child_1.ref();
455             this.el.set_model (  child_1.el  );
456
457             // init method
458
459             //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
460             this.el.set_entry_text_column(1);
461
462             //listeners
463             this.el.changed.connect( () => {
464                 if (this.loading) {
465                         return;
466                 }
467                 var ticket_id = this.selectedTicketId();
468                 
469                 var name = RooTicket.singleton().usernameLocal();
470                 
471                 if (ticket_id == "" || ticket_id == null) {
472                 
473                         var dt = new  DateTime.now_local();
474                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
475                         return;
476                 }
477                 
478                 
479                 var ticket = RooTicket.singleton().getById(ticket_id);
480                
481                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
482                 
483                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
484             });
485         }
486
487         // user defined functions
488         public string selectedTicketId () {
489         Gtk.TreeIter iter;
490                 Value val1;
491          
492          
493                 this.el.get_active_iter (out iter);
494                 _this.dbmodel.el.get_value (iter, 0, out val1);
495          
496         
497                 return  (string) val1;
498                 
499                 
500                 
501                 
502         }
503     }
504     public class Xcls_dbcellrenderer : Object
505     {
506         public Gtk.CellRendererText el;
507         private NewBranch  _this;
508
509
510             // my vars (def)
511
512         // ctor
513         public Xcls_dbcellrenderer(NewBranch _owner )
514         {
515             _this = _owner;
516             _this.dbcellrenderer = this;
517             this.el = new Gtk.CellRendererText();
518
519             // my vars (dec)
520
521             // set gobject values
522         }
523
524         // user defined functions
525     }
526
527     public class Xcls_dbmodel : Object
528     {
529         public Gtk.ListStore el;
530         private NewBranch  _this;
531
532
533             // my vars (def)
534
535         // ctor
536         public Xcls_dbmodel(NewBranch _owner )
537         {
538             _this = _owner;
539             _this.dbmodel = this;
540             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
541
542             // my vars (dec)
543
544             // set gobject values
545         }
546
547         // user defined functions
548         public void loadTickets (string project_id , string tid = "") {
549         
550         
551             
552             // fixme .. get project id from selection..
553             
554              RooTicket.singleton().loadTickets(
555                                 project_id,
556                                 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY :  RooTicket.Who.ME,
557                                  _this.btn_closed.el.active ? RooTicket.Status.ALL :  RooTicket.Status.ACTIVE
558                          );
559                 
560             _this.ticketsel.loading = true;
561         
562             this.el.clear();                                    
563             Gtk.TreeIter iter;
564             var el = this.el;
565             
566             el.append(out iter);
567         
568             
569             el.set_value(iter, 0, "");
570             el.set_value(iter, 1, "-- select a ticket --");
571             
572             _this.ticketsel.el.set_active_iter(iter);
573             var tickets = RooTicket.singleton().tickets;
574             foreach(var ticket in tickets) {
575             
576                 el.append(out iter);
577                 
578                 el.set_value(iter, 0, ticket.id);
579                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
580                 
581                 if (ticket.id == tid) {
582                             _this.ticketsel.el.set_active_iter(iter);
583                 }
584                 
585             }
586             
587             _this.ticketsel.loading = false;
588              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
589                                              
590         }
591     }
592
593
594     public class Xcls_Button12 : Object
595     {
596         public Gtk.Button el;
597         private NewBranch  _this;
598
599
600             // my vars (def)
601
602         // ctor
603         public Xcls_Button12(NewBranch _owner )
604         {
605             _this = _owner;
606             this.el = new Gtk.Button();
607
608             // my vars (dec)
609
610             // set gobject values
611             this.el.expand = false;
612             this.el.label = "New Ticket";
613
614             //listeners
615             this.el.clicked.connect( () => {
616                 _this.el.response(-1);
617                 Ticket.singleton().show(_this.repo);
618             
619             });
620         }
621
622         // user defined functions
623     }
624
625     public class Xcls_Label13 : Object
626     {
627         public Gtk.Label el;
628         private NewBranch  _this;
629
630
631             // my vars (def)
632
633         // ctor
634         public Xcls_Label13(NewBranch _owner )
635         {
636             _this = _owner;
637             this.el = new Gtk.Label( "Use this as branch name" );
638
639             // my vars (dec)
640
641             // set gobject values
642             this.el.halign = Gtk.Align.START;
643             this.el.justify = Gtk.Justification.RIGHT;
644             this.el.xalign = 0.900000f;
645         }
646
647         // user defined functions
648     }
649
650     public class Xcls_name : Object
651     {
652         public Gtk.Entry el;
653         private NewBranch  _this;
654
655
656             // my vars (def)
657
658         // ctor
659         public Xcls_name(NewBranch _owner )
660         {
661             _this = _owner;
662             _this.name = this;
663             this.el = new Gtk.Entry();
664
665             // my vars (dec)
666
667             // set gobject values
668             this.el.visible = true;
669         }
670
671         // user defined functions
672     }
673
674     public class Xcls_Button15 : Object
675     {
676         public Gtk.Button el;
677         private NewBranch  _this;
678
679
680             // my vars (def)
681
682         // ctor
683         public Xcls_Button15(NewBranch _owner )
684         {
685             _this = _owner;
686             this.el = new Gtk.Button();
687
688             // my vars (dec)
689
690             // set gobject values
691             this.el.label = "Create Branch";
692
693             // init method
694
695             {
696                this.el.get_style_context().add_class("suggested-action");
697             }
698
699             //listeners
700             this.el.clicked.connect( () => {
701                 GLib.debug("fire response = 1");
702                 _this.el.response(1);
703             });
704         }
705
706         // user defined functions
707     }
708
709     public class Xcls_Box16 : Object
710     {
711         public Gtk.Box el;
712         private NewBranch  _this;
713
714
715             // my vars (def)
716
717         // ctor
718         public Xcls_Box16(NewBranch _owner )
719         {
720             _this = _owner;
721             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
722
723             // my vars (dec)
724
725             // set gobject values
726             var child_0 = new Xcls_btn_not_me( _this );
727             child_0.ref();
728             this.el.add (  child_0.el  );
729             var child_1 = new Xcls_btn_closed( _this );
730             child_1.ref();
731             this.el.add (  child_1.el  );
732             var child_2 = new Xcls_Label19( _this );
733             child_2.ref();
734             this.el.add (  child_2.el  );
735         }
736
737         // user defined functions
738     }
739     public class Xcls_btn_not_me : Object
740     {
741         public Gtk.CheckButton el;
742         private NewBranch  _this;
743
744
745             // my vars (def)
746
747         // ctor
748         public Xcls_btn_not_me(NewBranch _owner )
749         {
750             _this = _owner;
751             _this.btn_not_me = this;
752             this.el = new Gtk.CheckButton();
753
754             // my vars (dec)
755
756             // set gobject values
757             this.el.label = "Show tickets not assigned to me";
758
759             //listeners
760             this.el.toggled.connect( () => {
761                 var project_id = _this.projectsel.selectedProjectId();
762                 _this.dbmodel.loadTickets(project_id);  
763             });
764         }
765
766         // user defined functions
767     }
768
769     public class Xcls_btn_closed : Object
770     {
771         public Gtk.CheckButton el;
772         private NewBranch  _this;
773
774
775             // my vars (def)
776
777         // ctor
778         public Xcls_btn_closed(NewBranch _owner )
779         {
780             _this = _owner;
781             _this.btn_closed = this;
782             this.el = new Gtk.CheckButton();
783
784             // my vars (dec)
785
786             // set gobject values
787             this.el.label = "Show closed Tickets";
788
789             //listeners
790             this.el.toggled.connect( () => {
791                 var project_id = _this.projectsel.selectedProjectId();
792                 _this.dbmodel.loadTickets(project_id);  
793                  
794             });
795         }
796
797         // user defined functions
798     }
799
800     public class Xcls_Label19 : Object
801     {
802         public Gtk.Label el;
803         private NewBranch  _this;
804
805
806             // my vars (def)
807
808         // ctor
809         public Xcls_Label19(NewBranch _owner )
810         {
811             _this = _owner;
812             this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
813
814             // my vars (dec)
815
816             // set gobject values
817             this.el.halign = Gtk.Align.END;
818             this.el.hexpand = true;
819             this.el.use_markup = true;
820
821             //listeners
822             this.el.activate_link.connect( (uri) => {
823                 if (uri == "refresh") {
824                         var curproj = RooTicket.singleton().getProjectByRepo(_this.repo);
825                          _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
826             
827                         _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);            
828                 }
829                 return true;
830             });
831         }
832
833         // user defined functions
834     }
835
836
837
838     public class Xcls_scrolled_window : Object
839     {
840         public Gtk.ScrolledWindow el;
841         private NewBranch  _this;
842
843
844             // my vars (def)
845
846         // ctor
847         public Xcls_scrolled_window(NewBranch _owner )
848         {
849             _this = _owner;
850             _this.scrolled_window = this;
851             this.el = new Gtk.ScrolledWindow( null, null );
852
853             // my vars (dec)
854
855             // set gobject values
856             var child_0 = new Xcls_WebView21( _this );
857             child_0.ref();
858             this.el.add (  child_0.el  );
859
860             // init method
861
862             {
863                 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
864             }
865         }
866
867         // user defined functions
868     }
869     public class Xcls_WebView21 : Object
870     {
871         public WebKit.WebView el;
872         private NewBranch  _this;
873
874
875             // my vars (def)
876
877         // ctor
878         public Xcls_WebView21(NewBranch _owner )
879         {
880             _this = _owner;
881             this.el = new WebKit.WebView();
882
883             // my vars (dec)
884         }
885
886         // user defined functions
887     }
888
889
890
891 }