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_Notebook2( _this );
55 this.el.get_content_area().add ( child_0.el );
58 this.el.delete_event.connect( (self, event) => {
63 this.el.response.connect( (self, response_id) => {
65 GLib.debug("got %d", (int) response_id);
70 // have they selected a ticket..
71 // make that the current active ticket?
72 // we really need to store locally what ticket is being worked on..
73 // in theory we could be working on multiple project and not merging..
74 // -- each repo would have their active ticket (only one per repo)
75 // -- so we could just store that in there
76 // -- initial load can check the contents of the ticket files on first scan.
79 if (response_id < 1) {
85 var ticket_id = _this.ticketsel.selectedTicketId();
87 if (this.repo != null) {
88 var bn = _this.name.el.get_text();
90 var res = this.repo.setActiveTicket(
91 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
94 // start the monitoring..
95 GitMonitor.gitmonitor.start();
101 this.running = false;
111 // user defined functions
112 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
114 // this.el.set_gravity(Gdk.Gravity.NORTH);
115 if (this.running) { // should not happen!!
116 GLib.error("new branch show called, when already being displayed?");
121 GitMonitor.gitmonitor.stop();
127 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
128 this.el.set_default_size( 500,200); // not sure why it grows..
129 GLib.debug("Loading tickets");
133 this.el.set_keep_above(true);
136 var curproj = RooProject.getProjectByRepo(this.repo);
137 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
139 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
140 _this.createbtn.updateState();
142 _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
144 var name = RooTicket.singleton().usernameLocal();
145 var ticket = RooTicket.singleton().getById(tid);
146 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
148 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
150 _this.view.loadTicket(tid);
154 public class Xcls_Notebook2 : Object
156 public Gtk.Notebook el;
157 private NewBranch _this;
163 public Xcls_Notebook2(NewBranch _owner )
166 this.el = new Gtk.Notebook();
170 // set gobject values
171 this.el.vexpand = true;
172 var child_0 = new Xcls_label_select_ticket( _this );
174 var child_1 = new Xcls_label_create_ticket( _this );
176 var child_2 = new Xcls_label_quick_commit( _this );
178 var child_3 = new Xcls_Box6( _this );
180 this.el.append_page ( child_3.el , _this.label_select_ticket.el );
181 var child_4 = new Xcls_Box26( _this );
183 this.el.append_page ( child_4.el , _this.label_create_ticket.el );
184 var child_5 = new Xcls_Box27( _this );
186 this.el.append_page ( child_5.el , _this.label_quick_commit.el );
189 // user defined functions
191 public class Xcls_label_select_ticket : Object
194 private NewBranch _this;
200 public Xcls_label_select_ticket(NewBranch _owner )
203 _this.label_select_ticket = this;
204 this.el = new Gtk.Label( "Select Existing Ticket to work on" );
208 // set gobject values
211 // user defined functions
214 public class Xcls_label_create_ticket : Object
217 private NewBranch _this;
223 public Xcls_label_create_ticket(NewBranch _owner )
226 _this.label_create_ticket = this;
227 this.el = new Gtk.Label( "Create a New Ticket" );
231 // set gobject values
234 // user defined functions
237 public class Xcls_label_quick_commit : Object
240 private NewBranch _this;
246 public Xcls_label_quick_commit(NewBranch _owner )
249 _this.label_quick_commit = this;
250 this.el = new Gtk.Label( "Quick Commit" );
254 // set gobject values
257 // user defined functions
260 public class Xcls_Box6 : Object
263 private NewBranch _this;
269 public Xcls_Box6(NewBranch _owner )
272 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
276 // set gobject values
277 this.el.homogeneous = false;
278 var child_0 = new Xcls_Table7( _this );
280 this.el.pack_start ( child_0.el , false,false,0 );
281 var child_1 = new Xcls_scrolled_window( _this );
283 this.el.add ( child_1.el );
286 // user defined functions
288 public class Xcls_Table7 : Object
291 private NewBranch _this;
297 public Xcls_Table7(NewBranch _owner )
300 this.el = new Gtk.Table( 5, 5, true );
304 // set gobject values
305 this.el.expand = false;
307 this.el.column_spacing = 4;
308 this.el.vexpand = false;
309 var child_0 = new Xcls_Label8( _this );
311 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
312 var child_1 = new Xcls_Label9( _this );
314 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
315 var child_2 = new Xcls_projectsel( _this );
317 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
318 var child_3 = new Xcls_ticketsel( _this );
320 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
321 var child_4 = new Xcls_Button16( _this );
323 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
324 var child_5 = new Xcls_Label17( _this );
326 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
327 var child_6 = new Xcls_name( _this );
329 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
330 var child_7 = new Xcls_createbtn( _this );
332 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
333 var child_8 = new Xcls_Box20( _this );
335 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
338 // user defined functions
340 public class Xcls_Label8 : Object
343 private NewBranch _this;
349 public Xcls_Label8(NewBranch _owner )
352 this.el = new Gtk.Label( "Project" );
356 // set gobject values
357 this.el.halign = Gtk.Align.START;
358 this.el.justify = Gtk.Justification.RIGHT;
359 this.el.visible = true;
362 // 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( "Ticket" );
381 // set gobject values
382 this.el.halign = Gtk.Align.START;
383 this.el.visible = true;
386 // user defined functions
389 public class Xcls_projectsel : Object
391 public Gtk.ComboBox el;
392 private NewBranch _this;
399 public Xcls_projectsel(NewBranch _owner )
402 _this.projectsel = this;
403 this.el = new Gtk.ComboBox.with_entry();
406 this.loading = false;
408 // set gobject values
409 var child_0 = new Xcls_prcellrenderer( _this );
411 this.el.pack_start ( child_0.el , true );
412 var child_1 = new Xcls_prmodel( _this );
414 this.el.set_model ( child_1.el );
418 this.el.set_entry_text_column(1);
421 this.el.changed.connect( () => {
425 var project_id = this.selectedProjectId();
426 _this.dbmodel.loadTickets(project_id);
429 /*if (this.loading) {
432 var ticket_id = this.selectedTicketId();
434 var name = RooTicket.singleton().usernameLocal();
436 if (ticket_id == "" || ticket_id == null) {
438 var dt = new DateTime.now_local();
439 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
444 var ticket = RooTicket.singleton().getById(ticket_id);
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);
453 // user defined functions
454 public string selectedProjectId () {
459 this.el.get_active_iter (out iter);
460 _this.prmodel.el.get_value (iter, 0, out val1);
463 return (string) val1;
470 public class Xcls_prcellrenderer : Object
472 public Gtk.CellRendererText el;
473 private NewBranch _this;
479 public Xcls_prcellrenderer(NewBranch _owner )
482 _this.prcellrenderer = this;
483 this.el = new Gtk.CellRendererText();
487 // set gobject values
490 // user defined functions
493 public class Xcls_prmodel : Object
495 public Gtk.ListStore el;
496 private NewBranch _this;
502 public Xcls_prmodel(NewBranch _owner )
505 _this.prmodel = this;
506 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
510 // set gobject values
513 // user defined functions
514 public void loadProjects (string id) {
518 _this.projectsel.loading = true;
527 el.set_value(iter, 0, "");
528 el.set_value(iter, 1, "-- select a project --");
530 _this.projectsel.el.set_active_iter(iter);
533 foreach(var project in RooProject.projects()) {
537 el.set_value(iter, 0, project.id);
538 el.set_value(iter, 1, project.name );
539 if (id == project.id) {
540 _this.projectsel.el.set_active_iter(iter);
545 _this.projectsel.loading = false;
546 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
552 public class Xcls_ticketsel : Object
554 public Gtk.ComboBox el;
555 private NewBranch _this;
562 public Xcls_ticketsel(NewBranch _owner )
565 _this.ticketsel = this;
566 this.el = new Gtk.ComboBox.with_entry();
569 this.loading = false;
571 // set gobject values
572 var child_0 = new Xcls_dbcellrenderer( _this );
574 this.el.pack_start ( child_0.el , true );
575 var child_1 = new Xcls_dbmodel( _this );
577 this.el.set_model ( child_1.el );
581 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
582 this.el.set_entry_text_column(1);
583 this.el.get_child().set_sensitive(false);
586 this.el.changed.connect( () => {
590 var ticket_id = this.selectedTicketId();
592 var name = RooTicket.singleton().usernameLocal();
594 this.el.get_child().get_style_context().remove_class("warning");
595 if (ticket_id == "" || ticket_id == null) {
597 var dt = new DateTime.now_local();
598 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
599 _this.view.loadTicket("");
601 this.el.get_child().get_style_context().add_class("warning");
602 _this.createbtn.updateState();
607 var ticket = RooTicket.singleton().getById(ticket_id);
609 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
610 _this.scrolled_window.el.show();
612 _this.view.loadTicket(ticket.id);
613 _this.createbtn.updateState();
615 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
619 // user defined functions
620 public string selectedTicketId () {
625 this.el.get_active_iter (out iter);
626 _this.dbmodel.el.get_value (iter, 0, out val1);
629 return (string) val1;
636 public class Xcls_dbcellrenderer : Object
638 public Gtk.CellRendererText el;
639 private NewBranch _this;
645 public Xcls_dbcellrenderer(NewBranch _owner )
648 _this.dbcellrenderer = this;
649 this.el = new Gtk.CellRendererText();
653 // set gobject values
656 // user defined functions
659 public class Xcls_dbmodel : Object
661 public Gtk.ListStore el;
662 private NewBranch _this;
668 public Xcls_dbmodel(NewBranch _owner )
671 _this.dbmodel = this;
672 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
676 // set gobject values
679 // user defined functions
680 public void loadTickets (string project_id , string tid = "") {
684 // fixme .. get project id from selection..
686 RooTicket.singleton().loadTickets(
688 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
689 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
692 _this.ticketsel.loading = true;
701 el.set_value(iter, 0, "");
702 el.set_value(iter, 1, "-- select a ticket --");
704 _this.ticketsel.el.set_active_iter(iter);
705 var tickets = RooTicket.singleton().tickets;
706 foreach(var ticket in tickets) {
710 el.set_value(iter, 0, ticket.id);
711 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
713 if (ticket.id == tid) {
714 _this.ticketsel.el.set_active_iter(iter);
719 _this.ticketsel.loading = false;
720 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
726 public class Xcls_Button16 : Object
728 public Gtk.Button el;
729 private NewBranch _this;
735 public Xcls_Button16(NewBranch _owner )
738 this.el = new Gtk.Button();
742 // set gobject values
743 this.el.expand = false;
744 this.el.label = "New Ticket";
747 this.el.clicked.connect( () => {
748 _this.el.response(-1);
749 Ticket.singleton().show(_this.repo);
754 // user defined functions
757 public class Xcls_Label17 : Object
760 private NewBranch _this;
766 public Xcls_Label17(NewBranch _owner )
769 this.el = new Gtk.Label( "Use this as branch name" );
773 // set gobject values
774 this.el.halign = Gtk.Align.START;
775 this.el.justify = Gtk.Justification.RIGHT;
776 this.el.xalign = 0.900000f;
779 // user defined functions
782 public class Xcls_name : Object
785 private NewBranch _this;
791 public Xcls_name(NewBranch _owner )
795 this.el = new Gtk.Entry();
799 // set gobject values
800 this.el.visible = true;
803 // user defined functions
806 public class Xcls_createbtn : Object
808 public Gtk.Button el;
809 private NewBranch _this;
815 public Xcls_createbtn(NewBranch _owner )
818 _this.createbtn = this;
819 this.el = new Gtk.Button();
823 // set gobject values
824 this.el.label = "Create Branch";
829 this.el.get_style_context().add_class("suggested-action");
833 this.el.clicked.connect( () => {
835 GLib.debug("fire response = 1");
837 var ticket_id = _this.ticketsel.selectedTicketId();
839 if (ticket_id == "") {
840 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
844 _this.el.response(1);
848 // user defined functions
849 public void updateState () {
851 var ticket_id = _this.ticketsel.selectedTicketId();
853 if (ticket_id == "") {
854 this.el.set_sensitive(false);
858 this.el.set_sensitive(true);
863 public class Xcls_Box20 : Object
866 private NewBranch _this;
872 public Xcls_Box20(NewBranch _owner )
875 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
879 // set gobject values
880 var child_0 = new Xcls_btn_not_me( _this );
882 this.el.add ( child_0.el );
883 var child_1 = new Xcls_btn_closed( _this );
885 this.el.add ( child_1.el );
886 var child_2 = new Xcls_Label23( _this );
888 this.el.add ( child_2.el );
891 // user defined functions
893 public class Xcls_btn_not_me : Object
895 public Gtk.CheckButton el;
896 private NewBranch _this;
902 public Xcls_btn_not_me(NewBranch _owner )
905 _this.btn_not_me = this;
906 this.el = new Gtk.CheckButton();
910 // set gobject values
911 this.el.label = "Show tickets not assigned to me";
914 this.el.toggled.connect( () => {
915 var project_id = _this.projectsel.selectedProjectId();
916 _this.dbmodel.loadTickets(project_id);
920 // user defined functions
923 public class Xcls_btn_closed : Object
925 public Gtk.CheckButton el;
926 private NewBranch _this;
932 public Xcls_btn_closed(NewBranch _owner )
935 _this.btn_closed = this;
936 this.el = new Gtk.CheckButton();
940 // set gobject values
941 this.el.label = "Show closed Tickets";
944 this.el.toggled.connect( () => {
945 var project_id = _this.projectsel.selectedProjectId();
946 _this.dbmodel.loadTickets(project_id);
951 // user defined functions
954 public class Xcls_Label23 : Object
957 private NewBranch _this;
963 public Xcls_Label23(NewBranch _owner )
966 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
970 // set gobject values
971 this.el.halign = Gtk.Align.END;
972 this.el.hexpand = true;
973 this.el.use_markup = true;
976 this.el.activate_link.connect( (uri) => {
977 if (uri == "refresh") {
979 var curproj = RooProject.getProjectByRepo(_this.repo);
980 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
982 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
988 // user defined functions
993 public class Xcls_scrolled_window : Object
995 public Gtk.ScrolledWindow el;
996 private NewBranch _this;
1002 public Xcls_scrolled_window(NewBranch _owner )
1005 _this.scrolled_window = this;
1006 this.el = new Gtk.ScrolledWindow( null, null );
1010 // set gobject values
1011 this.el.height_request = 500;
1012 this.el.vexpand = true;
1013 var child_0 = new Xcls_view( _this );
1015 this.el.add ( child_0.el );
1020 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1024 // user defined functions
1026 public class Xcls_view : Object
1028 public WebKit.WebView el;
1029 private NewBranch _this;
1035 public Xcls_view(NewBranch _owner )
1039 this.el = new WebKit.WebView();
1043 // set gobject values
1046 // user defined functions
1047 public void loadTicket (string tid) {
1049 _this.el.get_size(out w, out h);
1052 _this.scrolled_window.el.hide();
1053 _this.el.resize(w, 150);
1055 _this.scrolled_window.el.show();
1056 _this.el.resize(w, 800);
1059 var rs = RooTicket.singleton();
1060 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
1061 var hd = uri.get_http_headers();
1062 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
1063 hd.append("Authorization", "Basic %s".printf(authCode));
1065 this.el.load_request(uri);
1071 public class Xcls_Box26 : Object
1074 private NewBranch _this;
1080 public Xcls_Box26(NewBranch _owner )
1083 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1087 // set gobject values
1088 this.el.homogeneous = false;
1091 // user defined functions
1094 public class Xcls_Box27 : Object
1097 private NewBranch _this;
1103 public Xcls_Box27(NewBranch _owner )
1106 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1110 // set gobject values
1111 this.el.homogeneous = false;
1114 // user defined functions