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