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_build_module build_module;
16     public Xcls_dbcellrenderer dbcellrenderer;
17     public Xcls_dbmodel dbmodel;
18     public Xcls_name name;
19
20         // my vars (def)
21
22     // ctor
23     public NewBranch()
24     {
25         _this = this;
26         this.el = new Gtk.Dialog();
27
28         // my vars (dec)
29
30         // set gobject values
31         this.el.title = "Create a working branch ";
32         this.el.default_height = 200;
33         this.el.default_width = 500;
34         this.el.deletable = true;
35         this.el.modal = true;
36         var child_0 = new Xcls_VBox2( _this );
37         child_0.ref();
38         this.el.get_content_area().add (  child_0.el  );
39         var child_1 = new Xcls_Button10( _this );
40         child_1.ref();
41         this.el.add_action_widget (  child_1.el , 0 );
42         var child_2 = new Xcls_Button11( _this );
43         child_2.ref();
44         this.el.add_action_widget (  child_2.el , 1 );
45
46         //listeners
47         this.el.delete_event.connect( (self, event) => {
48             this.el.hide();
49             return true; 
50             //test  
51         });
52         this.el.response.connect( (self, response_id) =>  { 
53           
54                  GLib.debug("got %d", (int) response_id);
55                  _this.el.hide();
56                  
57         });
58         this.el.show.connect( (self)  => {
59          
60         
61           //test
62         });
63     }
64
65     // user defined functions
66     public   void show ( ) 
67     {
68          // this.el.set_gravity(Gdk.Gravity.NORTH);
69          
70         this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
71                 GLib.debug("Loading tickets"); 
72         _this.dbmodel.loadTickets();
73     
74         this.el.show_all();
75     
76     
77      
78         
79           
80     }
81     public class Xcls_VBox2 : Object
82     {
83         public Gtk.VBox el;
84         private NewBranch  _this;
85
86
87             // my vars (def)
88
89         // ctor
90         public Xcls_VBox2(NewBranch _owner )
91         {
92             _this = _owner;
93             this.el = new Gtk.VBox( true, 0 );
94
95             // my vars (dec)
96
97             // set gobject values
98             var child_0 = new Xcls_Table3( _this );
99             child_0.ref();
100             this.el.pack_start (  child_0.el , false,false,0 );
101         }
102
103         // user defined functions
104     }
105     public class Xcls_Table3 : Object
106     {
107         public Gtk.Table el;
108         private NewBranch  _this;
109
110
111             // my vars (def)
112
113         // ctor
114         public Xcls_Table3(NewBranch _owner )
115         {
116             _this = _owner;
117             this.el = new Gtk.Table( 2, 2, false );
118
119             // my vars (dec)
120
121             // set gobject values
122             this.el.margin = 2;
123             this.el.column_spacing = 2;
124             var child_0 = new Xcls_Label4( _this );
125             child_0.ref();
126             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
127             var child_1 = new Xcls_build_module( _this );
128             child_1.ref();
129             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
130             var child_2 = new Xcls_Label8( _this );
131             child_2.ref();
132             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
133             var child_3 = new Xcls_name( _this );
134             child_3.ref();
135             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
136         }
137
138         // user defined functions
139     }
140     public class Xcls_Label4 : Object
141     {
142         public Gtk.Label el;
143         private NewBranch  _this;
144
145
146             // my vars (def)
147
148         // ctor
149         public Xcls_Label4(NewBranch _owner )
150         {
151             _this = _owner;
152             this.el = new Gtk.Label( "Select Ticket" );
153
154             // my vars (dec)
155
156             // set gobject values
157             this.el.justify = Gtk.Justification.RIGHT;
158             this.el.xalign = 0.900000f;
159             this.el.visible = true;
160         }
161
162         // user defined functions
163     }
164
165     public class Xcls_build_module : Object
166     {
167         public Gtk.ComboBox el;
168         private NewBranch  _this;
169
170
171             // my vars (def)
172
173         // ctor
174         public Xcls_build_module(NewBranch _owner )
175         {
176             _this = _owner;
177             _this.build_module = this;
178             this.el = new Gtk.ComboBox();
179
180             // my vars (dec)
181
182             // set gobject values
183             var child_0 = new Xcls_dbcellrenderer( _this );
184             child_0.ref();
185             this.el.pack_start (  child_0.el , true );
186             var child_1 = new Xcls_dbmodel( _this );
187             child_1.ref();
188             this.el.set_model (  child_1.el  );
189
190             // init method
191
192             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
193
194             //listeners
195             this.el.changed.connect( () => {
196                 Gtk.TreeIter iter;
197                 Value val1;
198                 Value val2;
199              
200                 this.el.get_active_iter (out iter);
201                 _this.dbmodel.el.get_value (iter, 0, out val1);
202                 _this.dbmodel.el.get_value (iter, 1, out val2);
203             
204                 var ticket_id = (string) val1;
205                 
206                 var name = RooTicket.singleton().usernameLocal();
207                 
208                 if (ticket_id == "") {
209                 
210                         var dt = new  DateTime.now_local();
211                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
212                         return;
213                 }
214                 
215                 var ticket = RooTicket.singleton().getById(ticket_id);
216                
217                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
218                 
219                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
220             });
221         }
222
223         // user defined functions
224     }
225     public class Xcls_dbcellrenderer : Object
226     {
227         public Gtk.CellRendererText el;
228         private NewBranch  _this;
229
230
231             // my vars (def)
232
233         // ctor
234         public Xcls_dbcellrenderer(NewBranch _owner )
235         {
236             _this = _owner;
237             _this.dbcellrenderer = this;
238             this.el = new Gtk.CellRendererText();
239
240             // my vars (dec)
241
242             // set gobject values
243         }
244
245         // user defined functions
246     }
247
248     public class Xcls_dbmodel : Object
249     {
250         public Gtk.ListStore el;
251         private NewBranch  _this;
252
253
254             // my vars (def)
255
256         // ctor
257         public Xcls_dbmodel(NewBranch _owner )
258         {
259             _this = _owner;
260             _this.dbmodel = this;
261             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
262
263             // my vars (dec)
264
265             // set gobject values
266         }
267
268         // user defined functions
269         public void loadTickets () {
270         
271             RooTicket.singleton().loadTickets();
272             
273             
274         
275             this.el.clear();                                    
276             Gtk.TreeIter iter;
277             var el = this.el;
278             
279             el.append(out iter);
280         
281             
282             el.set_value(iter, 0, "");
283             el.set_value(iter, 1, "-- select a ticket --");
284             
285             _this.build_module.el.set_active_iter(iter);
286             var tickets = RooTicket.singleton().tickets;
287             foreach(var ticket in tickets) {
288             
289         
290                 el.append(out iter);
291                 
292                 el.set_value(iter, 0, ticket.id);
293                 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
294                 
295                 //if (data.get(i) == cur) {
296                  //   _this.build_module.el.set_active_iter(iter);
297                // }
298                 
299             }
300              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
301                                              
302         }
303     }
304
305
306     public class Xcls_Label8 : Object
307     {
308         public Gtk.Label el;
309         private NewBranch  _this;
310
311
312             // my vars (def)
313
314         // ctor
315         public Xcls_Label8(NewBranch _owner )
316         {
317             _this = _owner;
318             this.el = new Gtk.Label( "or use this as branch name" );
319
320             // my vars (dec)
321
322             // set gobject values
323             this.el.justify = Gtk.Justification.RIGHT;
324             this.el.xalign = 0.900000f;
325         }
326
327         // user defined functions
328     }
329
330     public class Xcls_name : Object
331     {
332         public Gtk.Entry el;
333         private NewBranch  _this;
334
335
336             // my vars (def)
337
338         // ctor
339         public Xcls_name(NewBranch _owner )
340         {
341             _this = _owner;
342             _this.name = this;
343             this.el = new Gtk.Entry();
344
345             // my vars (dec)
346
347             // set gobject values
348             this.el.visible = true;
349         }
350
351         // user defined functions
352     }
353
354
355
356     public class Xcls_Button10 : Object
357     {
358         public Gtk.Button el;
359         private NewBranch  _this;
360
361
362             // my vars (def)
363
364         // ctor
365         public Xcls_Button10(NewBranch _owner )
366         {
367             _this = _owner;
368             this.el = new Gtk.Button();
369
370             // my vars (dec)
371
372             // set gobject values
373             this.el.relief = Gtk.ReliefStyle.NONE;
374             this.el.label = "Do not create Branch";
375         }
376
377         // user defined functions
378     }
379
380     public class Xcls_Button11 : Object
381     {
382         public Gtk.Button el;
383         private NewBranch  _this;
384
385
386             // my vars (def)
387
388         // ctor
389         public Xcls_Button11(NewBranch _owner )
390         {
391             _this = _owner;
392             this.el = new Gtk.Button();
393
394             // my vars (dec)
395
396             // set gobject values
397             this.el.label = "Create Branch";
398         }
399
400         // user defined functions
401     }
402
403 }