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