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_projectsel projectsel;
16 public Xcls_prcellrenderer prcellrenderer;
17 public Xcls_prmodel prmodel;
18 public Xcls_ticketsel ticketsel;
19 public Xcls_dbcellrenderer dbcellrenderer;
20 public Xcls_dbmodel dbmodel;
21 public Xcls_name name;
22 public Xcls_createbtn createbtn;
23 public Xcls_btn_not_me btn_not_me;
24 public Xcls_btn_closed btn_closed;
25 public Xcls_scrolled_window scrolled_window;
26 public Xcls_view view;
27 public Xcls_label_select_ticket label_select_ticket;
28 public Xcls_label_create_ticket label_create_ticket;
29 public Xcls_label_quick_commit label_quick_commit;
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_Notebook22( _this );
58 this.el.add ( child_1.el );
59 var child_2 = new Xcls_Box26( _this );
61 this.el.append_page ( child_2.el , _this.label_select_ticket.el );
64 this.el.delete_event.connect( (self, event) => {
69 this.el.response.connect( (self, response_id) => {
71 GLib.debug("got %d", (int) response_id);
76 // have they selected a ticket..
77 // make that the current active ticket?
78 // we really need to store locally what ticket is being worked on..
79 // in theory we could be working on multiple project and not merging..
80 // -- each repo would have their active ticket (only one per repo)
81 // -- so we could just store that in there
82 // -- initial load can check the contents of the ticket files on first scan.
85 if (response_id < 1) {
91 var ticket_id = _this.ticketsel.selectedTicketId();
93 if (this.repo != null) {
94 var bn = _this.name.el.get_text();
96 var res = this.repo.setActiveTicket(
97 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
100 // start the monitoring..
101 GitMonitor.gitmonitor.start();
107 this.running = false;
117 // user defined functions
118 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
120 // this.el.set_gravity(Gdk.Gravity.NORTH);
121 if (this.running) { // should not happen!!
122 GLib.error("new branch show called, when already being displayed?");
127 GitMonitor.gitmonitor.stop();
133 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
134 this.el.set_default_size( 500,200); // not sure why it grows..
135 GLib.debug("Loading tickets");
139 this.el.set_keep_above(true);
142 var curproj = RooProject.getProjectByRepo(this.repo);
143 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
145 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
146 _this.createbtn.updateState();
148 _this.ticketsel.el.get_child().get_style_context().remove_class("warning");
150 var name = RooTicket.singleton().usernameLocal();
151 var ticket = RooTicket.singleton().getById(tid);
152 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
154 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
156 _this.view.loadTicket(tid);
160 public class Xcls_Box2 : Object
163 private NewBranch _this;
169 public Xcls_Box2(NewBranch _owner )
172 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
176 // set gobject values
177 var child_0 = new Xcls_Table3( _this );
179 this.el.pack_start ( child_0.el , false,false,0 );
180 var child_1 = new Xcls_scrolled_window( _this );
182 this.el.add ( child_1.el );
185 // user defined functions
187 public class Xcls_Table3 : Object
190 private NewBranch _this;
196 public Xcls_Table3(NewBranch _owner )
199 this.el = new Gtk.Table( 5, 5, true );
203 // set gobject values
204 this.el.expand = false;
206 this.el.column_spacing = 4;
207 this.el.vexpand = false;
208 var child_0 = new Xcls_Label4( _this );
210 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
211 var child_1 = new Xcls_Label5( _this );
213 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
214 var child_2 = new Xcls_projectsel( _this );
216 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
217 var child_3 = new Xcls_ticketsel( _this );
219 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
220 var child_4 = new Xcls_Button12( _this );
222 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
223 var child_5 = new Xcls_Label13( _this );
225 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
226 var child_6 = new Xcls_name( _this );
228 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
229 var child_7 = new Xcls_createbtn( _this );
231 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
232 var child_8 = new Xcls_Box16( _this );
234 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
237 // user defined functions
239 public class Xcls_Label4 : Object
242 private NewBranch _this;
248 public Xcls_Label4(NewBranch _owner )
251 this.el = new Gtk.Label( "Project" );
255 // set gobject values
256 this.el.halign = Gtk.Align.START;
257 this.el.justify = Gtk.Justification.RIGHT;
258 this.el.visible = true;
261 // user defined functions
264 public class Xcls_Label5 : Object
267 private NewBranch _this;
273 public Xcls_Label5(NewBranch _owner )
276 this.el = new Gtk.Label( "Ticket" );
280 // set gobject values
281 this.el.halign = Gtk.Align.START;
282 this.el.visible = true;
285 // user defined functions
288 public class Xcls_projectsel : Object
290 public Gtk.ComboBox el;
291 private NewBranch _this;
298 public Xcls_projectsel(NewBranch _owner )
301 _this.projectsel = this;
302 this.el = new Gtk.ComboBox.with_entry();
305 this.loading = false;
307 // set gobject values
308 var child_0 = new Xcls_prcellrenderer( _this );
310 this.el.pack_start ( child_0.el , true );
311 var child_1 = new Xcls_prmodel( _this );
313 this.el.set_model ( child_1.el );
317 this.el.set_entry_text_column(1);
320 this.el.changed.connect( () => {
324 var project_id = this.selectedProjectId();
325 _this.dbmodel.loadTickets(project_id);
328 /*if (this.loading) {
331 var ticket_id = this.selectedTicketId();
333 var name = RooTicket.singleton().usernameLocal();
335 if (ticket_id == "" || ticket_id == null) {
337 var dt = new DateTime.now_local();
338 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
343 var ticket = RooTicket.singleton().getById(ticket_id);
345 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
347 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
352 // user defined functions
353 public string selectedProjectId () {
358 this.el.get_active_iter (out iter);
359 _this.prmodel.el.get_value (iter, 0, out val1);
362 return (string) val1;
369 public class Xcls_prcellrenderer : Object
371 public Gtk.CellRendererText el;
372 private NewBranch _this;
378 public Xcls_prcellrenderer(NewBranch _owner )
381 _this.prcellrenderer = this;
382 this.el = new Gtk.CellRendererText();
386 // set gobject values
389 // user defined functions
392 public class Xcls_prmodel : Object
394 public Gtk.ListStore el;
395 private NewBranch _this;
401 public Xcls_prmodel(NewBranch _owner )
404 _this.prmodel = this;
405 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
409 // set gobject values
412 // user defined functions
413 public void loadProjects (string id) {
417 _this.projectsel.loading = true;
426 el.set_value(iter, 0, "");
427 el.set_value(iter, 1, "-- select a project --");
429 _this.projectsel.el.set_active_iter(iter);
432 foreach(var project in RooProject.projects()) {
436 el.set_value(iter, 0, project.id);
437 el.set_value(iter, 1, project.name );
438 if (id == project.id) {
439 _this.projectsel.el.set_active_iter(iter);
444 _this.projectsel.loading = false;
445 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
451 public class Xcls_ticketsel : Object
453 public Gtk.ComboBox el;
454 private NewBranch _this;
461 public Xcls_ticketsel(NewBranch _owner )
464 _this.ticketsel = this;
465 this.el = new Gtk.ComboBox.with_entry();
468 this.loading = false;
470 // set gobject values
471 var child_0 = new Xcls_dbcellrenderer( _this );
473 this.el.pack_start ( child_0.el , true );
474 var child_1 = new Xcls_dbmodel( _this );
476 this.el.set_model ( child_1.el );
480 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
481 this.el.set_entry_text_column(1);
482 this.el.get_child().set_sensitive(false);
485 this.el.changed.connect( () => {
489 var ticket_id = this.selectedTicketId();
491 var name = RooTicket.singleton().usernameLocal();
493 this.el.get_child().get_style_context().remove_class("warning");
494 if (ticket_id == "" || ticket_id == null) {
496 var dt = new DateTime.now_local();
497 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
498 _this.view.loadTicket("");
500 this.el.get_child().get_style_context().add_class("warning");
501 _this.createbtn.updateState();
506 var ticket = RooTicket.singleton().getById(ticket_id);
508 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
509 _this.scrolled_window.el.show();
511 _this.view.loadTicket(ticket.id);
512 _this.createbtn.updateState();
514 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
518 // user defined functions
519 public string selectedTicketId () {
524 this.el.get_active_iter (out iter);
525 _this.dbmodel.el.get_value (iter, 0, out val1);
528 return (string) val1;
535 public class Xcls_dbcellrenderer : Object
537 public Gtk.CellRendererText el;
538 private NewBranch _this;
544 public Xcls_dbcellrenderer(NewBranch _owner )
547 _this.dbcellrenderer = this;
548 this.el = new Gtk.CellRendererText();
552 // set gobject values
555 // user defined functions
558 public class Xcls_dbmodel : Object
560 public Gtk.ListStore el;
561 private NewBranch _this;
567 public Xcls_dbmodel(NewBranch _owner )
570 _this.dbmodel = this;
571 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
575 // set gobject values
578 // user defined functions
579 public void loadTickets (string project_id , string tid = "") {
583 // fixme .. get project id from selection..
585 RooTicket.singleton().loadTickets(
587 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
588 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
591 _this.ticketsel.loading = true;
600 el.set_value(iter, 0, "");
601 el.set_value(iter, 1, "-- select a ticket --");
603 _this.ticketsel.el.set_active_iter(iter);
604 var tickets = RooTicket.singleton().tickets;
605 foreach(var ticket in tickets) {
609 el.set_value(iter, 0, ticket.id);
610 el.set_value(iter, 1, "#%s %s".printf( ticket.id, ticket.summary));
612 if (ticket.id == tid) {
613 _this.ticketsel.el.set_active_iter(iter);
618 _this.ticketsel.loading = false;
619 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
625 public class Xcls_Button12 : Object
627 public Gtk.Button el;
628 private NewBranch _this;
634 public Xcls_Button12(NewBranch _owner )
637 this.el = new Gtk.Button();
641 // set gobject values
642 this.el.expand = false;
643 this.el.label = "New Ticket";
646 this.el.clicked.connect( () => {
647 _this.el.response(-1);
648 Ticket.singleton().show(_this.repo);
653 // user defined functions
656 public class Xcls_Label13 : Object
659 private NewBranch _this;
665 public Xcls_Label13(NewBranch _owner )
668 this.el = new Gtk.Label( "Use this as branch name" );
672 // set gobject values
673 this.el.halign = Gtk.Align.START;
674 this.el.justify = Gtk.Justification.RIGHT;
675 this.el.xalign = 0.900000f;
678 // user defined functions
681 public class Xcls_name : Object
684 private NewBranch _this;
690 public Xcls_name(NewBranch _owner )
694 this.el = new Gtk.Entry();
698 // set gobject values
699 this.el.visible = true;
702 // user defined functions
705 public class Xcls_createbtn : Object
707 public Gtk.Button el;
708 private NewBranch _this;
714 public Xcls_createbtn(NewBranch _owner )
717 _this.createbtn = this;
718 this.el = new Gtk.Button();
722 // set gobject values
723 this.el.label = "Create Branch";
728 this.el.get_style_context().add_class("suggested-action");
732 this.el.clicked.connect( () => {
734 GLib.debug("fire response = 1");
736 var ticket_id = _this.ticketsel.selectedTicketId();
738 if (ticket_id == "") {
739 _this.ticketsel.el.get_child().get_style_context().add_class("warning");
743 _this.el.response(1);
747 // user defined functions
748 public void updateState () {
750 var ticket_id = _this.ticketsel.selectedTicketId();
752 if (ticket_id == "") {
753 this.el.set_sensitive(false);
757 this.el.set_sensitive(true);
762 public class Xcls_Box16 : Object
765 private NewBranch _this;
771 public Xcls_Box16(NewBranch _owner )
774 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
778 // set gobject values
779 var child_0 = new Xcls_btn_not_me( _this );
781 this.el.add ( child_0.el );
782 var child_1 = new Xcls_btn_closed( _this );
784 this.el.add ( child_1.el );
785 var child_2 = new Xcls_Label19( _this );
787 this.el.add ( child_2.el );
790 // user defined functions
792 public class Xcls_btn_not_me : Object
794 public Gtk.CheckButton el;
795 private NewBranch _this;
801 public Xcls_btn_not_me(NewBranch _owner )
804 _this.btn_not_me = this;
805 this.el = new Gtk.CheckButton();
809 // set gobject values
810 this.el.label = "Show tickets not assigned to me";
813 this.el.toggled.connect( () => {
814 var project_id = _this.projectsel.selectedProjectId();
815 _this.dbmodel.loadTickets(project_id);
819 // user defined functions
822 public class Xcls_btn_closed : Object
824 public Gtk.CheckButton el;
825 private NewBranch _this;
831 public Xcls_btn_closed(NewBranch _owner )
834 _this.btn_closed = this;
835 this.el = new Gtk.CheckButton();
839 // set gobject values
840 this.el.label = "Show closed Tickets";
843 this.el.toggled.connect( () => {
844 var project_id = _this.projectsel.selectedProjectId();
845 _this.dbmodel.loadTickets(project_id);
850 // user defined functions
853 public class Xcls_Label19 : Object
856 private NewBranch _this;
862 public Xcls_Label19(NewBranch _owner )
865 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
869 // set gobject values
870 this.el.halign = Gtk.Align.END;
871 this.el.hexpand = true;
872 this.el.use_markup = true;
875 this.el.activate_link.connect( (uri) => {
876 if (uri == "refresh") {
878 var curproj = RooProject.getProjectByRepo(_this.repo);
879 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
881 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
887 // user defined functions
892 public class Xcls_scrolled_window : Object
894 public Gtk.ScrolledWindow el;
895 private NewBranch _this;
901 public Xcls_scrolled_window(NewBranch _owner )
904 _this.scrolled_window = this;
905 this.el = new Gtk.ScrolledWindow( null, null );
909 // set gobject values
910 this.el.height_request = 500;
911 this.el.vexpand = true;
912 var child_0 = new Xcls_view( _this );
914 this.el.add ( child_0.el );
919 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
923 // user defined functions
925 public class Xcls_view : Object
927 public WebKit.WebView el;
928 private NewBranch _this;
934 public Xcls_view(NewBranch _owner )
938 this.el = new WebKit.WebView();
942 // set gobject values
945 // user defined functions
946 public void loadTicket (string tid) {
948 _this.el.get_size(out w, out h);
951 _this.scrolled_window.el.hide();
952 _this.el.resize(w, 150);
954 _this.scrolled_window.el.show();
955 _this.el.resize(w, 800);
958 var rs = RooTicket.singleton();
959 var uri = new WebKit.URIRequest("https://roojs.com/admin.php/MTrack/View/" + tid);
960 var hd = uri.get_http_headers();
961 var authCode = Base64.encode ("%s:%s".printf(rs.username, rs.password).data);
962 hd.append("Authorization", "Basic %s".printf(authCode));
964 this.el.load_request(uri);
970 public class Xcls_Notebook22 : Object
972 public Gtk.Notebook el;
973 private NewBranch _this;
979 public Xcls_Notebook22(NewBranch _owner )
982 this.el = new Gtk.Notebook();
986 // set gobject values
987 this.el.vexpand = true;
988 var child_0 = new Xcls_label_select_ticket( _this );
990 var child_1 = new Xcls_label_create_ticket( _this );
992 var child_2 = new Xcls_label_quick_commit( _this );
996 // user defined functions
998 public class Xcls_label_select_ticket : Object
1000 public Gtk.Label el;
1001 private NewBranch _this;
1007 public Xcls_label_select_ticket(NewBranch _owner )
1010 _this.label_select_ticket = this;
1011 this.el = new Gtk.Label( "Select Existing Ticket to work on" );
1015 // set gobject values
1018 // user defined functions
1021 public class Xcls_label_create_ticket : Object
1023 public Gtk.Label el;
1024 private NewBranch _this;
1030 public Xcls_label_create_ticket(NewBranch _owner )
1033 _this.label_create_ticket = this;
1034 this.el = new Gtk.Label( "Create a new Ticket" );
1038 // set gobject values
1041 // user defined functions
1044 public class Xcls_label_quick_commit : Object
1046 public Gtk.Label el;
1047 private NewBranch _this;
1053 public Xcls_label_quick_commit(NewBranch _owner )
1056 _this.label_quick_commit = this;
1057 this.el = new Gtk.Label( "Quick Commit" );
1061 // set gobject values
1064 // user defined functions
1068 public class Xcls_Box26 : Object
1071 private NewBranch _this;
1077 public Xcls_Box26(NewBranch _owner )
1080 this.el = new Gtk.Box( null, 0 );
1084 // set gobject values
1085 this.el.homogeneous = false;
1088 // user defined functions