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.el.add_attribute(this.items[0].el , 'activatable', 6 );
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                                     clickable : true,
286                                     min_width : 50,
287                                     pack : "append_column",
288                                     title : "Auto Push",
289                                     init : function() {
290                                         XObject.prototype.init.call(this);
291                                         this.el.add_attribute(this.items[0].el , 'active', 5 );
292                                         this.el.add_attribute(this.items[0].el , 'activatable', 6 );
293                                     },
294                                     items : [
295                                         {
296                                             xtype: Gtk.CellRendererToggle,
297                                             pack : "pack_start",
298                                             mode : Gtk.CellRendererMode.ACTIVATABLE
299                                         }
300                                     ]
301                                 },
302                                 {
303                                     xtype: Gtk.TreeViewColumn,
304                                     min_width : 200,
305                                     pack : "append_column",
306                                     resizable : true,
307                                     title : "Repo",
308                                     init : function() {
309                                         XObject.prototype.init.call(this);
310                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
311                                     
312                                     },
313                                     items : [
314                                         {
315                                             xtype: Gtk.CellRendererText,
316                                             pack : "pack_start"
317                                         }
318                                     ]
319                                 },
320                                 {
321                                     xtype: Gtk.TreeViewColumn,
322                                     min_width : 50,
323                                     pack : "append_column",
324                                     title : "Current Branch",
325                                     init : function() {
326                                         XObject.prototype.init.call(this);
327                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
328                                     
329                                     },
330                                     items : [
331                                         {
332                                             xtype: Gtk.CellRendererText,
333                                             pack : "pack_start"
334                                         }
335                                     ]
336                                 },
337                                 {
338                                     xtype: Gtk.TreeViewColumn,
339                                     min_width : 50,
340                                     pack : "append_column",
341                                     title : "Last updated",
342                                     init : function() {
343                                         XObject.prototype.init.call(this);
344                                         this.el.add_attribute(this.items[0].el , 'markup', 3 );
345                                     
346                                     },
347                                     items : [
348                                         {
349                                             xtype: Gtk.CellRendererText,
350                                             pack : "pack_start"
351                                         }
352                                     ]
353                                 },
354                                 {
355                                     xtype: Gtk.TreeViewColumn,
356                                     min_width : 50,
357                                     pack : "append_column",
358                                     resizable : false,
359                                     title : "All Branches",
360                                     init : function() {
361                                         XObject.prototype.init.call(this);
362                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
363                                     
364                                     },
365                                     items : [
366                                         {
367                                             xtype: Gtk.CellRendererText,
368                                             pack : "pack_start"
369                                         }
370                                     ]
371                                 }
372                             ]
373                         },
374                         {
375                             xtype: Gtk.TreeView,
376                             pack : false,
377                             items : [
378                                 {
379                                     xtype: Gtk.ListStore,
380                                     pack : false
381                                 }
382                             ]
383                         }
384                     ]
385                 }
386             ]
387         },
388         {
389             xtype: Gtk.Button,
390             label : "Cancel",
391             pack : "add_action_widget,0"
392         },
393         {
394             xtype: Gtk.Button,
395             id : "ok_button",
396             label : "OK",
397             pack : "add_action_widget,1"
398         }
399     ]
400 });
401 Clones.init();
402 XObject.cache['/Clones'] = Clones;