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