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