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