1 static MergeBranch _MergeBranch;
3 public class MergeBranch : Object
6 private MergeBranch _this;
8 public static MergeBranch singleton()
10 if (_MergeBranch == null) {
11 _MergeBranch= new MergeBranch();
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_diff_view diff_view;
26 public Xcls_scrolled_window scrolled_window;
27 public Xcls_view view;
28 public Xcls_spinner spinner;
32 public RooTicket? ticket;
39 this.el = new Gtk.Dialog();
46 this.el.title = "Merge Branch";
47 this.el.default_height = 200;
48 this.el.default_width = 500;
49 this.el.deletable = true;
51 var child_0 = new Xcls_Box2( _this );
53 this.el.get_content_area().add ( child_0.el );
54 var child_1 = new Xcls_Button24( _this );
56 this.el.add_action_widget ( child_1.el , 0 );
57 var child_2 = new Xcls_Button25( _this );
59 this.el.add_action_widget ( child_2.el , 1 );
62 this.el.delete_event.connect( (self, event) => {
67 this.el.response.connect( (self, response_id) => {
69 GLib.debug("got %d", (int) response_id);
70 if (response_id < 1) {
73 GitMonitor.gitmonitor.start();
77 // have they selected a ticket..
78 // make that the current active ticket?
79 // we really need to store locally what ticket is being worked on..
80 // in theory we could be working on multiple project and not merging..
81 // -- each repo would have their active ticket (only one per repo)
82 // -- so we could just store that in there
83 // -- initial load can check the contents of the ticket files on first scan.
84 var ticket_id = _this.ticketsel.selectedTicketId();
86 if (this.repo != null) {
87 var bn = _this.name.el.get_text();
88 if (ticket_id != "" ) {
89 this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
91 this.repo.createBranchNamed(bn);
96 if (this.repo != null) {
98 _this.actionsel.selectedAction(),
99 _this.ticketsel.selectedTicketId(),
100 _this.name.el.get_text()
105 _this.actionsel.selectedAction(),
106 _this.ticketsel.selectedTicketId(),
107 _this.name.el.get_text()
110 this.running = false;
114 GitMonitor.gitmonitor.start();
120 // user defined functions
121 public void show ( RooTicket ticket, GitRepo? repo )
123 // this.el.set_gravity(Gdk.Gravity.NORTH);
127 GitMonitor.gitmonitor.stop();
131 _this.table.el.hide();
132 _this.scrolled_window.el.hide();
133 _this.spinner.el.show();
134 _this.spinner.el.start();
135 this.el.set_keep_above(true);
136 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
137 GLib.debug("Loading tickets");
142 this.ticket = ticket;
146 Timeout.add_seconds(1, () => {
147 _this.diff_view.el.get_buffer().set_text(repo.previewMerge());
148 // if we are not working on a ticket, then we should be able to pick one?
149 _this.dbmodel.loadTickets();
150 _this.actionmodel.loadActions();
151 _this.view.loadTicket(ticket.id);
152 _this.spinner.el.stop();
153 _this.spinner.el.hide();
155 this.table.el.show();
162 public class Xcls_Box2 : Object
165 private MergeBranch _this;
171 public Xcls_Box2(MergeBranch _owner )
174 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
178 // set gobject values
179 var child_0 = new Xcls_table( _this );
181 this.el.pack_start ( child_0.el , false,false,0 );
182 var child_1 = new Xcls_Notebook14( _this );
184 this.el.add ( child_1.el );
185 var child_2 = new Xcls_spinner( _this );
187 this.el.add ( child_2.el );
190 // user defined functions
192 public class Xcls_table : Object
195 private MergeBranch _this;
201 public Xcls_table(MergeBranch _owner )
205 this.el = new Gtk.Table( 2, 2, false );
209 // set gobject values
211 this.el.column_spacing = 2;
212 this.el.vexpand = false;
213 var child_0 = new Xcls_Label4( _this );
215 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
216 var child_1 = new Xcls_actionsel( _this );
218 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
219 var child_2 = new Xcls_Label8( _this );
221 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
222 var child_3 = new Xcls_ticketsel( _this );
224 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
225 var child_4 = new Xcls_Label12( _this );
227 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
228 var child_5 = new Xcls_name( _this );
230 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
233 // user defined functions
235 public class Xcls_Label4 : Object
238 private MergeBranch _this;
244 public Xcls_Label4(MergeBranch _owner )
247 this.el = new Gtk.Label( "Do what?" );
251 // set gobject values
252 this.el.justify = Gtk.Justification.RIGHT;
253 this.el.xalign = 0.900000f;
254 this.el.visible = true;
257 // user defined functions
260 public class Xcls_actionsel : Object
262 public Gtk.ComboBox el;
263 private MergeBranch _this;
270 public Xcls_actionsel(MergeBranch _owner )
273 _this.actionsel = this;
274 this.el = new Gtk.ComboBox();
277 this.loading = false;
279 // set gobject values
280 var child_0 = new Xcls_actioncellrenderer( _this );
282 this.el.pack_start ( child_0.el , true );
283 var child_1 = new Xcls_actionmodel( _this );
285 this.el.set_model ( child_1.el );
289 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
292 this.el.changed.connect( () => {
296 _this.name.updateText();
297 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
301 // user defined functions
302 public string selectedAction () {
306 this.el.get_active_iter (out iter);
307 _this.actionmodel.el.get_value (iter, 0, out val1);
309 return (string) val1;
312 public class Xcls_actioncellrenderer : Object
314 public Gtk.CellRendererText el;
315 private MergeBranch _this;
321 public Xcls_actioncellrenderer(MergeBranch _owner )
324 _this.actioncellrenderer = this;
325 this.el = new Gtk.CellRendererText();
329 // set gobject values
332 // user defined functions
335 public class Xcls_actionmodel : Object
337 public Gtk.ListStore el;
338 private MergeBranch _this;
344 public Xcls_actionmodel(MergeBranch _owner )
347 _this.actionmodel = this;
348 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
352 // set gobject values
355 // user defined functions
356 public void loadActions () {
360 _this.actionsel.loading = true;
369 el.set_value(iter, 0, "");
370 el.set_value(iter, 1, "-- select action --");
372 _this.actionsel.el.set_active_iter(iter);
375 el.set_value(iter, 0, "CLOSE");
376 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
380 el.set_value(iter, 0, "LEAVE");
381 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
384 el.set_value(iter, 0, "MASTER");
385 el.set_value(iter, 1, "Merge changes FROM master into this branch");
388 el.set_value(iter, 0, "EXIT");
389 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
393 _this.actionsel.loading = false;
394 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
400 public class Xcls_Label8 : Object
403 private MergeBranch _this;
409 public Xcls_Label8(MergeBranch _owner )
412 this.el = new Gtk.Label( "Select Ticket" );
416 // set gobject values
417 this.el.justify = Gtk.Justification.RIGHT;
418 this.el.xalign = 0.900000f;
419 this.el.visible = true;
422 // user defined functions
425 public class Xcls_ticketsel : Object
427 public Gtk.ComboBox el;
428 private MergeBranch _this;
435 public Xcls_ticketsel(MergeBranch _owner )
438 _this.ticketsel = this;
439 this.el = new Gtk.ComboBox();
444 // set gobject values
445 var child_0 = new Xcls_dbcellrenderer( _this );
447 this.el.pack_start ( child_0.el , true );
448 var child_1 = new Xcls_dbmodel( _this );
450 this.el.set_model ( child_1.el );
454 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
457 this.el.changed.connect( () => {
461 _this.view.loadTicket(this.selectedTicketId());
463 _this.name.updateText();
464 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
466 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
470 // user defined functions
471 public string selectedTicketId () {
476 this.el.get_active_iter (out iter);
477 _this.dbmodel.el.get_value (iter, 0, out val1);
480 return (string) val1;
487 public class Xcls_dbcellrenderer : Object
489 public Gtk.CellRendererText el;
490 private MergeBranch _this;
496 public Xcls_dbcellrenderer(MergeBranch _owner )
499 _this.dbcellrenderer = this;
500 this.el = new Gtk.CellRendererText();
504 // set gobject values
507 // user defined functions
510 public class Xcls_dbmodel : Object
513 private MergeBranch _this;
519 public Xcls_dbmodel(MergeBranch _owner )
522 _this.dbmodel = this;
523 this.el = new Gtk.();
528 // user defined functions
529 public void loadTickets () {
531 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
533 _this.ticketsel.loading = true;
540 el.set_value(iter, 0, "");
541 el.set_value(iter, 1, "-- select a ticket --");
543 _this.ticketsel.el.set_active_iter(iter);
545 if (_this.ticket != null && _this.ticket.id == "-1") {
547 el.set_value(iter, 0, "-1");
548 el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
549 _this.ticketsel.el.set_active_iter(iter);
555 var tickets = RooTicket.singleton().tickets;
556 foreach(var ticket in tickets) {
560 el.set_value(iter, 0, ticket.id);
561 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
562 if (_this.ticket != null && _this.ticket.id == ticket.id) {
563 _this.ticketsel.el.set_active_iter(iter);
568 _this.ticketsel.loading = false;
569 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
575 public class Xcls_Label12 : Object
578 private MergeBranch _this;
584 public Xcls_Label12(MergeBranch _owner )
587 this.el = new Gtk.Label( "Use this commit message" );
591 // set gobject values
592 this.el.justify = Gtk.Justification.RIGHT;
593 this.el.xalign = 0.900000f;
596 // user defined functions
599 public class Xcls_name : Object
602 private MergeBranch _this;
608 public Xcls_name(MergeBranch _owner )
612 this.el = new Gtk.Entry();
616 // set gobject values
617 this.el.visible = true;
620 // user defined functions
621 public void updateText () {
622 var ticket_id = _this.ticketsel.selectedTicketId();
624 RooTicket ticket = null;
625 if (ticket_id.length > 0){
626 ticket = RooTicket.singleton().getById(ticket_id);
629 var name = RooTicket.singleton().usernameLocal();
630 var action = _this.actionsel.selectedAction();
631 this.el.set_editable(true);
633 case "CLOSE": // merge changes and close..
634 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
636 case "LEAVE": // partial fix
637 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
639 case "MASTER": // merge master
640 case "EXIT": // just switch back...
641 this.el.set_editable(false);
642 this.el.set_text(""); // not relivant..
646 break; /// don't fix the text value.
653 public class Xcls_Notebook14 : Object
655 public Gtk.Notebook el;
656 private MergeBranch _this;
662 public Xcls_Notebook14(MergeBranch _owner )
665 this.el = new Gtk.Notebook();
669 // set gobject values
670 this.el.vexpand = true;
671 var child_0 = new Xcls_label_diff( _this );
673 var child_1 = new Xcls_label_ticket( _this );
675 var child_2 = new Xcls_Box17( _this );
677 this.el.append_page ( child_2.el , _this.label_diff.el );
678 var child_3 = new Xcls_Box20( _this );
680 this.el.append_page ( child_3.el , _this.label_ticket.el );
683 // user defined functions
685 public class Xcls_label_diff : Object
688 private MergeBranch _this;
694 public Xcls_label_diff(MergeBranch _owner )
697 _this.label_diff = this;
698 this.el = new Gtk.Label( "Projected Commit Diff" );
702 // set gobject values
705 // user defined functions
708 public class Xcls_label_ticket : Object
711 private MergeBranch _this;
717 public Xcls_label_ticket(MergeBranch _owner )
720 _this.label_ticket = this;
721 this.el = new Gtk.Label( "Ticket Details" );
725 // set gobject values
728 // user defined functions
731 public class Xcls_Box17 : Object
734 private MergeBranch _this;
740 public Xcls_Box17(MergeBranch _owner )
743 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
747 // set gobject values
748 this.el.homogeneous = false;
749 var child_0 = new Xcls_ScrolledWindow18( _this );
751 this.el.pack_start ( child_0.el , true,true,0 );
754 // user defined functions
756 public class Xcls_ScrolledWindow18 : Object
758 public Gtk.ScrolledWindow el;
759 private MergeBranch _this;
765 public Xcls_ScrolledWindow18(MergeBranch _owner )
768 this.el = new Gtk.ScrolledWindow( null, null );
772 // set gobject values
773 this.el.height_request = 400;
774 var child_0 = new Xcls_diff_view( _this );
776 this.el.add ( child_0.el );
779 // user defined functions
781 public class Xcls_diff_view : Object
783 public Gtk.SourceView el;
784 private MergeBranch _this;
790 public Xcls_diff_view(MergeBranch _owner )
793 _this.diff_view = this;
794 this.el = new Gtk.SourceView();
800 var description = Pango.FontDescription.from_string("monospace");
801 description.set_size(9000);
802 this.el.override_font(description);
805 // user defined functions
810 public class Xcls_Box20 : Object
813 private MergeBranch _this;
819 public Xcls_Box20(MergeBranch _owner )
822 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
826 // set gobject values
827 this.el.homogeneous = false;
828 var child_0 = new Xcls_scrolled_window( _this );
830 this.el.add ( child_0.el );
833 // user defined functions
835 public class Xcls_scrolled_window : Object
837 public Gtk.ScrolledWindow el;
838 private MergeBranch _this;
844 public Xcls_scrolled_window(MergeBranch _owner )
847 _this.scrolled_window = this;
848 this.el = new Gtk.ScrolledWindow( null, null );
852 // set gobject values
853 this.el.height_request = 500;
854 this.el.vexpand = true;
855 var child_0 = new Xcls_view( _this );
857 this.el.add ( child_0.el );
862 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
866 // user defined functions
868 public class Xcls_view : Object
870 public WebKit.WebView el;
871 private MergeBranch _this;
877 public Xcls_view(MergeBranch _owner )
881 this.el = new WebKit.WebView();
885 // set gobject values
888 // user defined functions
889 public void loadTicket (string tid) {
891 _this.el.get_size(out w, out h);
894 _this.scrolled_window.el.hide();
895 _this.el.resize(w, 150);
897 _this.scrolled_window.el.show();
898 _this.el.resize(w, 800);
901 var rs = RooTicket.singleton();
902 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
903 var hd = uri.get_http_headers();
904 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
905 hd.append("Authorization", "Basic %s".printf(authCode));
907 this.el.load_request(uri);
914 public class Xcls_spinner : Object
916 public Gtk.Spinner el;
917 private MergeBranch _this;
923 public Xcls_spinner(MergeBranch _owner )
926 _this.spinner = this;
927 this.el = new Gtk.Spinner();
931 // set gobject values
932 this.el.hexpand = true;
933 this.el.vexpand = true;
936 // user defined functions
940 public class Xcls_Button24 : Object
942 public Gtk.Button el;
943 private MergeBranch _this;
949 public Xcls_Button24(MergeBranch _owner )
952 this.el = new Gtk.Button();
956 // set gobject values
957 this.el.relief = Gtk.ReliefStyle.NONE;
958 this.el.label = "Cancel";
961 // user defined functions
964 public class Xcls_Button25 : Object
966 public Gtk.Button el;
967 private MergeBranch _this;
973 public Xcls_Button25(MergeBranch _owner )
976 this.el = new Gtk.Button();
980 // set gobject values
981 this.el.label = "Do Merge";
986 this.el.get_style_context().add_class("suggested-action");
990 // user defined functions