Fix #5560 - Gitlive - branching wip
[gitlive] / old_seed_version / Branches.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 Branches=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 : 300,
39     default_width : 500,
40     title : "Branches",
41     deletable : true,
42     modal : true,
43     show : function(c) {
44         
45         if (!this.el) {
46             this.init();
47         }
48         var _this = this;
49         this.get('/branchStore').load();
50         this.el.show_all();
51         
52         var run_ret = this.el.run();
53         if (run_ret < 1 ) {
54             return  "DONE";
55         }
56         print("RUN RETURN : " + run_ret);
57         return "DONE";
58         
59     },
60     items : [
61         {
62             xtype: Gtk.VBox,
63             pack : function(p,e) {
64                     p.el.get_content_area().pack_start(e.el,true,true,0)
65                 },
66             items : [
67                 {
68                     xtype: Gtk.HBox,
69                     pack : "pack_start,false,true",
70                     items : [
71                         {
72                             xtype: Gtk.Button,
73                             listeners : {
74                                 clicked : function (self) {
75                                 
76                                      return;
77                                     var RemoteEdit=    imports.RemoteEdit.RemoteEdit
78                                      RemoteEdit.repo = Remotes.repo;
79                                     RemoteEdit.el.set_transient_for(Remotes.el);
80                                 
81                                     var res =  RemoteEdit.show();
82                                     
83                                     if (res != false) {
84                                         Remotes.repo.remotes(res);
85                                     }
86                                     
87                                     this.get('/remotesStore').load();
88                                 
89                                     
90                                 }
91                             },
92                             label : "Pull",
93                             pack : "add"
94                         }
95                     ]
96                 },
97                 {
98                     xtype: Gtk.ScrolledWindow,
99                     init : function() {
100                         XObject.prototype.init.call(this);
101                           this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
102                     },
103                     items : [
104                         {
105                             xtype: Gtk.TreeView,
106                             listeners : {
107                                 cursor_changed : function (self)
108                                 {
109                                 
110                                    return;
111                                   // SEE SELECTION.CHANGED
112                                     if (this.el.get_selection().count_selected_rows() < 1) {
113                                         //nothing? - clea it?
114                                         return;
115                                     }
116                                         var ret = {};         
117                                     var model = this.get('/changedFilesStore');
118                                 
119                                      var s = this.el.get_selection();
120                                      var files = [];
121                                     s.selected_foreach(function(model,p,iter) {
122                                     
123                                        files.push( model.get_value(iter, 0).value.get_string());
124                                      
125                                     });
126                                     this.get('/patchview').showDiff(files); 
127                                     //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();
128                                      //print("OUT?" + value);// id..
129                                     // load the list in the right grid..
130                                      
131                                     return true;
132                                 
133                                 }
134                             },
135                             id : "branchView",
136                             pack : "add",
137                             init : function() {
138                                 XObject.prototype.init.call(this);
139                                     var description = new Pango.FontDescription.c_new();
140                                description.set_size(8000);
141                                  this.el.modify_font(description);
142                             
143                                  this.selection = this.el.get_selection();
144                                   this.selection.set_mode( Gtk.SelectionMode.MULTIPLE);
145                                 var _this = this;
146                               this.selection.signal['changed'].connect(function() {
147                                  _this.listeners.cursor_changed.apply(
148                                       _this, [ _this, '']
149                                    );
150                                          });
151                               },
152                             items : [
153                                 {
154                                     xtype: Gtk.ListStore,
155                                     id : "branchStore",
156                                     pack : "set_model",
157                                     init : function() {
158                                         XObject.prototype.init.call(this);
159                                         this.el.set_column_types ( 3, [
160                                            GObject.TYPE_STRING, // file  
161                                           GObject.TYPE_STRING, // added
162                                           GObject.TYPE_STRING, // removed
163                                       ] );
164                                     },
165                                     load : function(tr)
166                                     {
167                                         //this.insert(citer,iter,0);
168                                         this.el.clear();
169                                         
170                                         var tr = Branches.repo.getBranches();
171                                         
172                                         
173                                         for(var i =0 ; i < tr.length; i++) {
174                                             var ret = {  };
175                                            
176                                             this.el.append(ret);
177                                             
178                                             //print(JSON.stringify(ret,null,4));
179                                             var lastrev = tr[i].lastrev;
180                                             var remoterev = tr[i].remoterev;
181                                             
182                                             var lastrev = lastrev.length ? lastrev : remoterev;
183                                             
184                                             if (lastrev != remoterev) {
185                                                 lastrev = "Out of sync: remote=" + remoterev + ", local=" + lastrev;
186                                             }
187                                             
188                                      
189                                               
190                                             this.el.set_value(ret.iter, 0, ''  +  tr[i].name );
191                                             this.el.set_value(ret.iter, 1, '' + tr[i].remote );
192                                             this.el.set_value(ret.iter, 2, '' + lastrev );
193                                      
194                                             
195                                         }     
196                                     }
197                                 },
198                                 {
199                                     xtype: Gtk.TreeViewColumn,
200                                     min_width : 70,
201                                     pack : "append_column",
202                                     resizable : true,
203                                     title : "Local",
204                                     init : function() {
205                                         XObject.prototype.init.call(this);
206                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
207                                     
208                                     },
209                                     items : [
210                                         {
211                                             xtype: Gtk.CellRendererText,
212                                             pack : "pack_start"
213                                         }
214                                     ]
215                                 },
216                                 {
217                                     xtype: Gtk.TreeViewColumn,
218                                     min_width : 70,
219                                     pack : "append_column",
220                                     resizable : true,
221                                     title : "Remote",
222                                     init : function() {
223                                         XObject.prototype.init.call(this);
224                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
225                                     
226                                     },
227                                     items : [
228                                         {
229                                             xtype: Gtk.CellRendererText,
230                                             pack : "pack_start"
231                                         }
232                                     ]
233                                 },
234                                 {
235                                     xtype: Gtk.TreeViewColumn,
236                                     min_width : 200,
237                                     pack : "append_column",
238                                     title : "Status",
239                                     init : function() {
240                                         XObject.prototype.init.call(this);
241                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
242                                     
243                                     },
244                                     items : [
245                                         {
246                                             xtype: Gtk.CellRendererText,
247                                             pack : "pack_start"
248                                         }
249                                     ]
250                                 }
251                             ]
252                         },
253                         {
254                             xtype: Gtk.TreeView,
255                             pack : false,
256                             items : [
257                                 {
258                                     xtype: Gtk.ListStore,
259                                     pack : false
260                                 }
261                             ]
262                         }
263                     ]
264                 }
265             ]
266         },
267         {
268             xtype: Gtk.Button,
269             label : "Cancel",
270             pack : "add_action_widget,0"
271         },
272         {
273             xtype: Gtk.Button,
274             id : "ok_button",
275             label : "OK",
276             pack : "add_action_widget,1"
277         }
278     ]
279 });
280 Branches.init();
281 XObject.cache['/Branches'] = Branches;