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_label_diff label_diff;
24 public Xcls_scrolled_window scrolled_window;
25 public Xcls_view view;
26 public Xcls_spinner spinner;
30 public RooTicket? ticket;
37 this.el = new Gtk.Dialog();
44 this.el.title = "Merge Branch";
45 this.el.default_height = 200;
46 this.el.default_width = 500;
47 this.el.deletable = true;
49 var child_0 = new Xcls_Box2( _this );
51 this.el.get_content_area().add ( child_0.el );
52 var child_1 = new Xcls_Button20( _this );
54 this.el.add_action_widget ( child_1.el , 0 );
55 var child_2 = new Xcls_Button21( _this );
57 this.el.add_action_widget ( child_2.el , 1 );
60 this.el.delete_event.connect( (self, event) => {
65 this.el.response.connect( (self, response_id) => {
67 GLib.debug("got %d", (int) response_id);
68 if (response_id < 1) {
71 GitMonitor.gitmonitor.start();
75 // have they selected a ticket..
76 // make that the current active ticket?
77 // we really need to store locally what ticket is being worked on..
78 // in theory we could be working on multiple project and not merging..
79 // -- each repo would have their active ticket (only one per repo)
80 // -- so we could just store that in there
81 // -- initial load can check the contents of the ticket files on first scan.
82 var ticket_id = _this.ticketsel.selectedTicketId();
84 if (this.repo != null) {
85 var bn = _this.name.el.get_text();
86 if (ticket_id != "" ) {
87 this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
89 this.repo.createBranchNamed(bn);
94 if (this.repo != null) {
96 _this.actionsel.selectedAction(),
97 _this.ticketsel.selectedTicketId(),
98 _this.name.el.get_text()
103 _this.actionsel.selectedAction(),
104 _this.ticketsel.selectedTicketId(),
105 _this.name.el.get_text()
108 this.running = false;
112 GitMonitor.gitmonitor.start();
118 // user defined functions
119 public void show ( RooTicket ticket, GitRepo? repo )
121 // this.el.set_gravity(Gdk.Gravity.NORTH);
125 GitMonitor.gitmonitor.stop();
129 _this.table.el.hide();
130 _this.scrolled_window.el.hide();
131 _this.spinner.el.show();
132 _this.spinner.el.start();
133 this.el.set_keep_above(true);
134 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
135 GLib.debug("Loading tickets");
140 this.ticket = ticket;
144 Timeout.add_seconds(1, () => {
146 // if we are not working on a ticket, then we should be able to pick one?
147 _this.dbmodel.loadTickets();
148 _this.actionmodel.loadActions();
149 _this.view.loadTicket(ticket.id);
150 _this.spinner.el.stop();
151 _this.spinner.el.hide();
153 this.table.el.show();
160 public class Xcls_Box2 : Object
163 private MergeBranch _this;
169 public Xcls_Box2(MergeBranch _owner )
172 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
176 // set gobject values
177 var child_0 = new Xcls_table( _this );
179 this.el.pack_start ( child_0.el , false,false,0 );
180 var child_1 = new Xcls_Notebook14( _this );
182 this.el.add ( child_1.el );
183 var child_2 = new Xcls_scrolled_window( _this );
185 this.el.add ( child_2.el );
186 var child_3 = new Xcls_spinner( _this );
188 this.el.add ( child_3.el );
191 // user defined functions
193 public class Xcls_table : Object
196 private MergeBranch _this;
202 public Xcls_table(MergeBranch _owner )
206 this.el = new Gtk.Table( 2, 2, false );
210 // set gobject values
212 this.el.column_spacing = 2;
213 this.el.vexpand = false;
214 var child_0 = new Xcls_Label4( _this );
216 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
217 var child_1 = new Xcls_actionsel( _this );
219 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
220 var child_2 = new Xcls_Label8( _this );
222 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
223 var child_3 = new Xcls_ticketsel( _this );
225 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
226 var child_4 = new Xcls_Label12( _this );
228 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
229 var child_5 = new Xcls_name( _this );
231 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
234 // user defined functions
236 public class Xcls_Label4 : Object
239 private MergeBranch _this;
245 public Xcls_Label4(MergeBranch _owner )
248 this.el = new Gtk.Label( "Do what?" );
252 // set gobject values
253 this.el.justify = Gtk.Justification.RIGHT;
254 this.el.xalign = 0.900000f;
255 this.el.visible = true;
258 // user defined functions
261 public class Xcls_actionsel : Object
263 public Gtk.ComboBox el;
264 private MergeBranch _this;
271 public Xcls_actionsel(MergeBranch _owner )
274 _this.actionsel = this;
275 this.el = new Gtk.ComboBox();
278 this.loading = false;
280 // set gobject values
281 var child_0 = new Xcls_actioncellrenderer( _this );
283 this.el.pack_start ( child_0.el , true );
284 var child_1 = new Xcls_actionmodel( _this );
286 this.el.set_model ( child_1.el );
290 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
293 this.el.changed.connect( () => {
297 _this.name.updateText();
298 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
302 // user defined functions
303 public string selectedAction () {
307 this.el.get_active_iter (out iter);
308 _this.actionmodel.el.get_value (iter, 0, out val1);
310 return (string) val1;
313 public class Xcls_actioncellrenderer : Object
315 public Gtk.CellRendererText el;
316 private MergeBranch _this;
322 public Xcls_actioncellrenderer(MergeBranch _owner )
325 _this.actioncellrenderer = this;
326 this.el = new Gtk.CellRendererText();
330 // set gobject values
333 // user defined functions
336 public class Xcls_actionmodel : Object
338 public Gtk.ListStore el;
339 private MergeBranch _this;
345 public Xcls_actionmodel(MergeBranch _owner )
348 _this.actionmodel = this;
349 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
353 // set gobject values
356 // user defined functions
357 public void loadActions () {
361 _this.actionsel.loading = true;
370 el.set_value(iter, 0, "");
371 el.set_value(iter, 1, "-- select action --");
373 _this.actionsel.el.set_active_iter(iter);
376 el.set_value(iter, 0, "CLOSE");
377 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
381 el.set_value(iter, 0, "LEAVE");
382 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
385 el.set_value(iter, 0, "MASTER");
386 el.set_value(iter, 1, "Merge changes FROM master into this branch");
389 el.set_value(iter, 0, "EXIT");
390 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
394 _this.actionsel.loading = false;
395 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
401 public class Xcls_Label8 : Object
404 private MergeBranch _this;
410 public Xcls_Label8(MergeBranch _owner )
413 this.el = new Gtk.Label( "Select Ticket" );
417 // set gobject values
418 this.el.justify = Gtk.Justification.RIGHT;
419 this.el.xalign = 0.900000f;
420 this.el.visible = true;
423 // user defined functions
426 public class Xcls_ticketsel : Object
428 public Gtk.ComboBox el;
429 private MergeBranch _this;
436 public Xcls_ticketsel(MergeBranch _owner )
439 _this.ticketsel = this;
440 this.el = new Gtk.ComboBox();
445 // set gobject values
446 var child_0 = new Xcls_dbcellrenderer( _this );
448 this.el.pack_start ( child_0.el , true );
449 var child_1 = new Xcls_dbmodel( _this );
451 this.el.set_model ( child_1.el );
455 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
458 this.el.changed.connect( () => {
462 _this.view.loadTicket(this.selectedTicketId());
464 _this.name.updateText();
465 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
467 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
471 // user defined functions
472 public string selectedTicketId () {
477 this.el.get_active_iter (out iter);
478 _this.dbmodel.el.get_value (iter, 0, out val1);
481 return (string) val1;
488 public class Xcls_dbcellrenderer : Object
490 public Gtk.CellRendererText el;
491 private MergeBranch _this;
497 public Xcls_dbcellrenderer(MergeBranch _owner )
500 _this.dbcellrenderer = this;
501 this.el = new Gtk.CellRendererText();
505 // set gobject values
508 // user defined functions
511 public class Xcls_dbmodel : Object
514 private MergeBranch _this;
520 public Xcls_dbmodel(MergeBranch _owner )
523 _this.dbmodel = this;
524 this.el = new Gtk.();
529 // user defined functions
530 public void loadTickets () {
532 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
534 _this.ticketsel.loading = true;
541 el.set_value(iter, 0, "");
542 el.set_value(iter, 1, "-- select a ticket --");
544 _this.ticketsel.el.set_active_iter(iter);
546 if (_this.ticket != null && _this.ticket.id == "-1") {
548 el.set_value(iter, 0, "-1");
549 el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
550 _this.ticketsel.el.set_active_iter(iter);
556 var tickets = RooTicket.singleton().tickets;
557 foreach(var ticket in tickets) {
561 el.set_value(iter, 0, ticket.id);
562 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
563 if (_this.ticket != null && _this.ticket.id == ticket.id) {
564 _this.ticketsel.el.set_active_iter(iter);
569 _this.ticketsel.loading = false;
570 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
576 public class Xcls_Label12 : Object
579 private MergeBranch _this;
585 public Xcls_Label12(MergeBranch _owner )
588 this.el = new Gtk.Label( "Use this commit message" );
592 // set gobject values
593 this.el.justify = Gtk.Justification.RIGHT;
594 this.el.xalign = 0.900000f;
597 // user defined functions
600 public class Xcls_name : Object
603 private MergeBranch _this;
609 public Xcls_name(MergeBranch _owner )
613 this.el = new Gtk.Entry();
617 // set gobject values
618 this.el.visible = true;
621 // user defined functions
622 public void updateText () {
623 var ticket_id = _this.ticketsel.selectedTicketId();
625 RooTicket ticket = null;
626 if (ticket_id.length > 0){
627 ticket = RooTicket.singleton().getById(ticket_id);
630 var name = RooTicket.singleton().usernameLocal();
631 var action = _this.actionsel.selectedAction();
632 this.el.set_editable(true);
634 case "CLOSE": // merge changes and close..
635 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
637 case "LEAVE": // partial fix
638 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
640 case "MASTER": // merge master
641 case "EXIT": // just switch back...
642 this.el.set_editable(false);
643 this.el.set_text(""); // not relivant..
647 break; /// don't fix the text value.
654 public class Xcls_Notebook14 : Object
656 public Gtk.Notebook el;
657 private MergeBranch _this;
663 public Xcls_Notebook14(MergeBranch _owner )
666 this.el = new Gtk.Notebook();
670 // set gobject values
671 this.el.vexpand = true;
672 var child_0 = new Xcls_label_diff( _this );
674 var child_1 = new Xcls_Label16( _this );
678 // user defined functions
680 public class Xcls_label_diff : Object
683 private MergeBranch _this;
689 public Xcls_label_diff(MergeBranch _owner )
692 _this.label_diff = this;
693 this.el = new Gtk.Label( "Projected Commit Diff" );
697 // set gobject values
700 // user defined functions
703 public class Xcls_Label16 : Object
706 private MergeBranch _this;
712 public Xcls_Label16(MergeBranch _owner )
715 this.el = new Gtk.Label( "Ticket Details" );
719 // set gobject values
722 // user defined functions
726 public class Xcls_scrolled_window : Object
728 public Gtk.ScrolledWindow el;
729 private MergeBranch _this;
735 public Xcls_scrolled_window(MergeBranch _owner )
738 _this.scrolled_window = this;
739 this.el = new Gtk.ScrolledWindow( null, null );
743 // set gobject values
744 this.el.height_request = 500;
745 this.el.vexpand = true;
746 var child_0 = new Xcls_view( _this );
748 this.el.add ( child_0.el );
753 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
757 // user defined functions
759 public class Xcls_view : Object
761 public WebKit.WebView el;
762 private MergeBranch _this;
768 public Xcls_view(MergeBranch _owner )
772 this.el = new WebKit.WebView();
776 // set gobject values
779 // user defined functions
780 public void loadTicket (string tid) {
782 _this.el.get_size(out w, out h);
785 _this.scrolled_window.el.hide();
786 _this.el.resize(w, 150);
788 _this.scrolled_window.el.show();
789 _this.el.resize(w, 800);
792 var rs = RooTicket.singleton();
793 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
794 var hd = uri.get_http_headers();
795 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
796 hd.append("Authorization", "Basic %s".printf(authCode));
798 this.el.load_request(uri);
803 public class Xcls_spinner : Object
805 public Gtk.Spinner el;
806 private MergeBranch _this;
812 public Xcls_spinner(MergeBranch _owner )
815 _this.spinner = this;
816 this.el = new Gtk.Spinner();
820 // set gobject values
821 this.el.hexpand = true;
822 this.el.vexpand = true;
825 // user defined functions
829 public class Xcls_Button20 : Object
831 public Gtk.Button el;
832 private MergeBranch _this;
838 public Xcls_Button20(MergeBranch _owner )
841 this.el = new Gtk.Button();
845 // set gobject values
846 this.el.relief = Gtk.ReliefStyle.NONE;
847 this.el.label = "Cancel";
850 // user defined functions
853 public class Xcls_Button21 : Object
855 public Gtk.Button el;
856 private MergeBranch _this;
862 public Xcls_Button21(MergeBranch _owner )
865 this.el = new Gtk.Button();
869 // set gobject values
870 this.el.label = "Do Merge";
875 this.el.get_style_context().add_class("suggested-action");
879 // user defined functions