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_actionsel actionsel;
16 public Xcls_actioncellrenderer actioncellrenderer;
17 public Xcls_actionmodel actionmodel;
18 public Xcls_ticketsel ticketsel;
19 public Xcls_dbcellrenderer dbcellrenderer;
20 public Xcls_dbmodel dbmodel;
21 public Xcls_name name;
22 public Xcls_scrolled_window scrolled_window;
23 public Xcls_view view;
24 public Xcls_spinner spinner;
28 public RooTicket? ticket;
35 this.el = new Gtk.Dialog();
42 this.el.title = "Merge Branch";
43 this.el.default_height = 200;
44 this.el.default_width = 500;
45 this.el.deletable = true;
47 var child_0 = new Xcls_Box2( _this );
49 this.el.get_content_area().add ( child_0.el );
50 var child_1 = new Xcls_Button17( _this );
52 this.el.add_action_widget ( child_1.el , 0 );
53 var child_2 = new Xcls_Button18( _this );
55 this.el.add_action_widget ( child_2.el , 1 );
58 this.el.delete_event.connect( (self, event) => {
63 this.el.response.connect( (self, response_id) => {
65 GLib.debug("got %d", (int) response_id);
66 if (response_id < 1) {
69 GitMonitor.gitmonitor.start();
73 // have they selected a ticket..
74 // make that the current active ticket?
75 // we really need to store locally what ticket is being worked on..
76 // in theory we could be working on multiple project and not merging..
77 // -- each repo would have their active ticket (only one per repo)
78 // -- so we could just store that in there
79 // -- initial load can check the contents of the ticket files on first scan.
80 var ticket_id = _this.ticketsel.selectedTicketId();
82 if (this.repo != null) {
83 var bn = _this.name.el.get_text();
84 if (ticket_id != "" ) {
85 this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
87 this.repo.createBranchNamed(bn);
92 if (this.repo != null) {
94 _this.actionsel.selectedAction(),
95 _this.ticketsel.selectedTicketId(),
96 _this.name.el.get_text()
101 _this.actionsel.selectedAction(),
102 _this.ticketsel.selectedTicketId(),
103 _this.name.el.get_text()
106 this.running = false;
110 GitMonitor.gitmonitor.start();
114 this.el.show.connect( (self) => {
121 // user defined functions
122 public void show ( RooTicket ticket, GitRepo? repo )
124 // this.el.set_gravity(Gdk.Gravity.NORTH);
128 GitMonitor.gitmonitor.stop();
130 this.ticket = ticket;
133 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
134 GLib.debug("Loading tickets");
138 _this.dbmodel.loadTickets();
139 _this.actionmodel.loadActions();
140 _this.view.loadTicket(ticket.id);
143 public class Xcls_Box2 : Object
146 private MergeBranch _this;
152 public Xcls_Box2(MergeBranch _owner )
155 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
159 // set gobject values
160 var child_0 = new Xcls_Table3( _this );
162 this.el.pack_start ( child_0.el , false,false,0 );
163 var child_1 = new Xcls_scrolled_window( _this );
165 this.el.add ( child_1.el );
166 var child_2 = new Xcls_spinner( _this );
168 this.el.add ( child_2.el );
171 // user defined functions
173 public class Xcls_Table3 : Object
176 private MergeBranch _this;
182 public Xcls_Table3(MergeBranch _owner )
185 this.el = new Gtk.Table( 2, 2, false );
189 // set gobject values
191 this.el.column_spacing = 2;
192 this.el.vexpand = false;
193 var child_0 = new Xcls_Label4( _this );
195 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
196 var child_1 = new Xcls_actionsel( _this );
198 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
199 var child_2 = new Xcls_Label8( _this );
201 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
202 var child_3 = new Xcls_ticketsel( _this );
204 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
205 var child_4 = new Xcls_Label12( _this );
207 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
208 var child_5 = new Xcls_name( _this );
210 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
213 // user defined functions
215 public class Xcls_Label4 : Object
218 private MergeBranch _this;
224 public Xcls_Label4(MergeBranch _owner )
227 this.el = new Gtk.Label( "Do what?" );
231 // set gobject values
232 this.el.justify = Gtk.Justification.RIGHT;
233 this.el.xalign = 0.900000f;
234 this.el.visible = true;
237 // user defined functions
240 public class Xcls_actionsel : Object
242 public Gtk.ComboBox el;
243 private MergeBranch _this;
250 public Xcls_actionsel(MergeBranch _owner )
253 _this.actionsel = this;
254 this.el = new Gtk.ComboBox();
257 this.loading = false;
259 // set gobject values
260 var child_0 = new Xcls_actioncellrenderer( _this );
262 this.el.pack_start ( child_0.el , true );
263 var child_1 = new Xcls_actionmodel( _this );
265 this.el.set_model ( child_1.el );
269 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
272 this.el.changed.connect( () => {
276 _this.name.updateText();
277 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
281 // user defined functions
282 public string selectedAction () {
286 this.el.get_active_iter (out iter);
287 _this.actionmodel.el.get_value (iter, 0, out val1);
289 return (string) val1;
292 public class Xcls_actioncellrenderer : Object
294 public Gtk.CellRendererText el;
295 private MergeBranch _this;
301 public Xcls_actioncellrenderer(MergeBranch _owner )
304 _this.actioncellrenderer = this;
305 this.el = new Gtk.CellRendererText();
309 // set gobject values
312 // user defined functions
315 public class Xcls_actionmodel : Object
317 public Gtk.ListStore el;
318 private MergeBranch _this;
324 public Xcls_actionmodel(MergeBranch _owner )
327 _this.actionmodel = this;
328 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
332 // set gobject values
335 // user defined functions
336 public void loadActions () {
340 _this.actionsel.loading = true;
349 el.set_value(iter, 0, "");
350 el.set_value(iter, 1, "-- select action --");
352 _this.actionsel.el.set_active_iter(iter);
355 el.set_value(iter, 0, "CLOSE");
356 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
360 el.set_value(iter, 0, "LEAVE");
361 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
364 el.set_value(iter, 0, "MASTER");
365 el.set_value(iter, 1, "Merge changes FROM master into this branch");
368 el.set_value(iter, 0, "EXIT");
369 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
373 _this.actionsel.loading = false;
374 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
380 public class Xcls_Label8 : Object
383 private MergeBranch _this;
389 public Xcls_Label8(MergeBranch _owner )
392 this.el = new Gtk.Label( "Select Ticket" );
396 // set gobject values
397 this.el.justify = Gtk.Justification.RIGHT;
398 this.el.xalign = 0.900000f;
399 this.el.visible = true;
402 // user defined functions
405 public class Xcls_ticketsel : Object
407 public Gtk.ComboBox el;
408 private MergeBranch _this;
415 public Xcls_ticketsel(MergeBranch _owner )
418 _this.ticketsel = this;
419 this.el = new Gtk.ComboBox();
424 // set gobject values
425 var child_0 = new Xcls_dbcellrenderer( _this );
427 this.el.pack_start ( child_0.el , true );
428 var child_1 = new Xcls_dbmodel( _this );
430 this.el.set_model ( child_1.el );
434 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
437 this.el.changed.connect( () => {
441 _this.view.loadTicket(this.selectedTicketId());
443 _this.name.updateText();
444 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
446 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
450 // user defined functions
451 public string selectedTicketId () {
456 this.el.get_active_iter (out iter);
457 _this.dbmodel.el.get_value (iter, 0, out val1);
460 return (string) val1;
467 public class Xcls_dbcellrenderer : Object
469 public Gtk.CellRendererText el;
470 private MergeBranch _this;
476 public Xcls_dbcellrenderer(MergeBranch _owner )
479 _this.dbcellrenderer = this;
480 this.el = new Gtk.CellRendererText();
484 // set gobject values
487 // user defined functions
490 public class Xcls_dbmodel : Object
492 public Gtk.ListStore el;
493 private MergeBranch _this;
499 public Xcls_dbmodel(MergeBranch _owner )
502 _this.dbmodel = this;
503 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
507 // set gobject values
510 // user defined functions
511 public void loadTickets () {
513 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
515 _this.ticketsel.loading = true;
522 el.set_value(iter, 0, "");
523 el.set_value(iter, 1, "-- select a ticket --");
525 _this.ticketsel.el.set_active_iter(iter);
527 if (_this.ticket != null && _this.ticket.id == "-1") {
529 el.set_value(iter, 0, "-1");
530 el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
531 _this.ticketsel.el.set_active_iter(iter);
537 var tickets = RooTicket.singleton().tickets;
538 foreach(var ticket in tickets) {
542 el.set_value(iter, 0, ticket.id);
543 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
544 if (_this.ticket != null && _this.ticket.id == ticket.id) {
545 _this.ticketsel.el.set_active_iter(iter);
550 _this.ticketsel.loading = false;
551 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
557 public class Xcls_Label12 : Object
560 private MergeBranch _this;
566 public Xcls_Label12(MergeBranch _owner )
569 this.el = new Gtk.Label( "Use this commit message" );
573 // set gobject values
574 this.el.justify = Gtk.Justification.RIGHT;
575 this.el.xalign = 0.900000f;
578 // user defined functions
581 public class Xcls_name : Object
584 private MergeBranch _this;
590 public Xcls_name(MergeBranch _owner )
594 this.el = new Gtk.Entry();
598 // set gobject values
599 this.el.visible = true;
602 // user defined functions
603 public void updateText () {
604 var ticket_id = _this.ticketsel.selectedTicketId();
606 RooTicket ticket = null;
607 if (ticket_id.length > 0){
608 ticket = RooTicket.singleton().getById(ticket_id);
611 var name = RooTicket.singleton().usernameLocal();
612 var action = _this.actionsel.selectedAction();
613 this.el.set_editable(true);
615 case "CLOSE": // merge changes and close..
616 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
618 case "LEAVE": // partial fix
619 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
621 case "MASTER": // merge master
622 case "EXIT": // just switch back...
623 this.el.set_editable(false);
624 this.el.set_text(""); // not relivant..
628 break; /// don't fix the text value.
635 public class Xcls_scrolled_window : Object
637 public Gtk.ScrolledWindow el;
638 private MergeBranch _this;
644 public Xcls_scrolled_window(MergeBranch _owner )
647 _this.scrolled_window = this;
648 this.el = new Gtk.ScrolledWindow( null, null );
652 // set gobject values
653 this.el.height_request = 500;
654 this.el.vexpand = true;
655 var child_0 = new Xcls_view( _this );
657 this.el.add ( child_0.el );
662 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
666 // user defined functions
668 public class Xcls_view : Object
670 public WebKit.WebView el;
671 private MergeBranch _this;
677 public Xcls_view(MergeBranch _owner )
681 this.el = new WebKit.WebView();
685 // set gobject values
688 // user defined functions
689 public void loadTicket (string tid) {
691 _this.el.get_size(out w, out h);
694 _this.scrolled_window.el.hide();
695 _this.el.resize(w, 150);
697 _this.scrolled_window.el.show();
698 _this.el.resize(w, 800);
701 var rs = RooTicket.singleton();
702 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
703 var hd = uri.get_http_headers();
704 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
705 hd.append("Authorization", "Basic %s".printf(authCode));
707 this.el.load_request(uri);
712 public class Xcls_spinner : Object
714 public Gtk.Spinner el;
715 private MergeBranch _this;
721 public Xcls_spinner(MergeBranch _owner )
724 _this.spinner = this;
725 this.el = new Gtk.Spinner();
729 // set gobject values
730 this.el.hexpand = true;
731 this.el.vexpand = true;
734 // user defined functions
738 public class Xcls_Button17 : Object
740 public Gtk.Button el;
741 private MergeBranch _this;
747 public Xcls_Button17(MergeBranch _owner )
750 this.el = new Gtk.Button();
754 // set gobject values
755 this.el.relief = Gtk.ReliefStyle.NONE;
756 this.el.label = "Cancel";
759 // user defined functions
762 public class Xcls_Button18 : Object
764 public Gtk.Button el;
765 private MergeBranch _this;
771 public Xcls_Button18(MergeBranch _owner )
774 this.el = new Gtk.Button();
778 // set gobject values
779 this.el.label = "Do Merge";
782 // user defined functions