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