Final User interface tweaks to basic commit code (shows dialogs while it does stuff)
[gitlive] / Clones.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
12 Clones=new XObject({
13     xtype: Gtk.Dialog,
14     listeners : {
15         destroy_event : function (self, event) {
16               print("DESTROY?!");
17              return true;
18         },
19         response : function (self, id) {
20           // hide
21              //if (id < 1) {
22                 this.el.hide();
23                 return;
24             //}
25             if (typeof(this.get('bug').getValue()) != 'object') {
26                 print("ERROR");
27                 return;
28             }
29          
30             this.el.hide();
31                 
32             //var val = this.get('bug').getValue();
33              //   Seed.print(val);
34         }
35     },
36     border_width : 3,
37     default_height : 500,
38     default_width : 600,
39     title : "Manage Clones",
40     deletable : true,
41     modal : true,
42     show : function(c) {
43         
44         if (!this.el) {
45             this.init();
46         }
47         var _this = this;
48         /*[ 'xtype'  ].forEach(function(k) {
49             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
50         });
51         // shouild set path..
52         */
53         this.el.set_deletable(false);
54         this.el.show_all();
55         // load clones..
56             this.get('/reposStore').load();
57         
58         //this.get('/ok_button').el.set_sensitive(false);
59         
60         // block until we return.
61         var run_ret = this.el.run();
62         if (run_ret < 1 ) {
63             return  "DONE";
64         }
65         print("RUN RETURN : " + run_ret);
66         return "DONE";
67         //print(JSON.stringify(this.get('bug').getValue()));
68        // return this.get('bug').getValue();
69         //this.success = c.success;
70     },
71     items : [
72         {
73             xtype: Gtk.VBox,
74             id : "Clones",
75             pack : function(p,e) {
76                     p.el.get_content_area().pack_start(e.el,true,true,0)
77                 },
78             items : [
79                 {
80                     xtype: Gtk.HBox,
81                     pack : "pack_start,false,true",
82                     items : [
83                         {
84                             xtype: Gtk.Button,
85                             listeners : {
86                                 clicked : function (self) {
87                                 
88                                     var rv = this.get('/reposView');
89                                     var rs = this.get('/reposStore');
90                                     if (rv.el.get_selection().count_selected_rows() != 1) {
91                                         //nothing?
92                                         // error condition.
93                                         return;
94                                     }
95                                     var Remotes =     imports.Remotes.Remotes;
96                                     
97                                  
98                                     var ret = {};       
99                                     var s = rv.el.get_selection();
100                                     var path = '';
101                                     s.selected_foreach(function(model,p,iter) {
102                                                                                     
103                                        path = model.get_value(iter, 6).value.get_string();
104                                      
105                                     }); 
106                                 
107                                     var repo = false;
108                                     rs.repos.forEach(function(r) {
109                                         if (r.repopath == path) {
110                                             repo = r;
111                                         
112                                         }
113                                     
114                                     });
115                                     Remotes.repo = repo;
116                                     Remotes.el.set_transient_for(Clones.el);
117                                     Clones.el.set_title("Manage Clones - " + repo.repopath);
118                                     Remotes.show();
119                                     Clones.el.set_title("Manage Clones");
120                                 
121                                      
122                                     
123                                     
124                                     
125                                 
126                                        
127                                     
128                                     
129                                 }
130                             },
131                             label : "Remotes / Clones",
132                             pack : "add"
133                         },
134                         {
135                             xtype: Gtk.Button,
136                             listeners : {
137                                 clicked : function (self) {
138                                 
139                                     var rv = this.get('/reposView');
140                                     var rs = this.get('/reposStore');
141                                     if (rv.el.get_selection().count_selected_rows() != 1) {
142                                         //nothing?
143                                         // error condition.
144                                         return;
145                                     }
146                                     var Branches =     imports.Branches.Branches;
147                                     
148                                  
149                                     var ret = {};       
150                                     var s = rv.el.get_selection();
151                                     var path = '';
152                                     s.selected_foreach(function(model,p,iter) {
153                                                                                     
154                                        path = model.get_value(iter, 6).value.get_string();
155                                      
156                                     }); 
157                                 
158                                     var repo = false;
159                                     rs.repos.forEach(function(r) {
160                                         if (r.repopath == path) {
161                                             repo = r;
162                                         
163                                         }
164                                     
165                                     });
166                                     Branches.repo = repo;
167                                     Branches.el.set_transient_for(Clones.el);
168                                     Clones.el.set_title("Manage Clones - " + repo.repopath);
169                                     Branches.show();
170                                     Clones.el.set_title("Manage Clones");
171                                 
172                                      
173                                     
174                                     
175                                     
176                                 
177                                        
178                                     
179                                     
180                                 }
181                             },
182                             label : "Branches",
183                             pack : "add"
184                         },
185                         {
186                             xtype: Gtk.Button,
187                             listeners : {
188                                 clicked : function (self) {
189                                 
190                                     var rv = this.get('/reposView');
191                                     var rs = this.get('/reposStore');
192                                     if (rv.el.get_selection().count_selected_rows() != 1) {
193                                         //nothing?
194                                         // error condition.
195                                         return;
196                                     }
197                                     var Merger =     imports.Merger.Merger;
198                                     
199                                  
200                                     var ret = {};       
201                                     var s = rv.el.get_selection();
202                                     var path = '';
203                                     s.selected_foreach(function(model,p,iter) {
204                                                                                     
205                                        path = model.get_value(iter, 6).value.get_string();
206                                      
207                                     }); 
208                                 
209                                     var repo = false;
210                                     rs.repos.forEach(function(r) {
211                                         if (r.repopath == path) {
212                                             repo = r;
213                                         
214                                         }
215                                     
216                                     });
217                                     Merger.repo = repo;
218                                     Merger.el.set_transient_for(Clones.el);
219                                     Clones.el.set_title("Manage Clones - " + repo.repopath);
220                                     Merger.show();
221                                     Clones.el.set_title("Manage Clones");
222                                 
223                                     
224                                     
225                                 
226                                     
227                                 
228                                     
229                                     
230                                     
231                                     
232                                 
233                                        
234                                     
235                                     
236                                 }
237                             },
238                             label : "Run Merger",
239                             pack : "add"
240                         },
241                         {
242                             xtype: Gtk.Button,
243                             listeners : {
244                                 clicked : function (self) {
245                                     
246                                     
247                                  
248                                        
249                                     
250                                     
251                                 }
252                             },
253                             label : "Switch Branch",
254                             pack : "add"
255                         },
256                         {
257                             xtype: Gtk.Button,
258                             listeners : {
259                                 clicked : function (self) {
260                                     
261                                     
262                                  
263                                        
264                                     
265                                     
266                                 }
267                             },
268                             label : "Pull",
269                             pack : "add"
270                         }
271                     ]
272                 },
273                 {
274                     xtype: Gtk.ScrolledWindow,
275                     init : function() {
276                         XObject.prototype.init.call(this);
277                           this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
278                     },
279                     items : [
280                         {
281                             xtype: Gtk.TreeView,
282                             listeners : {
283                                 cursor_changed : function (self) {
284                                   // SEE SELECTION.CHANGED
285                                   
286                                   
287                                   return;
288                                   
289                                     if (this.el.get_selection().count_selected_rows() < 1) {
290                                         //nothing? - clea it?
291                                         return;
292                                     }
293                                         var ret = {};         
294                                     var model = this.get('/changedFilesStore');
295                                 
296                                      var s = this.el.get_selection();
297                                      var files = [];
298                                     s.selected_foreach(function(model,p,iter) {
299                                     
300                                        files.push( model.get_value(iter, 0).value.get_string());
301                                      
302                                     });
303                                     this.get('/patchview').showDiff(files); 
304                                     //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();
305                                      //print("OUT?" + value);// id..
306                                     // load the list in the right grid..
307                                      
308                                     return true;
309                                 
310                                 }
311                             },
312                             id : "reposView",
313                             pack : "add",
314                             init : function() {
315                                 XObject.prototype.init.call(this);
316                                     var description = new Pango.FontDescription.c_new();
317                                description.set_size(10000);
318                                  this.el.modify_font(description);
319                             
320                                  this.selection = this.el.get_selection();
321                                   this.selection.set_mode( Gtk.SelectionMode.MULTIPLE);
322                                 var _this = this;
323                                 
324                                 
325                               this.selection.signal['changed'].connect(function() {
326                                  _this.listeners.cursor_changed.apply(
327                                       _this, [ _this, '']
328                                    );
329                                          });
330                               },
331                             items : [
332                                 {
333                                     xtype: Gtk.ListStore,
334                                     id : "reposStore",
335                                     pack : "set_model",
336                                     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                                              var hi;
365                                              try {
366                                                  //tr[i].debug=1;
367                                                   hi = tr[i].history('/', 1, 'branch', tr[i].currentBranch.name );
368                                     //             print(JSON.stringify(hi,null,4));
369                                              } catch(e) { print(e);}
370                                               
371                                             this.el.set_value(ret.iter, 0, '' +  tr[i].repopath.split('/').pop() );
372                                             this.el.set_value(ret.iter, 1, '' + tr[i].currentBranch.name   );
373                                             this.el.set_value(ret.iter, 2, '' + tr[i].branches.map(
374                                                             function(e) { return e.name; 
375                                                         }).join(', ') 
376                                              );
377                                             this.el.set_value(ret.iter, 3, '' +  (!hi  ? '??' : hi[0].changed_raw));        
378                                             this.el.set_value(ret.iter, 4, tr[i].autocommit() );                
379                                             this.el.set_value(ret.iter, 5, tr[i].autopush() );                        
380                                             this.el.set_value(ret.iter, 6,  tr[i].repopath );  
381                                             // highlight color.
382                                             var cb = tr[i].currentBranch;
383                                             //print(JSON.stringify(cb,null,4));
384                                             var col = cb.lastrev == cb.remoterev ? '#ffffff' : '#ff0000';
385                                             this.el.set_value(ret.iter, 7, col  );      
386                                             
387                                         }     
388                                     }
389                                 },
390                                 {
391                                     xtype: Gtk.TreeViewColumn,
392                                     min_width : 50,
393                                     pack : "append_column",
394                                     title : "Auto Commit",
395                                     init : function() {
396                                         XObject.prototype.init.call(this);
397                                         this.el.add_attribute(this.items[0].el , 'active', 4 );
398                                         this.items[0].el.set_activatable(true);
399                                     
400                                     },
401                                     items : [
402                                         {
403                                             xtype: Gtk.CellRendererToggle,
404                                             listeners : {
405                                                 toggled : function (self, path) {
406                                                     var ret ={} ;
407                                                     var store = this.get('/reposStore');
408                                                     store.el.get_iter_from_string(ret, path);
409                                                                                                                  
410                                                     var value =   store.el.get_value(ret.iter,4).value.get_boolean();
411                                                                                                                  
412                                                     //print(JSON.stringify(value));
413                                                     store.el.set_value(ret.iter,4, !value);
414                                                     
415                                                 }
416                                             },
417                                             pack : "pack_start",
418                                             mode : Gtk.CellRendererMode.ACTIVATABLE
419                                         }
420                                     ]
421                                 },
422                                 {
423                                     xtype: Gtk.TreeViewColumn,
424                                     min_width : 50,
425                                     pack : "append_column",
426                                     title : "Auto Push",
427                                     init : function() {
428                                         XObject.prototype.init.call(this);
429                                         this.el.add_attribute(this.items[0].el , 'active', 5 );
430                                           this.items[0].el.set_activatable(true);
431                                     },
432                                     items : [
433                                         {
434                                             xtype: Gtk.CellRendererToggle,
435                                             listeners : {
436                                                 toggled : function (self, path) {
437                                                     var ret ={} ;
438                                                     var store = this.get('/reposStore');
439                                                     store.el.get_iter_from_string(ret, path);
440                                                                                                                  
441                                                     var value =   store.el.get_value(ret.iter,5).value.get_boolean();
442                                                                                                                  
443                                                     //print(JSON.stringify(value));
444                                                     store.el.set_value(ret.iter,5, !value);
445                                                     
446                                                 }
447                                             },
448                                             pack : "pack_start",
449                                             mode : Gtk.CellRendererMode.ACTIVATABLE
450                                         }
451                                     ]
452                                 },
453                                 {
454                                     xtype: Gtk.TreeViewColumn,
455                                     min_width : 200,
456                                     pack : "append_column",
457                                     resizable : true,
458                                     title : "Repo",
459                                     init : function() {
460                                         XObject.prototype.init.call(this);
461                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
462                                     
463                                     },
464                                     items : [
465                                         {
466                                             xtype: Gtk.CellRendererText,
467                                             pack : "pack_start"
468                                         }
469                                     ]
470                                 },
471                                 {
472                                     xtype: Gtk.TreeViewColumn,
473                                     min_width : 50,
474                                     pack : "append_column",
475                                     title : "Current Branch",
476                                     init : function() {
477                                         XObject.prototype.init.call(this);
478                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
479                                          this.el.add_attribute(this.items[0].el , 'cell-background', 7 );
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 : "Last updated",
494                                     init : function() {
495                                         XObject.prototype.init.call(this);
496                                         this.el.add_attribute(this.items[0].el , 'markup', 3 );
497                                     
498                                     },
499                                     items : [
500                                         {
501                                             xtype: Gtk.CellRendererText,
502                                             pack : "pack_start"
503                                         }
504                                     ]
505                                 },
506                                 {
507                                     xtype: Gtk.TreeViewColumn,
508                                     min_width : 50,
509                                     pack : "append_column",
510                                     resizable : false,
511                                     title : "All Branches",
512                                     init : function() {
513                                         XObject.prototype.init.call(this);
514                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
515                                     
516                                     },
517                                     items : [
518                                         {
519                                             xtype: Gtk.CellRendererText,
520                                             pack : "pack_start"
521                                         }
522                                     ]
523                                 }
524                             ]
525                         },
526                         {
527                             xtype: Gtk.TreeView,
528                             pack : false,
529                             items : [
530                                 {
531                                     xtype: Gtk.ListStore,
532                                     pack : false
533                                 }
534                             ]
535                         }
536                     ]
537                 }
538             ]
539         },
540         {
541             xtype: Gtk.Button,
542             id : "ok_button",
543             label : "Close",
544             pack : "add_action_widget,1"
545         }
546     ]
547 });
548 Clones.init();
549 XObject.cache['/Clones'] = Clones;