sync
[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
24     // ctor
25     public NewBranch()
26     {
27         _this = this;
28         this.el = new Gtk.Dialog();
29
30         // my vars (dec)
31         this.repo = null;
32         this.running = false;
33
34         // set gobject values
35         this.el.title = "Create a working branch ";
36         this.el.default_height = 200;
37         this.el.default_width = 500;
38         this.el.deletable = true;
39         this.el.modal = true;
40         var child_0 = new Xcls_VBox2( _this );
41         child_0.ref();
42         this.el.get_content_area().add (  child_0.el  );
43         var child_1 = new Xcls_Button10( _this );
44         child_1.ref();
45         this.el.add_action_widget (  child_1.el , 0 );
46         var child_2 = new Xcls_Button11( _this );
47         child_2.ref();
48         this.el.add_action_widget (  child_2.el , 1 );
49
50         //listeners
51         this.el.delete_event.connect( (self, event) => {
52             this.el.hide();
53             this.running = false;
54             return true; 
55             //test  
56         });
57         this.el.response.connect( (self, response_id) =>  { 
58           
59                 GLib.debug("got %d", (int) response_id);
60                 if (response_id == 0) {
61                     _this.el.hide();    
62                     this.running = false; 
63                         GitMonitor.gitmonitor.start();      
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                 if (ticket_id != "" ) {
79                                 this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);
80                         } else {
81                                 this.repo.createBranchNamed(bn);
82                         }
83             }
84                 GitMonitor.gitmonitor.start();
85                             this.running = false; 
86         
87                  
88                  
89                  
90         
91                  
92         });
93         this.el.show.connect( (self)  => {
94          
95         
96           //test
97         });
98     }
99
100     // user defined functions
101     public   void show ( GitRepo repo ) 
102     {
103          // this.el.set_gravity(Gdk.Gravity.NORTH);
104         if (this.running) {
105                 return;
106         }
107         this.running  = true;
108         GitMonitor.gitmonitor.stop();
109         
110         this.repo = repo;
111         
112         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
113                 GLib.debug("Loading tickets"); 
114     
115     
116         this.el.show_all();
117         _this.dbmodel.loadTickets();
118     
119     }
120     public class Xcls_VBox2 : Object
121     {
122         public Gtk.VBox el;
123         private NewBranch  _this;
124
125
126             // my vars (def)
127
128         // ctor
129         public Xcls_VBox2(NewBranch _owner )
130         {
131             _this = _owner;
132             this.el = new Gtk.VBox( true, 0 );
133
134             // my vars (dec)
135
136             // set gobject values
137             var child_0 = new Xcls_Table3( _this );
138             child_0.ref();
139             this.el.pack_start (  child_0.el , false,false,0 );
140         }
141
142         // user defined functions
143     }
144     public class Xcls_Table3 : Object
145     {
146         public Gtk.Table el;
147         private NewBranch  _this;
148
149
150             // my vars (def)
151
152         // ctor
153         public Xcls_Table3(NewBranch _owner )
154         {
155             _this = _owner;
156             this.el = new Gtk.Table( 2, 2, false );
157
158             // my vars (dec)
159
160             // set gobject values
161             this.el.margin = 2;
162             this.el.column_spacing = 2;
163             var child_0 = new Xcls_Label4( _this );
164             child_0.ref();
165             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
166             var child_1 = new Xcls_ticketsel( _this );
167             child_1.ref();
168             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
169             var child_2 = new Xcls_Label8( _this );
170             child_2.ref();
171             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
172             var child_3 = new Xcls_name( _this );
173             child_3.ref();
174             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
175         }
176
177         // user defined functions
178     }
179     public class Xcls_Label4 : Object
180     {
181         public Gtk.Label el;
182         private NewBranch  _this;
183
184
185             // my vars (def)
186
187         // ctor
188         public Xcls_Label4(NewBranch _owner )
189         {
190             _this = _owner;
191             this.el = new Gtk.Label( "Select Ticket" );
192
193             // my vars (dec)
194
195             // set gobject values
196             this.el.justify = Gtk.Justification.RIGHT;
197             this.el.xalign = 0.900000f;
198             this.el.visible = true;
199         }
200
201         // user defined functions
202     }
203
204     public class Xcls_ticketsel : Object
205     {
206         public Gtk.ComboBox el;
207         private NewBranch  _this;
208
209
210             // my vars (def)
211         public bool loading;
212
213         // ctor
214         public Xcls_ticketsel(NewBranch _owner )
215         {
216             _this = _owner;
217             _this.ticketsel = this;
218             this.el = new Gtk.ComboBox();
219
220             // my vars (dec)
221             this.loading = false;
222
223             // set gobject values
224             var child_0 = new Xcls_dbcellrenderer( _this );
225             child_0.ref();
226             this.el.pack_start (  child_0.el , true );
227             var child_1 = new Xcls_dbmodel( _this );
228             child_1.ref();
229             this.el.set_model (  child_1.el  );
230
231             // init method
232
233             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
234
235             //listeners
236             this.el.changed.connect( () => {
237                 if (this.loading) {
238                         return;
239                 }
240                 var ticket_id = this.selectedTicketId();
241                 
242                 var name = RooTicket.singleton().usernameLocal();
243                 
244                 if (ticket_id == "" || ticket_id == null) {
245                 
246                         var dt = new  DateTime.now_local();
247                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
248                         return;
249                 }
250                 
251                 
252                 var ticket = RooTicket.singleton().getById(ticket_id);
253                
254                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
255                 
256                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
257             });
258         }
259
260         // user defined functions
261         public string selectedTicketId () {
262         Gtk.TreeIter iter;
263                 Value val1;
264          
265          
266                 this.el.get_active_iter (out iter);
267                 _this.dbmodel.el.get_value (iter, 0, out val1);
268          
269         
270                 return  (string) val1;
271                 
272                 
273                 
274                 
275         }
276     }
277     public class Xcls_dbcellrenderer : Object
278     {
279         public Gtk.CellRendererText el;
280         private NewBranch  _this;
281
282
283             // my vars (def)
284
285         // ctor
286         public Xcls_dbcellrenderer(NewBranch _owner )
287         {
288             _this = _owner;
289             _this.dbcellrenderer = this;
290             this.el = new Gtk.CellRendererText();
291
292             // my vars (dec)
293
294             // set gobject values
295         }
296
297         // user defined functions
298     }
299
300     public class Xcls_dbmodel : Object
301     {
302         public Gtk.ListStore el;
303         private NewBranch  _this;
304
305
306             // my vars (def)
307
308         // ctor
309         public Xcls_dbmodel(NewBranch _owner )
310         {
311             _this = _owner;
312             _this.dbmodel = this;
313             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
314
315             // my vars (dec)
316
317             // set gobject values
318         }
319
320         // user defined functions
321         public void loadTickets () {
322         
323             RooTicket.singleton().loadTickets();
324             
325             _this.ticketsel.loading = true;
326         
327             this.el.clear();                                    
328             Gtk.TreeIter iter;
329             var el = this.el;
330             
331             el.append(out iter);
332         
333             
334             el.set_value(iter, 0, "");
335             el.set_value(iter, 1, "-- select a ticket --");
336             
337             _this.ticketsel.el.set_active_iter(iter);
338             var tickets = RooTicket.singleton().tickets;
339             foreach(var ticket in tickets) {
340             
341                 el.append(out iter);
342                 
343                 el.set_value(iter, 0, ticket.id);
344                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
345                 
346                 //if (data.get(i) == cur) {
347                  //   _this.build_module.el.set_active_iter(iter);
348                // }
349                 
350             }
351             
352             _this.ticketsel.loading = false;
353              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
354                                              
355         }
356     }
357
358
359     public class Xcls_Label8 : Object
360     {
361         public Gtk.Label el;
362         private NewBranch  _this;
363
364
365             // my vars (def)
366
367         // ctor
368         public Xcls_Label8(NewBranch _owner )
369         {
370             _this = _owner;
371             this.el = new Gtk.Label( "or use this as branch name" );
372
373             // my vars (dec)
374
375             // set gobject values
376             this.el.justify = Gtk.Justification.RIGHT;
377             this.el.xalign = 0.900000f;
378         }
379
380         // user defined functions
381     }
382
383     public class Xcls_name : Object
384     {
385         public Gtk.Entry el;
386         private NewBranch  _this;
387
388
389             // my vars (def)
390
391         // ctor
392         public Xcls_name(NewBranch _owner )
393         {
394             _this = _owner;
395             _this.name = this;
396             this.el = new Gtk.Entry();
397
398             // my vars (dec)
399
400             // set gobject values
401             this.el.visible = true;
402         }
403
404         // user defined functions
405     }
406
407
408
409     public class Xcls_Button10 : Object
410     {
411         public Gtk.Button el;
412         private NewBranch  _this;
413
414
415             // my vars (def)
416
417         // ctor
418         public Xcls_Button10(NewBranch _owner )
419         {
420             _this = _owner;
421             this.el = new Gtk.Button();
422
423             // my vars (dec)
424
425             // set gobject values
426             this.el.relief = Gtk.ReliefStyle.NONE;
427             this.el.label = "Do not create Branch";
428         }
429
430         // user defined functions
431     }
432
433     public class Xcls_Button11 : Object
434     {
435         public Gtk.Button el;
436         private NewBranch  _this;
437
438
439             // my vars (def)
440
441         // ctor
442         public Xcls_Button11(NewBranch _owner )
443         {
444             _this = _owner;
445             this.el = new Gtk.Button();
446
447             // my vars (dec)
448
449             // set gobject values
450             this.el.label = "Create Branch";
451         }
452
453         // user defined functions
454     }
455
456 }