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