Clone.bjs
[gitlive] / Clone.vala
1 static Clone  _Clone;
2
3 public class Clone : Object
4 {
5     public Gtk.Popover el;
6     private Clone  _this;
7
8     public static Clone singleton()
9     {
10         if (_Clone == null) {
11             _Clone= new Clone();
12         }
13         return _Clone;
14     }
15     public Xcls_projectsel projectsel;
16     public Xcls_prcellrenderer prcellrenderer;
17     public Xcls_prmodel prmodel;
18
19         // my vars (def)
20     public GitRepo repo;
21
22     // ctor
23     public Clone()
24     {
25         _this = this;
26         this.el = new Gtk.Popover( null );
27
28         // my vars (dec)
29
30         // set gobject values
31         this.el.border_width = 0;
32         this.el.modal = true;
33         this.el.position = Gtk.PositionType.RIGHT;
34         var child_0 = new Xcls_Box2( _this );
35         child_0.ref();
36         this.el.add (  child_0.el  );
37     }
38
39     // user defined functions
40     public void show (Gtk.Widget btn, Gdk.Rectangle rect, GitRepo repo) {
41         _this.repo = repo;
42         // get the active project.
43          var lm = Gtk.SourceLanguageManager.get_default();
44                     
45     //    ((Gtk.SourceBuffer)(_this.view.el.get_buffer())) .set_language(
46       //      lm.get_language("html")
47      //   );
48       
49         //print (project.fn);
50         //project.runhtml = project.runhtml || '';
51         _this.diff_view.el.get_buffer().set_text(repo.git_diff);
52         _this.status_view.el.get_buffer().set_text(repo.git_status);
53            
54                 //console.log('show all');
55         this.el.set_modal(true);
56         this.el.set_relative_to(btn);
57         this.el.set_pointing_to(rect);
58       
59         //this.el.set_position(Gtk.PositionType.RIGHT);
60     
61         // window + header?
62          GLib.debug("SHOWALL - POPIP\n");
63         this.el.show_all();
64         //this.el.set_size_request(800,500);
65     //  this.diff_view.el.grab_focus();
66         
67         //this.el.show_all();
68     }
69     public class Xcls_Box2 : Object
70     {
71         public Gtk.Box el;
72         private Clone  _this;
73
74
75             // my vars (def)
76
77         // ctor
78         public Xcls_Box2(Clone _owner )
79         {
80             _this = _owner;
81             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
82
83             // my vars (dec)
84
85             // set gobject values
86             this.el.homogeneous = false;
87             this.el.border_width = 5;
88             var child_0 = new Xcls_Box3( _this );
89             child_0.ref();
90             this.el.pack_end (  child_0.el , false,false,0 );
91         }
92
93         // user defined functions
94     }
95     public class Xcls_Box3 : Object
96     {
97         public Gtk.Box el;
98         private Clone  _this;
99
100
101             // my vars (def)
102
103         // ctor
104         public Xcls_Box3(Clone _owner )
105         {
106             _this = _owner;
107             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
108
109             // my vars (dec)
110
111             // set gobject values
112             this.el.homogeneous = true;
113             this.el.expand = false;
114             this.el.vexpand = false;
115             var child_0 = new Xcls_projectsel( _this );
116             child_0.ref();
117             this.el.attach_defaults (  child_0.el , 0,1,1,2 );
118             var child_1 = new Xcls_Button7( _this );
119             child_1.ref();
120             this.el.add (  child_1.el  );
121         }
122
123         // user defined functions
124     }
125     public class Xcls_projectsel : Object
126     {
127         public Gtk.ComboBox el;
128         private Clone  _this;
129
130
131             // my vars (def)
132         public bool loading;
133
134         // ctor
135         public Xcls_projectsel(Clone _owner )
136         {
137             _this = _owner;
138             _this.projectsel = this;
139             this.el = new Gtk.ComboBox.with_entry();
140
141             // my vars (dec)
142             this.loading = false;
143
144             // set gobject values
145             var child_0 = new Xcls_prcellrenderer( _this );
146             child_0.ref();
147             this.el.pack_start (  child_0.el , true );
148             var child_1 = new Xcls_prmodel( _this );
149             child_1.ref();
150             this.el.set_model (  child_1.el  );
151
152             // init method
153
154             this.el.set_entry_text_column(1);
155
156             //listeners
157             this.el.changed.connect( () => {
158                 if (this.loading) {
159                         return;
160                 }
161                 var project_id = this.selectedProjectId();
162                 _this.dbmodel.loadTickets(project_id);
163                 
164                 
165                 /*if (this.loading) {
166                         return;
167                 }
168                 var ticket_id = this.selectedTicketId();
169                 
170                 var name = RooTicket.singleton().usernameLocal();
171                 
172                 if (ticket_id == "" || ticket_id == null) {
173                 
174                         var dt = new  DateTime.now_local();
175                         _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
176                         return;
177                 }
178                 
179                 
180                 var ticket = RooTicket.singleton().getById(ticket_id);
181                
182                 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
183                 
184                 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
185                 */
186             });
187         }
188
189         // user defined functions
190         public string selectedProjectId () {
191                 Gtk.TreeIter iter;
192                 Value val1;
193          
194          
195                 this.el.get_active_iter (out iter);
196                 _this.prmodel.el.get_value (iter, 0, out val1);
197          
198         
199                 return  (string) val1;
200                 
201                 
202                 
203                 
204         }
205     }
206     public class Xcls_prcellrenderer : Object
207     {
208         public Gtk.CellRendererText el;
209         private Clone  _this;
210
211
212             // my vars (def)
213
214         // ctor
215         public Xcls_prcellrenderer(Clone _owner )
216         {
217             _this = _owner;
218             _this.prcellrenderer = this;
219             this.el = new Gtk.CellRendererText();
220
221             // my vars (dec)
222
223             // set gobject values
224         }
225
226         // user defined functions
227     }
228
229     public class Xcls_prmodel : Object
230     {
231         public Gtk.ListStore el;
232         private Clone  _this;
233
234
235             // my vars (def)
236
237         // ctor
238         public Xcls_prmodel(Clone _owner )
239         {
240             _this = _owner;
241             _this.prmodel = this;
242             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
243
244             // my vars (dec)
245
246             // set gobject values
247         }
248
249         // user defined functions
250         public void loadProjects (string id) {
251         
252             var rt = RooTicket.singleton();
253             rt.loadProjects();
254             
255             _this.projectsel.loading = true;
256         
257             this.el.clear();                                    
258             Gtk.TreeIter iter;
259             var el = this.el;
260             
261             el.append(out iter);
262         
263             
264             el.set_value(iter, 0, "");
265             el.set_value(iter, 1, "-- select a project --");
266             if (id == "") {
267                     _this.projectsel.el.set_active_iter(iter);
268             }
269             var projects = rt.projects;
270             foreach(var project in projects) {
271             
272                 el.append(out iter);
273                 
274                 el.set_value(iter, 0, project.id);
275                 el.set_value(iter, 1,  project.name );
276                 if (id == project.id) {
277                            _this.projectsel.el.set_active_iter(iter);
278                     }   
279                 
280             }
281             
282             _this.projectsel.loading = false;
283              //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
284                                              
285         }
286     }
287
288
289     public class Xcls_Button7 : Object
290     {
291         public Gtk.Button el;
292         private Clone  _this;
293
294
295             // my vars (def)
296
297         // ctor
298         public Xcls_Button7(Clone _owner )
299         {
300             _this = _owner;
301             this.el = new Gtk.Button();
302
303             // my vars (dec)
304
305             // set gobject values
306             this.el.label = "Checkout";
307
308             //listeners
309             this.el.button_press_event.connect( () => {
310                    _this.el.hide();
311                     return false;
312             });
313         }
314
315         // user defined functions
316     }
317
318
319
320 }