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