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