Uncommited changes synced
[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
25         // my vars (def)
26     public GitRepo? repo;
27     public bool running;
28     public Gee.ArrayList<GitMonitorQueue> queue;
29
30     // ctor
31     public NewBranch()
32     {
33         _this = this;
34         this.el = new Gtk.Dialog();
35
36         // my vars (dec)
37         this.repo = null;
38         this.running = false;
39         this.queue = null;
40
41         // set gobject values
42         this.el.title = "Create a working branch ";
43         this.el.default_height = 200;
44         this.el.default_width = 500;
45         this.el.deletable = true;
46         this.el.modal = true;
47         var child_0 = new Xcls_VBox2( _this );
48         child_0.ref();
49         this.el.get_content_area().add (  child_0.el  );
50
51         //listeners
52         this.el.delete_event.connect( (self, event) => {
53             this.el.hide();
54             return true; 
55             //test  
56         });
57         this.el.response.connect( (self, response_id) =>  { 
58           
59                 GLib.debug("got %d", (int) response_id);
60                 if (response_id < 1) {
61                     _this.el.hide();    
62                     this.running = false; 
63                         return;
64                 }
65                  
66                 // have they selected a ticket..
67                 // make that the current active ticket?
68                 // we really need to store locally what ticket is being worked on..
69                 // in theory we could be working on multiple project and not merging..
70                 // -- each repo would have their active ticket (only one per repo)
71                 // -- so we could just store that in there
72                 // -- initial load can check the contents of the ticket files on first scan.
73                 var ticket_id = _this.ticketsel.selectedTicketId();
74                 
75             if (this.repo != null) {
76                 var bn = _this.name.el.get_text();
77         
78                         var res = this.repo.setActiveTicket(                    
79                                  RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
80                          );
81                          if (res) {
82                                 // start the monitoring..
83                                  GitMonitor.gitmonitor.start();
84                                  
85                          }
86             }
87             
88         
89             this.running = false; 
90         
91                 this.el.hide();
92                  
93                  
94         
95                  
96         });
97     }
98
99     // user defined functions
100     public   void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" ) 
101     {
102          // this.el.set_gravity(Gdk.Gravity.NORTH);
103         if (this.running) { // should not happen!!
104                 GLib.error("new branch show called, when already being displayed?");
105         }
106         this.queue = queue;
107         
108         this.running  = true;
109         GitMonitor.gitmonitor.stop();
110         
111         this.repo = repo;
112         
113          
114         
115         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
116         this.el.set_default_size( 500,200); // not sure why it grows..
117         GLib.debug("Loading tickets"); 
118          
119     
120         this.el.show_all();
121         this.el.set_keep_above(true);
122        
123         
124         var curproj = RooTicket.singleton().getProjectByRepo(this.repo);
125          _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
126         
127         _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
128         if (tid != "") {
129                 var name = RooTicket.singleton().usernameLocal();
130                 var ticket = RooTicket.singleton().getById(tid);
131                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
132         }
133     
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 project_id = this.selectedProjectId();
299                 _this.dbmodel.loadTickets(project_id);
300                 
301                 
302                 /*if (this.loading) {
303                         return;
304                 }
305                 var ticket_id = this.selectedTicketId();
306                 
307                 var name = RooTicket.singleton().usernameLocal();
308                 
309                 if (ticket_id == "" || ticket_id == null) {
310                 
311                         var dt = new  DateTime.now_local();
312                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
313                         return;
314                 }
315                 
316                 
317                 var ticket = RooTicket.singleton().getById(ticket_id);
318                
319                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
320                 
321                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
322                 */
323             });
324         }
325
326         // user defined functions
327         public string selectedProjectId () {
328                 Gtk.TreeIter iter;
329                 Value val1;
330          
331          
332                 this.el.get_active_iter (out iter);
333                 _this.prmodel.el.get_value (iter, 0, out val1);
334          
335         
336                 return  (string) val1;
337                 
338                 
339                 
340                 
341         }
342     }
343     public class Xcls_prcellrenderer : Object
344     {
345         public Gtk.CellRendererText el;
346         private NewBranch  _this;
347
348
349             // my vars (def)
350
351         // ctor
352         public Xcls_prcellrenderer(NewBranch _owner )
353         {
354             _this = _owner;
355             _this.prcellrenderer = this;
356             this.el = new Gtk.CellRendererText();
357
358             // my vars (dec)
359
360             // set gobject values
361         }
362
363         // user defined functions
364     }
365
366     public class Xcls_prmodel : Object
367     {
368         public Gtk.ListStore el;
369         private NewBranch  _this;
370
371
372             // my vars (def)
373
374         // ctor
375         public Xcls_prmodel(NewBranch _owner )
376         {
377             _this = _owner;
378             _this.prmodel = this;
379             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
380
381             // my vars (dec)
382
383             // set gobject values
384         }
385
386         // user defined functions
387         public void loadProjects (string id) {
388         
389             var rt = RooTicket.singleton();
390             rt.loadProjects();
391             
392             _this.projectsel.loading = true;
393         
394             this.el.clear();                                    
395             Gtk.TreeIter iter;
396             var el = this.el;
397             
398             el.append(out iter);
399         
400             
401             el.set_value(iter, 0, "");
402             el.set_value(iter, 1, "-- select a project --");
403             if (id == "") {
404                     _this.projectsel.el.set_active_iter(iter);
405             }
406             var projects = rt.projects;
407             foreach(var project in projects) {
408             
409                 el.append(out iter);
410                 
411                 el.set_value(iter, 0, project.id);
412                 el.set_value(iter, 1,  project.name );
413                 if (id == project.id) {
414                            _this.projectsel.el.set_active_iter(iter);
415                     }   
416                 
417             }
418             
419             _this.projectsel.loading = false;
420              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
421                                              
422         }
423     }
424
425
426     public class Xcls_ticketsel : Object
427     {
428         public Gtk.ComboBox el;
429         private NewBranch  _this;
430
431
432             // my vars (def)
433         public bool loading;
434
435         // ctor
436         public Xcls_ticketsel(NewBranch _owner )
437         {
438             _this = _owner;
439             _this.ticketsel = this;
440             this.el = new Gtk.ComboBox.with_entry();
441
442             // my vars (dec)
443             this.loading = false;
444
445             // set gobject values
446             var child_0 = new Xcls_dbcellrenderer( _this );
447             child_0.ref();
448             this.el.pack_start (  child_0.el , true );
449             var child_1 = new Xcls_dbmodel( _this );
450             child_1.ref();
451             this.el.set_model (  child_1.el  );
452
453             // init method
454
455             //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
456             this.el.set_entry_text_column(1);
457
458             //listeners
459             this.el.changed.connect( () => {
460                 if (this.loading) {
461                         return;
462                 }
463                 var ticket_id = this.selectedTicketId();
464                 
465                 var name = RooTicket.singleton().usernameLocal();
466                 
467                 if (ticket_id == "" || ticket_id == null) {
468                 
469                         var dt = new  DateTime.now_local();
470                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
471                         return;
472                 }
473                 
474                 
475                 var ticket = RooTicket.singleton().getById(ticket_id);
476                
477                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
478                 
479                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
480             });
481         }
482
483         // user defined functions
484         public string selectedTicketId () {
485         Gtk.TreeIter iter;
486                 Value val1;
487          
488          
489                 this.el.get_active_iter (out iter);
490                 _this.dbmodel.el.get_value (iter, 0, out val1);
491          
492         
493                 return  (string) val1;
494                 
495                 
496                 
497                 
498         }
499     }
500     public class Xcls_dbcellrenderer : Object
501     {
502         public Gtk.CellRendererText el;
503         private NewBranch  _this;
504
505
506             // my vars (def)
507
508         // ctor
509         public Xcls_dbcellrenderer(NewBranch _owner )
510         {
511             _this = _owner;
512             _this.dbcellrenderer = this;
513             this.el = new Gtk.CellRendererText();
514
515             // my vars (dec)
516
517             // set gobject values
518         }
519
520         // user defined functions
521     }
522
523     public class Xcls_dbmodel : Object
524     {
525         public Gtk.ListStore el;
526         private NewBranch  _this;
527
528
529             // my vars (def)
530
531         // ctor
532         public Xcls_dbmodel(NewBranch _owner )
533         {
534             _this = _owner;
535             _this.dbmodel = this;
536             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
537
538             // my vars (dec)
539
540             // set gobject values
541         }
542
543         // user defined functions
544         public void loadTickets (string project_id , string tid = "") {
545         
546         
547             
548             // fixme .. get project id from selection..
549             
550              RooTicket.singleton().loadTickets(
551                                 project_id,
552                                 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY :  RooTicket.Who.ME,
553                                  _this.btn_closed.el.active ? RooTicket.Status.ALL :  RooTicket.Status.ACTIVE
554                          );
555                 
556             _this.ticketsel.loading = true;
557         
558             this.el.clear();                                    
559             Gtk.TreeIter iter;
560             var el = this.el;
561             
562             el.append(out iter);
563         
564             
565             el.set_value(iter, 0, "");
566             el.set_value(iter, 1, "-- select a ticket --");
567             
568             _this.ticketsel.el.set_active_iter(iter);
569             var tickets = RooTicket.singleton().tickets;
570             foreach(var ticket in tickets) {
571             
572                 el.append(out iter);
573                 
574                 el.set_value(iter, 0, ticket.id);
575                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
576                 
577                 if (ticket.id == tid) {
578                             _this.ticketsel.el.set_active_iter(iter);
579                 }
580                 
581             }
582             
583             _this.ticketsel.loading = false;
584              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
585                                              
586         }
587     }
588
589
590     public class Xcls_Button12 : Object
591     {
592         public Gtk.Button el;
593         private NewBranch  _this;
594
595
596             // my vars (def)
597
598         // ctor
599         public Xcls_Button12(NewBranch _owner )
600         {
601             _this = _owner;
602             this.el = new Gtk.Button();
603
604             // my vars (dec)
605
606             // set gobject values
607             this.el.expand = false;
608             this.el.label = "New Ticket";
609
610             //listeners
611             this.el.clicked.connect( () => {
612                 _this.el.response(-1);
613                 Ticket.singleton().show(_this.repo);
614             
615             });
616         }
617
618         // user defined functions
619     }
620
621     public class Xcls_Label13 : Object
622     {
623         public Gtk.Label el;
624         private NewBranch  _this;
625
626
627             // my vars (def)
628
629         // ctor
630         public Xcls_Label13(NewBranch _owner )
631         {
632             _this = _owner;
633             this.el = new Gtk.Label( "Use this as branch name" );
634
635             // my vars (dec)
636
637             // set gobject values
638             this.el.halign = Gtk.Align.START;
639             this.el.justify = Gtk.Justification.RIGHT;
640             this.el.xalign = 0.900000f;
641         }
642
643         // user defined functions
644     }
645
646     public class Xcls_name : Object
647     {
648         public Gtk.Entry el;
649         private NewBranch  _this;
650
651
652             // my vars (def)
653
654         // ctor
655         public Xcls_name(NewBranch _owner )
656         {
657             _this = _owner;
658             _this.name = this;
659             this.el = new Gtk.Entry();
660
661             // my vars (dec)
662
663             // set gobject values
664             this.el.visible = true;
665         }
666
667         // user defined functions
668     }
669
670     public class Xcls_Button15 : Object
671     {
672         public Gtk.Button el;
673         private NewBranch  _this;
674
675
676             // my vars (def)
677
678         // ctor
679         public Xcls_Button15(NewBranch _owner )
680         {
681             _this = _owner;
682             this.el = new Gtk.Button();
683
684             // my vars (dec)
685
686             // set gobject values
687             this.el.label = "Create Branch";
688
689             // init method
690
691             {
692                this.el.get_style_context().add_class("suggested-action");
693             }
694
695             //listeners
696             this.el.clicked.connect( () => {
697                 GLib.debug("fire response = 1");
698                 _this.el.response(1);
699             });
700         }
701
702         // user defined functions
703     }
704
705     public class Xcls_Box16 : Object
706     {
707         public Gtk.Box el;
708         private NewBranch  _this;
709
710
711             // my vars (def)
712
713         // ctor
714         public Xcls_Box16(NewBranch _owner )
715         {
716             _this = _owner;
717             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
718
719             // my vars (dec)
720
721             // set gobject values
722             var child_0 = new Xcls_btn_not_me( _this );
723             child_0.ref();
724             this.el.add (  child_0.el  );
725             var child_1 = new Xcls_btn_closed( _this );
726             child_1.ref();
727             this.el.add (  child_1.el  );
728             var child_2 = new Xcls_Label19( _this );
729             child_2.ref();
730             this.el.add (  child_2.el  );
731         }
732
733         // user defined functions
734     }
735     public class Xcls_btn_not_me : Object
736     {
737         public Gtk.CheckButton el;
738         private NewBranch  _this;
739
740
741             // my vars (def)
742
743         // ctor
744         public Xcls_btn_not_me(NewBranch _owner )
745         {
746             _this = _owner;
747             _this.btn_not_me = this;
748             this.el = new Gtk.CheckButton();
749
750             // my vars (dec)
751
752             // set gobject values
753             this.el.label = "Show tickets not assigned to me";
754
755             //listeners
756             this.el.toggled.connect( () => {
757                 var project_id = _this.projectsel.selectedProjectId();
758                 _this.dbmodel.loadTickets(project_id);  
759             });
760         }
761
762         // user defined functions
763     }
764
765     public class Xcls_btn_closed : Object
766     {
767         public Gtk.CheckButton el;
768         private NewBranch  _this;
769
770
771             // my vars (def)
772
773         // ctor
774         public Xcls_btn_closed(NewBranch _owner )
775         {
776             _this = _owner;
777             _this.btn_closed = this;
778             this.el = new Gtk.CheckButton();
779
780             // my vars (dec)
781
782             // set gobject values
783             this.el.label = "Show closed Tickets";
784
785             //listeners
786             this.el.toggled.connect( () => {
787                 var project_id = _this.projectsel.selectedProjectId();
788                 _this.dbmodel.loadTickets(project_id);  
789                  
790             });
791         }
792
793         // user defined functions
794     }
795
796     public class Xcls_Label19 : Object
797     {
798         public Gtk.Label el;
799         private NewBranch  _this;
800
801
802             // my vars (def)
803
804         // ctor
805         public Xcls_Label19(NewBranch _owner )
806         {
807             _this = _owner;
808             this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
809
810             // my vars (dec)
811
812             // set gobject values
813             this.el.halign = Gtk.Align.END;
814             this.el.hexpand = true;
815             this.el.use_markup = true;
816
817             //listeners
818             this.el.activate_link.connect( (uri) => {
819                 if (uri == "refresh") {
820                         var curproj = RooTicket.singleton().getProjectByRepo(_this.repo);
821                          _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
822             
823                         _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);            
824                 }
825                 return true;
826             });
827         }
828
829         // user defined functions
830     }
831
832
833
834
835 }