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