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