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_scrolled_window scrolled_window;
16 public Xcls_view view;
17 public Xcls_label_select_ticket label_select_ticket;
18 public Xcls_label_create_ticket label_create_ticket;
19 public Xcls_label_quick_commit label_quick_commit;
20 public Xcls_projectsel projectsel;
21 public Xcls_prcellrenderer prcellrenderer;
22 public Xcls_prmodel prmodel;
23 public Xcls_ticketsel ticketsel;
24 public Xcls_dbcellrenderer dbcellrenderer;
25 public Xcls_dbmodel dbmodel;
26 public Xcls_name name;
27 public Xcls_createbtn createbtn;
28 public Xcls_btn_not_me btn_not_me;
29 public Xcls_btn_closed btn_closed;
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_Notebook5( _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
174 var child_0 = new Xcls_scrolled_window( _this );
176 this.el.add ( child_0.el );
179 // user defined functions
181 public class Xcls_scrolled_window : Object
183 public Gtk.ScrolledWindow el;
184 private NewBranch _this;
190 public Xcls_scrolled_window(NewBranch _owner )
193 _this.scrolled_window = this;
194 this.el = new Gtk.ScrolledWindow( null, null );
198 // set gobject values
199 this.el.height_request = 500;
200 this.el.vexpand = true;
201 var child_0 = new Xcls_view( _this );
203 this.el.add ( child_0.el );
208 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
212 // user defined functions
214 public class Xcls_view : Object
216 public WebKit.WebView el;
217 private NewBranch _this;
223 public Xcls_view(NewBranch _owner )
227 this.el = new WebKit.WebView();
231 // set gobject values
234 // user defined functions
235 public void loadTicket (string tid) {
237 _this.el.get_size(out w, out h);
240 _this.scrolled_window.el.hide();
241 _this.el.resize(w, 150);
243 _this.scrolled_window.el.show();
244 _this.el.resize(w, 800);
247 var rs = RooTicket.singleton();
248 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
249 var hd = uri.get_http_headers();
250 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
251 hd.append("Authorization", "Basic %s".printf(authCode));
253 this.el.load_request(uri);
259 public class Xcls_Notebook5 : Object
261 public Gtk.Notebook el;
262 private NewBranch _this;
268 public Xcls_Notebook5(NewBranch _owner )
271 this.el = new Gtk.Notebook();
275 // set gobject values
276 this.el.vexpand = true;
277 var child_0 = new Xcls_label_select_ticket( _this );
279 var child_1 = new Xcls_label_create_ticket( _this );
281 var child_2 = new Xcls_label_quick_commit( _this );
283 var child_3 = new Xcls_Box9( _this );
285 this.el.append_page ( child_3.el , _this.label_select_ticket.el );
286 var child_4 = new Xcls_Box27( _this );
288 this.el.append_page ( child_4.el , _this.label_create_ticket.el );
289 var child_5 = new Xcls_Box28( _this );
291 this.el.append_page ( child_5.el , _this.label_quick_commit.el );
294 // user defined functions
296 public class Xcls_label_select_ticket : Object
299 private NewBranch _this;
305 public Xcls_label_select_ticket(NewBranch _owner )
308 _this.label_select_ticket = this;
309 this.el = new Gtk.Label( "Select Existing Ticket to work on" );
313 // set gobject values
316 // user defined functions
319 public class Xcls_label_create_ticket : Object
322 private NewBranch _this;
328 public Xcls_label_create_ticket(NewBranch _owner )
331 _this.label_create_ticket = this;
332 this.el = new Gtk.Label( "Create a new Ticket" );
336 // set gobject values
339 // user defined functions
342 public class Xcls_label_quick_commit : Object
345 private NewBranch _this;
351 public Xcls_label_quick_commit(NewBranch _owner )
354 _this.label_quick_commit = this;
355 this.el = new Gtk.Label( "Quick Commit" );
359 // set gobject values
362 // user defined functions
365 public class Xcls_Box9 : Object
368 private NewBranch _this;
374 public Xcls_Box9(NewBranch _owner )
377 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
381 // set gobject values
382 this.el.homogeneous = false;
383 var child_0 = new Xcls_Table10( _this );
385 this.el.pack_start ( child_0.el , false,false,0 );
388 // user defined functions
390 public class Xcls_Table10 : Object
393 private NewBranch _this;
399 public Xcls_Table10(NewBranch _owner )
402 this.el = new Gtk.Table( 5, 5, true );
406 // set gobject values
407 this.el.expand = false;
409 this.el.column_spacing = 4;
410 this.el.vexpand = false;
411 var child_0 = new Xcls_Label11( _this );
413 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
414 var child_1 = new Xcls_Label12( _this );
416 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
417 var child_2 = new Xcls_projectsel( _this );
419 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
420 var child_3 = new Xcls_ticketsel( _this );
422 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
423 var child_4 = new Xcls_Button19( _this );
425 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
426 var child_5 = new Xcls_Label20( _this );
428 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
429 var child_6 = new Xcls_name( _this );
431 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
432 var child_7 = new Xcls_createbtn( _this );
434 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
435 var child_8 = new Xcls_Box23( _this );
437 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
440 // user defined functions
442 public class Xcls_Label11 : Object
445 private NewBranch _this;
451 public Xcls_Label11(NewBranch _owner )
454 this.el = new Gtk.Label( "Project" );
458 // set gobject values
459 this.el.halign = Gtk.Align.START;
460 this.el.justify = Gtk.Justification.RIGHT;
461 this.el.visible = true;
464 // user defined functions
467 public class Xcls_Label12 : Object
470 private NewBranch _this;
476 public Xcls_Label12(NewBranch _owner )
479 this.el = new Gtk.Label( "Ticket" );
483 // set gobject values
484 this.el.halign = Gtk.Align.START;
485 this.el.visible = true;
488 // user defined functions
491 public class Xcls_projectsel : Object
493 public Gtk.ComboBox el;
494 private NewBranch _this;
501 public Xcls_projectsel(NewBranch _owner )
504 _this.projectsel = this;
505 this.el = new Gtk.ComboBox.with_entry();
508 this.loading = false;
510 // set gobject values
511 var child_0 = new Xcls_prcellrenderer( _this );
513 this.el.pack_start ( child_0.el , true );
514 var child_1 = new Xcls_prmodel( _this );
516 this.el.set_model ( child_1.el );
520 this.el.set_entry_text_column(1);
523 this.el.changed.connect( () => {
527 var project_id = this.selectedProjectId();
528 _this.dbmodel.loadTickets(project_id);
531 /*if (this.loading) {
534 var ticket_id = this.selectedTicketId();
536 var name = RooTicket.singleton().usernameLocal();
538 if (ticket_id == "" || ticket_id == null) {
540 var dt = new DateTime.now_local();
541 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
546 var ticket = RooTicket.singleton().getById(ticket_id);
548 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
550 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
555 // user defined functions
556 public string selectedProjectId () {
561 this.el.get_active_iter (out iter);
562 _this.prmodel.el.get_value (iter, 0, out val1);
565 return (string) val1;
572 public class Xcls_prcellrenderer : Object
574 public Gtk.CellRendererText el;
575 private NewBranch _this;
581 public Xcls_prcellrenderer(NewBranch _owner )
584 _this.prcellrenderer = this;
585 this.el = new Gtk.CellRendererText();
589 // set gobject values
592 // user defined functions
595 public class Xcls_prmodel : Object
597 public Gtk.ListStore el;
598 private NewBranch _this;
604 public Xcls_prmodel(NewBranch _owner )
607 _this.prmodel = this;
608 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
612 // set gobject values
615 // user defined functions
616 public void loadProjects (string id) {
620 _this.projectsel.loading = true;
629 el.set_value(iter, 0, "");
630 el.set_value(iter, 1, "-- select a project --");
632 _this.projectsel.el.set_active_iter(iter);
635 foreach(var project in RooProject.projects()) {
639 el.set_value(iter, 0, project.id);
640 el.set_value(iter, 1, project.name );
641 if (id == project.id) {
642 _this.projectsel.el.set_active_iter(iter);
647 _this.projectsel.loading = false;
648 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
654 public class Xcls_ticketsel : Object
656 public Gtk.ComboBox el;
657 private NewBranch _this;
664 public Xcls_ticketsel(NewBranch _owner )
667 _this.ticketsel = this;
668 this.el = new Gtk.ComboBox.with_entry();
671 this.loading = false;
673 // set gobject values
674 var child_0 = new Xcls_dbcellrenderer( _this );
676 this.el.pack_start ( child_0.el , true );
677 var child_1 = new Xcls_dbmodel( _this );
679 this.el.set_model ( child_1.el );
683 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
684 this.el.set_entry_text_column(1);
685 this.el.get_child().set_sensitive(false);
688 this.el.changed.connect( () => {
692 var ticket_id = this.selectedTicketId();
694 var name = RooTicket.singleton().usernameLocal();
696 this.el.get_child().get_style_context().remove_class("warning");
697 if (ticket_id == "" || ticket_id == null) {
699 var dt = new DateTime.now_local();
700 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
701 _this.view.loadTicket("");
703 this.el.get_child().get_style_context().add_class("warning");
704 _this.createbtn.updateState();
709 var ticket = RooTicket.singleton().getById(ticket_id);
711 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
712 _this.scrolled_window.el.show();
714 _this.view.loadTicket(ticket.id);
715 _this.createbtn.updateState();
717 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
721 // user defined functions
722 public string selectedTicketId () {
727 this.el.get_active_iter (out iter);
728 _this.dbmodel.el.get_value (iter, 0, out val1);
731 return (string) val1;
738 public class Xcls_dbcellrenderer : Object
740 public Gtk.CellRendererText el;
741 private NewBranch _this;
747 public Xcls_dbcellrenderer(NewBranch _owner )
750 _this.dbcellrenderer = this;
751 this.el = new Gtk.CellRendererText();
755 // set gobject values
758 // user defined functions
761 public class Xcls_dbmodel : Object
763 public Gtk.ListStore el;
764 private NewBranch _this;
770 public Xcls_dbmodel(NewBranch _owner )
773 _this.dbmodel = this;
774 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
778 // set gobject values
781 // user defined functions
782 public void loadTickets (string project_id , string tid = "") {
786 // fixme .. get project id from selection..
788 RooTicket.singleton().loadTickets(
790 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
791 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
794 _this.ticketsel.loading = true;
803 el.set_value(iter, 0, "");
804 el.set_value(iter, 1, "-- select a ticket --");
806 _this.ticketsel.el.set_active_iter(iter);
807 var tickets = RooTicket.singleton().tickets;
808 foreach(var ticket in tickets) {
812 el.set_value(iter, 0, ticket.id);
813 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
815 if (ticket.id == tid) {
816 _this.ticketsel.el.set_active_iter(iter);
821 _this.ticketsel.loading = false;
822 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
828 public class Xcls_Button19 : Object
830 public Gtk.Button el;
831 private NewBranch _this;
837 public Xcls_Button19(NewBranch _owner )
840 this.el = new Gtk.Button();
844 // set gobject values
845 this.el.expand = false;
846 this.el.label = "New Ticket";
849 this.el.clicked.connect( () => {
850 _this.el.response(-1);
851 Ticket.singleton().show(_this.repo);
856 // user defined functions
859 public class Xcls_Label20 : Object
862 private NewBranch _this;
868 public Xcls_Label20(NewBranch _owner )
871 this.el = new Gtk.Label( "Use this as branch name" );
875 // set gobject values
876 this.el.halign = Gtk.Align.START;
877 this.el.justify = Gtk.Justification.RIGHT;
878 this.el.xalign = 0.900000f;
881 // user defined functions
884 public class Xcls_name : Object
887 private NewBranch _this;
893 public Xcls_name(NewBranch _owner )
897 this.el = new Gtk.Entry();
901 // set gobject values
902 this.el.visible = true;
905 // user defined functions
908 public class Xcls_createbtn : Object
910 public Gtk.Button el;
911 private NewBranch _this;
917 public Xcls_createbtn(NewBranch _owner )
920 _this.createbtn = this;
921 this.el = new Gtk.Button();
925 // set gobject values
926 this.el.label = "Create Branch";
931 this.el.get_style_context().add_class("suggested-action");
935 this.el.clicked.connect( () => {
937 GLib.debug("fire response = 1");
939 var ticket_id = _this.ticketsel.selectedTicketId();
941 if (ticket_id == "") {
942 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
946 _this.el.response(1);
950 // user defined functions
951 public void updateState () {
953 var ticket_id = _this.ticketsel.selectedTicketId();
955 if (ticket_id == "") {
956 this.el.set_sensitive(false);
960 this.el.set_sensitive(true);
965 public class Xcls_Box23 : Object
968 private NewBranch _this;
974 public Xcls_Box23(NewBranch _owner )
977 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
981 // set gobject values
982 var child_0 = new Xcls_btn_not_me( _this );
984 this.el.add ( child_0.el );
985 var child_1 = new Xcls_btn_closed( _this );
987 this.el.add ( child_1.el );
988 var child_2 = new Xcls_Label26( _this );
990 this.el.add ( child_2.el );
993 // user defined functions
995 public class Xcls_btn_not_me : Object
997 public Gtk.CheckButton el;
998 private NewBranch _this;
1004 public Xcls_btn_not_me(NewBranch _owner )
1007 _this.btn_not_me = this;
1008 this.el = new Gtk.CheckButton();
1012 // set gobject values
1013 this.el.label = "Show tickets not assigned to me";
1016 this.el.toggled.connect( () => {
1017 var project_id = _this.projectsel.selectedProjectId();
1018 _this.dbmodel.loadTickets(project_id);
1022 // user defined functions
1025 public class Xcls_btn_closed : Object
1027 public Gtk.CheckButton el;
1028 private NewBranch _this;
1034 public Xcls_btn_closed(NewBranch _owner )
1037 _this.btn_closed = this;
1038 this.el = new Gtk.CheckButton();
1042 // set gobject values
1043 this.el.label = "Show closed Tickets";
1046 this.el.toggled.connect( () => {
1047 var project_id = _this.projectsel.selectedProjectId();
1048 _this.dbmodel.loadTickets(project_id);
1053 // user defined functions
1056 public class Xcls_Label26 : Object
1058 public Gtk.Label el;
1059 private NewBranch _this;
1065 public Xcls_Label26(NewBranch _owner )
1068 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
1072 // set gobject values
1073 this.el.halign = Gtk.Align.END;
1074 this.el.hexpand = true;
1075 this.el.use_markup = true;
1078 this.el.activate_link.connect( (uri) => {
1079 if (uri == "refresh") {
1080 RooProject.reload();
1081 var curproj = RooProject.getProjectByRepo(_this.repo);
1082 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
1084 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
1090 // user defined functions
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