3af05b832336de4b05d73666d770dbe39f0a6c1b
[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               print("DESTROY?!");
17              return true;
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         this.el.set_deletable(false);
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                                     var rv = this.get('/reposView');
89                                     var rs = this.get('/reposStore');
90                                     if (rv.el.get_selection().count_selected_rows() != 1) {
91                                         //nothing?
92                                         // error condition.
93                                         return;
94                                     }
95                                     var Remotes =     imports.Remotes.Remotes;
96                                     
97                                  
98                                     var ret = {};       
99                                     var s = rv.el.get_selection();
100                                     var path = '';
101                                     s.selected_foreach(function(model,p,iter) {
102                                                                                     
103                                        path = model.get_value(iter, 6).value.get_string();
104                                      
105                                     }); 
106                                 
107                                     var repo = false;
108                                     rs.repos.forEach(function(r) {
109                                         if (r.repopath == path) {
110                                             repo = r;
111                                         
112                                         }
113                                     
114                                     });
115                                     Remotes.repo = repo;
116                                     Remotes.el.set_transient_for(Clones.el);
117                                     Clones.el.set_title("Manage Clones - " + repo.repopath);
118                                     Remotes.show();
119                                     Clones.el.set_title("Manage Clones");
120                                 
121                                      
122                                     
123                                     
124                                     
125                                 
126                                        
127                                     
128                                     
129                                 }
130                             },
131                             label : "Remotes / Clones",
132                             pack : "add"
133                         },
134                         {
135                             xtype: Gtk.Button,
136                             listeners : {
137                                 clicked : function (self) {
138                                 
139                                     var rv = this.get('/reposView');
140                                     var rs = this.get('/reposStore');
141                                     if (rv.el.get_selection().count_selected_rows() != 1) {
142                                         //nothing?
143                                         // error condition.
144                                         return;
145                                     }
146                                     var Branches =     imports.Branches.Branches;
147                                     
148                                  
149                                     var ret = {};       
150                                     var s = rv.el.get_selection();
151                                     var path = '';
152                                     s.selected_foreach(function(model,p,iter) {
153                                                                                     
154                                        path = model.get_value(iter, 6).value.get_string();
155                                      
156                                     }); 
157                                 
158                                     var repo = false;
159                                     rs.repos.forEach(function(r) {
160                                         if (r.repopath == path) {
161                                             repo = r;
162                                         
163                                         }
164                                     
165                                     });
166                                     Branches.repo = repo;
167                                     Branches.el.set_transient_for(Clones.el);
168                                     Clones.el.set_title("Manage Clones - " + repo.repopath);
169                                     Branches.show();
170                                     Clones.el.set_title("Manage Clones");
171                                 
172                                      
173                                     
174                                     
175                                     
176                                 
177                                        
178                                     
179                                     
180                                 }
181                             },
182                             label : "Branches",
183                             pack : "add"
184                         },
185                         {
186                             xtype: Gtk.Button,
187                             listeners : {
188                                 clicked : function (self) {
189                                 
190                                     var rv = this.get('/reposView');
191                                     var rs = this.get('/reposStore');
192                                     if (rv.el.get_selection().count_selected_rows() != 1) {
193                                         //nothing?
194                                         // error condition.
195                                         return;
196                                     }
197                                     var Merger =     imports.Merger.Merger;
198                                     
199                                  
200                                     var ret = {};       
201                                     var s = rv.el.get_selection();
202                                     var path = '';
203                                     s.selected_foreach(function(model,p,iter) {
204                                                                                     
205                                        path = model.get_value(iter, 6).value.get_string();
206                                      
207                                     }); 
208                                 
209                                     var repo = false;
210                                     rs.repos.forEach(function(r) {
211                                         if (r.repopath == path) {
212                                             repo = r;
213                                         
214                                         }
215                                     
216                                     });
217                                     Merger.repo = repo;
218                                     Merger.el.set_transient_for(Clones.el);
219                                     Clones.el.set_title("Manage Clones - " + repo.repopath);
220                                     Merger.show();
221                                     Clones.el.set_title("Manage Clones");
222                                 
223                                     
224                                     
225                                 
226                                     
227                                 
228                                     
229                                     
230                                     
231                                     
232                                 
233                                        
234                                     
235                                     
236                                 }
237                             },
238                             label : "Run Merger",
239                             pack : "add"
240                         },
241                         {
242                             xtype: Gtk.Button,
243                             listeners : {
244                                 clicked : function (self) {
245                                     
246                                     
247                                  
248                                        
249                                     
250                                     
251                                 }
252                             },
253                             label : "Switch Branch",
254                             pack : "add"
255                         },
256                         {
257                             xtype: Gtk.Button,
258                             listeners : {
259                                 clicked : function (self) {
260                                     
261                                     
262                                  
263                                        
264                                     
265                                     
266                                 }
267                             },
268                             label : "Pull",
269                             pack : "add"
270                         }
271                     ]
272                 },
273                 {
274                     xtype: Gtk.ScrolledWindow,
275                     init : function() {
276                         XObject.prototype.init.call(this);
277                           this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
278                     },
279                     items : [
280                         {
281                             xtype: Gtk.TreeView,
282                             listeners : {
283                                 cursor_changed : function (self) {
284                                   // SEE SELECTION.CHANGED
285                                   
286                                   
287                                   return;
288                                   
289                                     if (this.el.get_selection().count_selected_rows() < 1) {
290                                         //nothing? - clea it?
291                                         return;
292                                     }
293                                         var ret = {};         
294                                     var model = this.get('/changedFilesStore');
295                                 
296                                      var s = this.el.get_selection();
297                                      var files = [];
298                                     s.selected_foreach(function(model,p,iter) {
299                                     
300                                        files.push( model.get_value(iter, 0).value.get_string());
301                                      
302                                     });
303                                     this.get('/patchview').showDiff(files); 
304                                     //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();
305                                      //print("OUT?" + value);// id..
306                                     // load the list in the right grid..
307                                      
308                                     return true;
309                                 
310                                 }
311                             },
312                             id : "reposView",
313                             pack : "add",
314                             init : function() {
315                                 XObject.prototype.init.call(this);
316                                     var description = new Pango.FontDescription.c_new();
317                                description.set_size(10000);
318                                  this.el.modify_font(description);
319                             
320                                  this.selection = this.el.get_selection();
321                                   this.selection.set_mode( Gtk.SelectionMode.MULTIPLE);
322                                 var _this = this;
323                                 
324                                 
325                               this.selection.signal['changed'].connect(function() {
326                                  _this.listeners.cursor_changed.apply(
327                                       _this, [ _this, '']
328                                    );
329                                          });
330                               },
331                             items : [
332                                 {
333                                     xtype: Gtk.ListStore,
334                                     id : "reposStore",
335                                     pack : "set_model",
336                                     pathToRepo : function(path) {
337                                     
338                                         var tr= this.repos;
339                                     
340                                         
341                                         for(var i =0 ; i < tr.length; i++) {
342                                             if (tr[i].repopath == path) {
343                                                 return tr;
344                                             }
345                                         } 
346                                         return false; 
347                                     },
348                                     init : function() {
349                                         XObject.prototype.init.call(this);
350                                         this.el.set_column_types ( 8, [
351                                            GObject.TYPE_STRING, // repo  
352                                           GObject.TYPE_STRING, // current branch
353                                           GObject.TYPE_STRING, // all branch      
354                                           GObject.TYPE_STRING, // updated
355                                            GObject.TYPE_BOOLEAN, // auto-commit
356                                             GObject.TYPE_BOOLEAN, // auto-push
357                                                GObject.TYPE_STRING, // repopath
358                                                GObject.TYPE_STRING // color highighling 
359                                       ] );
360                                     },
361                                     load : function()
362                                     {
363                                         //this.insert(citer,iter,0);
364                                         print("getting list");
365                                         this.repos = imports.Scm.Repo.Repo.list();
366                                         var tr= this.repos;
367                                         this.el.clear();
368                                         
369                                         for(var i =0 ; i < tr.length; i++) {
370                                             var ret = {  };
371                                            
372                                             this.el.append(ret);
373                                             
374                                             //print(JSON.stringify(ret,null,4));
375                                              tr[i].getBranches();
376                                              tr[i].getStatus();
377                                              var hi;
378                                              try {
379                                                  //tr[i].debug=1;
380                                                   hi = tr[i].history('/', 1, 'branch', tr[i].currentBranch.name );
381                                     //             print(JSON.stringify(hi,null,4));
382                                              } catch(e) { print(e);}
383                                               
384                                             this.el.set_value(ret.iter, 0, '' +  tr[i].repopath.split('/').pop() );
385                                             this.el.set_value(ret.iter, 1, '' + tr[i].currentBranch.name   );
386                                             this.el.set_value(ret.iter, 2, '' + tr[i].branches.map(
387                                                             function(e) { return e.name; 
388                                                         }).join(', ') 
389                                              );
390                                             this.el.set_value(ret.iter, 3, '' +  (!hi  ? '??' : hi[0].changed_raw));        
391                                             this.el.set_value(ret.iter, 4, tr[i].autocommit() );                
392                                             this.el.set_value(ret.iter, 5, tr[i].autopush() );                        
393                                             this.el.set_value(ret.iter, 6,  tr[i].repopath );  
394                                             // highlight color.
395                                             var cb = tr[i].currentBranch;
396                                             //print(JSON.stringify(cb,null,4));
397                                             var col = '#ffffff';
398                                             if (cb.lastrev != cb.remoterev) {
399                                                 col =  '#ff0000';
400                                             }
401                                             if (tr[i].hasLocalChanges) {
402                                                 col =  '#0000ff';
403                                             }
404                                             if  ((cb.lastrev != cb.remoterev) && (tr[i].hasLocalChanges)) {
405                                                 col =  '#ff00ff';
406                                             }
407                                             
408                                             this.el.set_value(ret.iter, 7, col  );      
409                                             
410                                         }     
411                                     }
412                                 },
413                                 {
414                                     xtype: Gtk.TreeViewColumn,
415                                     min_width : 50,
416                                     pack : "append_column",
417                                     title : "Auto Commit",
418                                     init : function() {
419                                         XObject.prototype.init.call(this);
420                                         this.el.add_attribute(this.items[0].el , 'active', 4 );
421                                         this.items[0].el.set_activatable(true);
422                                     
423                                     },
424                                     items : [
425                                         {
426                                             xtype: Gtk.CellRendererToggle,
427                                             listeners : {
428                                                 toggled : function (self, path) {
429                                                     var ret ={} ;
430                                                     var store = this.get('/reposStore');
431                                                     store.el.get_iter_from_string(ret, path);
432                                                                                                                  
433                                                     var value =   store.el.get_value(ret.iter,4).value.get_boolean();
434                                                                                                                  
435                                                     //print(JSON.stringify(value));
436                                                     store.el.set_value(ret.iter,4, !value);
437                                                     
438                                                      var path =  store.el.get_value(ret.iter, 6).value.get_string();
439                                                      print("VAL: " + store.el.get_value(ret.iter, 6).value);     
440                                                      print("PATH: " + path);
441                                                      
442                                                      
443                                                      var repo = store.pathToRepo(path);
444                                                      repo.autocommit(!value);
445                                                      
446                                                     
447                                                     
448                                                 }
449                                             },
450                                             pack : "pack_start",
451                                             mode : Gtk.CellRendererMode.ACTIVATABLE
452                                         }
453                                     ]
454                                 },
455                                 {
456                                     xtype: Gtk.TreeViewColumn,
457                                     min_width : 50,
458                                     pack : "append_column",
459                                     title : "Auto Push",
460                                     init : function() {
461                                         XObject.prototype.init.call(this);
462                                         this.el.add_attribute(this.items[0].el , 'active', 5 );
463                                           this.items[0].el.set_activatable(true);
464                                     },
465                                     items : [
466                                         {
467                                             xtype: Gtk.CellRendererToggle,
468                                             listeners : {
469                                                 toggled : function (self, path) {
470                                                     var ret ={} ;
471                                                     var store = this.get('/reposStore');
472                                                     store.el.get_iter_from_string(ret, path);
473                                                                                                                  
474                                                     var value =   store.el.get_value(ret.iter,5).value.get_boolean();
475                                                                                                                  
476                                                     //print(JSON.stringify(value));
477                                                     store.el.set_value(ret.iter,5, !value);
478                                                       var path =  store.el.get_value(ret.iter, 6).value.get_string();
479                                                      var repo = store.pathToRepo(path);
480                                                      repo.autopush(!value);
481                                                      
482                                                 }
483                                             },
484                                             pack : "pack_start",
485                                             mode : Gtk.CellRendererMode.ACTIVATABLE
486                                         }
487                                     ]
488                                 },
489                                 {
490                                     xtype: Gtk.TreeViewColumn,
491                                     min_width : 200,
492                                     pack : "append_column",
493                                     resizable : true,
494                                     title : "Repo",
495                                     init : function() {
496                                         XObject.prototype.init.call(this);
497                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
498                                     
499                                     },
500                                     items : [
501                                         {
502                                             xtype: Gtk.CellRendererText,
503                                             pack : "pack_start"
504                                         }
505                                     ]
506                                 },
507                                 {
508                                     xtype: Gtk.TreeViewColumn,
509                                     min_width : 50,
510                                     pack : "append_column",
511                                     title : "Current Branch",
512                                     init : function() {
513                                         XObject.prototype.init.call(this);
514                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
515                                          this.el.add_attribute(this.items[0].el , 'cell-background', 7 );
516                                     
517                                     },
518                                     items : [
519                                         {
520                                             xtype: Gtk.CellRendererText,
521                                             pack : "pack_start"
522                                         }
523                                     ]
524                                 },
525                                 {
526                                     xtype: Gtk.TreeViewColumn,
527                                     min_width : 50,
528                                     pack : "append_column",
529                                     title : "Last updated",
530                                     init : function() {
531                                         XObject.prototype.init.call(this);
532                                         this.el.add_attribute(this.items[0].el , 'markup', 3 );
533                                     
534                                     },
535                                     items : [
536                                         {
537                                             xtype: Gtk.CellRendererText,
538                                             pack : "pack_start"
539                                         }
540                                     ]
541                                 },
542                                 {
543                                     xtype: Gtk.TreeViewColumn,
544                                     min_width : 50,
545                                     pack : "append_column",
546                                     resizable : false,
547                                     title : "All Branches",
548                                     init : function() {
549                                         XObject.prototype.init.call(this);
550                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
551                                     
552                                     },
553                                     items : [
554                                         {
555                                             xtype: Gtk.CellRendererText,
556                                             pack : "pack_start"
557                                         }
558                                     ]
559                                 }
560                             ]
561                         },
562                         {
563                             xtype: Gtk.TreeView,
564                             pack : false,
565                             items : [
566                                 {
567                                     xtype: Gtk.ListStore,
568                                     pack : false
569                                 }
570                             ]
571                         }
572                     ]
573                 }
574             ]
575         },
576         {
577             xtype: Gtk.Button,
578             id : "ok_button",
579             label : "Close",
580             pack : "add_action_widget,1"
581         }
582     ]
583 });
584 Clones.init();
585 XObject.cache['/Clones'] = Clones;