Fix #5560 - Gitlive - branching wip
[gitlive] / old_seed_version / 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                                     init : function() {
337                                         XObject.prototype.init.call(this);
338                                         this.el.set_column_types ( 8, [
339                                            GObject.TYPE_STRING, // repo  
340                                           GObject.TYPE_STRING, // current branch
341                                           GObject.TYPE_STRING, // all branch      
342                                           GObject.TYPE_STRING, // updated
343                                            GObject.TYPE_BOOLEAN, // auto-commit
344                                             GObject.TYPE_BOOLEAN, // auto-push
345                                                GObject.TYPE_STRING, // repopath
346                                                GObject.TYPE_STRING // color highighling 
347                                       ] );
348                                     },
349                                     load : function()
350                                     {
351                                         //this.insert(citer,iter,0);
352                                         print("getting list");
353                                         this.repos = imports.Scm.Repo.Repo.list();
354                                         var tr= this.repos;
355                                         this.el.clear();
356                                         
357                                         for(var i =0 ; i < tr.length; i++) {
358                                             var ret = {  };
359                                            
360                                             this.el.append(ret);
361                                             
362                                             //print(JSON.stringify(ret,null,4));
363                                              tr[i].getBranches();
364                                              tr[i].getStatus();
365                                              var hi;
366                                              try {
367                                                  //tr[i].debug=1;
368                                                   hi = tr[i].history('/', 1, 'branch', tr[i].currentBranch.name );
369                                     //             print(JSON.stringify(hi,null,4));
370                                              } catch(e) { print(e);}
371                                               
372                                             this.el.set_value(ret.iter, 0, '' +  tr[i].repopath.split('/').pop() );
373                                             this.el.set_value(ret.iter, 1, '' + tr[i].currentBranch.name   );
374                                             this.el.set_value(ret.iter, 2, '' + tr[i].branches.map(
375                                                             function(e) { return e.name; 
376                                                         }).join(', ') 
377                                              );
378                                             this.el.set_value(ret.iter, 3, '' +  (!hi  ? '??' : hi[0].changed_raw));        
379                                             this.el.set_value(ret.iter, 4, tr[i].autocommit() );                
380                                             this.el.set_value(ret.iter, 5, tr[i].autopush() );                        
381                                             this.el.set_value(ret.iter, 6,  tr[i].repopath );  
382                                             // highlight color.
383                                             var cb = tr[i].currentBranch;
384                                             //print(JSON.stringify(cb,null,4));
385                                             var col = '#ffffff';
386                                             if (cb.lastrev != cb.remoterev) {
387                                                 col =  '#ff0000';
388                                             }
389                                             if (tr[i].hasLocalChanges) {
390                                                 col =  '#0000ff';
391                                             }
392                                             if  ((cb.lastrev != cb.remoterev) && (tr[i].hasLocalChanges)) {
393                                                 col =  '#ff00ff';
394                                             }
395                                             
396                                             this.el.set_value(ret.iter, 7, col  );      
397                                             
398                                         }     
399                                     },
400                                     pathToRepo : function(path) {
401                                     
402                                         var tr= this.repos;
403                                     
404                                         
405                                         for(var i =0 ; i < tr.length; i++) {
406                                             if (tr[i].repopath == path) {
407                                                 return tr[i];
408                                             }
409                                         } 
410                                         return false; 
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                                                      var repo = imports.Scm.Repo.Repo.get(path);
440                                                      repo.autocommit(!value);
441                                                      
442                                                     
443                                                     
444                                                 }
445                                             },
446                                             pack : "pack_start",
447                                             mode : Gtk.CellRendererMode.ACTIVATABLE
448                                         }
449                                     ]
450                                 },
451                                 {
452                                     xtype: Gtk.TreeViewColumn,
453                                     min_width : 50,
454                                     pack : "append_column",
455                                     title : "Auto Push",
456                                     init : function() {
457                                         XObject.prototype.init.call(this);
458                                         this.el.add_attribute(this.items[0].el , 'active', 5 );
459                                           this.items[0].el.set_activatable(true);
460                                     },
461                                     items : [
462                                         {
463                                             xtype: Gtk.CellRendererToggle,
464                                             listeners : {
465                                                 toggled : function (self, path) {
466                                                     var ret ={} ;
467                                                     var store = this.get('/reposStore');
468                                                     store.el.get_iter_from_string(ret, path);
469                                                                                                                  
470                                                     var value =   store.el.get_value(ret.iter,5).value.get_boolean();
471                                                                                                                  
472                                                     //print(JSON.stringify(value));
473                                                     store.el.set_value(ret.iter,5, !value);
474                                                       var path =  store.el.get_value(ret.iter, 6).value.get_string();
475                                                      var repo = imports.Scm.Repo.Repo.get(path);
476                                                      repo.autopush(!value);
477                                                      
478                                                 }
479                                             },
480                                             pack : "pack_start",
481                                             mode : Gtk.CellRendererMode.ACTIVATABLE
482                                         }
483                                     ]
484                                 },
485                                 {
486                                     xtype: Gtk.TreeViewColumn,
487                                     min_width : 200,
488                                     pack : "append_column",
489                                     resizable : true,
490                                     title : "Repo",
491                                     init : function() {
492                                         XObject.prototype.init.call(this);
493                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
494                                     
495                                     },
496                                     items : [
497                                         {
498                                             xtype: Gtk.CellRendererText,
499                                             pack : "pack_start"
500                                         }
501                                     ]
502                                 },
503                                 {
504                                     xtype: Gtk.TreeViewColumn,
505                                     min_width : 50,
506                                     pack : "append_column",
507                                     title : "Current Branch",
508                                     init : function() {
509                                         XObject.prototype.init.call(this);
510                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
511                                          this.el.add_attribute(this.items[0].el , 'cell-background', 7 );
512                                     
513                                     },
514                                     items : [
515                                         {
516                                             xtype: Gtk.CellRendererText,
517                                             pack : "pack_start"
518                                         }
519                                     ]
520                                 },
521                                 {
522                                     xtype: Gtk.TreeViewColumn,
523                                     min_width : 50,
524                                     pack : "append_column",
525                                     title : "Last updated",
526                                     init : function() {
527                                         XObject.prototype.init.call(this);
528                                         this.el.add_attribute(this.items[0].el , 'markup', 3 );
529                                     
530                                     },
531                                     items : [
532                                         {
533                                             xtype: Gtk.CellRendererText,
534                                             pack : "pack_start"
535                                         }
536                                     ]
537                                 },
538                                 {
539                                     xtype: Gtk.TreeViewColumn,
540                                     min_width : 50,
541                                     pack : "append_column",
542                                     resizable : false,
543                                     title : "All Branches",
544                                     init : function() {
545                                         XObject.prototype.init.call(this);
546                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
547                                     
548                                     },
549                                     items : [
550                                         {
551                                             xtype: Gtk.CellRendererText,
552                                             pack : "pack_start"
553                                         }
554                                     ]
555                                 }
556                             ]
557                         },
558                         {
559                             xtype: Gtk.TreeView,
560                             pack : false,
561                             items : [
562                                 {
563                                     xtype: Gtk.ListStore,
564                                     pack : false
565                                 }
566                             ]
567                         }
568                     ]
569                 }
570             ]
571         },
572         {
573             xtype: Gtk.Button,
574             id : "ok_button",
575             label : "Close",
576             pack : "add_action_widget,1"
577         }
578     ]
579 });
580 Clones.init();
581 XObject.cache['/Clones'] = Clones;