1 static NewBranch _NewBranch;
3 public class NewBranch : Object
6 private NewBranch _this;
8 public static NewBranch singleton()
10 if (_NewBranch == null) {
11 _NewBranch= new NewBranch();
15 public Xcls_label_select_ticket label_select_ticket;
16 public Xcls_label_create_ticket label_create_ticket;
17 public Xcls_label_quick_commit label_quick_commit;
18 public Xcls_projectsel projectsel;
19 public Xcls_prcellrenderer prcellrenderer;
20 public Xcls_prmodel prmodel;
21 public Xcls_ticketsel ticketsel;
22 public Xcls_dbcellrenderer dbcellrenderer;
23 public Xcls_dbmodel dbmodel;
24 public Xcls_name name;
25 public Xcls_createbtn createbtn;
26 public Xcls_btn_not_me btn_not_me;
27 public Xcls_btn_closed btn_closed;
28 public Xcls_scrolled_window scrolled_window;
29 public Xcls_view view;
34 public Gee.ArrayList<GitMonitorQueue> queue;
40 this.el = new Gtk.Dialog();
48 this.el.title = "Create a working branch ";
49 this.el.default_height = 500;
50 this.el.default_width = 500;
51 this.el.deletable = true;
53 var child_0 = new Xcls_Box2( _this );
55 this.el.get_content_area().add ( child_0.el );
56 var child_1 = new Xcls_Notebook3( _this );
58 this.el.add ( child_1.el );
61 this.el.delete_event.connect( (self, event) => {
66 this.el.response.connect( (self, response_id) => {
68 GLib.debug("got %d", (int) response_id);
73 // have they selected a ticket..
74 // make that the current active ticket?
75 // we really need to store locally what ticket is being worked on..
76 // in theory we could be working on multiple project and not merging..
77 // -- each repo would have their active ticket (only one per repo)
78 // -- so we could just store that in there
79 // -- initial load can check the contents of the ticket files on first scan.
82 if (response_id < 1) {
88 var ticket_id = _this.ticketsel.selectedTicketId();
90 if (this.repo != null) {
91 var bn = _this.name.el.get_text();
93 var res = this.repo.setActiveTicket(
94 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
97 // start the monitoring..
98 GitMonitor.gitmonitor.start();
104 this.running = false;
114 // user defined functions
115 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
117 // this.el.set_gravity(Gdk.Gravity.NORTH);
118 if (this.running) { // should not happen!!
119 GLib.error("new branch show called, when already being displayed?");
124 GitMonitor.gitmonitor.stop();
130 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
131 this.el.set_default_size( 500,200); // not sure why it grows..
132 GLib.debug("Loading tickets");
136 this.el.set_keep_above(true);
139 var curproj = RooProject.getProjectByRepo(this.repo);
140 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
142 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
143 _this.createbtn.updateState();
145 _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
147 var name = RooTicket.singleton().usernameLocal();
148 var ticket = RooTicket.singleton().getById(tid);
149 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
151 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
153 _this.view.loadTicket(tid);
157 public class Xcls_Box2 : Object
160 private NewBranch _this;
166 public Xcls_Box2(NewBranch _owner )
169 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
173 // set gobject values
176 // user defined functions
179 public class Xcls_Notebook3 : Object
181 public Gtk.Notebook el;
182 private NewBranch _this;
188 public Xcls_Notebook3(NewBranch _owner )
191 this.el = new Gtk.Notebook();
195 // set gobject values
196 this.el.vexpand = true;
197 var child_0 = new Xcls_label_select_ticket( _this );
199 var child_1 = new Xcls_label_create_ticket( _this );
201 var child_2 = new Xcls_label_quick_commit( _this );
203 var child_3 = new Xcls_Box7( _this );
205 this.el.append_page ( child_3.el , _this.label_select_ticket.el );
206 var child_4 = new Xcls_Box27( _this );
208 this.el.append_page ( child_4.el , _this.label_create_ticket.el );
209 var child_5 = new Xcls_Box28( _this );
211 this.el.append_page ( child_5.el , _this.label_quick_commit.el );
214 // user defined functions
216 public class Xcls_label_select_ticket : Object
219 private NewBranch _this;
225 public Xcls_label_select_ticket(NewBranch _owner )
228 _this.label_select_ticket = this;
229 this.el = new Gtk.Label( "Select Existing Ticket to work on" );
233 // set gobject values
236 // user defined functions
239 public class Xcls_label_create_ticket : Object
242 private NewBranch _this;
248 public Xcls_label_create_ticket(NewBranch _owner )
251 _this.label_create_ticket = this;
252 this.el = new Gtk.Label( "Create a new Ticket" );
256 // set gobject values
259 // user defined functions
262 public class Xcls_label_quick_commit : Object
265 private NewBranch _this;
271 public Xcls_label_quick_commit(NewBranch _owner )
274 _this.label_quick_commit = this;
275 this.el = new Gtk.Label( "Quick Commit" );
279 // set gobject values
282 // user defined functions
285 public class Xcls_Box7 : Object
288 private NewBranch _this;
294 public Xcls_Box7(NewBranch _owner )
297 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
301 // set gobject values
302 this.el.homogeneous = false;
303 var child_0 = new Xcls_Table8( _this );
305 this.el.pack_start ( child_0.el , false,false,0 );
306 var child_1 = new Xcls_scrolled_window( _this );
308 this.el.add ( child_1.el );
311 // user defined functions
313 public class Xcls_Table8 : Object
316 private NewBranch _this;
322 public Xcls_Table8(NewBranch _owner )
325 this.el = new Gtk.Table( 5, 5, true );
329 // set gobject values
330 this.el.expand = false;
332 this.el.column_spacing = 4;
333 this.el.vexpand = false;
334 var child_0 = new Xcls_Label9( _this );
336 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
337 var child_1 = new Xcls_Label10( _this );
339 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
340 var child_2 = new Xcls_projectsel( _this );
342 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
343 var child_3 = new Xcls_ticketsel( _this );
345 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
346 var child_4 = new Xcls_Button17( _this );
348 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
349 var child_5 = new Xcls_Label18( _this );
351 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
352 var child_6 = new Xcls_name( _this );
354 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
355 var child_7 = new Xcls_createbtn( _this );
357 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
358 var child_8 = new Xcls_Box21( _this );
360 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
363 // user defined functions
365 public class Xcls_Label9 : Object
368 private NewBranch _this;
374 public Xcls_Label9(NewBranch _owner )
377 this.el = new Gtk.Label( "Project" );
381 // set gobject values
382 this.el.halign = Gtk.Align.START;
383 this.el.justify = Gtk.Justification.RIGHT;
384 this.el.visible = true;
387 // user defined functions
390 public class Xcls_Label10 : Object
393 private NewBranch _this;
399 public Xcls_Label10(NewBranch _owner )
402 this.el = new Gtk.Label( "Ticket" );
406 // set gobject values
407 this.el.halign = Gtk.Align.START;
408 this.el.visible = true;
411 // user defined functions
414 public class Xcls_projectsel : Object
416 public Gtk.ComboBox el;
417 private NewBranch _this;
424 public Xcls_projectsel(NewBranch _owner )
427 _this.projectsel = this;
428 this.el = new Gtk.ComboBox.with_entry();
431 this.loading = false;
433 // set gobject values
434 var child_0 = new Xcls_prcellrenderer( _this );
436 this.el.pack_start ( child_0.el , true );
437 var child_1 = new Xcls_prmodel( _this );
439 this.el.set_model ( child_1.el );
443 this.el.set_entry_text_column(1);
446 this.el.changed.connect( () => {
450 var project_id = this.selectedProjectId();
451 _this.dbmodel.loadTickets(project_id);
454 /*if (this.loading) {
457 var ticket_id = this.selectedTicketId();
459 var name = RooTicket.singleton().usernameLocal();
461 if (ticket_id == "" || ticket_id == null) {
463 var dt = new DateTime.now_local();
464 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
469 var ticket = RooTicket.singleton().getById(ticket_id);
471 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
473 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
478 // user defined functions
479 public string selectedProjectId () {
484 this.el.get_active_iter (out iter);
485 _this.prmodel.el.get_value (iter, 0, out val1);
488 return (string) val1;
495 public class Xcls_prcellrenderer : Object
497 public Gtk.CellRendererText el;
498 private NewBranch _this;
504 public Xcls_prcellrenderer(NewBranch _owner )
507 _this.prcellrenderer = this;
508 this.el = new Gtk.CellRendererText();
512 // set gobject values
515 // user defined functions
518 public class Xcls_prmodel : Object
520 public Gtk.ListStore el;
521 private NewBranch _this;
527 public Xcls_prmodel(NewBranch _owner )
530 _this.prmodel = this;
531 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
535 // set gobject values
538 // user defined functions
539 public void loadProjects (string id) {
543 _this.projectsel.loading = true;
552 el.set_value(iter, 0, "");
553 el.set_value(iter, 1, "-- select a project --");
555 _this.projectsel.el.set_active_iter(iter);
558 foreach(var project in RooProject.projects()) {
562 el.set_value(iter, 0, project.id);
563 el.set_value(iter, 1, project.name );
564 if (id == project.id) {
565 _this.projectsel.el.set_active_iter(iter);
570 _this.projectsel.loading = false;
571 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
577 public class Xcls_ticketsel : Object
579 public Gtk.ComboBox el;
580 private NewBranch _this;
587 public Xcls_ticketsel(NewBranch _owner )
590 _this.ticketsel = this;
591 this.el = new Gtk.ComboBox.with_entry();
594 this.loading = false;
596 // set gobject values
597 var child_0 = new Xcls_dbcellrenderer( _this );
599 this.el.pack_start ( child_0.el , true );
600 var child_1 = new Xcls_dbmodel( _this );
602 this.el.set_model ( child_1.el );
606 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
607 this.el.set_entry_text_column(1);
608 this.el.get_child().set_sensitive(false);
611 this.el.changed.connect( () => {
615 var ticket_id = this.selectedTicketId();
617 var name = RooTicket.singleton().usernameLocal();
619 this.el.get_child().get_style_context().remove_class("warning");
620 if (ticket_id == "" || ticket_id == null) {
622 var dt = new DateTime.now_local();
623 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
624 _this.view.loadTicket("");
626 this.el.get_child().get_style_context().add_class("warning");
627 _this.createbtn.updateState();
632 var ticket = RooTicket.singleton().getById(ticket_id);
634 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
635 _this.scrolled_window.el.show();
637 _this.view.loadTicket(ticket.id);
638 _this.createbtn.updateState();
640 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
644 // user defined functions
645 public string selectedTicketId () {
650 this.el.get_active_iter (out iter);
651 _this.dbmodel.el.get_value (iter, 0, out val1);
654 return (string) val1;
661 public class Xcls_dbcellrenderer : Object
663 public Gtk.CellRendererText el;
664 private NewBranch _this;
670 public Xcls_dbcellrenderer(NewBranch _owner )
673 _this.dbcellrenderer = this;
674 this.el = new Gtk.CellRendererText();
678 // set gobject values
681 // user defined functions
684 public class Xcls_dbmodel : Object
686 public Gtk.ListStore el;
687 private NewBranch _this;
693 public Xcls_dbmodel(NewBranch _owner )
696 _this.dbmodel = this;
697 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
701 // set gobject values
704 // user defined functions
705 public void loadTickets (string project_id , string tid = "") {
709 // fixme .. get project id from selection..
711 RooTicket.singleton().loadTickets(
713 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
714 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
717 _this.ticketsel.loading = true;
726 el.set_value(iter, 0, "");
727 el.set_value(iter, 1, "-- select a ticket --");
729 _this.ticketsel.el.set_active_iter(iter);
730 var tickets = RooTicket.singleton().tickets;
731 foreach(var ticket in tickets) {
735 el.set_value(iter, 0, ticket.id);
736 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
738 if (ticket.id == tid) {
739 _this.ticketsel.el.set_active_iter(iter);
744 _this.ticketsel.loading = false;
745 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
751 public class Xcls_Button17 : Object
753 public Gtk.Button el;
754 private NewBranch _this;
760 public Xcls_Button17(NewBranch _owner )
763 this.el = new Gtk.Button();
767 // set gobject values
768 this.el.expand = false;
769 this.el.label = "New Ticket";
772 this.el.clicked.connect( () => {
773 _this.el.response(-1);
774 Ticket.singleton().show(_this.repo);
779 // user defined functions
782 public class Xcls_Label18 : Object
785 private NewBranch _this;
791 public Xcls_Label18(NewBranch _owner )
794 this.el = new Gtk.Label( "Use this as branch name" );
798 // set gobject values
799 this.el.halign = Gtk.Align.START;
800 this.el.justify = Gtk.Justification.RIGHT;
801 this.el.xalign = 0.900000f;
804 // user defined functions
807 public class Xcls_name : Object
810 private NewBranch _this;
816 public Xcls_name(NewBranch _owner )
820 this.el = new Gtk.Entry();
824 // set gobject values
825 this.el.visible = true;
828 // user defined functions
831 public class Xcls_createbtn : Object
833 public Gtk.Button el;
834 private NewBranch _this;
840 public Xcls_createbtn(NewBranch _owner )
843 _this.createbtn = this;
844 this.el = new Gtk.Button();
848 // set gobject values
849 this.el.label = "Create Branch";
854 this.el.get_style_context().add_class("suggested-action");
858 this.el.clicked.connect( () => {
860 GLib.debug("fire response = 1");
862 var ticket_id = _this.ticketsel.selectedTicketId();
864 if (ticket_id == "") {
865 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
869 _this.el.response(1);
873 // user defined functions
874 public void updateState () {
876 var ticket_id = _this.ticketsel.selectedTicketId();
878 if (ticket_id == "") {
879 this.el.set_sensitive(false);
883 this.el.set_sensitive(true);
888 public class Xcls_Box21 : Object
891 private NewBranch _this;
897 public Xcls_Box21(NewBranch _owner )
900 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
904 // set gobject values
905 var child_0 = new Xcls_btn_not_me( _this );
907 this.el.add ( child_0.el );
908 var child_1 = new Xcls_btn_closed( _this );
910 this.el.add ( child_1.el );
911 var child_2 = new Xcls_Label24( _this );
913 this.el.add ( child_2.el );
916 // user defined functions
918 public class Xcls_btn_not_me : Object
920 public Gtk.CheckButton el;
921 private NewBranch _this;
927 public Xcls_btn_not_me(NewBranch _owner )
930 _this.btn_not_me = this;
931 this.el = new Gtk.CheckButton();
935 // set gobject values
936 this.el.label = "Show tickets not assigned to me";
939 this.el.toggled.connect( () => {
940 var project_id = _this.projectsel.selectedProjectId();
941 _this.dbmodel.loadTickets(project_id);
945 // user defined functions
948 public class Xcls_btn_closed : Object
950 public Gtk.CheckButton el;
951 private NewBranch _this;
957 public Xcls_btn_closed(NewBranch _owner )
960 _this.btn_closed = this;
961 this.el = new Gtk.CheckButton();
965 // set gobject values
966 this.el.label = "Show closed Tickets";
969 this.el.toggled.connect( () => {
970 var project_id = _this.projectsel.selectedProjectId();
971 _this.dbmodel.loadTickets(project_id);
976 // user defined functions
979 public class Xcls_Label24 : Object
982 private NewBranch _this;
988 public Xcls_Label24(NewBranch _owner )
991 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
995 // set gobject values
996 this.el.halign = Gtk.Align.END;
997 this.el.hexpand = true;
998 this.el.use_markup = true;
1001 this.el.activate_link.connect( (uri) => {
1002 if (uri == "refresh") {
1003 RooProject.reload();
1004 var curproj = RooProject.getProjectByRepo(_this.repo);
1005 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
1007 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
1013 // user defined functions
1018 public class Xcls_scrolled_window : Object
1020 public Gtk.ScrolledWindow el;
1021 private NewBranch _this;
1027 public Xcls_scrolled_window(NewBranch _owner )
1030 _this.scrolled_window = this;
1031 this.el = new Gtk.ScrolledWindow( null, null );
1035 // set gobject values
1036 this.el.height_request = 500;
1037 this.el.vexpand = true;
1038 var child_0 = new Xcls_view( _this );
1040 this.el.add ( child_0.el );
1045 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1049 // user defined functions
1051 public class Xcls_view : Object
1053 public WebKit.WebView el;
1054 private NewBranch _this;
1060 public Xcls_view(NewBranch _owner )
1064 this.el = new WebKit.WebView();
1068 // set gobject values
1071 // user defined functions
1072 public void loadTicket (string tid) {
1074 _this.el.get_size(out w, out h);
1077 _this.scrolled_window.el.hide();
1078 _this.el.resize(w, 150);
1080 _this.scrolled_window.el.show();
1081 _this.el.resize(w, 800);
1084 var rs = RooTicket.singleton();
1085 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
1086 var hd = uri.get_http_headers();
1087 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
1088 hd.append("Authorization", "Basic %s".printf(authCode));
1090 this.el.load_request(uri);
1096 public class Xcls_Box27 : Object
1099 private NewBranch _this;
1105 public Xcls_Box27(NewBranch _owner )
1108 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1112 // set gobject values
1113 this.el.homogeneous = false;
1116 // user defined functions
1119 public class Xcls_Box28 : Object
1122 private NewBranch _this;
1128 public Xcls_Box28(NewBranch _owner )
1131 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1135 // set gobject values
1136 this.el.homogeneous = false;
1139 // user defined functions