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 ( 7, [
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                                                GObject.TYPE_BOOLEAN // active
233                                       ] );
234                                     },
235                                     load : function()
236                                     {
237                                         //this.insert(citer,iter,0);
238                                         print("getting list");
239                                         var tr = imports.Scm.Repo.Repo.list();
240                                         
241                                         this.el.clear();
242                                         for(var i =0 ; i < tr.length; i++) {
243                                             var ret = {  };
244                                            
245                                             this.el.append(ret);
246                                             
247                                             //print(JSON.stringify(ret,null,4));
248                                              tr[i].getBranches();
249                                               
250                                             this.el.set_value(ret.iter, 0, '' +  tr[i].repopath.split('/').pop() );
251                                             this.el.set_value(ret.iter, 1, '' + tr[i].currentBranch   );
252                                             this.el.set_value(ret.iter, 2, '' + tr[i].branches.map(
253                                                             function(e) { return e.name; 
254                                                         }).join(', ') 
255                                              );
256                                             this.el.set_value(ret.iter, 3, '' + 'tbc' );        
257                                             this.el.set_value(ret.iter, 4, tr[i].autocommit() );                
258                                             this.el.set_value(ret.iter, 5, tr[i].autopush() );                        
259                                             this.el.set_value(ret.iter, 6, true );      
260                                             
261                                         }     
262                                     }
263                                 },
264                                 {
265                                     xtype: Gtk.TreeViewColumn,
266                                     min_width : 50,
267                                     pack : "append_column",
268                                     title : "Auto Commit",
269                                     init : function() {
270                                         XObject.prototype.init.call(this);
271                                         this.el.add_attribute(this.items[0].el , 'active', 4 );
272                                         this.items[0].el.set_activatable(true);
273                                     
274                                     },
275                                     items : [
276                                         {
277                                             xtype: Gtk.CellRendererToggle,
278                                             pack : "pack_start",
279                                             mode : Gtk.CellRendererMode.ACTIVATABLE
280                                         }
281                                     ]
282                                 },
283                                 {
284                                     xtype: Gtk.TreeViewColumn,
285                                     min_width : 50,
286                                     pack : "append_column",
287                                     title : "Auto Push",
288                                     init : function() {
289                                         XObject.prototype.init.call(this);
290                                         this.el.add_attribute(this.items[0].el , 'active', 5 );
291                                         this.el.add_attribute(this.items[0].el , 'activatable', 6 );
292                                     },
293                                     items : [
294                                         {
295                                             xtype: Gtk.CellRendererToggle,
296                                             pack : "pack_start",
297                                             mode : Gtk.CellRendererMode.ACTIVATABLE
298                                         }
299                                     ]
300                                 },
301                                 {
302                                     xtype: Gtk.TreeViewColumn,
303                                     min_width : 200,
304                                     pack : "append_column",
305                                     resizable : true,
306                                     title : "Repo",
307                                     init : function() {
308                                         XObject.prototype.init.call(this);
309                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
310                                     
311                                     },
312                                     items : [
313                                         {
314                                             xtype: Gtk.CellRendererText,
315                                             pack : "pack_start"
316                                         }
317                                     ]
318                                 },
319                                 {
320                                     xtype: Gtk.TreeViewColumn,
321                                     min_width : 50,
322                                     pack : "append_column",
323                                     title : "Current Branch",
324                                     init : function() {
325                                         XObject.prototype.init.call(this);
326                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
327                                     
328                                     },
329                                     items : [
330                                         {
331                                             xtype: Gtk.CellRendererText,
332                                             pack : "pack_start"
333                                         }
334                                     ]
335                                 },
336                                 {
337                                     xtype: Gtk.TreeViewColumn,
338                                     min_width : 50,
339                                     pack : "append_column",
340                                     title : "Last updated",
341                                     init : function() {
342                                         XObject.prototype.init.call(this);
343                                         this.el.add_attribute(this.items[0].el , 'markup', 3 );
344                                     
345                                     },
346                                     items : [
347                                         {
348                                             xtype: Gtk.CellRendererText,
349                                             pack : "pack_start"
350                                         }
351                                     ]
352                                 },
353                                 {
354                                     xtype: Gtk.TreeViewColumn,
355                                     min_width : 50,
356                                     pack : "append_column",
357                                     resizable : false,
358                                     title : "All Branches",
359                                     init : function() {
360                                         XObject.prototype.init.call(this);
361                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
362                                     
363                                     },
364                                     items : [
365                                         {
366                                             xtype: Gtk.CellRendererText,
367                                             pack : "pack_start"
368                                         }
369                                     ]
370                                 }
371                             ]
372                         },
373                         {
374                             xtype: Gtk.TreeView,
375                             pack : false,
376                             items : [
377                                 {
378                                     xtype: Gtk.ListStore,
379                                     pack : false
380                                 }
381                             ]
382                         }
383                     ]
384                 }
385             ]
386         },
387         {
388             xtype: Gtk.Button,
389             label : "Cancel",
390             pack : "add_action_widget,0"
391         },
392         {
393             xtype: Gtk.Button,
394             id : "ok_button",
395             label : "OK",
396             pack : "add_action_widget,1"
397         }
398     ]
399 });
400 Clones.init();
401 XObject.cache['/Clones'] = Clones;