Clones.js
[gitlive] / Clones.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
12 Clones=new XObject({
13     xtype: Gtk.Dialog,
14     listeners : {
15         destroy_event : function (self, event) {
16              this.el.hide();
17                         return false;
18         },
19         response : function (self, id) {
20           // hide
21              //if (id < 1) {
22                 this.el.hide();
23                 return;
24             //}
25             if (typeof(this.get('bug').getValue()) != 'object') {
26                 print("ERROR");
27                 return;
28             }
29          
30             this.el.hide();
31                 
32             //var val = this.get('bug').getValue();
33              //   Seed.print(val);
34         }
35     },
36     border_width : 3,
37     default_height : 500,
38     default_width : 600,
39     title : "Manage Clones",
40     deletable : true,
41     modal : true,
42     show : function(c) {
43         
44         if (!this.el) {
45             this.init();
46         }
47         var _this = this;
48         /*[ 'xtype'  ].forEach(function(k) {
49             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
50         });
51         // shouild set path..
52         */
53      
54         this.el.show_all();
55         // load clones..
56             this.get('/reposStore').load();
57         
58         //this.get('/ok_button').el.set_sensitive(false);
59         
60         // block until we return.
61         var run_ret = this.el.run();
62         if (run_ret < 1 ) {
63             return  "DONE";
64         }
65         print("RUN RETURN : " + run_ret);
66         return "DONE";
67         //print(JSON.stringify(this.get('bug').getValue()));
68        // return this.get('bug').getValue();
69         //this.success = c.success;
70     },
71     items : [
72         {
73             xtype: Gtk.VBox,
74             id : "Clones",
75             pack : function(p,e) {
76                     p.el.get_content_area().pack_start(e.el,true,true,0)
77                 },
78             items : [
79                 {
80                     xtype: Gtk.HBox,
81                     pack : "pack_start,false,true",
82                     items : [
83                         {
84                             xtype: Gtk.Button,
85                             listeners : {
86                                 clicked : function (self) {
87                                 
88                                     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                                              
365                                              var hi = tr[i].history('/', 1, 'branch', tr[i].currentBranch.name );
366                                              print(JSON.stringify(hi));
367                                               
368                                             this.el.set_value(ret.iter, 0, '' +  tr[i].repopath.split('/').pop() );
369                                             this.el.set_value(ret.iter, 1, '' + tr[i].currentBranch.name   );
370                                             this.el.set_value(ret.iter, 2, '' + tr[i].branches.map(
371                                                             function(e) { return e.name; 
372                                                         }).join(', ') 
373                                              );
374                                             this.el.set_value(ret.iter, 3, '' + 'tbc' );        
375                                             this.el.set_value(ret.iter, 4, tr[i].autocommit() );                
376                                             this.el.set_value(ret.iter, 5, tr[i].autopush() );                        
377                                             this.el.set_value(ret.iter, 6,  tr[i].repopath );  
378                                             // highlight color.
379                                             var cb = tr[i].currentBranch;
380                                             print(JSON.stringify(cb,null,4));
381                                             var col = cb.lastrev == cb.remoterev ? '#ffffff' : '#ff0000';
382                                             this.el.set_value(ret.iter, 7, col  );      
383                                             
384                                         }     
385                                     }
386                                 },
387                                 {
388                                     xtype: Gtk.TreeViewColumn,
389                                     min_width : 50,
390                                     pack : "append_column",
391                                     title : "Auto Commit",
392                                     init : function() {
393                                         XObject.prototype.init.call(this);
394                                         this.el.add_attribute(this.items[0].el , 'active', 4 );
395                                         this.items[0].el.set_activatable(true);
396                                     
397                                     },
398                                     items : [
399                                         {
400                                             xtype: Gtk.CellRendererToggle,
401                                             listeners : {
402                                                 toggled : function (self, path) {
403                                                     var ret ={} ;
404                                                     var store = this.get('/reposStore');
405                                                     store.el.get_iter_from_string(ret, path);
406                                                                                                                  
407                                                     var value =   store.el.get_value(ret.iter,4).value.get_boolean();
408                                                                                                                  
409                                                     //print(JSON.stringify(value));
410                                                     store.el.set_value(ret.iter,4, !value);
411                                                     
412                                                 }
413                                             },
414                                             pack : "pack_start",
415                                             mode : Gtk.CellRendererMode.ACTIVATABLE
416                                         }
417                                     ]
418                                 },
419                                 {
420                                     xtype: Gtk.TreeViewColumn,
421                                     min_width : 50,
422                                     pack : "append_column",
423                                     title : "Auto Push",
424                                     init : function() {
425                                         XObject.prototype.init.call(this);
426                                         this.el.add_attribute(this.items[0].el , 'active', 5 );
427                                           this.items[0].el.set_activatable(true);
428                                     },
429                                     items : [
430                                         {
431                                             xtype: Gtk.CellRendererToggle,
432                                             listeners : {
433                                                 toggled : function (self, path) {
434                                                     var ret ={} ;
435                                                     var store = this.get('/reposStore');
436                                                     store.el.get_iter_from_string(ret, path);
437                                                                                                                  
438                                                     var value =   store.el.get_value(ret.iter,5).value.get_boolean();
439                                                                                                                  
440                                                     //print(JSON.stringify(value));
441                                                     store.el.set_value(ret.iter,5, !value);
442                                                     
443                                                 }
444                                             },
445                                             pack : "pack_start",
446                                             mode : Gtk.CellRendererMode.ACTIVATABLE
447                                         }
448                                     ]
449                                 },
450                                 {
451                                     xtype: Gtk.TreeViewColumn,
452                                     min_width : 200,
453                                     pack : "append_column",
454                                     resizable : true,
455                                     title : "Repo",
456                                     init : function() {
457                                         XObject.prototype.init.call(this);
458                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
459                                     
460                                     },
461                                     items : [
462                                         {
463                                             xtype: Gtk.CellRendererText,
464                                             pack : "pack_start"
465                                         }
466                                     ]
467                                 },
468                                 {
469                                     xtype: Gtk.TreeViewColumn,
470                                     min_width : 50,
471                                     pack : "append_column",
472                                     title : "Current Branch",
473                                     init : function() {
474                                         XObject.prototype.init.call(this);
475                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
476                                          this.el.add_attribute(this.items[0].el , 'cell-background', 7 );
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 : "Last updated",
491                                     init : function() {
492                                         XObject.prototype.init.call(this);
493                                         this.el.add_attribute(this.items[0].el , 'markup', 3 );
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                                     resizable : false,
508                                     title : "All Branches",
509                                     init : function() {
510                                         XObject.prototype.init.call(this);
511                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
512                                     
513                                     },
514                                     items : [
515                                         {
516                                             xtype: Gtk.CellRendererText,
517                                             pack : "pack_start"
518                                         }
519                                     ]
520                                 }
521                             ]
522                         },
523                         {
524                             xtype: Gtk.TreeView,
525                             pack : false,
526                             items : [
527                                 {
528                                     xtype: Gtk.ListStore,
529                                     pack : false
530                                 }
531                             ]
532                         }
533                     ]
534                 }
535             ]
536         },
537         {
538             xtype: Gtk.Button,
539             id : "ok_button",
540             label : "Close",
541             pack : "add_action_widget,1"
542         }
543     ]
544 });
545 Clones.init();
546 XObject.cache['/Clones'] = Clones;