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_label_ticket label_ticket;
25 public Xcls_diff_view diff_view;
26 public Xcls_scrolled_window scrolled_window;
27 public Xcls_view view;
28 public Xcls_spinner spinner;
32 public RooTicket? ticket;
39 this.el = new Gtk.Dialog();
46 this.el.title = "Merge Branch";
47 this.el.default_height = 200;
48 this.el.default_width = 500;
49 this.el.deletable = true;
51 var child_0 = new Xcls_Box2( _this );
53 this.el.get_content_area().add ( child_0.el );
54 var child_1 = new Xcls_Button24( _this );
56 this.el.add_action_widget ( child_1.el , 0 );
57 var child_2 = new Xcls_Button25( _this );
59 this.el.add_action_widget ( child_2.el , 1 );
62 this.el.delete_event.connect( (self, event) => {
67 this.el.response.connect( (self, response_id) => {
69 GLib.debug("got %d", (int) response_id);
70 if (response_id < 1) {
73 GitMonitor.gitmonitor.start();
77 // have they selected a ticket..
78 // make that the current active ticket?
79 // we really need to store locally what ticket is being worked on..
80 // in theory we could be working on multiple project and not merging..
81 // -- each repo would have their active ticket (only one per repo)
82 // -- so we could just store that in there
83 // -- initial load can check the contents of the ticket files on first scan.
84 var ticket_id = _this.ticketsel.selectedTicketId();
86 if (this.repo != null) {
87 var bn = _this.name.el.get_text();
88 if (ticket_id != "" ) {
89 this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
91 this.repo.createBranchNamed(bn);
96 if (this.repo != null) {
98 _this.actionsel.selectedAction(),
99 _this.ticketsel.selectedTicketId(),
100 _this.name.el.get_text()
105 _this.actionsel.selectedAction(),
106 _this.ticketsel.selectedTicketId(),
107 _this.name.el.get_text()
110 this.running = false;
114 GitMonitor.gitmonitor.start();
120 // user defined functions
121 public void show ( RooTicket ticket, GitRepo? repo )
123 // this.el.set_gravity(Gdk.Gravity.NORTH);
127 GitMonitor.gitmonitor.stop();
131 _this.table.el.hide();
132 _this.scrolled_window.el.hide();
133 _this.spinner.el.show();
134 _this.spinner.el.start();
135 this.el.set_keep_above(true);
136 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
137 GLib.debug("Loading tickets");
140 this.ticket = ticket;
144 Timeout.add_seconds(1, () => {
145 _this.diff_view.el.get_buffer().set_text(
146 repo != null ? repo.previewMerge() : GitRepo.previewMerges(ticket.id)
148 // if we are not working on a ticket, then we should be able to pick one?
149 _this.dbmodel.loadTickets();
150 _this.actionmodel.loadActions();
151 _this.view.loadTicket(ticket.id);
152 _this.spinner.el.stop();
153 _this.spinner.el.hide();
155 this.table.el.show();
162 public class Xcls_Box2 : Object
165 private MergeBranch _this;
171 public Xcls_Box2(MergeBranch _owner )
174 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
178 // set gobject values
179 var child_0 = new Xcls_table( _this );
181 this.el.pack_start ( child_0.el , false,false,0 );
182 var child_1 = new Xcls_Notebook14( _this );
184 this.el.add ( child_1.el );
185 var child_2 = new Xcls_spinner( _this );
187 this.el.add ( child_2.el );
190 // user defined functions
192 public class Xcls_table : Object
195 private MergeBranch _this;
201 public Xcls_table(MergeBranch _owner )
205 this.el = new Gtk.Table( 2, 2, false );
209 // set gobject values
211 this.el.column_spacing = 2;
212 this.el.vexpand = false;
213 var child_0 = new Xcls_Label4( _this );
215 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
216 var child_1 = new Xcls_actionsel( _this );
218 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
219 var child_2 = new Xcls_Label8( _this );
221 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
222 var child_3 = new Xcls_ticketsel( _this );
224 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
225 var child_4 = new Xcls_Label12( _this );
227 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
228 var child_5 = new Xcls_name( _this );
230 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
233 // user defined functions
235 public class Xcls_Label4 : Object
238 private MergeBranch _this;
244 public Xcls_Label4(MergeBranch _owner )
247 this.el = new Gtk.Label( "Do what?" );
251 // set gobject values
252 this.el.justify = Gtk.Justification.RIGHT;
253 this.el.xalign = 0.900000f;
254 this.el.visible = true;
257 // user defined functions
260 public class Xcls_actionsel : Object
262 public Gtk.ComboBox el;
263 private MergeBranch _this;
270 public Xcls_actionsel(MergeBranch _owner )
273 _this.actionsel = this;
274 this.el = new Gtk.ComboBox();
277 this.loading = false;
279 // set gobject values
280 var child_0 = new Xcls_actioncellrenderer( _this );
282 this.el.pack_start ( child_0.el , true );
283 var child_1 = new Xcls_actionmodel( _this );
285 this.el.set_model ( child_1.el );
289 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
292 this.el.changed.connect( () => {
296 _this.name.updateText();
297 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
301 // user defined functions
302 public string selectedAction () {
306 this.el.get_active_iter (out iter);
307 _this.actionmodel.el.get_value (iter, 0, out val1);
309 return (string) val1;
312 public class Xcls_actioncellrenderer : Object
314 public Gtk.CellRendererText el;
315 private MergeBranch _this;
321 public Xcls_actioncellrenderer(MergeBranch _owner )
324 _this.actioncellrenderer = this;
325 this.el = new Gtk.CellRendererText();
329 // set gobject values
332 // user defined functions
335 public class Xcls_actionmodel : Object
337 public Gtk.ListStore el;
338 private MergeBranch _this;
344 public Xcls_actionmodel(MergeBranch _owner )
347 _this.actionmodel = this;
348 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
352 // set gobject values
355 // user defined functions
356 public void loadActions () {
360 _this.actionsel.loading = true;
369 el.set_value(iter, 0, "");
370 el.set_value(iter, 1, "-- select action --");
372 _this.actionsel.el.set_active_iter(iter);
375 el.set_value(iter, 0, "CLOSE");
376 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
380 el.set_value(iter, 0, "LEAVE");
381 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
384 el.set_value(iter, 0, "MASTER");
385 el.set_value(iter, 1, "Merge changes FROM master into this branch");
388 el.set_value(iter, 0, "EXIT");
389 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
393 _this.actionsel.loading = false;
394 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
400 public class Xcls_Label8 : Object
403 private MergeBranch _this;
409 public Xcls_Label8(MergeBranch _owner )
412 this.el = new Gtk.Label( "Select Ticket" );
416 // set gobject values
417 this.el.justify = Gtk.Justification.RIGHT;
418 this.el.xalign = 0.900000f;
419 this.el.visible = true;
422 // user defined functions
425 public class Xcls_ticketsel : Object
427 public Gtk.ComboBox el;
428 private MergeBranch _this;
435 public Xcls_ticketsel(MergeBranch _owner )
438 _this.ticketsel = this;
439 this.el = new Gtk.ComboBox();
444 // set gobject values
445 var child_0 = new Xcls_dbcellrenderer( _this );
447 this.el.pack_start ( child_0.el , true );
448 var child_1 = new Xcls_dbmodel( _this );
450 this.el.set_model ( child_1.el );
454 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
457 this.el.changed.connect( () => {
461 _this.view.loadTicket(this.selectedTicketId());
463 _this.name.updateText();
464 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
466 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
470 // user defined functions
471 public string selectedTicketId () {
476 this.el.get_active_iter (out iter);
477 _this.dbmodel.el.get_value (iter, 0, out val1);
480 return (string) val1;
487 public class Xcls_dbcellrenderer : Object
489 public Gtk.CellRendererText el;
490 private MergeBranch _this;
496 public Xcls_dbcellrenderer(MergeBranch _owner )
499 _this.dbcellrenderer = this;
500 this.el = new Gtk.CellRendererText();
504 // set gobject values
507 // user defined functions
510 public class Xcls_dbmodel : Object
512 public Gtk.ListStore el;
513 private MergeBranch _this;
519 public Xcls_dbmodel(MergeBranch _owner )
522 _this.dbmodel = this;
523 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
527 // set gobject values
530 // user defined functions
531 public void loadTickets () {
533 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
535 _this.ticketsel.loading = true;
542 el.set_value(iter, 0, "");
543 el.set_value(iter, 1, "-- select a ticket --");
545 _this.ticketsel.el.set_active_iter(iter);
547 if (_this.ticket != null && _this.ticket.id == "-1") {
549 el.set_value(iter, 0, "-1");
550 el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
551 _this.ticketsel.el.set_active_iter(iter);
557 var tickets = RooTicket.singleton().tickets;
558 foreach(var ticket in tickets) {
562 el.set_value(iter, 0, ticket.id);
563 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
564 if (_this.ticket != null && _this.ticket.id == ticket.id) {
565 _this.ticketsel.el.set_active_iter(iter);
570 _this.ticketsel.loading = false;
571 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
577 public class Xcls_Label12 : Object
580 private MergeBranch _this;
586 public Xcls_Label12(MergeBranch _owner )
589 this.el = new Gtk.Label( "Use this commit message" );
593 // set gobject values
594 this.el.justify = Gtk.Justification.RIGHT;
595 this.el.xalign = 0.900000f;
598 // user defined functions
601 public class Xcls_name : Object
604 private MergeBranch _this;
610 public Xcls_name(MergeBranch _owner )
614 this.el = new Gtk.Entry();
618 // set gobject values
619 this.el.visible = true;
622 // user defined functions
623 public void updateText () {
624 var ticket_id = _this.ticketsel.selectedTicketId();
626 RooTicket ticket = null;
627 if (ticket_id.length > 0){
628 ticket = RooTicket.singleton().getById(ticket_id);
631 var name = RooTicket.singleton().usernameLocal();
632 var action = _this.actionsel.selectedAction();
633 this.el.set_editable(true);
635 case "CLOSE": // merge changes and close..
636 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
638 case "LEAVE": // partial fix
639 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
641 case "MASTER": // merge master
642 case "EXIT": // just switch back...
643 this.el.set_editable(false);
644 this.el.set_text(""); // not relivant..
648 break; /// don't fix the text value.
655 public class Xcls_Notebook14 : Object
657 public Gtk.Notebook el;
658 private MergeBranch _this;
664 public Xcls_Notebook14(MergeBranch _owner )
667 this.el = new Gtk.Notebook();
671 // set gobject values
672 this.el.vexpand = true;
673 var child_0 = new Xcls_label_diff( _this );
675 var child_1 = new Xcls_label_ticket( _this );
677 var child_2 = new Xcls_Box17( _this );
679 this.el.append_page ( child_2.el , _this.label_diff.el );
680 var child_3 = new Xcls_Box20( _this );
682 this.el.append_page ( child_3.el , _this.label_ticket.el );
685 // user defined functions
687 public class Xcls_label_diff : Object
690 private MergeBranch _this;
696 public Xcls_label_diff(MergeBranch _owner )
699 _this.label_diff = this;
700 this.el = new Gtk.Label( "Projected Commit Diff" );
704 // set gobject values
707 // user defined functions
710 public class Xcls_label_ticket : Object
713 private MergeBranch _this;
719 public Xcls_label_ticket(MergeBranch _owner )
722 _this.label_ticket = this;
723 this.el = new Gtk.Label( "Ticket Details" );
727 // set gobject values
730 // user defined functions
733 public class Xcls_Box17 : Object
736 private MergeBranch _this;
742 public Xcls_Box17(MergeBranch _owner )
745 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
749 // set gobject values
750 this.el.homogeneous = false;
751 var child_0 = new Xcls_ScrolledWindow18( _this );
753 this.el.pack_start ( child_0.el , true,true,0 );
756 // user defined functions
758 public class Xcls_ScrolledWindow18 : Object
760 public Gtk.ScrolledWindow el;
761 private MergeBranch _this;
767 public Xcls_ScrolledWindow18(MergeBranch _owner )
770 this.el = new Gtk.ScrolledWindow( null, null );
774 // set gobject values
775 this.el.height_request = 400;
776 var child_0 = new Xcls_diff_view( _this );
778 this.el.add ( child_0.el );
781 // user defined functions
783 public class Xcls_diff_view : Object
785 public Gtk.SourceView el;
786 private MergeBranch _this;
792 public Xcls_diff_view(MergeBranch _owner )
795 _this.diff_view = this;
796 this.el = new Gtk.SourceView();
802 var description = Pango.FontDescription.from_string("monospace");
803 description.set_size(9000);
804 this.el.override_font(description);
805 var lm = Gtk.SourceLanguageManager.get_default();
807 ((Gtk.SourceBuffer)(this.el.get_buffer())).set_language(
808 lm.get_language("diff")
812 // user defined functions
817 public class Xcls_Box20 : Object
820 private MergeBranch _this;
826 public Xcls_Box20(MergeBranch _owner )
829 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
833 // set gobject values
834 this.el.homogeneous = false;
835 var child_0 = new Xcls_scrolled_window( _this );
837 this.el.add ( child_0.el );
840 // user defined functions
842 public class Xcls_scrolled_window : Object
844 public Gtk.ScrolledWindow el;
845 private MergeBranch _this;
851 public Xcls_scrolled_window(MergeBranch _owner )
854 _this.scrolled_window = this;
855 this.el = new Gtk.ScrolledWindow( null, null );
859 // set gobject values
860 this.el.height_request = 500;
861 this.el.vexpand = true;
862 var child_0 = new Xcls_view( _this );
864 this.el.add ( child_0.el );
869 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
873 // user defined functions
875 public class Xcls_view : Object
877 public WebKit.WebView el;
878 private MergeBranch _this;
884 public Xcls_view(MergeBranch _owner )
888 this.el = new WebKit.WebView();
892 // set gobject values
895 // user defined functions
896 public void loadTicket (string tid) {
898 _this.el.get_size(out w, out h);
901 _this.scrolled_window.el.hide();
902 _this.el.resize(w, 150);
904 _this.scrolled_window.el.show();
905 _this.el.resize(w, 800);
908 var rs = RooTicket.singleton();
909 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
910 var hd = uri.get_http_headers();
911 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
912 hd.append("Authorization", "Basic %s".printf(authCode));
914 this.el.load_request(uri);
921 public class Xcls_spinner : Object
923 public Gtk.Spinner el;
924 private MergeBranch _this;
930 public Xcls_spinner(MergeBranch _owner )
933 _this.spinner = this;
934 this.el = new Gtk.Spinner();
938 // set gobject values
939 this.el.hexpand = true;
940 this.el.vexpand = true;
943 // user defined functions
947 public class Xcls_Button24 : Object
949 public Gtk.Button el;
950 private MergeBranch _this;
956 public Xcls_Button24(MergeBranch _owner )
959 this.el = new Gtk.Button();
963 // set gobject values
964 this.el.relief = Gtk.ReliefStyle.NONE;
965 this.el.label = "Cancel";
968 // user defined functions
971 public class Xcls_Button25 : Object
973 public Gtk.Button el;
974 private MergeBranch _this;
980 public Xcls_Button25(MergeBranch _owner )
983 this.el = new Gtk.Button();
987 // set gobject values
988 this.el.label = "Do Merge";
993 this.el.get_style_context().add_class("suggested-action");
997 // user defined functions