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