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