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