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