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