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