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();
157 public class Xcls_Box2 : Object
160 private MergeBranch _this;
166 public Xcls_Box2(MergeBranch _owner )
169 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
173 // set gobject values
174 var child_0 = new Xcls_table( _this );
176 this.el.pack_start ( child_0.el , false,false,0 );
177 var child_1 = new Xcls_scrolled_window( _this );
179 this.el.add ( child_1.el );
180 var child_2 = new Xcls_spinner( _this );
182 this.el.add ( child_2.el );
185 // user defined functions
187 public class Xcls_table : Object
190 private MergeBranch _this;
196 public Xcls_table(MergeBranch _owner )
200 this.el = new Gtk.Table( 2, 2, false );
204 // set gobject values
206 this.el.column_spacing = 2;
207 this.el.vexpand = false;
208 var child_0 = new Xcls_Label4( _this );
210 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
211 var child_1 = new Xcls_actionsel( _this );
213 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
214 var child_2 = new Xcls_Label8( _this );
216 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
217 var child_3 = new Xcls_ticketsel( _this );
219 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
220 var child_4 = new Xcls_Label12( _this );
222 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
223 var child_5 = new Xcls_name( _this );
225 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
228 // user defined functions
230 public class Xcls_Label4 : Object
233 private MergeBranch _this;
239 public Xcls_Label4(MergeBranch _owner )
242 this.el = new Gtk.Label( "Do what?" );
246 // set gobject values
247 this.el.justify = Gtk.Justification.RIGHT;
248 this.el.xalign = 0.900000f;
249 this.el.visible = true;
252 // user defined functions
255 public class Xcls_actionsel : Object
257 public Gtk.ComboBox el;
258 private MergeBranch _this;
265 public Xcls_actionsel(MergeBranch _owner )
268 _this.actionsel = this;
269 this.el = new Gtk.ComboBox();
272 this.loading = false;
274 // set gobject values
275 var child_0 = new Xcls_actioncellrenderer( _this );
277 this.el.pack_start ( child_0.el , true );
278 var child_1 = new Xcls_actionmodel( _this );
280 this.el.set_model ( child_1.el );
284 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
287 this.el.changed.connect( () => {
291 _this.name.updateText();
292 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
296 // user defined functions
297 public string selectedAction () {
301 this.el.get_active_iter (out iter);
302 _this.actionmodel.el.get_value (iter, 0, out val1);
304 return (string) val1;
307 public class Xcls_actioncellrenderer : Object
309 public Gtk.CellRendererText el;
310 private MergeBranch _this;
316 public Xcls_actioncellrenderer(MergeBranch _owner )
319 _this.actioncellrenderer = this;
320 this.el = new Gtk.CellRendererText();
324 // set gobject values
327 // user defined functions
330 public class Xcls_actionmodel : Object
332 public Gtk.ListStore el;
333 private MergeBranch _this;
339 public Xcls_actionmodel(MergeBranch _owner )
342 _this.actionmodel = this;
343 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
347 // set gobject values
350 // user defined functions
351 public void loadActions () {
355 _this.actionsel.loading = true;
364 el.set_value(iter, 0, "");
365 el.set_value(iter, 1, "-- select action --");
367 _this.actionsel.el.set_active_iter(iter);
370 el.set_value(iter, 0, "CLOSE");
371 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
375 el.set_value(iter, 0, "LEAVE");
376 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
379 el.set_value(iter, 0, "MASTER");
380 el.set_value(iter, 1, "Merge changes FROM master into this branch");
383 el.set_value(iter, 0, "EXIT");
384 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
388 _this.actionsel.loading = false;
389 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
395 public class Xcls_Label8 : Object
398 private MergeBranch _this;
404 public Xcls_Label8(MergeBranch _owner )
407 this.el = new Gtk.Label( "Select Ticket" );
411 // set gobject values
412 this.el.justify = Gtk.Justification.RIGHT;
413 this.el.xalign = 0.900000f;
414 this.el.visible = true;
417 // user defined functions
420 public class Xcls_ticketsel : Object
422 public Gtk.ComboBox el;
423 private MergeBranch _this;
430 public Xcls_ticketsel(MergeBranch _owner )
433 _this.ticketsel = this;
434 this.el = new Gtk.ComboBox();
439 // set gobject values
440 var child_0 = new Xcls_dbcellrenderer( _this );
442 this.el.pack_start ( child_0.el , true );
443 var child_1 = new Xcls_dbmodel( _this );
445 this.el.set_model ( child_1.el );
449 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
452 this.el.changed.connect( () => {
456 _this.view.loadTicket(this.selectedTicketId());
458 _this.name.updateText();
459 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
461 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
465 // user defined functions
466 public string selectedTicketId () {
471 this.el.get_active_iter (out iter);
472 _this.dbmodel.el.get_value (iter, 0, out val1);
475 return (string) val1;
482 public class Xcls_dbcellrenderer : Object
484 public Gtk.CellRendererText el;
485 private MergeBranch _this;
491 public Xcls_dbcellrenderer(MergeBranch _owner )
494 _this.dbcellrenderer = this;
495 this.el = new Gtk.CellRendererText();
499 // set gobject values
502 // user defined functions
505 public class Xcls_dbmodel : Object
507 public Gtk.ListStore el;
508 private MergeBranch _this;
514 public Xcls_dbmodel(MergeBranch _owner )
517 _this.dbmodel = this;
518 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
522 // set gobject values
525 // user defined functions
526 public void loadTickets () {
528 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
530 _this.ticketsel.loading = true;
537 el.set_value(iter, 0, "");
538 el.set_value(iter, 1, "-- select a ticket --");
540 _this.ticketsel.el.set_active_iter(iter);
542 if (_this.ticket != null && _this.ticket.id == "-1") {
544 el.set_value(iter, 0, "-1");
545 el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
546 _this.ticketsel.el.set_active_iter(iter);
552 var tickets = RooTicket.singleton().tickets;
553 foreach(var ticket in tickets) {
557 el.set_value(iter, 0, ticket.id);
558 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
559 if (_this.ticket != null && _this.ticket.id == ticket.id) {
560 _this.ticketsel.el.set_active_iter(iter);
565 _this.ticketsel.loading = false;
566 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
572 public class Xcls_Label12 : Object
575 private MergeBranch _this;
581 public Xcls_Label12(MergeBranch _owner )
584 this.el = new Gtk.Label( "Use this commit message" );
588 // set gobject values
589 this.el.justify = Gtk.Justification.RIGHT;
590 this.el.xalign = 0.900000f;
593 // user defined functions
596 public class Xcls_name : Object
599 private MergeBranch _this;
605 public Xcls_name(MergeBranch _owner )
609 this.el = new Gtk.Entry();
613 // set gobject values
614 this.el.visible = true;
617 // user defined functions
618 public void updateText () {
619 var ticket_id = _this.ticketsel.selectedTicketId();
621 RooTicket ticket = null;
622 if (ticket_id.length > 0){
623 ticket = RooTicket.singleton().getById(ticket_id);
626 var name = RooTicket.singleton().usernameLocal();
627 var action = _this.actionsel.selectedAction();
628 this.el.set_editable(true);
630 case "CLOSE": // merge changes and close..
631 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
633 case "LEAVE": // partial fix
634 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
636 case "MASTER": // merge master
637 case "EXIT": // just switch back...
638 this.el.set_editable(false);
639 this.el.set_text(""); // not relivant..
643 break; /// don't fix the text value.
650 public class Xcls_scrolled_window : Object
652 public Gtk.ScrolledWindow el;
653 private MergeBranch _this;
659 public Xcls_scrolled_window(MergeBranch _owner )
662 _this.scrolled_window = this;
663 this.el = new Gtk.ScrolledWindow( null, null );
667 // set gobject values
668 this.el.height_request = 500;
669 this.el.vexpand = true;
670 var child_0 = new Xcls_view( _this );
672 this.el.add ( child_0.el );
677 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
681 // user defined functions
683 public class Xcls_view : Object
685 public WebKit.WebView el;
686 private MergeBranch _this;
692 public Xcls_view(MergeBranch _owner )
696 this.el = new WebKit.WebView();
700 // set gobject values
703 // user defined functions
704 public void loadTicket (string tid) {
706 _this.el.get_size(out w, out h);
709 _this.scrolled_window.el.hide();
710 _this.el.resize(w, 150);
712 _this.scrolled_window.el.show();
713 _this.el.resize(w, 800);
716 var rs = RooTicket.singleton();
717 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
718 var hd = uri.get_http_headers();
719 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
720 hd.append("Authorization", "Basic %s".printf(authCode));
722 this.el.load_request(uri);
727 public class Xcls_spinner : Object
729 public Gtk.Spinner el;
730 private MergeBranch _this;
736 public Xcls_spinner(MergeBranch _owner )
739 _this.spinner = this;
740 this.el = new Gtk.Spinner();
744 // set gobject values
745 this.el.hexpand = true;
746 this.el.vexpand = true;
749 // user defined functions
753 public class Xcls_Button17 : Object
755 public Gtk.Button el;
756 private MergeBranch _this;
762 public Xcls_Button17(MergeBranch _owner )
765 this.el = new Gtk.Button();
769 // set gobject values
770 this.el.relief = Gtk.ReliefStyle.NONE;
771 this.el.label = "Cancel";
774 // user defined functions
777 public class Xcls_Button18 : Object
779 public Gtk.Button el;
780 private MergeBranch _this;
786 public Xcls_Button18(MergeBranch _owner )
789 this.el = new Gtk.Button();
793 // set gobject values
794 this.el.label = "Do Merge";
799 this.el.get_style_context().add_class("suggested-action");
803 // user defined functions