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_scrolled_window scrolled_window;
24 public Xcls_view view;
25 public Xcls_spinner spinner;
29 public RooTicket? ticket;
36 this.el = new Gtk.Dialog();
43 this.el.title = "Merge Branch";
44 this.el.default_height = 200;
45 this.el.default_width = 500;
46 this.el.deletable = true;
48 var child_0 = new Xcls_Box2( _this );
50 this.el.get_content_area().add ( child_0.el );
51 var child_1 = new Xcls_Button17( _this );
53 this.el.add_action_widget ( child_1.el , 0 );
54 var child_2 = new Xcls_Button18( _this );
56 this.el.add_action_widget ( child_2.el , 1 );
59 this.el.delete_event.connect( (self, event) => {
64 this.el.response.connect( (self, response_id) => {
66 GLib.debug("got %d", (int) response_id);
67 if (response_id < 1) {
70 GitMonitor.gitmonitor.start();
74 // have they selected a ticket..
75 // make that the current active ticket?
76 // we really need to store locally what ticket is being worked on..
77 // in theory we could be working on multiple project and not merging..
78 // -- each repo would have their active ticket (only one per repo)
79 // -- so we could just store that in there
80 // -- initial load can check the contents of the ticket files on first scan.
81 var ticket_id = _this.ticketsel.selectedTicketId();
83 if (this.repo != null) {
84 var bn = _this.name.el.get_text();
85 if (ticket_id != "" ) {
86 this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
88 this.repo.createBranchNamed(bn);
93 if (this.repo != null) {
95 _this.actionsel.selectedAction(),
96 _this.ticketsel.selectedTicketId(),
97 _this.name.el.get_text()
102 _this.actionsel.selectedAction(),
103 _this.ticketsel.selectedTicketId(),
104 _this.name.el.get_text()
107 this.running = false;
111 GitMonitor.gitmonitor.start();
117 // user defined functions
118 public void show ( RooTicket ticket, GitRepo? repo )
120 // this.el.set_gravity(Gdk.Gravity.NORTH);
124 GitMonitor.gitmonitor.stop();
128 _this.table.el.hide();
129 _this.scrolled_window.el.hide();
130 _this.spinner.el.show();
131 _this.spinner.el.start();
132 this.el.set_keep_above(true);
133 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
134 GLib.debug("Loading tickets");
139 this.ticket = ticket;
143 Timeout.add_seconds(1, () => {
145 // if we are not working on a ticket, then we should be able to pick one?
146 _this.dbmodel.loadTickets();
147 _this.actionmodel.loadActions();
148 _this.view.loadTicket(ticket.id);
149 _this.spinner.el.stop();
150 _this.spinner.el.hide();
152 this.table.el.show();
159 public class Xcls_Box2 : Object
162 private MergeBranch _this;
168 public Xcls_Box2(MergeBranch _owner )
171 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
175 // set gobject values
176 var child_0 = new Xcls_table( _this );
178 this.el.pack_start ( child_0.el , false,false,0 );
179 var child_1 = new Xcls_scrolled_window( _this );
181 this.el.add ( child_1.el );
182 var child_2 = new Xcls_spinner( _this );
184 this.el.add ( child_2.el );
187 // user defined functions
189 public class Xcls_table : Object
192 private MergeBranch _this;
198 public Xcls_table(MergeBranch _owner )
202 this.el = new Gtk.Table( 2, 2, false );
206 // set gobject values
208 this.el.column_spacing = 2;
209 this.el.vexpand = false;
210 var child_0 = new Xcls_Label4( _this );
212 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
213 var child_1 = new Xcls_actionsel( _this );
215 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
216 var child_2 = new Xcls_Label8( _this );
218 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
219 var child_3 = new Xcls_ticketsel( _this );
221 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
222 var child_4 = new Xcls_Label12( _this );
224 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
225 var child_5 = new Xcls_name( _this );
227 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
230 // user defined functions
232 public class Xcls_Label4 : Object
235 private MergeBranch _this;
241 public Xcls_Label4(MergeBranch _owner )
244 this.el = new Gtk.Label( "Do what?" );
248 // set gobject values
249 this.el.justify = Gtk.Justification.RIGHT;
250 this.el.xalign = 0.900000f;
251 this.el.visible = true;
254 // user defined functions
257 public class Xcls_actionsel : Object
259 public Gtk.ComboBox el;
260 private MergeBranch _this;
267 public Xcls_actionsel(MergeBranch _owner )
270 _this.actionsel = this;
271 this.el = new Gtk.ComboBox();
274 this.loading = false;
276 // set gobject values
277 var child_0 = new Xcls_actioncellrenderer( _this );
279 this.el.pack_start ( child_0.el , true );
280 var child_1 = new Xcls_actionmodel( _this );
282 this.el.set_model ( child_1.el );
286 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
289 this.el.changed.connect( () => {
293 _this.name.updateText();
294 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
298 // user defined functions
299 public string selectedAction () {
303 this.el.get_active_iter (out iter);
304 _this.actionmodel.el.get_value (iter, 0, out val1);
306 return (string) val1;
309 public class Xcls_actioncellrenderer : Object
311 public Gtk.CellRendererText el;
312 private MergeBranch _this;
318 public Xcls_actioncellrenderer(MergeBranch _owner )
321 _this.actioncellrenderer = this;
322 this.el = new Gtk.CellRendererText();
326 // set gobject values
329 // user defined functions
332 public class Xcls_actionmodel : Object
334 public Gtk.ListStore el;
335 private MergeBranch _this;
341 public Xcls_actionmodel(MergeBranch _owner )
344 _this.actionmodel = this;
345 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
349 // set gobject values
352 // user defined functions
353 public void loadActions () {
357 _this.actionsel.loading = true;
366 el.set_value(iter, 0, "");
367 el.set_value(iter, 1, "-- select action --");
369 _this.actionsel.el.set_active_iter(iter);
372 el.set_value(iter, 0, "CLOSE");
373 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
377 el.set_value(iter, 0, "LEAVE");
378 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
381 el.set_value(iter, 0, "MASTER");
382 el.set_value(iter, 1, "Merge changes FROM master into this branch");
385 el.set_value(iter, 0, "EXIT");
386 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
390 _this.actionsel.loading = false;
391 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
397 public class Xcls_Label8 : Object
400 private MergeBranch _this;
406 public Xcls_Label8(MergeBranch _owner )
409 this.el = new Gtk.Label( "Select Ticket" );
413 // set gobject values
414 this.el.justify = Gtk.Justification.RIGHT;
415 this.el.xalign = 0.900000f;
416 this.el.visible = true;
419 // user defined functions
422 public class Xcls_ticketsel : Object
424 public Gtk.ComboBox el;
425 private MergeBranch _this;
432 public Xcls_ticketsel(MergeBranch _owner )
435 _this.ticketsel = this;
436 this.el = new Gtk.ComboBox();
441 // set gobject values
442 var child_0 = new Xcls_dbcellrenderer( _this );
444 this.el.pack_start ( child_0.el , true );
445 var child_1 = new Xcls_dbmodel( _this );
447 this.el.set_model ( child_1.el );
451 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
454 this.el.changed.connect( () => {
458 _this.view.loadTicket(this.selectedTicketId());
460 _this.name.updateText();
461 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
463 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
467 // user defined functions
468 public string selectedTicketId () {
473 this.el.get_active_iter (out iter);
474 _this.dbmodel.el.get_value (iter, 0, out val1);
477 return (string) val1;
484 public class Xcls_dbcellrenderer : Object
486 public Gtk.CellRendererText el;
487 private MergeBranch _this;
493 public Xcls_dbcellrenderer(MergeBranch _owner )
496 _this.dbcellrenderer = this;
497 this.el = new Gtk.CellRendererText();
501 // set gobject values
504 // user defined functions
507 public class Xcls_dbmodel : Object
509 public Gtk.ListStore el;
510 private MergeBranch _this;
516 public Xcls_dbmodel(MergeBranch _owner )
519 _this.dbmodel = this;
520 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
524 // set gobject values
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_scrolled_window : Object
654 public Gtk.ScrolledWindow el;
655 private MergeBranch _this;
661 public Xcls_scrolled_window(MergeBranch _owner )
664 _this.scrolled_window = this;
665 this.el = new Gtk.ScrolledWindow( null, null );
669 // set gobject values
670 this.el.height_request = 500;
671 this.el.vexpand = true;
672 var child_0 = new Xcls_view( _this );
674 this.el.add ( child_0.el );
679 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
683 // user defined functions
685 public class Xcls_view : Object
687 public WebKit.WebView el;
688 private MergeBranch _this;
694 public Xcls_view(MergeBranch _owner )
698 this.el = new WebKit.WebView();
702 // set gobject values
705 // user defined functions
706 public void loadTicket (string tid) {
708 _this.el.get_size(out w, out h);
711 _this.scrolled_window.el.hide();
712 _this.el.resize(w, 150);
714 _this.scrolled_window.el.show();
715 _this.el.resize(w, 800);
718 var rs = RooTicket.singleton();
719 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
720 var hd = uri.get_http_headers();
721 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
722 hd.append("Authorization", "Basic %s".printf(authCode));
724 this.el.load_request(uri);
729 public class Xcls_spinner : Object
731 public Gtk.Spinner el;
732 private MergeBranch _this;
738 public Xcls_spinner(MergeBranch _owner )
741 _this.spinner = this;
742 this.el = new Gtk.Spinner();
746 // set gobject values
747 this.el.hexpand = true;
748 this.el.vexpand = true;
751 // user defined functions
755 public class Xcls_Button17 : Object
757 public Gtk.Button el;
758 private MergeBranch _this;
764 public Xcls_Button17(MergeBranch _owner )
767 this.el = new Gtk.Button();
771 // set gobject values
772 this.el.relief = Gtk.ReliefStyle.NONE;
773 this.el.label = "Cancel";
776 // user defined functions
779 public class Xcls_Button18 : Object
781 public Gtk.Button el;
782 private MergeBranch _this;
788 public Xcls_Button18(MergeBranch _owner )
791 this.el = new Gtk.Button();
795 // set gobject values
796 this.el.label = "Do Merge";
801 this.el.get_style_context().add_class("suggested-action");
805 // user defined functions