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