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