Merger.js
[gitlive] / Merger.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 Merger=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 : 700,
38     default_width : 800,
39     id : "Merger",
40     title : "Merger",
41     deletable : true,
42     show : function(c) {
43         
44         if (!this.el) {
45             this.init();
46         }
47         var _this = this;
48          
49           //this.el.set_title("Merger - ??? ");
50     //   this.el.set_title("Merger - " + this.repo.repopath);
51     
52     
53     
54          /// load up branches
55          this.get('/workingCombo').model.load(Merger.repo.branches);
56          
57          this.get('/releaseCombo').model.load(Merger.repo.branches);
58     
59         this.el.show_all();
60         //this.get('/ok_button').el.set_sensitive(false);
61         
62         // block until we return.
63         var run_ret = this.el.run();
64         if (run_ret < 1 ) {
65             return  "DONE";
66         }
67         print("RUN RETURN : " + run_ret);
68         return "DONE";
69         //print(JSON.stringify(this.get('bug').getValue()));
70        // return this.get('bug').getValue();
71         //this.success = c.success;
72     },
73     items : [
74         {
75             xtype: Gtk.VBox,
76             pack : function(p,e) {
77                     p.el.get_content_area().pack_start(e.el,true,true,0)
78                 },
79             items : [
80                 {
81                     xtype: Gtk.HBox,
82                     pack : "pack_start,false,true",
83                     items : [
84                         {
85                             xtype: Gtk.Button,
86                             listeners : {
87                                 clicked : function (self) {
88                                     
89                                     
90                                  
91                                     var hist = Merger.repo.dayTree('/', false, 'rev', 'github..master');
92                                     this.get('/historyTreeStore').load(hist);
93                                         
94                                        
95                                     
96                                     
97                                 }
98                             },
99                             label : "Select Branch",
100                             pack : "add"
101                         },
102                         {
103                             xtype: Gtk.Label,
104                             label : "Working Branch"
105                         },
106                         {
107                             xtype: Gtk.ComboBox,
108                             id : "workingCombo",
109                             load : function() {
110                                 
111                             },
112                             init : function() {
113                                 this.el = new Gtk.ComboBox.with_entry();
114                                 
115                                 
116                                 this.model  = new XObject(this.model);
117                                 this.model.init();
118                                 this.el.set_model(this.model.el);
119                                 this.el.set_entry_text_column (0);
120                                  XObject.prototype.init.call(this);
121                                 
122                             },
123                             model : {
124                                 xtype: Gtk.ListStore,
125                                 init : function() {
126                                     XObject.prototype.init.call(this);
127                                     this.el.set_column_types ( 3, [
128                                            GObject.TYPE_STRING, // file  
129                                           GObject.TYPE_STRING, // added
130                                           GObject.TYPE_STRING, // removed
131                                       ] );
132                                 },
133                                 load : function(tr)
134                                 {
135                                     //this.insert(citer,iter,0);
136                                     this.el.clear();
137                                     
138                                     for(var i =0 ; i < tr.length; i++) {
139                                         var ret = {  };
140                                         this.el.append(ret);
141                                         //print(JSON.stringify(ret,null,4));
142                                          
143                                           
144                                         this.el.set_value(ret.iter, 0, '' + tr[i].name );
145                                         this.el.set_value(ret.iter, 1, '' + tr[i].rev  );
146                                  
147                                         
148                                     }     
149                                     
150                                     
151                                 }
152                             }
153                         },
154                         {
155                             xtype: Gtk.Label,
156                             label : "Release Branch"
157                         },
158                         {
159                             xtype: Gtk.ComboBox,
160                             id : "releaseCombo",
161                             init : function() {
162                                 this.el = new Gtk.ComboBox.with_entry();
163                                 
164                                 
165                                 this.model  = new XObject(this.model);
166                                 this.model.init();
167                                 this.el.set_model(this.model.el);
168                                 this.el.set_entry_text_column (0);
169                                  XObject.prototype.init.call(this);
170                                 
171                             },
172                             model : {
173                                 xtype: Gtk.ListStore,
174                                 init : function() {
175                                     XObject.prototype.init.call(this);
176                                     this.el.set_column_types ( 3, [
177                                            GObject.TYPE_STRING, // file  
178                                           GObject.TYPE_STRING, // added
179                                           GObject.TYPE_STRING, // removed
180                                       ] );
181                                 },
182                                 load : function(tr)
183                                 {
184                                     //this.insert(citer,iter,0);
185                                     this.el.clear();
186                                     
187                                     for(var i =0 ; i < tr.length; i++) {
188                                         var ret = {  };
189                                         this.el.append(ret);
190                                         //print(JSON.stringify(ret,null,4));
191                                          
192                                           
193                                         this.el.set_value(ret.iter, 0, ''  +  tr[i].name );
194                                         this.el.set_value(ret.iter, 1, '' + tr[i].rev  );
195                                  
196                                         
197                                     }     
198                                 }
199                             }
200                         }
201                     ]
202                 },
203                 {
204                     xtype: Gtk.VPaned,
205                     pack : "pack_end,true,true,0",
206                     position : 400,
207                     items : [
208                         {
209                             xtype: Gtk.HPaned,
210                             pack : "add",
211                             position : 200,
212                             items : [
213                                 {
214                                     xtype: Gtk.ScrolledWindow,
215                                     init : function() {
216                                         XObject.prototype.init.call(this);
217                                          this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
218                                     },
219                                     items : [
220                                         {
221                                             xtype: Gtk.TreeView,
222                                             listeners : {
223                                                 cursor_changed : function (self) {
224                                                 
225                                                     if (this.el.get_selection().count_selected_rows() < 1) {
226                                                         //nothing?
227                                                         return;
228                                                     }
229                                                     var model = this.get('/historyTreeStore');
230                                                     var ret = {};        
231                                                      var s = this.el.get_selection();
232                                                     s.get_selected(ret);
233                                                     
234                                                     var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();
235                                                      print("OUT?" + value);// id..
236                                                     // load the list in the right grid..
237                                                     var Repo = imports.Scm.Git.Repo.Repo;
238                                                     
239                                                     
240                                                    
241                                                     var files = Merger.repo.changedFiles('/',   'rev', 'github..' + value);
242                                                     this.get('/changedFilesStore').load(files);
243                                                     return true;
244                                                 
245                                                 }
246                                             },
247                                             pack : "add",
248                                             init : function() {
249                                                 XObject.prototype.init.call(this);
250                                                     var description = new Pango.FontDescription.c_new();
251                                                description.set_size(8000);
252                                                  this.el.modify_font(description);
253                                             
254                                                  this.selection = this.el.get_selection();
255                                                   this.selection.set_mode( Gtk.SelectionMode.SINGLE);
256                                                 var _this = this;
257                                                 /*
258                                              780                                                                     
259                                              781                                                                         // is this really needed??
260                                              782                                                                         this.selection.signal['changed'].connect(function() {
261                                              783                                                                                 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
262                                              784                                                                                     _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
263                                              785                                                                                 );
264                                              786                                                                         });
265                                              787                                                                         
266                                              */
267                                              },
268                                             items : [
269                                                 {
270                                                     xtype: Gtk.TreeStore,
271                                                     id : "historyTreeStore",
272                                                     pack : "set_model",
273                                                     init : function() {
274                                                         XObject.prototype.init.call(this);
275                                                         this.el.set_column_types ( 3, [
276                                                            GObject.TYPE_STRING, // title 
277                                                           GObject.TYPE_STRING, // rev 
278                                                       ] );
279                                                     },
280                                                     load : function(tr,iter)
281                                                     {
282                                                         //this.insert(citer,iter,0);
283                                                         if (!iter) {
284                                                             this.el.clear();
285                                                         }
286                                                         
287                                                         for(var i =0 ; i < tr.length; i++) {
288                                                             var ret = {  };
289                                                             if (iter) {
290                                                                 this.el.insert(ret ,iter,-1);
291                                                             } else {
292                                                                 this.el.append(ret);
293                                                             }
294                                                             //print(JSON.stringify(ret,null,4));
295                                                              
296                                                               
297                                                             this.el.set_value(ret.iter, 0, ''  +  tr[i].text );
298                                                             this.el.set_value(ret.iter, 1, '' + tr[i].rev  );
299                                                      
300                                                             if (tr[i].children && tr[i].children.length) {
301                                                                 this.load(tr[i].children, ret.iter);
302                                                             }
303                                                         }     
304                                                     }
305                                                 },
306                                                 {
307                                                     xtype: Gtk.TreeViewColumn,
308                                                     pack : "append_column",
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                                         }
323                                     ]
324                                 },
325                                 {
326                                     xtype: Gtk.ScrolledWindow,
327                                     init : function() {
328                                         XObject.prototype.init.call(this);
329                                           this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
330                                     },
331                                     items : [
332                                         {
333                                             xtype: Gtk.TreeView,
334                                             listeners : {
335                                                 cursor_changed : function (self) {
336                                                   // SEE SELECTION.CHANGED
337                                                     if (this.el.get_selection().count_selected_rows() < 1) {
338                                                         //nothing? - clea it?
339                                                         return;
340                                                     }
341                                                         var ret = {};         
342                                                     var model = this.get('/changedFilesStore');
343                                                 
344                                                      var s = this.el.get_selection();
345                                                      var files = [];
346                                                     s.selected_foreach(function(model,p,iter) {
347                                                     
348                                                        files.push( model.get_value(iter, 0).value.get_string());
349                                                      
350                                                     });
351                                                     this.get('/patchview').showDiff(files); 
352                                                     //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();
353                                                      //print("OUT?" + value);// id..
354                                                     // load the list in the right grid..
355                                                      
356                                                     return true;
357                                                 
358                                                 }
359                                             },
360                                             id : "changedFilesView",
361                                             pack : "add",
362                                             init : function() {
363                                                 XObject.prototype.init.call(this);
364                                                     var description = new Pango.FontDescription.c_new();
365                                                description.set_size(8000);
366                                                  this.el.modify_font(description);
367                                             
368                                                  this.selection = this.el.get_selection();
369                                                   this.selection.set_mode( Gtk.SelectionMode.MULTIPLE);
370                                                 var _this = this;
371                                               this.selection.signal['changed'].connect(function() {
372                                                  _this.listeners.cursor_changed.apply(
373                                                       _this, [ _this, '']
374                                                    );
375                                                          });
376                                               },
377                                             items : [
378                                                 {
379                                                     xtype: Gtk.ListStore,
380                                                     id : "changedFilesStore",
381                                                     pack : "set_model",
382                                                     init : function() {
383                                                         XObject.prototype.init.call(this);
384                                                         this.el.set_column_types ( 3, [
385                                                            GObject.TYPE_STRING, // file  
386                                                           GObject.TYPE_STRING, // added
387                                                           GObject.TYPE_STRING, // removed
388                                                       ] );
389                                                     },
390                                                     load : function(tr)
391                                                     {
392                                                         //this.insert(citer,iter,0);
393                                                         this.el.clear();
394                                                         for(var i =0 ; i < tr.length; i++) {
395                                                             var ret = {  };
396                                                            
397                                                             this.el.append(ret);
398                                                             
399                                                             //print(JSON.stringify(ret,null,4));
400                                                              
401                                                               
402                                                             this.el.set_value(ret.iter, 0, ''  +  tr[i].filename );
403                                                             this.el.set_value(ret.iter, 1, '' + tr[i].added  );
404                                                             this.el.set_value(ret.iter, 2, '' + tr[i].removed  );
405                                                      
406                                                             
407                                                         }     
408                                                     }
409                                                 },
410                                                 {
411                                                     xtype: Gtk.TreeViewColumn,
412                                                     resizable : true,
413                                                     min_width : 200,
414                                                     pack : "append_column",
415                                                     title : "Filename",
416                                                     init : function() {
417                                                         XObject.prototype.init.call(this);
418                                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
419                                                     
420                                                     },
421                                                     items : [
422                                                         {
423                                                             xtype: Gtk.CellRendererText,
424                                                             pack : "pack_start"
425                                                         }
426                                                     ]
427                                                 },
428                                                 {
429                                                     xtype: Gtk.TreeViewColumn,
430                                                     min_width : 50,
431                                                     pack : "append_column",
432                                                     title : "Added",
433                                                     init : function() {
434                                                         XObject.prototype.init.call(this);
435                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
436                                                     
437                                                     },
438                                                     items : [
439                                                         {
440                                                             xtype: Gtk.CellRendererText,
441                                                             pack : "pack_start"
442                                                         }
443                                                     ]
444                                                 },
445                                                 {
446                                                     xtype: Gtk.TreeViewColumn,
447                                                     min_width : 50,
448                                                     pack : "append_column",
449                                                     title : "Removed",
450                                                     init : function() {
451                                                         XObject.prototype.init.call(this);
452                                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
453                                                     
454                                                     },
455                                                     items : [
456                                                         {
457                                                             xtype: Gtk.CellRendererText,
458                                                             pack : "pack_start"
459                                                         }
460                                                     ]
461                                                 }
462                                             ]
463                                         },
464                                         {
465                                             xtype: Gtk.TreeView,
466                                             pack : false,
467                                             items : [
468                                                 {
469                                                     xtype: Gtk.ListStore,
470                                                     pack : false
471                                                 }
472                                             ]
473                                         }
474                                     ]
475                                 }
476                             ]
477                         },
478                         {
479                             xtype: Gtk.VBox,
480                             items : [
481                                 {
482                                     xtype: Gtk.HBox,
483                                     pack : "pack_start,false,false,0",
484                                     items : [
485                                         {
486                                             xtype: Gtk.Button,
487                                             label : "Commit diff (no merge)"
488                                         },
489                                         {
490                                             xtype: Gtk.Button,
491                                             label : "Commit diff (merge after)"
492                                         }
493                                     ]
494                                 },
495                                 {
496                                     xtype: Gtk.ScrolledWindow,
497                                     pack : "pack_end,true,true,0",
498                                     init : function() {
499                                         XObject.prototype.init.call(this);
500                                           this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
501                                     },
502                                     items : [
503                                         {
504                                             xtype: WebKit.WebView,
505                                             id : "patchview",
506                                             pack : "add",
507                                             showDiff : function(files) {
508                                                 
509                                              
510                                                 var diff = Merger.repo.diff(files, 'github', 'master');
511                                                 
512                                                // remove..
513                                                 var s  = "document.body.textContent='';var pre  = document.createElement('pre'); document.body.appendChild(pre);";
514                                                 s += "pre.textContent =  " +
515                                                          JSON.stringify(repo.lastCmd + "\n") + '+  ' + 
516                                                        JSON.stringify(diff) + ";";
517                                                 print(s);
518                                                     
519                                                 this.el.execute_script(s);
520                                                     
521                                                     
522                                                 
523                                                 
524                                                 
525                                             }
526                                         }
527                                     ]
528                                 }
529                             ]
530                         }
531                     ]
532                 }
533             ]
534         },
535         {
536             xtype: Gtk.Button,
537             label : "Cancel",
538             pack : "add_action_widget,0"
539         },
540         {
541             xtype: Gtk.Button,
542             id : "ok_button",
543             label : "OK",
544             pack : "add_action_widget,1"
545         }
546     ]
547 });
548 Merger.init();
549 XObject.cache['/Merger'] = Merger;