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