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 _this.dbmodel.loadTickets();
146 _this.actionmodel.loadActions();
147 _this.view.loadTicket(ticket.id);
148 _this.spinner.el.stop();
149 _this.spinner.el.hide();
151 this.table.el.show();
158 public class Xcls_Box2 : Object
161 private MergeBranch _this;
167 public Xcls_Box2(MergeBranch _owner )
170 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
174 // set gobject values
175 var child_0 = new Xcls_table( _this );
177 this.el.pack_start ( child_0.el , false,false,0 );
178 var child_1 = new Xcls_scrolled_window( _this );
180 this.el.add ( child_1.el );
181 var child_2 = new Xcls_spinner( _this );
183 this.el.add ( child_2.el );
186 // user defined functions
188 public class Xcls_table : Object
191 private MergeBranch _this;
197 public Xcls_table(MergeBranch _owner )
201 this.el = new Gtk.Table( 2, 2, false );
205 // set gobject values
207 this.el.column_spacing = 2;
208 this.el.vexpand = false;
209 var child_0 = new Xcls_Label4( _this );
211 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
212 var child_1 = new Xcls_actionsel( _this );
214 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
215 var child_2 = new Xcls_Label8( _this );
217 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
218 var child_3 = new Xcls_ticketsel( _this );
220 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
221 var child_4 = new Xcls_Label12( _this );
223 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
224 var child_5 = new Xcls_name( _this );
226 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
229 // user defined functions
231 public class Xcls_Label4 : Object
234 private MergeBranch _this;
240 public Xcls_Label4(MergeBranch _owner )
243 this.el = new Gtk.Label( "Do what?" );
247 // set gobject values
248 this.el.justify = Gtk.Justification.RIGHT;
249 this.el.xalign = 0.900000f;
250 this.el.visible = true;
253 // user defined functions
256 public class Xcls_actionsel : Object
258 public Gtk.ComboBox el;
259 private MergeBranch _this;
266 public Xcls_actionsel(MergeBranch _owner )
269 _this.actionsel = this;
270 this.el = new Gtk.ComboBox();
273 this.loading = false;
275 // set gobject values
276 var child_0 = new Xcls_actioncellrenderer( _this );
278 this.el.pack_start ( child_0.el , true );
279 var child_1 = new Xcls_actionmodel( _this );
281 this.el.set_model ( child_1.el );
285 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
288 this.el.changed.connect( () => {
292 _this.name.updateText();
293 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
297 // user defined functions
298 public string selectedAction () {
302 this.el.get_active_iter (out iter);
303 _this.actionmodel.el.get_value (iter, 0, out val1);
305 return (string) val1;
308 public class Xcls_actioncellrenderer : Object
310 public Gtk.CellRendererText el;
311 private MergeBranch _this;
317 public Xcls_actioncellrenderer(MergeBranch _owner )
320 _this.actioncellrenderer = this;
321 this.el = new Gtk.CellRendererText();
325 // set gobject values
328 // user defined functions
331 public class Xcls_actionmodel : Object
333 public Gtk.ListStore el;
334 private MergeBranch _this;
340 public Xcls_actionmodel(MergeBranch _owner )
343 _this.actionmodel = this;
344 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
348 // set gobject values
351 // user defined functions
352 public void loadActions () {
356 _this.actionsel.loading = true;
365 el.set_value(iter, 0, "");
366 el.set_value(iter, 1, "-- select action --");
368 _this.actionsel.el.set_active_iter(iter);
371 el.set_value(iter, 0, "CLOSE");
372 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
376 el.set_value(iter, 0, "LEAVE");
377 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
380 el.set_value(iter, 0, "MASTER");
381 el.set_value(iter, 1, "Merge changes FROM master into this branch");
384 el.set_value(iter, 0, "EXIT");
385 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
389 _this.actionsel.loading = false;
390 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
396 public class Xcls_Label8 : Object
399 private MergeBranch _this;
405 public Xcls_Label8(MergeBranch _owner )
408 this.el = new Gtk.Label( "Select Ticket" );
412 // set gobject values
413 this.el.justify = Gtk.Justification.RIGHT;
414 this.el.xalign = 0.900000f;
415 this.el.visible = true;
418 // user defined functions
421 public class Xcls_ticketsel : Object
423 public Gtk.ComboBox el;
424 private MergeBranch _this;
431 public Xcls_ticketsel(MergeBranch _owner )
434 _this.ticketsel = this;
435 this.el = new Gtk.ComboBox();
440 // set gobject values
441 var child_0 = new Xcls_dbcellrenderer( _this );
443 this.el.pack_start ( child_0.el , true );
444 var child_1 = new Xcls_dbmodel( _this );
446 this.el.set_model ( child_1.el );
450 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
453 this.el.changed.connect( () => {
457 _this.view.loadTicket(this.selectedTicketId());
459 _this.name.updateText();
460 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
462 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
466 // user defined functions
467 public string selectedTicketId () {
472 this.el.get_active_iter (out iter);
473 _this.dbmodel.el.get_value (iter, 0, out val1);
476 return (string) val1;
483 public class Xcls_dbcellrenderer : Object
485 public Gtk.CellRendererText el;
486 private MergeBranch _this;
492 public Xcls_dbcellrenderer(MergeBranch _owner )
495 _this.dbcellrenderer = this;
496 this.el = new Gtk.CellRendererText();
500 // set gobject values
503 // user defined functions
506 public class Xcls_dbmodel : Object
508 public Gtk.ListStore el;
509 private MergeBranch _this;
515 public Xcls_dbmodel(MergeBranch _owner )
518 _this.dbmodel = this;
519 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
523 // set gobject values
526 // user defined functions
527 public void loadTickets () {
529 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
531 _this.ticketsel.loading = true;
538 el.set_value(iter, 0, "");
539 el.set_value(iter, 1, "-- select a ticket --");
541 _this.ticketsel.el.set_active_iter(iter);
543 if (_this.ticket != null && _this.ticket.id == "-1") {
545 el.set_value(iter, 0, "-1");
546 el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
547 _this.ticketsel.el.set_active_iter(iter);
553 var tickets = RooTicket.singleton().tickets;
554 foreach(var ticket in tickets) {
558 el.set_value(iter, 0, ticket.id);
559 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
560 if (_this.ticket != null && _this.ticket.id == ticket.id) {
561 _this.ticketsel.el.set_active_iter(iter);
566 _this.ticketsel.loading = false;
567 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
573 public class Xcls_Label12 : Object
576 private MergeBranch _this;
582 public Xcls_Label12(MergeBranch _owner )
585 this.el = new Gtk.Label( "Use this commit message" );
589 // set gobject values
590 this.el.justify = Gtk.Justification.RIGHT;
591 this.el.xalign = 0.900000f;
594 // user defined functions
597 public class Xcls_name : Object
600 private MergeBranch _this;
606 public Xcls_name(MergeBranch _owner )
610 this.el = new Gtk.Entry();
614 // set gobject values
615 this.el.visible = true;
618 // user defined functions
619 public void updateText () {
620 var ticket_id = _this.ticketsel.selectedTicketId();
622 RooTicket ticket = null;
623 if (ticket_id.length > 0){
624 ticket = RooTicket.singleton().getById(ticket_id);
627 var name = RooTicket.singleton().usernameLocal();
628 var action = _this.actionsel.selectedAction();
629 this.el.set_editable(true);
631 case "CLOSE": // merge changes and close..
632 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
634 case "LEAVE": // partial fix
635 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
637 case "MASTER": // merge master
638 case "EXIT": // just switch back...
639 this.el.set_editable(false);
640 this.el.set_text(""); // not relivant..
644 break; /// don't fix the text value.
651 public class Xcls_scrolled_window : Object
653 public Gtk.ScrolledWindow el;
654 private MergeBranch _this;
660 public Xcls_scrolled_window(MergeBranch _owner )
663 _this.scrolled_window = this;
664 this.el = new Gtk.ScrolledWindow( null, null );
668 // set gobject values
669 this.el.height_request = 500;
670 this.el.vexpand = true;
671 var child_0 = new Xcls_view( _this );
673 this.el.add ( child_0.el );
678 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
682 // user defined functions
684 public class Xcls_view : Object
686 public WebKit.WebView el;
687 private MergeBranch _this;
693 public Xcls_view(MergeBranch _owner )
697 this.el = new WebKit.WebView();
701 // set gobject values
704 // user defined functions
705 public void loadTicket (string tid) {
707 _this.el.get_size(out w, out h);
710 _this.scrolled_window.el.hide();
711 _this.el.resize(w, 150);
713 _this.scrolled_window.el.show();
714 _this.el.resize(w, 800);
717 var rs = RooTicket.singleton();
718 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
719 var hd = uri.get_http_headers();
720 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
721 hd.append("Authorization", "Basic %s".printf(authCode));
723 this.el.load_request(uri);
728 public class Xcls_spinner : Object
730 public Gtk.Spinner el;
731 private MergeBranch _this;
737 public Xcls_spinner(MergeBranch _owner )
740 _this.spinner = this;
741 this.el = new Gtk.Spinner();
745 // set gobject values
746 this.el.hexpand = true;
747 this.el.vexpand = true;
750 // user defined functions
754 public class Xcls_Button17 : Object
756 public Gtk.Button el;
757 private MergeBranch _this;
763 public Xcls_Button17(MergeBranch _owner )
766 this.el = new Gtk.Button();
770 // set gobject values
771 this.el.relief = Gtk.ReliefStyle.NONE;
772 this.el.label = "Cancel";
775 // user defined functions
778 public class Xcls_Button18 : Object
780 public Gtk.Button el;
781 private MergeBranch _this;
787 public Xcls_Button18(MergeBranch _owner )
790 this.el = new Gtk.Button();
794 // set gobject values
795 this.el.label = "Do Merge";
800 this.el.get_style_context().add_class("suggested-action");
804 // user defined functions