Fix #5560 - Gitlive - branching wip
[gitlive] / old_seed_version / Commit.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 Commit=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     ' modal' : true,
37     border_width : 3,
38     default_height : 500,
39     default_width : 800,
40     title : "Commit",
41     deletable : true,
42     modal : true,
43     show : function(c) {
44         
45         if (!this.el) {
46             this.init();
47         }
48         var _this = this;
49         
50         
51         this.files = c.files;
52         this.release = c.release;
53         this.rev = c.rev;
54         
55         this.repo = c.repo;
56     
57         this.get('/commitDate').el.set_text(c.changed);
58         this.get('/commitAuthor').el.set_text(c.author);
59         this.get('/commitMsg').el.get_buffer().set_text('');
60         this.get('/commitPatch').showDiff(c.files);
61         
62         this.el.show_all();
63         
64         var run_ret = this.el.run();
65         if (run_ret < 1 ) {
66             return false;
67         }
68         var buf = this.get('/commitMsg').el.get_buffer();
69         var e = {};
70         var s = {};
71         buf.get_start_iter(s);
72         buf.get_end_iter(e);
73         
74         var ret=  {
75             date :  this.get('/commitDate').el.get_text(),
76             author :  this.get('/commitAuthor').el.get_text(),
77             message : buf.get_text(s.value, e.value, false)
78         };
79      
80         return ret;
81         
82         
83         
84     },
85     items : [
86         {
87             xtype: Gtk.VBox,
88             pack : function(p,e) {
89                     p.el.get_content_area().pack_start(e.el,true,true,10);
90                 },
91             items : [
92                 {
93                     xtype: Gtk.HBox,
94                     pack : "pack_start,false,true,2",
95                     items : [
96                         {
97                             xtype: Gtk.Label,
98                             label : "Fixes",
99                             pack : "pack_start,false,false,10",
100                             width_request : 50
101                         },
102                         {
103                             xtype: Gtk.ComboBox,
104                             listeners : {
105                                 changed : function (self) {
106                                    var val = this.el.get_child().get_text();
107                                    print(JSON.stringify(val));
108                                    if (!val.length) {
109                                        return;
110                                    }
111                                    
112                                    var name = this.get('/remoteName').el.get_text();
113                                    if (name.length) {
114                                        return;
115                                    }
116                                    // fill in name
117                                    var val = imports.Scm.Git.Repo.Repo.parseURL(val);
118                                    if ((typeof(val.host) != 'undefined') && val.host.length) {
119                                        var host = val.host;
120                                        // need to add github owner...
121                                         if (host.match(/github.com$/)) {
122                                           host += '.' + val.path.split('/').shift();
123                                         }
124                                    
125                                    
126                                         this.get('/remoteName').el.set_text(host);
127                                    }
128                                     
129                                    
130                                 }
131                             },
132                             id : "commitFixes",
133                             init : function() {
134                                 this.el = new Gtk.ComboBox.with_entry();
135                                 
136                                 
137                                 this.model  = new XObject(this.model);
138                                 this.model.init();
139                                 this.el.set_model(this.model.el);
140                                 this.el.set_entry_text_column (0);
141                                  XObject.prototype.init.call(this);
142                                 
143                             },
144                             load : function(tr)
145                             {
146                                 //this.insert(citer,iter,0);
147                                 this.model.el.clear();
148                                 
149                                 var master = false;
150                                 var working = false;
151                                 
152                                 for(var i =0 ; i < tr.length; i++) {
153                                     var ret = {  };
154                                     this.model.el.append(ret);
155                                     //print(JSON.stringify(ret,null,4));
156                                     if (tr[i].name == 'master') {
157                                         master = i;
158                                     }
159                                     if (tr[i].name == 'working') {
160                                         working = i;
161                                     }          
162                                     this.model.el.set_value(ret.iter, 0, '' + tr[i].name );
163                                     this.model.el.set_value(ret.iter, 1, '' + tr[i].rev  );
164                              
165                                     
166                                 }     
167                                 if (master !== false) {
168                                     this.el.set_active(master);
169                                 }
170                                 if (working !== false) {
171                                     this.el.set_active(working);
172                                 }
173                                 
174                             },
175                             model : {
176                                 xtype: Gtk.ListStore,
177                                 init : function() {
178                                     XObject.prototype.init.call(this);
179                                     this.el.set_column_types ( 3, [
180                                            GObject.TYPE_STRING, // file  
181                                           GObject.TYPE_STRING, // added
182                                           GObject.TYPE_STRING, // removed
183                                       ] );
184                                 }
185                             }
186                         }
187                     ]
188                 },
189                 {
190                     xtype: Gtk.HBox,
191                     pack : "pack_start,false,true,2",
192                     items : [
193                         {
194                             xtype: Gtk.Label,
195                             label : "Date",
196                             pack : "pack_start,false,false,10",
197                             width_request : 50,
198                             xalign : 1
199                         },
200                         {
201                             xtype: Gtk.Entry,
202                             id : "commitDate"
203                         }
204                     ]
205                 },
206                 {
207                     xtype: Gtk.HBox,
208                     pack : "pack_start,false,true,2",
209                     items : [
210                         {
211                             xtype: Gtk.Label,
212                             label : "Author",
213                             pack : "pack_start,false,false,10",
214                             width_request : 50,
215                             xalign : 1
216                         },
217                         {
218                             xtype: Gtk.Entry,
219                             id : "commitAuthor"
220                         }
221                     ]
222                 },
223                 {
224                     xtype: Gtk.HBox,
225                     pack : "pack_start,false,false,2",
226                     items : [
227                         {
228                             xtype: Gtk.Label,
229                             label : "Message",
230                             pack : "pack_start,false,false,10",
231                             width_request : 50,
232                             xalign : 1
233                         },
234                         {
235                             xtype: Gtk.TextView,
236                             height_request : 100,
237                             id : "commitMsg",
238                             pack : "add"
239                         }
240                     ]
241                 },
242                 {
243                     xtype: Gtk.ScrolledWindow,
244                     height_request : 200,
245                     pack : "pack_end,true,true,0",
246                     init : function() {
247                         XObject.prototype.init.call(this);
248                           this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
249                     },
250                     items : [
251                         {
252                             xtype: WebKit.WebView,
253                             id : "commitPatch",
254                             pack : "add",
255                             clear : function() {
256                                 
257                                 
258                                 
259                                  
260                                // remove..
261                                 var s  = "document.body.textContent='';"
262                                     
263                                 this.el.execute_script(s);
264                                     
265                                     
266                                 
267                                 
268                                 
269                             },
270                             showDiff : function(files) {
271                                 this.clear();
272                                 
273                                 
274                                 
275                                 if (Commit.release === false) {
276                                     return;
277                                 }
278                                 
279                                 var diff = Commit.repo.diff(files, Commit.release, Commit.rev);
280                                 
281                                // remove..
282                                 var s  = "var pre  = document.createElement('pre'); document.body.appendChild(pre);";
283                                 s += "pre.textContent =  " +
284                                          JSON.stringify(Commit.repo.lastCmd + "\n") + '+  ' + 
285                                          JSON.stringify(diff) + ";";
286                                     
287                                 this.el.execute_script(s);
288                                     
289                                     
290                                 
291                                 
292                                 
293                             }
294                         }
295                     ]
296                 }
297             ]
298         },
299         {
300             xtype: Gtk.Button,
301             label : "Cancel",
302             pack : "add_action_widget,0"
303         },
304         {
305             xtype: Gtk.Button,
306             id : "ok_button",
307             label : "Add",
308             pack : "add_action_widget,1"
309         }
310     ]
311 });
312 Commit.init();
313 XObject.cache['/Commit'] = Commit;