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