Clones.js
[gitlive] / Clones.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
12 Clones=new XObject({
13     xtype: Gtk.Dialog,
14     listeners : {
15         destroy_event : function (self, event) {
16              this.el.hide();
17                         return false;
18         },
19         response : function (self, id) {
20           // hide
21              //if (id < 1) {
22                 this.el.hide();
23                 return;
24             //}
25             if (typeof(this.get('bug').getValue()) != 'object') {
26                 print("ERROR");
27                 return;
28             }
29          
30             this.el.hide();
31                 
32             //var val = this.get('bug').getValue();
33              //   Seed.print(val);
34         }
35     },
36     border_width : 3,
37     default_height : 500,
38     default_width : 600,
39     title : "Manage Clones",
40     deletable : true,
41     modal : true,
42     show : function(c) {
43         
44         if (!this.el) {
45             this.init();
46         }
47         var _this = this;
48         /*[ 'xtype'  ].forEach(function(k) {
49             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
50         });
51         // shouild set path..
52         */
53      
54         this.el.show_all();
55         // load clones..
56             this.get('/reposStore').load();
57         
58         //this.get('/ok_button').el.set_sensitive(false);
59         
60         // block until we return.
61         var run_ret = this.el.run();
62         if (run_ret < 1 ) {
63             return  "DONE";
64         }
65         print("RUN RETURN : " + run_ret);
66         return "DONE";
67         //print(JSON.stringify(this.get('bug').getValue()));
68        // return this.get('bug').getValue();
69         //this.success = c.success;
70     },
71     items : [
72         {
73             xtype: Gtk.VBox,
74             pack : function(p,e) {
75                     p.el.get_content_area().pack_start(e.el,true,true,0)
76                 },
77             items : [
78                 {
79                     xtype: Gtk.HBox,
80                     pack : "pack_start,false,true",
81                     items : [
82                         {
83                             xtype: Gtk.Button,
84                             listeners : {
85                                 clicked : function (self) {
86                                     
87                                     
88                                  
89                                        
90                                     
91                                     
92                                 }
93                             },
94                             label : "Add Clone",
95                             pack : "add"
96                         },
97                         {
98                             xtype: Gtk.Button,
99                             listeners : {
100                                 clicked : function (self) {
101                                     
102                                     
103                                  
104                                        
105                                     
106                                     
107                                 }
108                             },
109                             label : "Add Branch",
110                             pack : "add"
111                         },
112                         {
113                             xtype: Gtk.Button,
114                             listeners : {
115                                 clicked : function (self) {
116                                 
117                                     var rv = this.get('/reposView');
118                                     var rs = this.get('/reposStore');
119                                     if (rv.el.get_selection().count_selected_rows() != 1) {
120                                         //nothing?
121                                         // error condition.
122                                         return;
123                                     }
124                                     var Merger =     imports.Merger.Merger;
125                                     
126                                  
127                                     var ret = {};       
128                                     var s = rv.el.get_selection();
129                                     var path = '';
130                                     s.selected_foreach(function(model,p,iter) {
131                                                                                     
132                                        path = model.get_value(iter, 6).value.get_string();
133                                      
134                                     }); 
135                                 
136                                 
137                                     rs.repos.forEach(function(r) {
138                                         if (r.repopath == path) {
139                                             Merger.repo = r;
140                                             Merger.show();
141                                         
142                                         }
143                                     
144                                     });
145                                     
146                                     
147                                 
148                                     
149                                 
150                                     
151                                     
152                                     
153                                     
154                                 
155                                        
156                                     
157                                     
158                                 }
159                             },
160                             label : "Run Merger",
161                             pack : "add"
162                         },
163                         {
164                             xtype: Gtk.Button,
165                             listeners : {
166                                 clicked : function (self) {
167                                     
168                                     
169                                  
170                                        
171                                     
172                                     
173                                 }
174                             },
175                             label : "Switch Branch",
176                             pack : "add"
177                         },
178                         {
179                             xtype: Gtk.Button,
180                             listeners : {
181                                 clicked : function (self) {
182                                     
183                                     
184                                  
185                                        
186                                     
187                                     
188                                 }
189                             },
190                             label : "Pull",
191                             pack : "add"
192                         }
193                     ]
194                 },
195                 {
196                     xtype: Gtk.ScrolledWindow,
197                     init : function() {
198                         XObject.prototype.init.call(this);
199                           this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
200                     },
201                     items : [
202                         {
203                             xtype: Gtk.TreeView,
204                             listeners : {
205                                 cursor_changed : function (self) {
206                                   // SEE SELECTION.CHANGED
207                                   
208                                   
209                                   return;
210                                   
211                                     if (this.el.get_selection().count_selected_rows() < 1) {
212                                         //nothing? - clea it?
213                                         return;
214                                     }
215                                         var ret = {};         
216                                     var model = this.get('/changedFilesStore');
217                                 
218                                      var s = this.el.get_selection();
219                                      var files = [];
220                                     s.selected_foreach(function(model,p,iter) {
221                                     
222                                        files.push( model.get_value(iter, 0).value.get_string());
223                                      
224                                     });
225                                     this.get('/patchview').showDiff(files); 
226                                     //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();
227                                      //print("OUT?" + value);// id..
228                                     // load the list in the right grid..
229                                      
230                                     return true;
231                                 
232                                 }
233                             },
234                             id : "reposView",
235                             pack : "add",
236                             init : function() {
237                                 XObject.prototype.init.call(this);
238                                     var description = new Pango.FontDescription.c_new();
239                                description.set_size(10000);
240                                  this.el.modify_font(description);
241                             
242                                  this.selection = this.el.get_selection();
243                                   this.selection.set_mode( Gtk.SelectionMode.MULTIPLE);
244                                 var _this = this;
245                                 
246                                 
247                               this.selection.signal['changed'].connect(function() {
248                                  _this.listeners.cursor_changed.apply(
249                                       _this, [ _this, '']
250                                    );
251                                          });
252                               },
253                             items : [
254                                 {
255                                     xtype: Gtk.ListStore,
256                                     id : "reposStore",
257                                     pack : "set_model",
258                                     init : function() {
259                                         XObject.prototype.init.call(this);
260                                         this.el.set_column_types ( 7, [
261                                            GObject.TYPE_STRING, // repo  
262                                           GObject.TYPE_STRING, // current branch
263                                           GObject.TYPE_STRING, // all branch      
264                                           GObject.TYPE_STRING, // updated
265                                            GObject.TYPE_BOOLEAN, // auto-commit
266                                             GObject.TYPE_BOOLEAN, // auto-push
267                                                GObject.TYPE_STRING // repopath
268                                       ] );
269                                     },
270                                     load : function()
271                                     {
272                                         //this.insert(citer,iter,0);
273                                         print("getting list");
274                                         this.repos = imports.Scm.Repo.Repo.list();
275                                         var tr= this.repos;
276                                         this.el.clear();
277                                         
278                                         for(var i =0 ; i < tr.length; i++) {
279                                             var ret = {  };
280                                            
281                                             this.el.append(ret);
282                                             
283                                             //print(JSON.stringify(ret,null,4));
284                                              tr[i].getBranches();
285                                               
286                                             this.el.set_value(ret.iter, 0, '' +  tr[i].repopath.split('/').pop() );
287                                             this.el.set_value(ret.iter, 1, '' + tr[i].currentBranch   );
288                                             this.el.set_value(ret.iter, 2, '' + tr[i].branches.map(
289                                                             function(e) { return e.name; 
290                                                         }).join(', ') 
291                                              );
292                                             this.el.set_value(ret.iter, 3, '' + 'tbc' );        
293                                             this.el.set_value(ret.iter, 4, tr[i].autocommit() );                
294                                             this.el.set_value(ret.iter, 5, tr[i].autopush() );                        
295                                             this.el.set_value(ret.iter, 6,  tr[i].repopath );      
296                                             
297                                         }     
298                                     }
299                                 },
300                                 {
301                                     xtype: Gtk.TreeViewColumn,
302                                     min_width : 50,
303                                     pack : "append_column",
304                                     title : "Auto Commit",
305                                     init : function() {
306                                         XObject.prototype.init.call(this);
307                                         this.el.add_attribute(this.items[0].el , 'active', 4 );
308                                         this.items[0].el.set_activatable(true);
309                                     
310                                     },
311                                     items : [
312                                         {
313                                             xtype: Gtk.CellRendererToggle,
314                                             listeners : {
315                                                 toggled : function (self, path) {
316                                                     var ret ={} ;
317                                                     var store = this.get('/reposStore');
318                                                     store.el.get_iter_from_string(ret, path);
319                                                                                                                  
320                                                     var value =   store.el.get_value(ret.iter,4).value.get_boolean();
321                                                                                                                  
322                                                     //print(JSON.stringify(value));
323                                                     store.el.set_value(ret.iter,4, !value);
324                                                     
325                                                 }
326                                             },
327                                             pack : "pack_start",
328                                             mode : Gtk.CellRendererMode.ACTIVATABLE
329                                         }
330                                     ]
331                                 },
332                                 {
333                                     xtype: Gtk.TreeViewColumn,
334                                     min_width : 50,
335                                     pack : "append_column",
336                                     title : "Auto Push",
337                                     init : function() {
338                                         XObject.prototype.init.call(this);
339                                         this.el.add_attribute(this.items[0].el , 'active', 5 );
340                                           this.items[0].el.set_activatable(true);
341                                     },
342                                     items : [
343                                         {
344                                             xtype: Gtk.CellRendererToggle,
345                                             listeners : {
346                                                 toggled : function (self, path) {
347                                                     var ret ={} ;
348                                                     var store = this.get('/reposStore');
349                                                     store.el.get_iter_from_string(ret, path);
350                                                                                                                  
351                                                     var value =   store.el.get_value(ret.iter,5).value.get_boolean();
352                                                                                                                  
353                                                     //print(JSON.stringify(value));
354                                                     store.el.set_value(ret.iter,5, !value);
355                                                     
356                                                 }
357                                             },
358                                             pack : "pack_start",
359                                             mode : Gtk.CellRendererMode.ACTIVATABLE
360                                         }
361                                     ]
362                                 },
363                                 {
364                                     xtype: Gtk.TreeViewColumn,
365                                     min_width : 200,
366                                     pack : "append_column",
367                                     resizable : true,
368                                     title : "Repo",
369                                     init : function() {
370                                         XObject.prototype.init.call(this);
371                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
372                                     
373                                     },
374                                     items : [
375                                         {
376                                             xtype: Gtk.CellRendererText,
377                                             pack : "pack_start"
378                                         }
379                                     ]
380                                 },
381                                 {
382                                     xtype: Gtk.TreeViewColumn,
383                                     min_width : 50,
384                                     pack : "append_column",
385                                     title : "Current Branch",
386                                     init : function() {
387                                         XObject.prototype.init.call(this);
388                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
389                                     
390                                     },
391                                     items : [
392                                         {
393                                             xtype: Gtk.CellRendererText,
394                                             pack : "pack_start"
395                                         }
396                                     ]
397                                 },
398                                 {
399                                     xtype: Gtk.TreeViewColumn,
400                                     min_width : 50,
401                                     pack : "append_column",
402                                     title : "Last updated",
403                                     init : function() {
404                                         XObject.prototype.init.call(this);
405                                         this.el.add_attribute(this.items[0].el , 'markup', 3 );
406                                     
407                                     },
408                                     items : [
409                                         {
410                                             xtype: Gtk.CellRendererText,
411                                             pack : "pack_start"
412                                         }
413                                     ]
414                                 },
415                                 {
416                                     xtype: Gtk.TreeViewColumn,
417                                     min_width : 50,
418                                     pack : "append_column",
419                                     resizable : false,
420                                     title : "All Branches",
421                                     init : function() {
422                                         XObject.prototype.init.call(this);
423                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
424                                     
425                                     },
426                                     items : [
427                                         {
428                                             xtype: Gtk.CellRendererText,
429                                             pack : "pack_start"
430                                         }
431                                     ]
432                                 }
433                             ]
434                         },
435                         {
436                             xtype: Gtk.TreeView,
437                             pack : false,
438                             items : [
439                                 {
440                                     xtype: Gtk.ListStore,
441                                     pack : false
442                                 }
443                             ]
444                         }
445                     ]
446                 }
447             ]
448         },
449         {
450             xtype: Gtk.Button,
451             label : "Cancel",
452             pack : "add_action_widget,0"
453         },
454         {
455             xtype: Gtk.Button,
456             id : "ok_button",
457             label : "OK",
458             pack : "add_action_widget,1"
459         }
460     ]
461 });
462 Clones.init();
463 XObject.cache['/Clones'] = Clones;