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