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 : "Working Branch"
87                         },
88                         {
89                             xtype: Gtk.ComboBox,
90                             listeners : {
91                                 changed : function (self) {
92                                    this.get('/historyTreeStore').loadTree();
93                                 }
94                             },
95                             id : "workingCombo",
96                             init : function() {
97                                 this.el = new Gtk.ComboBox.with_entry();
98                                 
99                                 
100                                 this.model  = new XObject(this.model);
101                                 this.model.init();
102                                 this.el.set_model(this.model.el);
103                                 this.el.set_entry_text_column (0);
104                                  XObject.prototype.init.call(this);
105                                 
106                             },
107                             load : function(tr)
108                             {
109                                 //this.insert(citer,iter,0);
110                                 this.model.el.clear();
111                                 
112                                 var master = false;
113                                 var working = false;
114                                 
115                                 for(var i =0 ; i < tr.length; i++) {
116                                     var ret = {  };
117                                     this.model.el.append(ret);
118                                     //print(JSON.stringify(ret,null,4));
119                                     if (tr[i].name == 'master') {
120                                         master = i;
121                                     }
122                                     if (tr[i].name == 'working') {
123                                         working = i;
124                                     }          
125                                     this.model.el.set_value(ret.iter, 0, '' + tr[i].name );
126                                     this.model.el.set_value(ret.iter, 1, '' + tr[i].rev  );
127                              
128                                     
129                                 }     
130                                 if (master !== false) {
131                                     this.el.set_active(master);
132                                 }
133                                 if (working !== false) {
134                                     this.el.set_active(working);
135                                 }
136                                 
137                             },
138                             model : {
139                                 xtype: Gtk.ListStore,
140                                 init : function() {
141                                     XObject.prototype.init.call(this);
142                                     this.el.set_column_types ( 3, [
143                                            GObject.TYPE_STRING, // file  
144                                           GObject.TYPE_STRING, // added
145                                           GObject.TYPE_STRING, // removed
146                                       ] );
147                                 }
148                             }
149                         },
150                         {
151                             xtype: Gtk.Label,
152                             label : "Release Branch"
153                         },
154                         {
155                             xtype: Gtk.ComboBox,
156                             listeners : {
157                                 changed : function (self) {
158                                    this.get('/historyTreeStore').loadTree();
159                                 }
160                             },
161                             id : "releaseCombo",
162                             init : function() {
163                                 this.el = new Gtk.ComboBox.with_entry();
164                                 
165                                 
166                                 this.model  = new XObject(this.model);
167                                 this.model.init();
168                                 this.el.set_model(this.model.el);
169                                 this.el.set_entry_text_column (0);
170                                  XObject.prototype.init.call(this);
171                                 
172                             },
173                             load : function(tr)
174                             {
175                                 //this.insert(citer,iter,0);
176                                 this.model.el.clear();
177                                 
178                                 var master = false;
179                                 var release = false;
180                                 
181                                 for(var i =0 ; i < tr.length; i++) {
182                                     var ret = {  };
183                                     this.model.el.append(ret);
184                                     //print(JSON.stringify(ret,null,4));
185                                     if (tr[i].name == 'master') {
186                                         master = i;
187                                     }
188                                     if (tr[i].name == 'release') {
189                                         release = i;
190                                     }          
191                                     this.model.el.set_value(ret.iter, 0, '' + tr[i].name );
192                                     this.model.el.set_value(ret.iter, 1, '' + tr[i].rev  );
193                              
194                                     
195                                 }     
196                                 if (master !== false) {
197                                     this.el.set_active(master);
198                                 }
199                                 if (release !== false) {
200                                     this.el.set_active(release);
201                                 }
202                                 
203                             },
204                             model : {
205                                 xtype: Gtk.ListStore,
206                                 init : function() {
207                                     XObject.prototype.init.call(this);
208                                     this.el.set_column_types ( 3, [
209                                            GObject.TYPE_STRING, // file  
210                                           GObject.TYPE_STRING, // added
211                                           GObject.TYPE_STRING, // removed
212                                       ] );
213                                 }
214                             }
215                         }
216                     ]
217                 },
218                 {
219                     xtype: Gtk.VPaned,
220                     pack : "pack_end,true,true,0",
221                     position : 400,
222                     items : [
223                         {
224                             xtype: Gtk.HPaned,
225                             pack : "add",
226                             position : 200,
227                             items : [
228                                 {
229                                     xtype: Gtk.ScrolledWindow,
230                                     init : function() {
231                                         XObject.prototype.init.call(this);
232                                          this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
233                                     },
234                                     items : [
235                                         {
236                                             xtype: Gtk.TreeView,
237                                             listeners : {
238                                                 cursor_changed : function (self) {
239                                                 
240                                                     if (this.el.get_selection().count_selected_rows() < 1) {
241                                                         //nothing?
242                                                         return;
243                                                     }
244                                                     var model = this.get('/historyTreeStore');
245                                                     var ret = {};        
246                                                      var s = this.el.get_selection();
247                                                     s.get_selected(ret);
248                                                     
249                                                     var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();
250                                                      print("OUT?" + value);// id..
251                                                     // load the list in the right grid..
252                                                     var Repo = imports.Scm.Git.Repo.Repo;
253                                                     
254                                                     
255                                                    
256                                                     if (model.release === false) {
257                                                         return;
258                                                     }
259                                                     model.rev = value;
260                                                    
261                                                     var files = Merger.repo.changedFiles('/',   'rev', model.release + '..' + value);
262                                                     this.get('/changedFilesStore').load(files);
263                                                     return true;
264                                                 
265                                                 }
266                                             },
267                                             pack : "add",
268                                             init : function() {
269                                                 XObject.prototype.init.call(this);
270                                                     var description = new Pango.FontDescription.c_new();
271                                                description.set_size(8000);
272                                                  this.el.modify_font(description);
273                                             
274                                                  this.selection = this.el.get_selection();
275                                                   this.selection.set_mode( Gtk.SelectionMode.SINGLE);
276                                                 var _this = this;
277                                                 /*
278                                              780                                                                     
279                                              781                                                                         // is this really needed??
280                                              782                                                                         this.selection.signal['changed'].connect(function() {
281                                              783                                                                                 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
282                                              784                                                                                     _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
283                                              785                                                                                 );
284                                              786                                                                         });
285                                              787                                                                         
286                                              */
287                                              },
288                                             items : [
289                                                 {
290                                                     xtype: Gtk.TreeStore,
291                                                     id : "historyTreeStore",
292                                                     pack : "set_model",
293                                                     release : false,
294                                                     init : function() {
295                                                         XObject.prototype.init.call(this);
296                                                         this.el.set_column_types ( 3, [
297                                                            GObject.TYPE_STRING, // title 
298                                                           GObject.TYPE_STRING, // rev 
299                                                       ] );
300                                                     },
301                                                     load : function(tr,iter)
302                                                     {
303                                                         //this.insert(citer,iter,0);
304                                                         if (!iter) {
305                                                             this.el.clear();
306                                                         }
307                                                         
308                                                         for(var i =0 ; i < tr.length; i++) {
309                                                             var ret = {  };
310                                                             if (iter) {
311                                                                 this.el.insert(ret ,iter,-1);
312                                                             } else {
313                                                                 this.el.append(ret);
314                                                             }
315                                                             //print(JSON.stringify(ret,null,4));
316                                                              
317                                                               
318                                                             this.el.set_value(ret.iter, 0, ''  +  tr[i].text );
319                                                             this.el.set_value(ret.iter, 1, '' + tr[i].rev  );
320                                                      
321                                                             if (tr[i].children && tr[i].children.length) {
322                                                                 this.load(tr[i].children, ret.iter);
323                                                             }
324                                                         }     
325                                                     },
326                                                     loadTree : function() {
327                                                     
328                                                            this.working = false;
329                                                        
330                                                        var wid = this.get('/workingCombo').el.get_active();
331                                                        var rid = this.get('/releaseCombo').el.get_active();
332                                                        if (wid < 0 || rid < 0 || rid == wid) {
333                                                         return;
334                                                        }
335                                                        
336                                                        var w = Merger.repo.branches[wid];
337                                                        var r = Merger.repo.branches[rid];
338                                                        
339                                                     
340                                                     
341                                                         var rev = r.name + '..' + w.name;
342                                                         this.release = r.name;
343                                                     
344                                                         var hist = Merger.repo.dayTree('/', false, 'rev', rev);
345                                                         this.load(hist);
346                                                             
347                                                            
348                                                     }
349                                                 },
350                                                 {
351                                                     xtype: Gtk.TreeViewColumn,
352                                                     pack : "append_column",
353                                                     title : "History",
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;