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