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();
115 this.el.show.connect( (self) => {
122 // user defined functions
123 public void show ( RooTicket ticket, GitRepo? repo )
125 // this.el.set_gravity(Gdk.Gravity.NORTH);
129 GitMonitor.gitmonitor.stop();
131 this.ticket = ticket;
134 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
135 GLib.debug("Loading tickets");
139 _this.dbmodel.loadTickets();
140 _this.actionmodel.loadActions();
141 _this.view.loadTicket(ticket.id);
144 public class Xcls_Box2 : Object
147 private MergeBranch _this;
153 public Xcls_Box2(MergeBranch _owner )
156 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
160 // set gobject values
161 var child_0 = new Xcls_table( _this );
163 this.el.pack_start ( child_0.el , false,false,0 );
164 var child_1 = new Xcls_scrolled_window( _this );
166 this.el.add ( child_1.el );
167 var child_2 = new Xcls_spinner( _this );
169 this.el.add ( child_2.el );
172 // user defined functions
174 public class Xcls_table : Object
177 private MergeBranch _this;
183 public Xcls_table(MergeBranch _owner )
187 this.el = new Gtk.Table( 2, 2, false );
191 // set gobject values
193 this.el.column_spacing = 2;
194 this.el.vexpand = false;
195 var child_0 = new Xcls_Label4( _this );
197 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
198 var child_1 = new Xcls_actionsel( _this );
200 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
201 var child_2 = new Xcls_Label8( _this );
203 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
204 var child_3 = new Xcls_ticketsel( _this );
206 this.el.attach_defaults ( child_3.el , 1,2,1,2 );
207 var child_4 = new Xcls_Label12( _this );
209 this.el.attach_defaults ( child_4.el , 0,1,2,3 );
210 var child_5 = new Xcls_name( _this );
212 this.el.attach_defaults ( child_5.el , 1,2,2,3 );
215 // user defined functions
217 public class Xcls_Label4 : Object
220 private MergeBranch _this;
226 public Xcls_Label4(MergeBranch _owner )
229 this.el = new Gtk.Label( "Do what?" );
233 // set gobject values
234 this.el.justify = Gtk.Justification.RIGHT;
235 this.el.xalign = 0.900000f;
236 this.el.visible = true;
239 // user defined functions
242 public class Xcls_actionsel : Object
244 public Gtk.ComboBox el;
245 private MergeBranch _this;
252 public Xcls_actionsel(MergeBranch _owner )
255 _this.actionsel = this;
256 this.el = new Gtk.ComboBox();
259 this.loading = false;
261 // set gobject values
262 var child_0 = new Xcls_actioncellrenderer( _this );
264 this.el.pack_start ( child_0.el , true );
265 var child_1 = new Xcls_actionmodel( _this );
267 this.el.set_model ( child_1.el );
271 this.el.add_attribute(_this.actioncellrenderer.el , "markup", 1 );
274 this.el.changed.connect( () => {
278 _this.name.updateText();
279 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
283 // user defined functions
284 public string selectedAction () {
288 this.el.get_active_iter (out iter);
289 _this.actionmodel.el.get_value (iter, 0, out val1);
291 return (string) val1;
294 public class Xcls_actioncellrenderer : Object
296 public Gtk.CellRendererText el;
297 private MergeBranch _this;
303 public Xcls_actioncellrenderer(MergeBranch _owner )
306 _this.actioncellrenderer = this;
307 this.el = new Gtk.CellRendererText();
311 // set gobject values
314 // user defined functions
317 public class Xcls_actionmodel : Object
319 public Gtk.ListStore el;
320 private MergeBranch _this;
326 public Xcls_actionmodel(MergeBranch _owner )
329 _this.actionmodel = this;
330 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
334 // set gobject values
337 // user defined functions
338 public void loadActions () {
342 _this.actionsel.loading = true;
351 el.set_value(iter, 0, "");
352 el.set_value(iter, 1, "-- select action --");
354 _this.actionsel.el.set_active_iter(iter);
357 el.set_value(iter, 0, "CLOSE");
358 el.set_value(iter, 1, "Merge changes to master - and CLOSE ticket");
362 el.set_value(iter, 0, "LEAVE");
363 el.set_value(iter, 1, "Merge changes to master - and LEAVE ticket open");
366 el.set_value(iter, 0, "MASTER");
367 el.set_value(iter, 1, "Merge changes FROM master into this branch");
370 el.set_value(iter, 0, "EXIT");
371 el.set_value(iter, 1, "Switch back to MASTER branch - no merge");
375 _this.actionsel.loading = false;
376 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
382 public class Xcls_Label8 : Object
385 private MergeBranch _this;
391 public Xcls_Label8(MergeBranch _owner )
394 this.el = new Gtk.Label( "Select Ticket" );
398 // set gobject values
399 this.el.justify = Gtk.Justification.RIGHT;
400 this.el.xalign = 0.900000f;
401 this.el.visible = true;
404 // user defined functions
407 public class Xcls_ticketsel : Object
409 public Gtk.ComboBox el;
410 private MergeBranch _this;
417 public Xcls_ticketsel(MergeBranch _owner )
420 _this.ticketsel = this;
421 this.el = new Gtk.ComboBox();
426 // set gobject values
427 var child_0 = new Xcls_dbcellrenderer( _this );
429 this.el.pack_start ( child_0.el , true );
430 var child_1 = new Xcls_dbmodel( _this );
432 this.el.set_model ( child_1.el );
436 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
439 this.el.changed.connect( () => {
443 _this.view.loadTicket(this.selectedTicketId());
445 _this.name.updateText();
446 //_this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
448 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
452 // user defined functions
453 public string selectedTicketId () {
458 this.el.get_active_iter (out iter);
459 _this.dbmodel.el.get_value (iter, 0, out val1);
462 return (string) val1;
469 public class Xcls_dbcellrenderer : Object
471 public Gtk.CellRendererText el;
472 private MergeBranch _this;
478 public Xcls_dbcellrenderer(MergeBranch _owner )
481 _this.dbcellrenderer = this;
482 this.el = new Gtk.CellRendererText();
486 // set gobject values
489 // user defined functions
492 public class Xcls_dbmodel : Object
494 public Gtk.ListStore el;
495 private MergeBranch _this;
501 public Xcls_dbmodel(MergeBranch _owner )
504 _this.dbmodel = this;
505 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
509 // set gobject values
512 // user defined functions
513 public void loadTickets () {
515 RooTicket.singleton().loadTickets("",RooTicket.Who.ME, RooTicket.Status.ACTIVE);
517 _this.ticketsel.loading = true;
524 el.set_value(iter, 0, "");
525 el.set_value(iter, 1, "-- select a ticket --");
527 _this.ticketsel.el.set_active_iter(iter);
529 if (_this.ticket != null && _this.ticket.id == "-1") {
531 el.set_value(iter, 0, "-1");
532 el.set_value(iter, 1, "Temporary Branch - No ticket specified/relivant");
533 _this.ticketsel.el.set_active_iter(iter);
539 var tickets = RooTicket.singleton().tickets;
540 foreach(var ticket in tickets) {
544 el.set_value(iter, 0, ticket.id);
545 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
546 if (_this.ticket != null && _this.ticket.id == ticket.id) {
547 _this.ticketsel.el.set_active_iter(iter);
552 _this.ticketsel.loading = false;
553 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
559 public class Xcls_Label12 : Object
562 private MergeBranch _this;
568 public Xcls_Label12(MergeBranch _owner )
571 this.el = new Gtk.Label( "Use this commit message" );
575 // set gobject values
576 this.el.justify = Gtk.Justification.RIGHT;
577 this.el.xalign = 0.900000f;
580 // user defined functions
583 public class Xcls_name : Object
586 private MergeBranch _this;
592 public Xcls_name(MergeBranch _owner )
596 this.el = new Gtk.Entry();
600 // set gobject values
601 this.el.visible = true;
604 // user defined functions
605 public void updateText () {
606 var ticket_id = _this.ticketsel.selectedTicketId();
608 RooTicket ticket = null;
609 if (ticket_id.length > 0){
610 ticket = RooTicket.singleton().getById(ticket_id);
613 var name = RooTicket.singleton().usernameLocal();
614 var action = _this.actionsel.selectedAction();
615 this.el.set_editable(true);
617 case "CLOSE": // merge changes and close..
618 this.el.set_text("Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
620 case "LEAVE": // partial fix
621 this.el.set_text("Partial Fix #%s - %s".printf(ticket_id, ticket != null ? ticket.summary : ""));
623 case "MASTER": // merge master
624 case "EXIT": // just switch back...
625 this.el.set_editable(false);
626 this.el.set_text(""); // not relivant..
630 break; /// don't fix the text value.
637 public class Xcls_scrolled_window : Object
639 public Gtk.ScrolledWindow el;
640 private MergeBranch _this;
646 public Xcls_scrolled_window(MergeBranch _owner )
649 _this.scrolled_window = this;
650 this.el = new Gtk.ScrolledWindow( null, null );
654 // set gobject values
655 this.el.height_request = 500;
656 this.el.vexpand = true;
657 var child_0 = new Xcls_view( _this );
659 this.el.add ( child_0.el );
664 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
668 // user defined functions
670 public class Xcls_view : Object
672 public WebKit.WebView el;
673 private MergeBranch _this;
679 public Xcls_view(MergeBranch _owner )
683 this.el = new WebKit.WebView();
687 // set gobject values
690 // user defined functions
691 public void loadTicket (string tid) {
693 _this.el.get_size(out w, out h);
696 _this.scrolled_window.el.hide();
697 _this.el.resize(w, 150);
699 _this.scrolled_window.el.show();
700 _this.el.resize(w, 800);
703 var rs = RooTicket.singleton();
704 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
705 var hd = uri.get_http_headers();
706 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
707 hd.append("Authorization", "Basic %s".printf(authCode));
709 this.el.load_request(uri);
714 public class Xcls_spinner : Object
716 public Gtk.Spinner el;
717 private MergeBranch _this;
723 public Xcls_spinner(MergeBranch _owner )
726 _this.spinner = this;
727 this.el = new Gtk.Spinner();
731 // set gobject values
732 this.el.hexpand = true;
733 this.el.vexpand = true;
736 // user defined functions
740 public class Xcls_Button17 : Object
742 public Gtk.Button el;
743 private MergeBranch _this;
749 public Xcls_Button17(MergeBranch _owner )
752 this.el = new Gtk.Button();
756 // set gobject values
757 this.el.relief = Gtk.ReliefStyle.NONE;
758 this.el.label = "Cancel";
761 // user defined functions
764 public class Xcls_Button18 : Object
766 public Gtk.Button el;
767 private MergeBranch _this;
773 public Xcls_Button18(MergeBranch _owner )
776 this.el = new Gtk.Button();
780 // set gobject values
781 this.el.label = "Do Merge";
784 // user defined functions