NewBranch.bjs
[gitlive] / NewBranch.vala
1 static NewBranch  _NewBranch;
2
3 public class NewBranch : Object
4 {
5     public Gtk.Dialog el;
6     private NewBranch  _this;
7
8     public static NewBranch singleton()
9     {
10         if (_NewBranch == null) {
11             _NewBranch= new NewBranch();
12         }
13         return _NewBranch;
14     }
15     public Xcls_ticketsel ticketsel;
16     public Xcls_dbcellrenderer dbcellrenderer;
17     public Xcls_dbmodel dbmodel;
18     public Xcls_name name;
19
20         // my vars (def)
21     public GitRepo? repo;
22     public bool running;
23     public Gee.ArrayList<GitMonitorQueue> queue;
24
25     // ctor
26     public NewBranch()
27     {
28         _this = this;
29         this.el = new Gtk.Dialog();
30
31         // my vars (dec)
32         this.repo = null;
33         this.running = false;
34         this.queue = null;
35
36         // set gobject values
37         this.el.title = "Create a working branch ";
38         this.el.default_height = 200;
39         this.el.default_width = 500;
40         this.el.deletable = true;
41         this.el.modal = true;
42         var child_0 = new Xcls_VBox2( _this );
43         child_0.ref();
44         this.el.get_content_area().add (  child_0.el  );
45         var child_1 = new Xcls_Button11( _this );
46         child_1.ref();
47         this.el.add_action_widget (  child_1.el , 0 );
48         var child_2 = new Xcls_Button12( _this );
49         child_2.ref();
50         this.el.add_action_widget (  child_2.el , 1 );
51
52         //listeners
53         this.el.delete_event.connect( (self, event) => {
54             this.el.hide();
55             return true; 
56             //test  
57         });
58         this.el.response.connect( (self, response_id) =>  { 
59           
60                 GLib.debug("got %d", (int) response_id);
61                 if (response_id == 0) {
62                     _this.el.hide();    
63                     this.running = false; 
64                         return;
65                 }
66                  
67                 // have they selected a ticket..
68                 // make that the current active ticket?
69                 // we really need to store locally what ticket is being worked on..
70                 // in theory we could be working on multiple project and not merging..
71                 // -- each repo would have their active ticket (only one per repo)
72                 // -- so we could just store that in there
73                 // -- initial load can check the contents of the ticket files on first scan.
74                 var ticket_id = _this.ticketsel.selectedTicketId();
75                 
76             if (this.repo != null) {
77                 var bn = _this.name.el.get_text();
78         
79                         var res = this.repo.setActiveTicket(                    
80                                  RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
81                          );
82                          if (res) {
83                                 // start the monitoring..
84                                  GitMonitor.gitmonitor.start();
85                                  
86                          }
87             }
88             
89         
90             this.running = false; 
91         
92                 this.el.hide();
93                  
94                  
95         
96                  
97         });
98         this.el.show.connect( (self)  => {
99          
100         
101           //test
102         });
103     }
104
105     // user defined functions
106     public   void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue ) 
107     {
108          // this.el.set_gravity(Gdk.Gravity.NORTH);
109         if (this.running) { // should not happen!!
110                 GLib.error("new branch show called, when already being displayed?");
111         }
112         this.queue = queue;
113         
114         this.running  = true;
115         GitMonitor.gitmonitor.stop();
116         
117         this.repo = repo;
118         
119         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
120                 GLib.debug("Loading tickets"); 
121     
122     
123         this.el.show_all();
124             this.el.set_keep_above(true);
125         _this.dbmodel.loadTickets();
126         this.el.run();
127     
128     }
129     public class Xcls_VBox2 : Object
130     {
131         public Gtk.VBox el;
132         private NewBranch  _this;
133
134
135             // my vars (def)
136
137         // ctor
138         public Xcls_VBox2(NewBranch _owner )
139         {
140             _this = _owner;
141             this.el = new Gtk.VBox( true, 0 );
142
143             // my vars (dec)
144
145             // set gobject values
146             var child_0 = new Xcls_Table3( _this );
147             child_0.ref();
148             this.el.pack_start (  child_0.el , false,false,0 );
149         }
150
151         // user defined functions
152     }
153     public class Xcls_Table3 : Object
154     {
155         public Gtk.Table el;
156         private NewBranch  _this;
157
158
159             // my vars (def)
160
161         // ctor
162         public Xcls_Table3(NewBranch _owner )
163         {
164             _this = _owner;
165             this.el = new Gtk.Table( 5, 6, false );
166
167             // my vars (dec)
168
169             // set gobject values
170             this.el.margin = 2;
171             this.el.column_spacing = 2;
172             var child_0 = new Xcls_Label4( _this );
173             child_0.ref();
174             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
175             var child_1 = new Xcls_Label5( _this );
176             child_1.ref();
177             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
178             var child_2 = new Xcls_ticketsel( _this );
179             child_2.ref();
180             this.el.attach_defaults (  child_2.el , 1,5,1,2 );
181             var child_3 = new Xcls_Label9( _this );
182             child_3.ref();
183             this.el.attach_defaults (  child_3.el , 0,1,2,3 );
184             var child_4 = new Xcls_name( _this );
185             child_4.ref();
186             this.el.attach_defaults (  child_4.el , 0,5,3,4 );
187         }
188
189         // user defined functions
190     }
191     public class Xcls_Label4 : Object
192     {
193         public Gtk.Label el;
194         private NewBranch  _this;
195
196
197             // my vars (def)
198
199         // ctor
200         public Xcls_Label4(NewBranch _owner )
201         {
202             _this = _owner;
203             this.el = new Gtk.Label( "Project" );
204
205             // my vars (dec)
206
207             // set gobject values
208             this.el.halign = Gtk.Align.START;
209             this.el.justify = Gtk.Justification.RIGHT;
210             this.el.visible = true;
211         }
212
213         // user defined functions
214     }
215
216     public class Xcls_Label5 : Object
217     {
218         public Gtk.Label el;
219         private NewBranch  _this;
220
221
222             // my vars (def)
223
224         // ctor
225         public Xcls_Label5(NewBranch _owner )
226         {
227             _this = _owner;
228             this.el = new Gtk.Label( "Ticket" );
229
230             // my vars (dec)
231
232             // set gobject values
233             this.el.halign = Gtk.Align.START;
234             this.el.visible = true;
235         }
236
237         // user defined functions
238     }
239
240     public class Xcls_ticketsel : Object
241     {
242         public Gtk.ComboBox el;
243         private NewBranch  _this;
244
245
246             // my vars (def)
247         public bool loading;
248
249         // ctor
250         public Xcls_ticketsel(NewBranch _owner )
251         {
252             _this = _owner;
253             _this.ticketsel = this;
254             this.el = new Gtk.ComboBox();
255
256             // my vars (dec)
257             this.loading = false;
258
259             // set gobject values
260             var child_0 = new Xcls_dbcellrenderer( _this );
261             child_0.ref();
262             this.el.pack_start (  child_0.el , true );
263             var child_1 = new Xcls_dbmodel( _this );
264             child_1.ref();
265             this.el.set_model (  child_1.el  );
266
267             // init method
268
269             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
270
271             //listeners
272             this.el.changed.connect( () => {
273                 if (this.loading) {
274                         return;
275                 }
276                 var ticket_id = this.selectedTicketId();
277                 
278                 var name = RooTicket.singleton().usernameLocal();
279                 
280                 if (ticket_id == "" || ticket_id == null) {
281                 
282                         var dt = new  DateTime.now_local();
283                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
284                         return;
285                 }
286                 
287                 
288                 var ticket = RooTicket.singleton().getById(ticket_id);
289                
290                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
291                 
292                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
293             });
294         }
295
296         // user defined functions
297         public string selectedTicketId () {
298         Gtk.TreeIter iter;
299                 Value val1;
300          
301          
302                 this.el.get_active_iter (out iter);
303                 _this.dbmodel.el.get_value (iter, 0, out val1);
304          
305         
306                 return  (string) val1;
307                 
308                 
309                 
310                 
311         }
312     }
313     public class Xcls_dbcellrenderer : Object
314     {
315         public Gtk.CellRendererText el;
316         private NewBranch  _this;
317
318
319             // my vars (def)
320
321         // ctor
322         public Xcls_dbcellrenderer(NewBranch _owner )
323         {
324             _this = _owner;
325             _this.dbcellrenderer = this;
326             this.el = new Gtk.CellRendererText();
327
328             // my vars (dec)
329
330             // set gobject values
331         }
332
333         // user defined functions
334     }
335
336     public class Xcls_dbmodel : Object
337     {
338         public Gtk.ListStore el;
339         private NewBranch  _this;
340
341
342             // my vars (def)
343
344         // ctor
345         public Xcls_dbmodel(NewBranch _owner )
346         {
347             _this = _owner;
348             _this.dbmodel = this;
349             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
350
351             // my vars (dec)
352
353             // set gobject values
354         }
355
356         // user defined functions
357         public void loadTickets () {
358         
359             RooTicket.singleton().loadTickets();
360             
361             _this.ticketsel.loading = true;
362         
363             this.el.clear();                                    
364             Gtk.TreeIter iter;
365             var el = this.el;
366             
367             el.append(out iter);
368         
369             
370             el.set_value(iter, 0, "");
371             el.set_value(iter, 1, "-- select a ticket --");
372             
373             _this.ticketsel.el.set_active_iter(iter);
374             var tickets = RooTicket.singleton().tickets;
375             foreach(var ticket in tickets) {
376             
377                 el.append(out iter);
378                 
379                 el.set_value(iter, 0, ticket.id);
380                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
381                 
382                 //if (data.get(i) == cur) {
383                  //   _this.build_module.el.set_active_iter(iter);
384                // }
385                 
386             }
387             
388             _this.ticketsel.loading = false;
389              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
390                                              
391         }
392     }
393
394
395     public class Xcls_Label9 : Object
396     {
397         public Gtk.Label el;
398         private NewBranch  _this;
399
400
401             // my vars (def)
402
403         // ctor
404         public Xcls_Label9(NewBranch _owner )
405         {
406             _this = _owner;
407             this.el = new Gtk.Label( "Use this as branch name" );
408
409             // my vars (dec)
410
411             // set gobject values
412             this.el.halign = Gtk.Align.START;
413             this.el.justify = Gtk.Justification.RIGHT;
414             this.el.xalign = 0.900000f;
415         }
416
417         // user defined functions
418     }
419
420     public class Xcls_name : Object
421     {
422         public Gtk.Entry el;
423         private NewBranch  _this;
424
425
426             // my vars (def)
427
428         // ctor
429         public Xcls_name(NewBranch _owner )
430         {
431             _this = _owner;
432             _this.name = this;
433             this.el = new Gtk.Entry();
434
435             // my vars (dec)
436
437             // set gobject values
438             this.el.visible = true;
439         }
440
441         // user defined functions
442     }
443
444
445
446     public class Xcls_Button11 : Object
447     {
448         public Gtk.Button el;
449         private NewBranch  _this;
450
451
452             // my vars (def)
453
454         // ctor
455         public Xcls_Button11(NewBranch _owner )
456         {
457             _this = _owner;
458             this.el = new Gtk.Button();
459
460             // my vars (dec)
461
462             // set gobject values
463             this.el.relief = Gtk.ReliefStyle.NONE;
464             this.el.label = "Do not create Branch";
465         }
466
467         // user defined functions
468     }
469
470     public class Xcls_Button12 : Object
471     {
472         public Gtk.Button el;
473         private NewBranch  _this;
474
475
476             // my vars (def)
477
478         // ctor
479         public Xcls_Button12(NewBranch _owner )
480         {
481             _this = _owner;
482             this.el = new Gtk.Button();
483
484             // my vars (dec)
485
486             // set gobject values
487             this.el.label = "Create Branch";
488         }
489
490         // user defined functions
491     }
492
493 }