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