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