cda845387c10e520c4183508be49d7df3059056a
[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_scrolled_window( _this );
185             child_2.ref();
186             this.el.add (  child_2.el  );
187             var child_3 = new Xcls_spinner( _this );
188             child_3.ref();
189             this.el.add (  child_3.el  );
190         }
191
192         // user defined functions
193     }
194     public class Xcls_table : Object
195     {
196         public Gtk.Table el;
197         private MergeBranch  _this;
198
199
200             // my vars (def)
201
202         // ctor
203         public Xcls_table(MergeBranch _owner )
204         {
205             _this = _owner;
206             _this.table = this;
207             this.el = new Gtk.Table( 2, 2, false );
208
209             // my vars (dec)
210
211             // set gobject values
212             this.el.margin = 2;
213             this.el.column_spacing = 2;
214             this.el.vexpand = false;
215             var child_0 = new Xcls_Label4( _this );
216             child_0.ref();
217             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
218             var child_1 = new Xcls_actionsel( _this );
219             child_1.ref();
220             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
221             var child_2 = new Xcls_Label8( _this );
222             child_2.ref();
223             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
224             var child_3 = new Xcls_ticketsel( _this );
225             child_3.ref();
226             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
227             var child_4 = new Xcls_Label12( _this );
228             child_4.ref();
229             this.el.attach_defaults (  child_4.el , 0,1,2,3 );
230             var child_5 = new Xcls_name( _this );
231             child_5.ref();
232             this.el.attach_defaults (  child_5.el , 1,2,2,3 );
233         }
234
235         // user defined functions
236     }
237     public class Xcls_Label4 : Object
238     {
239         public Gtk.Label el;
240         private MergeBranch  _this;
241
242
243             // my vars (def)
244
245         // ctor
246         public Xcls_Label4(MergeBranch _owner )
247         {
248             _this = _owner;
249             this.el = new Gtk.Label( "Do what?" );
250
251             // my vars (dec)
252
253             // set gobject values
254             this.el.justify = Gtk.Justification.RIGHT;
255             this.el.xalign = 0.900000f;
256             this.el.visible = true;
257         }
258
259         // user defined functions
260     }
261
262     public class Xcls_actionsel : Object
263     {
264         public Gtk.ComboBox el;
265         private MergeBranch  _this;
266
267
268             // my vars (def)
269         public bool loading;
270
271         // ctor
272         public Xcls_actionsel(MergeBranch _owner )
273         {
274             _this = _owner;
275             _this.actionsel = this;
276             this.el = new Gtk.ComboBox();
277
278             // my vars (dec)
279             this.loading = false;
280
281             // set gobject values
282             var child_0 = new Xcls_actioncellrenderer( _this );
283             child_0.ref();
284             this.el.pack_start (  child_0.el , true );
285             var child_1 = new Xcls_actionmodel( _this );
286             child_1.ref();
287             this.el.set_model (  child_1.el  );
288
289             // init method
290
291             this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
292
293             //listeners
294             this.el.changed.connect( () => {
295                 if (this.loading) {
296                         return;
297                 }
298                 _this.name.updateText();
299                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
300             });
301         }
302
303         // user defined functions
304         public string selectedAction () {
305                 Gtk.TreeIter iter;
306                 Value val1;
307          
308                 this.el.get_active_iter (out iter);
309                 _this.actionmodel.el.get_value (iter, 0, out val1);
310         
311                 return  (string) val1;
312         }
313     }
314     public class Xcls_actioncellrenderer : Object
315     {
316         public Gtk.CellRendererText el;
317         private MergeBranch  _this;
318
319
320             // my vars (def)
321
322         // ctor
323         public Xcls_actioncellrenderer(MergeBranch _owner )
324         {
325             _this = _owner;
326             _this.actioncellrenderer = this;
327             this.el = new Gtk.CellRendererText();
328
329             // my vars (dec)
330
331             // set gobject values
332         }
333
334         // user defined functions
335     }
336
337     public class Xcls_actionmodel : Object
338     {
339         public Gtk.ListStore el;
340         private MergeBranch  _this;
341
342
343             // my vars (def)
344
345         // ctor
346         public Xcls_actionmodel(MergeBranch _owner )
347         {
348             _this = _owner;
349             _this.actionmodel = this;
350             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
351
352             // my vars (dec)
353
354             // set gobject values
355         }
356
357         // user defined functions
358         public void loadActions () {
359         
360          
361             
362             _this.actionsel.loading = true;
363         
364             this.el.clear();                                    
365             Gtk.TreeIter iter;
366             var el = this.el;
367             
368             el.append(out iter);
369         
370             
371             el.set_value(iter, 0, "");
372             el.set_value(iter, 1, "-- select action  --");
373             
374             _this.actionsel.el.set_active_iter(iter);
375         
376             el.append(out iter);    
377             el.set_value(iter, 0, "CLOSE");
378             el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
379                 
380                 
381             el.append(out iter);    
382             el.set_value(iter, 0, "LEAVE");
383             el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
384         
385             el.append(out iter);    
386             el.set_value(iter, 0, "MASTER");
387             el.set_value(iter, 1, "Merge changes FROM master into this branch");    
388             
389             el.append(out iter);    
390             el.set_value(iter, 0, "EXIT");
391             el.set_value(iter, 1, "Switch back to MASTER branch - no merge");    
392             
393             
394             
395             _this.actionsel.loading = false;
396              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
397                                              
398         }
399     }
400
401
402     public class Xcls_Label8 : Object
403     {
404         public Gtk.Label el;
405         private MergeBranch  _this;
406
407
408             // my vars (def)
409
410         // ctor
411         public Xcls_Label8(MergeBranch _owner )
412         {
413             _this = _owner;
414             this.el = new Gtk.Label( "Select Ticket" );
415
416             // my vars (dec)
417
418             // set gobject values
419             this.el.justify = Gtk.Justification.RIGHT;
420             this.el.xalign = 0.900000f;
421             this.el.visible = true;
422         }
423
424         // user defined functions
425     }
426
427     public class Xcls_ticketsel : Object
428     {
429         public Gtk.ComboBox el;
430         private MergeBranch  _this;
431
432
433             // my vars (def)
434         public bool loading;
435
436         // ctor
437         public Xcls_ticketsel(MergeBranch _owner )
438         {
439             _this = _owner;
440             _this.ticketsel = this;
441             this.el = new Gtk.ComboBox();
442
443             // my vars (dec)
444             this.loading = true;
445
446             // set gobject values
447             var child_0 = new Xcls_dbcellrenderer( _this );
448             child_0.ref();
449             this.el.pack_start (  child_0.el , true );
450             var child_1 = new Xcls_dbmodel( _this );
451             child_1.ref();
452             this.el.set_model (  child_1.el  );
453
454             // init method
455
456             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
457
458             //listeners
459             this.el.changed.connect( () => {
460                 if (this.loading) {
461                         return;
462                 }
463                 _this.view.loadTicket(this.selectedTicketId());
464                  
465                 _this.name.updateText();
466                 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
467                 
468                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
469             });
470         }
471
472         // user defined functions
473         public string selectedTicketId () {
474         Gtk.TreeIter iter;
475                 Value val1;
476          
477          
478                 this.el.get_active_iter (out iter);
479                 _this.dbmodel.el.get_value (iter, 0, out val1);
480          
481         
482                 return  (string) val1;
483                 
484                 
485                 
486                 
487         }
488     }
489     public class Xcls_dbcellrenderer : Object
490     {
491         public Gtk.CellRendererText el;
492         private MergeBranch  _this;
493
494
495             // my vars (def)
496
497         // ctor
498         public Xcls_dbcellrenderer(MergeBranch _owner )
499         {
500             _this = _owner;
501             _this.dbcellrenderer = this;
502             this.el = new Gtk.CellRendererText();
503
504             // my vars (dec)
505
506             // set gobject values
507         }
508
509         // user defined functions
510     }
511
512     public class Xcls_dbmodel : Object
513     {
514         public Gtk. el;
515         private MergeBranch  _this;
516
517
518             // my vars (def)
519
520         // ctor
521         public Xcls_dbmodel(MergeBranch _owner )
522         {
523             _this = _owner;
524             _this.dbmodel = this;
525             this.el = new Gtk.();
526
527             // my vars (dec)
528         }
529
530         // user defined functions
531         public void loadTickets () {
532         
533             RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
534             
535             _this.ticketsel.loading = true;
536         
537             this.el.clear();                                    
538             Gtk.TreeIter iter;
539             var el = this.el;
540             
541             el.append(out iter);
542             el.set_value(iter, 0, "");
543             el.set_value(iter, 1, "-- select a ticket --");
544             
545             _this.ticketsel.el.set_active_iter(iter);
546             
547             if (_this.ticket != null &&  _this.ticket.id == "-1") {
548                         el.append(out iter);
549                         el.set_value(iter, 0, "-1");
550                         el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
551                 _this.ticketsel.el.set_active_iter(iter);       
552             }
553             
554             
555             
556             
557             var tickets = RooTicket.singleton().tickets;
558             foreach(var ticket in tickets) {
559             
560                 el.append(out iter);
561         
562                 el.set_value(iter, 0, ticket.id);
563                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
564                         if (_this.ticket != null && _this.ticket.id == ticket.id) {
565                             _this.ticketsel.el.set_active_iter(iter);
566                     }
567                 
568             }
569             
570             _this.ticketsel.loading = false;
571              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
572                                              
573         }
574     }
575
576
577     public class Xcls_Label12 : Object
578     {
579         public Gtk.Label el;
580         private MergeBranch  _this;
581
582
583             // my vars (def)
584
585         // ctor
586         public Xcls_Label12(MergeBranch _owner )
587         {
588             _this = _owner;
589             this.el = new Gtk.Label( "Use this commit message" );
590
591             // my vars (dec)
592
593             // set gobject values
594             this.el.justify = Gtk.Justification.RIGHT;
595             this.el.xalign = 0.900000f;
596         }
597
598         // user defined functions
599     }
600
601     public class Xcls_name : Object
602     {
603         public Gtk.Entry el;
604         private MergeBranch  _this;
605
606
607             // my vars (def)
608
609         // ctor
610         public Xcls_name(MergeBranch _owner )
611         {
612             _this = _owner;
613             _this.name = this;
614             this.el = new Gtk.Entry();
615
616             // my vars (dec)
617
618             // set gobject values
619             this.el.visible = true;
620         }
621
622         // user defined functions
623         public void updateText () {
624                 var ticket_id = _this.ticketsel.selectedTicketId();
625                 
626                 RooTicket ticket = null;
627                 if (ticket_id.length > 0){
628                         ticket = RooTicket.singleton().getById(ticket_id);
629                 }
630                 
631                 var name = RooTicket.singleton().usernameLocal();
632                 var action = _this.actionsel.selectedAction();
633                 this.el.set_editable(true); 
634                 switch (action) {
635                         case "CLOSE": // merge changes and close..
636                                 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
637                                 break;
638                         case "LEAVE": // partial fix    
639                                 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id,   ticket != null ? ticket.summary : ""));
640                                 break;
641                         case "MASTER": // merge master
642                         case "EXIT": // just switch back...             
643                                 this.el.set_editable(false);
644                                 this.el.set_text(""); // not relivant..                         
645                                 break;
646                         default:
647                         
648                                 break; /// don't fix the text value.
649                 }
650            
651         }
652     }
653
654
655     public class Xcls_Notebook14 : Object
656     {
657         public Gtk.Notebook el;
658         private MergeBranch  _this;
659
660
661             // my vars (def)
662
663         // ctor
664         public Xcls_Notebook14(MergeBranch _owner )
665         {
666             _this = _owner;
667             this.el = new Gtk.Notebook();
668
669             // my vars (dec)
670
671             // set gobject values
672             this.el.vexpand = true;
673             var child_0 = new Xcls_label_diff( _this );
674             child_0.ref();
675             var child_1 = new Xcls_label_ticket( _this );
676             child_1.ref();
677             var child_2 = new Xcls_Box17( _this );
678             child_2.ref();
679             this.el.append_page (  child_2.el , _this.label_diff.el );
680             var child_3 = new Xcls_Box18( _this );
681             child_3.ref();
682             this.el.append_page (  child_3.el , _this.label_status.el );
683         }
684
685         // user defined functions
686     }
687     public class Xcls_label_diff : Object
688     {
689         public Gtk.Label el;
690         private MergeBranch  _this;
691
692
693             // my vars (def)
694
695         // ctor
696         public Xcls_label_diff(MergeBranch _owner )
697         {
698             _this = _owner;
699             _this.label_diff = this;
700             this.el = new Gtk.Label( "Projected Commit Diff" );
701
702             // my vars (dec)
703
704             // set gobject values
705         }
706
707         // user defined functions
708     }
709
710     public class Xcls_label_ticket : Object
711     {
712         public Gtk.Label el;
713         private MergeBranch  _this;
714
715
716             // my vars (def)
717
718         // ctor
719         public Xcls_label_ticket(MergeBranch _owner )
720         {
721             _this = _owner;
722             _this.label_ticket = this;
723             this.el = new Gtk.Label( "Ticket Details" );
724
725             // my vars (dec)
726
727             // set gobject values
728         }
729
730         // user defined functions
731     }
732
733     public class Xcls_Box17 : Object
734     {
735         public Gtk.Box el;
736         private MergeBranch  _this;
737
738
739             // my vars (def)
740
741         // ctor
742         public Xcls_Box17(MergeBranch _owner )
743         {
744             _this = _owner;
745             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
746
747             // my vars (dec)
748
749             // set gobject values
750             this.el.homogeneous = false;
751         }
752
753         // user defined functions
754     }
755
756     public class Xcls_Box18 : Object
757     {
758         public Gtk.Box el;
759         private MergeBranch  _this;
760
761
762             // my vars (def)
763
764         // ctor
765         public Xcls_Box18(MergeBranch _owner )
766         {
767             _this = _owner;
768             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
769
770             // my vars (dec)
771
772             // set gobject values
773             this.el.homogeneous = false;
774         }
775
776         // user defined functions
777     }
778
779
780     public class Xcls_scrolled_window : Object
781     {
782         public Gtk.ScrolledWindow el;
783         private MergeBranch  _this;
784
785
786             // my vars (def)
787
788         // ctor
789         public Xcls_scrolled_window(MergeBranch _owner )
790         {
791             _this = _owner;
792             _this.scrolled_window = this;
793             this.el = new Gtk.ScrolledWindow( null, null );
794
795             // my vars (dec)
796
797             // set gobject values
798             this.el.height_request = 500;
799             this.el.vexpand = true;
800             var child_0 = new Xcls_view( _this );
801             child_0.ref();
802             this.el.add (  child_0.el  );
803
804             // init method
805
806             {
807                 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
808             }
809         }
810
811         // user defined functions
812     }
813     public class Xcls_view : Object
814     {
815         public WebKit.WebView el;
816         private MergeBranch  _this;
817
818
819             // my vars (def)
820
821         // ctor
822         public Xcls_view(MergeBranch _owner )
823         {
824             _this = _owner;
825             _this.view = this;
826             this.el = new WebKit.WebView();
827
828             // my vars (dec)
829
830             // set gobject values
831         }
832
833         // user defined functions
834         public void loadTicket (string tid) {
835                 int h,w;
836                 _this.el.get_size(out w, out h);
837                 
838                 if (tid == "") {
839                         _this.scrolled_window.el.hide();
840                         _this.el.resize(w, 150);
841                 } else {
842                         _this.scrolled_window.el.show();
843                         _this.el.resize(w, 800);
844                 }
845                 
846                 var rs =  RooTicket.singleton();                
847                 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
848                 var hd = uri.get_http_headers();
849                 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
850                 hd.append("Authorization", "Basic %s".printf(authCode));
851                 
852                  this.el.load_request(uri);
853         }
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 }