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