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