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_Button21( _this );
55 this.el.add_action_widget ( child_1.el , 0 );
56 var child_2 = new Xcls_Button22( _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_scrolled_window( _this );
186 this.el.add ( child_2.el );
187 var child_3 = new Xcls_spinner( _this );
189 this.el.add ( child_3.el );
192 // user defined functions
194 public class Xcls_table : Object
197 private MergeBranch _this;
203 public Xcls_table(MergeBranch _owner )
207 this.el = new Gtk.Table( 2, 2, false );
211 // set gobject values
213 this.el.column_spacing = 2;
214 this.el.vexpand = false;
215 var child_0 = new Xcls_Label4( _this );
217 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
218 var child_1 = new Xcls_actionsel( _this );
220 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
221 var child_2 = new Xcls_Label8( _this );
223 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
224 var child_3 = new Xcls_ticketsel( _this );
226 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
227 var child_4 = new Xcls_Label12( _this );
229 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
230 var child_5 = new Xcls_name( _this );
232 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
235 // user defined functions
237 public class Xcls_Label4 : Object
240 private MergeBranch _this;
246 public Xcls_Label4(MergeBranch _owner )
249 this.el = new Gtk.Label( "Do what?" );
253 // set gobject values
254 this.el.justify = Gtk.Justification.RIGHT;
255 this.el.xalign = 0.900000f;
256 this.el.visible = true;
259 // user defined functions
262 public class Xcls_actionsel : Object
264 public Gtk.ComboBox el;
265 private MergeBranch _this;
272 public Xcls_actionsel(MergeBranch _owner )
275 _this.actionsel = this;
276 this.el = new Gtk.ComboBox();
279 this.loading = false;
281 // set gobject values
282 var child_0 = new Xcls_actioncellrenderer( _this );
284 this.el.pack_start ( child_0.el , true );
285 var child_1 = new Xcls_actionmodel( _this );
287 this.el.set_model ( child_1.el );
291 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
294 this.el.changed.connect( () => {
298 _this.name.updateText();
299 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
303 // user defined functions
304 public string selectedAction () {
308 this.el.get_active_iter (out iter);
309 _this.actionmodel.el.get_value (iter, 0, out val1);
311 return (string) val1;
314 public class Xcls_actioncellrenderer : Object
316 public Gtk.CellRendererText el;
317 private MergeBranch _this;
323 public Xcls_actioncellrenderer(MergeBranch _owner )
326 _this.actioncellrenderer = this;
327 this.el = new Gtk.CellRendererText();
331 // set gobject values
334 // user defined functions
337 public class Xcls_actionmodel : Object
339 public Gtk.ListStore el;
340 private MergeBranch _this;
346 public Xcls_actionmodel(MergeBranch _owner )
349 _this.actionmodel = this;
350 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
354 // set gobject values
357 // user defined functions
358 public void loadActions () {
362 _this.actionsel.loading = true;
371 el.set_value(iter, 0, "");
372 el.set_value(iter, 1, "-- select action --");
374 _this.actionsel.el.set_active_iter(iter);
377 el.set_value(iter, 0, "CLOSE");
378 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
382 el.set_value(iter, 0, "LEAVE");
383 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
386 el.set_value(iter, 0, "MASTER");
387 el.set_value(iter, 1, "Merge changes FROM master into this branch");
390 el.set_value(iter, 0, "EXIT");
391 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
395 _this.actionsel.loading = false;
396 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
402 public class Xcls_Label8 : Object
405 private MergeBranch _this;
411 public Xcls_Label8(MergeBranch _owner )
414 this.el = new Gtk.Label( "Select Ticket" );
418 // set gobject values
419 this.el.justify = Gtk.Justification.RIGHT;
420 this.el.xalign = 0.900000f;
421 this.el.visible = true;
424 // user defined functions
427 public class Xcls_ticketsel : Object
429 public Gtk.ComboBox el;
430 private MergeBranch _this;
437 public Xcls_ticketsel(MergeBranch _owner )
440 _this.ticketsel = this;
441 this.el = new Gtk.ComboBox();
446 // set gobject values
447 var child_0 = new Xcls_dbcellrenderer( _this );
449 this.el.pack_start ( child_0.el , true );
450 var child_1 = new Xcls_dbmodel( _this );
452 this.el.set_model ( child_1.el );
456 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
459 this.el.changed.connect( () => {
463 _this.view.loadTicket(this.selectedTicketId());
465 _this.name.updateText();
466 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
468 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
472 // user defined functions
473 public string selectedTicketId () {
478 this.el.get_active_iter (out iter);
479 _this.dbmodel.el.get_value (iter, 0, out val1);
482 return (string) val1;
489 public class Xcls_dbcellrenderer : Object
491 public Gtk.CellRendererText el;
492 private MergeBranch _this;
498 public Xcls_dbcellrenderer(MergeBranch _owner )
501 _this.dbcellrenderer = this;
502 this.el = new Gtk.CellRendererText();
506 // set gobject values
509 // user defined functions
512 public class Xcls_dbmodel : Object
515 private MergeBranch _this;
521 public Xcls_dbmodel(MergeBranch _owner )
524 _this.dbmodel = this;
525 this.el = new Gtk.();
530 // user defined functions
531 public void loadTickets () {
533 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
535 _this.ticketsel.loading = true;
542 el.set_value(iter, 0, "");
543 el.set_value(iter, 1, "-- select a ticket --");
545 _this.ticketsel.el.set_active_iter(iter);
547 if (_this.ticket != null && _this.ticket.id == "-1") {
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);
557 var tickets = RooTicket.singleton().tickets;
558 foreach(var ticket in tickets) {
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);
570 _this.ticketsel.loading = false;
571 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
577 public class Xcls_Label12 : Object
580 private MergeBranch _this;
586 public Xcls_Label12(MergeBranch _owner )
589 this.el = new Gtk.Label( "Use this commit message" );
593 // set gobject values
594 this.el.justify = Gtk.Justification.RIGHT;
595 this.el.xalign = 0.900000f;
598 // user defined functions
601 public class Xcls_name : Object
604 private MergeBranch _this;
610 public Xcls_name(MergeBranch _owner )
614 this.el = new Gtk.Entry();
618 // set gobject values
619 this.el.visible = true;
622 // user defined functions
623 public void updateText () {
624 var ticket_id = _this.ticketsel.selectedTicketId();
626 RooTicket ticket = null;
627 if (ticket_id.length > 0){
628 ticket = RooTicket.singleton().getById(ticket_id);
631 var name = RooTicket.singleton().usernameLocal();
632 var action = _this.actionsel.selectedAction();
633 this.el.set_editable(true);
635 case "CLOSE": // merge changes and close..
636 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
638 case "LEAVE": // partial fix
639 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
641 case "MASTER": // merge master
642 case "EXIT": // just switch back...
643 this.el.set_editable(false);
644 this.el.set_text(""); // not relivant..
648 break; /// don't fix the text value.
655 public class Xcls_Notebook14 : Object
657 public Gtk.Notebook el;
658 private MergeBranch _this;
664 public Xcls_Notebook14(MergeBranch _owner )
667 this.el = new Gtk.Notebook();
671 // set gobject values
672 this.el.vexpand = true;
673 var child_0 = new Xcls_label_diff( _this );
675 var child_1 = new Xcls_label_ticket( _this );
677 var child_2 = new Xcls_Box17( _this );
679 this.el.append_page ( child_2.el , _this.label_status.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;
750 // user defined functions
754 public class Xcls_scrolled_window : Object
756 public Gtk.ScrolledWindow el;
757 private MergeBranch _this;
763 public Xcls_scrolled_window(MergeBranch _owner )
766 _this.scrolled_window = this;
767 this.el = new Gtk.ScrolledWindow( null, null );
771 // set gobject values
772 this.el.height_request = 500;
773 this.el.vexpand = true;
774 var child_0 = new Xcls_view( _this );
776 this.el.add ( child_0.el );
781 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
785 // user defined functions
787 public class Xcls_view : Object
789 public WebKit.WebView el;
790 private MergeBranch _this;
796 public Xcls_view(MergeBranch _owner )
800 this.el = new WebKit.WebView();
804 // set gobject values
807 // user defined functions
808 public void loadTicket (string tid) {
810 _this.el.get_size(out w, out h);
813 _this.scrolled_window.el.hide();
814 _this.el.resize(w, 150);
816 _this.scrolled_window.el.show();
817 _this.el.resize(w, 800);
820 var rs = RooTicket.singleton();
821 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
822 var hd = uri.get_http_headers();
823 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
824 hd.append("Authorization", "Basic %s".printf(authCode));
826 this.el.load_request(uri);
831 public class Xcls_spinner : Object
833 public Gtk.Spinner el;
834 private MergeBranch _this;
840 public Xcls_spinner(MergeBranch _owner )
843 _this.spinner = this;
844 this.el = new Gtk.Spinner();
848 // set gobject values
849 this.el.hexpand = true;
850 this.el.vexpand = true;
853 // user defined functions
857 public class Xcls_Button21 : Object
859 public Gtk.Button el;
860 private MergeBranch _this;
866 public Xcls_Button21(MergeBranch _owner )
869 this.el = new Gtk.Button();
873 // set gobject values
874 this.el.relief = Gtk.ReliefStyle.NONE;
875 this.el.label = "Cancel";
878 // user defined functions
881 public class Xcls_Button22 : Object
883 public Gtk.Button el;
884 private MergeBranch _this;
890 public Xcls_Button22(MergeBranch _owner )
893 this.el = new Gtk.Button();
897 // set gobject values
898 this.el.label = "Do Merge";
903 this.el.get_style_context().add_class("suggested-action");
907 // user defined functions