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