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