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