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