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();
126 this.ticket = ticket;
129 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
130 GLib.debug("Loading tickets");
134 _this.dbmodel.loadTickets();
135 _this.actionmodel.loadActions();
136 _this.view.loadTicket(ticket.id);
139 public class Xcls_Box2 : Object
142 private MergeBranch _this;
148 public Xcls_Box2(MergeBranch _owner )
151 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
155 // set gobject values
156 var child_0 = new Xcls_table( _this );
158 this.el.pack_start ( child_0.el , false,false,0 );
159 var child_1 = new Xcls_scrolled_window( _this );
161 this.el.add ( child_1.el );
162 var child_2 = new Xcls_spinner( _this );
164 this.el.add ( child_2.el );
167 // user defined functions
169 public class Xcls_table : Object
172 private MergeBranch _this;
178 public Xcls_table(MergeBranch _owner )
182 this.el = new Gtk.Table( 2, 2, false );
186 // set gobject values
188 this.el.column_spacing = 2;
189 this.el.vexpand = false;
190 var child_0 = new Xcls_Label4( _this );
192 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
193 var child_1 = new Xcls_actionsel( _this );
195 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
196 var child_2 = new Xcls_Label8( _this );
198 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
199 var child_3 = new Xcls_ticketsel( _this );
201 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
202 var child_4 = new Xcls_Label12( _this );
204 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
205 var child_5 = new Xcls_name( _this );
207 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
210 // user defined functions
212 public class Xcls_Label4 : Object
215 private MergeBranch _this;
221 public Xcls_Label4(MergeBranch _owner )
224 this.el = new Gtk.Label( "Do what?" );
228 // set gobject values
229 this.el.justify = Gtk.Justification.RIGHT;
230 this.el.xalign = 0.900000f;
231 this.el.visible = true;
234 // user defined functions
237 public class Xcls_actionsel : Object
239 public Gtk.ComboBox el;
240 private MergeBranch _this;
247 public Xcls_actionsel(MergeBranch _owner )
250 _this.actionsel = this;
251 this.el = new Gtk.ComboBox();
254 this.loading = false;
256 // set gobject values
257 var child_0 = new Xcls_actioncellrenderer( _this );
259 this.el.pack_start ( child_0.el , true );
260 var child_1 = new Xcls_actionmodel( _this );
262 this.el.set_model ( child_1.el );
266 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
269 this.el.changed.connect( () => {
273 _this.name.updateText();
274 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
278 // user defined functions
279 public string selectedAction () {
283 this.el.get_active_iter (out iter);
284 _this.actionmodel.el.get_value (iter, 0, out val1);
286 return (string) val1;
289 public class Xcls_actioncellrenderer : Object
291 public Gtk.CellRendererText el;
292 private MergeBranch _this;
298 public Xcls_actioncellrenderer(MergeBranch _owner )
301 _this.actioncellrenderer = this;
302 this.el = new Gtk.CellRendererText();
306 // set gobject values
309 // user defined functions
312 public class Xcls_actionmodel : Object
314 public Gtk.ListStore el;
315 private MergeBranch _this;
321 public Xcls_actionmodel(MergeBranch _owner )
324 _this.actionmodel = this;
325 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
329 // set gobject values
332 // user defined functions
333 public void loadActions () {
337 _this.actionsel.loading = true;
346 el.set_value(iter, 0, "");
347 el.set_value(iter, 1, "-- select action --");
349 _this.actionsel.el.set_active_iter(iter);
352 el.set_value(iter, 0, "CLOSE");
353 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
357 el.set_value(iter, 0, "LEAVE");
358 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
361 el.set_value(iter, 0, "MASTER");
362 el.set_value(iter, 1, "Merge changes FROM master into this branch");
365 el.set_value(iter, 0, "EXIT");
366 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
370 _this.actionsel.loading = false;
371 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
377 public class Xcls_Label8 : Object
380 private MergeBranch _this;
386 public Xcls_Label8(MergeBranch _owner )
389 this.el = new Gtk.Label( "Select Ticket" );
393 // set gobject values
394 this.el.justify = Gtk.Justification.RIGHT;
395 this.el.xalign = 0.900000f;
396 this.el.visible = true;
399 // user defined functions
402 public class Xcls_ticketsel : Object
404 public Gtk.ComboBox el;
405 private MergeBranch _this;
412 public Xcls_ticketsel(MergeBranch _owner )
415 _this.ticketsel = this;
416 this.el = new Gtk.ComboBox();
421 // set gobject values
422 var child_0 = new Xcls_dbcellrenderer( _this );
424 this.el.pack_start ( child_0.el , true );
425 var child_1 = new Xcls_dbmodel( _this );
427 this.el.set_model ( child_1.el );
431 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
434 this.el.changed.connect( () => {
438 _this.view.loadTicket(this.selectedTicketId());
440 _this.name.updateText();
441 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
443 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
447 // user defined functions
448 public string selectedTicketId () {
453 this.el.get_active_iter (out iter);
454 _this.dbmodel.el.get_value (iter, 0, out val1);
457 return (string) val1;
464 public class Xcls_dbcellrenderer : Object
466 public Gtk.CellRendererText el;
467 private MergeBranch _this;
473 public Xcls_dbcellrenderer(MergeBranch _owner )
476 _this.dbcellrenderer = this;
477 this.el = new Gtk.CellRendererText();
481 // set gobject values
484 // user defined functions
487 public class Xcls_dbmodel : Object
489 public Gtk.ListStore el;
490 private MergeBranch _this;
496 public Xcls_dbmodel(MergeBranch _owner )
499 _this.dbmodel = this;
500 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
504 // set gobject values
507 // user defined functions
508 public void loadTickets () {
510 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
512 _this.ticketsel.loading = true;
519 el.set_value(iter, 0, "");
520 el.set_value(iter, 1, "-- select a ticket --");
522 _this.ticketsel.el.set_active_iter(iter);
524 if (_this.ticket != null && _this.ticket.id == "-1") {
526 el.set_value(iter, 0, "-1");
527 el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
528 _this.ticketsel.el.set_active_iter(iter);
534 var tickets = RooTicket.singleton().tickets;
535 foreach(var ticket in tickets) {
539 el.set_value(iter, 0, ticket.id);
540 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
541 if (_this.ticket != null && _this.ticket.id == ticket.id) {
542 _this.ticketsel.el.set_active_iter(iter);
547 _this.ticketsel.loading = false;
548 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
554 public class Xcls_Label12 : Object
557 private MergeBranch _this;
563 public Xcls_Label12(MergeBranch _owner )
566 this.el = new Gtk.Label( "Use this commit message" );
570 // set gobject values
571 this.el.justify = Gtk.Justification.RIGHT;
572 this.el.xalign = 0.900000f;
575 // user defined functions
578 public class Xcls_name : Object
581 private MergeBranch _this;
587 public Xcls_name(MergeBranch _owner )
591 this.el = new Gtk.Entry();
595 // set gobject values
596 this.el.visible = true;
599 // user defined functions
600 public void updateText () {
601 var ticket_id = _this.ticketsel.selectedTicketId();
603 RooTicket ticket = null;
604 if (ticket_id.length > 0){
605 ticket = RooTicket.singleton().getById(ticket_id);
608 var name = RooTicket.singleton().usernameLocal();
609 var action = _this.actionsel.selectedAction();
610 this.el.set_editable(true);
612 case "CLOSE": // merge changes and close..
613 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
615 case "LEAVE": // partial fix
616 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
618 case "MASTER": // merge master
619 case "EXIT": // just switch back...
620 this.el.set_editable(false);
621 this.el.set_text(""); // not relivant..
625 break; /// don't fix the text value.
632 public class Xcls_scrolled_window : Object
634 public Gtk.ScrolledWindow el;
635 private MergeBranch _this;
641 public Xcls_scrolled_window(MergeBranch _owner )
644 _this.scrolled_window = this;
645 this.el = new Gtk.ScrolledWindow( null, null );
649 // set gobject values
650 this.el.height_request = 500;
651 this.el.vexpand = true;
652 var child_0 = new Xcls_view( _this );
654 this.el.add ( child_0.el );
659 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
663 // user defined functions
665 public class Xcls_view : Object
667 public WebKit.WebView el;
668 private MergeBranch _this;
674 public Xcls_view(MergeBranch _owner )
678 this.el = new WebKit.WebView();
682 // set gobject values
685 // user defined functions
686 public void loadTicket (string tid) {
688 _this.el.get_size(out w, out h);
691 _this.scrolled_window.el.hide();
692 _this.el.resize(w, 150);
694 _this.scrolled_window.el.show();
695 _this.el.resize(w, 800);
698 var rs = RooTicket.singleton();
699 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
700 var hd = uri.get_http_headers();
701 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
702 hd.append("Authorization", "Basic %s".printf(authCode));
704 this.el.load_request(uri);
709 public class Xcls_spinner : Object
711 public Gtk.Spinner el;
712 private MergeBranch _this;
718 public Xcls_spinner(MergeBranch _owner )
721 _this.spinner = this;
722 this.el = new Gtk.Spinner();
726 // set gobject values
727 this.el.hexpand = true;
728 this.el.vexpand = true;
731 // user defined functions
735 public class Xcls_Button17 : Object
737 public Gtk.Button el;
738 private MergeBranch _this;
744 public Xcls_Button17(MergeBranch _owner )
747 this.el = new Gtk.Button();
751 // set gobject values
752 this.el.relief = Gtk.ReliefStyle.NONE;
753 this.el.label = "Cancel";
756 // user defined functions
759 public class Xcls_Button18 : Object
761 public Gtk.Button el;
762 private MergeBranch _this;
768 public Xcls_Button18(MergeBranch _owner )
771 this.el = new Gtk.Button();
775 // set gobject values
776 this.el.label = "Do Merge";
781 this.el.get_style_context().add_class("suggested-action");
785 // user defined functions