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_scrolled_window scrolled_window;
26 public Xcls_view view;
27 public Xcls_spinner spinner;
31 public RooTicket? ticket;
38 this.el = new Gtk.Dialog();
45 this.el.title = "Merge Branch";
46 this.el.default_height = 200;
47 this.el.default_width = 500;
48 this.el.deletable = true;
50 var child_0 = new Xcls_Box2( _this );
52 this.el.get_content_area().add ( child_0.el );
53 var child_1 = new Xcls_Button22( _this );
55 this.el.add_action_widget ( child_1.el , 0 );
56 var child_2 = new Xcls_Button23( _this );
58 this.el.add_action_widget ( child_2.el , 1 );
61 this.el.delete_event.connect( (self, event) => {
66 this.el.response.connect( (self, response_id) => {
68 GLib.debug("got %d", (int) response_id);
69 if (response_id < 1) {
72 GitMonitor.gitmonitor.start();
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();
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);
90 this.repo.createBranchNamed(bn);
95 if (this.repo != null) {
97 _this.actionsel.selectedAction(),
98 _this.ticketsel.selectedTicketId(),
99 _this.name.el.get_text()
104 _this.actionsel.selectedAction(),
105 _this.ticketsel.selectedTicketId(),
106 _this.name.el.get_text()
109 this.running = false;
113 GitMonitor.gitmonitor.start();
119 // user defined functions
120 public void show ( RooTicket ticket, GitRepo? repo )
122 // this.el.set_gravity(Gdk.Gravity.NORTH);
126 GitMonitor.gitmonitor.stop();
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");
141 this.ticket = ticket;
145 Timeout.add_seconds(1, () => {
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();
154 this.table.el.show();
161 public class Xcls_Box2 : Object
164 private MergeBranch _this;
170 public Xcls_Box2(MergeBranch _owner )
173 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
177 // set gobject values
178 var child_0 = new Xcls_table( _this );
180 this.el.pack_start ( child_0.el , false,false,0 );
181 var child_1 = new Xcls_Notebook14( _this );
183 this.el.add ( child_1.el );
184 var child_2 = new Xcls_spinner( _this );
186 this.el.add ( child_2.el );
189 // user defined functions
191 public class Xcls_table : Object
194 private MergeBranch _this;
200 public Xcls_table(MergeBranch _owner )
204 this.el = new Gtk.Table( 2, 2, false );
208 // set gobject values
210 this.el.column_spacing = 2;
211 this.el.vexpand = false;
212 var child_0 = new Xcls_Label4( _this );
214 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
215 var child_1 = new Xcls_actionsel( _this );
217 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
218 var child_2 = new Xcls_Label8( _this );
220 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
221 var child_3 = new Xcls_ticketsel( _this );
223 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
224 var child_4 = new Xcls_Label12( _this );
226 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
227 var child_5 = new Xcls_name( _this );
229 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
232 // user defined functions
234 public class Xcls_Label4 : Object
237 private MergeBranch _this;
243 public Xcls_Label4(MergeBranch _owner )
246 this.el = new Gtk.Label( "Do what?" );
250 // set gobject values
251 this.el.justify = Gtk.Justification.RIGHT;
252 this.el.xalign = 0.900000f;
253 this.el.visible = true;
256 // user defined functions
259 public class Xcls_actionsel : Object
261 public Gtk.ComboBox el;
262 private MergeBranch _this;
269 public Xcls_actionsel(MergeBranch _owner )
272 _this.actionsel = this;
273 this.el = new Gtk.ComboBox();
276 this.loading = false;
278 // set gobject values
279 var child_0 = new Xcls_actioncellrenderer( _this );
281 this.el.pack_start ( child_0.el , true );
282 var child_1 = new Xcls_actionmodel( _this );
284 this.el.set_model ( child_1.el );
288 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
291 this.el.changed.connect( () => {
295 _this.name.updateText();
296 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
300 // user defined functions
301 public string selectedAction () {
305 this.el.get_active_iter (out iter);
306 _this.actionmodel.el.get_value (iter, 0, out val1);
308 return (string) val1;
311 public class Xcls_actioncellrenderer : Object
313 public Gtk.CellRendererText el;
314 private MergeBranch _this;
320 public Xcls_actioncellrenderer(MergeBranch _owner )
323 _this.actioncellrenderer = this;
324 this.el = new Gtk.CellRendererText();
328 // set gobject values
331 // user defined functions
334 public class Xcls_actionmodel : Object
336 public Gtk.ListStore el;
337 private MergeBranch _this;
343 public Xcls_actionmodel(MergeBranch _owner )
346 _this.actionmodel = this;
347 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
351 // set gobject values
354 // user defined functions
355 public void loadActions () {
359 _this.actionsel.loading = true;
368 el.set_value(iter, 0, "");
369 el.set_value(iter, 1, "-- select action --");
371 _this.actionsel.el.set_active_iter(iter);
374 el.set_value(iter, 0, "CLOSE");
375 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
379 el.set_value(iter, 0, "LEAVE");
380 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
383 el.set_value(iter, 0, "MASTER");
384 el.set_value(iter, 1, "Merge changes FROM master into this branch");
387 el.set_value(iter, 0, "EXIT");
388 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
392 _this.actionsel.loading = false;
393 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
399 public class Xcls_Label8 : Object
402 private MergeBranch _this;
408 public Xcls_Label8(MergeBranch _owner )
411 this.el = new Gtk.Label( "Select Ticket" );
415 // set gobject values
416 this.el.justify = Gtk.Justification.RIGHT;
417 this.el.xalign = 0.900000f;
418 this.el.visible = true;
421 // user defined functions
424 public class Xcls_ticketsel : Object
426 public Gtk.ComboBox el;
427 private MergeBranch _this;
434 public Xcls_ticketsel(MergeBranch _owner )
437 _this.ticketsel = this;
438 this.el = new Gtk.ComboBox();
443 // set gobject values
444 var child_0 = new Xcls_dbcellrenderer( _this );
446 this.el.pack_start ( child_0.el , true );
447 var child_1 = new Xcls_dbmodel( _this );
449 this.el.set_model ( child_1.el );
453 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
456 this.el.changed.connect( () => {
460 _this.view.loadTicket(this.selectedTicketId());
462 _this.name.updateText();
463 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
465 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
469 // user defined functions
470 public string selectedTicketId () {
475 this.el.get_active_iter (out iter);
476 _this.dbmodel.el.get_value (iter, 0, out val1);
479 return (string) val1;
486 public class Xcls_dbcellrenderer : Object
488 public Gtk.CellRendererText el;
489 private MergeBranch _this;
495 public Xcls_dbcellrenderer(MergeBranch _owner )
498 _this.dbcellrenderer = this;
499 this.el = new Gtk.CellRendererText();
503 // set gobject values
506 // user defined functions
509 public class Xcls_dbmodel : Object
512 private MergeBranch _this;
518 public Xcls_dbmodel(MergeBranch _owner )
521 _this.dbmodel = this;
522 this.el = new Gtk.();
527 // user defined functions
528 public void loadTickets () {
530 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
532 _this.ticketsel.loading = true;
539 el.set_value(iter, 0, "");
540 el.set_value(iter, 1, "-- select a ticket --");
542 _this.ticketsel.el.set_active_iter(iter);
544 if (_this.ticket != null && _this.ticket.id == "-1") {
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);
554 var tickets = RooTicket.singleton().tickets;
555 foreach(var ticket in tickets) {
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);
567 _this.ticketsel.loading = false;
568 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
574 public class Xcls_Label12 : Object
577 private MergeBranch _this;
583 public Xcls_Label12(MergeBranch _owner )
586 this.el = new Gtk.Label( "Use this commit message" );
590 // set gobject values
591 this.el.justify = Gtk.Justification.RIGHT;
592 this.el.xalign = 0.900000f;
595 // user defined functions
598 public class Xcls_name : Object
601 private MergeBranch _this;
607 public Xcls_name(MergeBranch _owner )
611 this.el = new Gtk.Entry();
615 // set gobject values
616 this.el.visible = true;
619 // user defined functions
620 public void updateText () {
621 var ticket_id = _this.ticketsel.selectedTicketId();
623 RooTicket ticket = null;
624 if (ticket_id.length > 0){
625 ticket = RooTicket.singleton().getById(ticket_id);
628 var name = RooTicket.singleton().usernameLocal();
629 var action = _this.actionsel.selectedAction();
630 this.el.set_editable(true);
632 case "CLOSE": // merge changes and close..
633 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
635 case "LEAVE": // partial fix
636 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
638 case "MASTER": // merge master
639 case "EXIT": // just switch back...
640 this.el.set_editable(false);
641 this.el.set_text(""); // not relivant..
645 break; /// don't fix the text value.
652 public class Xcls_Notebook14 : Object
654 public Gtk.Notebook el;
655 private MergeBranch _this;
661 public Xcls_Notebook14(MergeBranch _owner )
664 this.el = new Gtk.Notebook();
668 // set gobject values
669 this.el.vexpand = true;
670 var child_0 = new Xcls_label_diff( _this );
672 var child_1 = new Xcls_label_ticket( _this );
674 var child_2 = new Xcls_Box17( _this );
676 this.el.append_page ( child_2.el , _this.label_diff.el );
677 var child_3 = new Xcls_Box20( _this );
679 this.el.append_page ( child_3.el , _this.label_ticket.el );
682 // user defined functions
684 public class Xcls_label_diff : Object
687 private MergeBranch _this;
693 public Xcls_label_diff(MergeBranch _owner )
696 _this.label_diff = this;
697 this.el = new Gtk.Label( "Projected Commit Diff" );
701 // set gobject values
704 // user defined functions
707 public class Xcls_label_ticket : Object
710 private MergeBranch _this;
716 public Xcls_label_ticket(MergeBranch _owner )
719 _this.label_ticket = this;
720 this.el = new Gtk.Label( "Ticket Details" );
724 // set gobject values
727 // user defined functions
730 public class Xcls_Box17 : Object
733 private MergeBranch _this;
739 public Xcls_Box17(MergeBranch _owner )
742 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
746 // set gobject values
747 this.el.homogeneous = false;
748 var child_0 = new Xcls_scrolled_window( _this );
750 this.el.add ( child_0.el );
753 // user defined functions
755 public class Xcls_scrolled_window : Object
757 public Gtk.ScrolledWindow el;
758 private MergeBranch _this;
764 public Xcls_scrolled_window(MergeBranch _owner )
767 _this.scrolled_window = this;
768 this.el = new Gtk.ScrolledWindow( null, null );
772 // set gobject values
773 this.el.height_request = 500;
774 this.el.vexpand = true;
775 var child_0 = new Xcls_view( _this );
777 this.el.add ( child_0.el );
782 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
786 // user defined functions
788 public class Xcls_view : Object
790 public WebKit.WebView el;
791 private MergeBranch _this;
797 public Xcls_view(MergeBranch _owner )
801 this.el = new WebKit.WebView();
805 // set gobject values
808 // user defined functions
809 public void loadTicket (string tid) {
811 _this.el.get_size(out w, out h);
814 _this.scrolled_window.el.hide();
815 _this.el.resize(w, 150);
817 _this.scrolled_window.el.show();
818 _this.el.resize(w, 800);
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));
827 this.el.load_request(uri);
833 public class Xcls_Box20 : Object
836 private MergeBranch _this;
842 public Xcls_Box20(MergeBranch _owner )
845 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
849 // set gobject values
850 this.el.homogeneous = false;
853 // user defined functions
857 public class Xcls_spinner : Object
859 public Gtk.Spinner el;
860 private MergeBranch _this;
866 public Xcls_spinner(MergeBranch _owner )
869 _this.spinner = this;
870 this.el = new Gtk.Spinner();
874 // set gobject values
875 this.el.hexpand = true;
876 this.el.vexpand = true;
879 // user defined functions
883 public class Xcls_Button22 : Object
885 public Gtk.Button el;
886 private MergeBranch _this;
892 public Xcls_Button22(MergeBranch _owner )
895 this.el = new Gtk.Button();
899 // set gobject values
900 this.el.relief = Gtk.ReliefStyle.NONE;
901 this.el.label = "Cancel";
904 // user defined functions
907 public class Xcls_Button23 : Object
909 public Gtk.Button el;
910 private MergeBranch _this;
916 public Xcls_Button23(MergeBranch _owner )
919 this.el = new Gtk.Button();
923 // set gobject values
924 this.el.label = "Do Merge";
929 this.el.get_style_context().add_class("suggested-action");
933 // user defined functions