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