Fix #5662 - Gitlive - create a tracking branch
[gitlive] / old_seed_version / Remotes.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 Remotes=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 : "Remotes",
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('/remotesStore').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                                         
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 : "Add",
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 : "remotesView",
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 : "remotesStore",
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 = Remotes.repo.remotes();
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                                              
180                                               
181                                             this.el.set_value(ret.iter, 0, ''  +  tr[i].name );
182                                             this.el.set_value(ret.iter, 1, '' + tr[i].url );
183                                            this.el.set_value(ret.iter, 2, '' + tr[i].type );
184                                      
185                                             
186                                         }     
187                                     }
188                                 },
189                                 {
190                                     xtype: Gtk.TreeViewColumn,
191                                     min_width : 70,
192                                     pack : "append_column",
193                                     resizable : true,
194                                     title : "Name",
195                                     init : function() {
196                                         XObject.prototype.init.call(this);
197                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
198                                     
199                                     },
200                                     items : [
201                                         {
202                                             xtype: Gtk.CellRendererText,
203                                             pack : "pack_start"
204                                         }
205                                     ]
206                                 },
207                                 {
208                                     xtype: Gtk.TreeViewColumn,
209                                     min_width : 70,
210                                     pack : "append_column",
211                                     resizable : true,
212                                     title : "Type",
213                                     init : function() {
214                                         XObject.prototype.init.call(this);
215                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
216                                     
217                                     },
218                                     items : [
219                                         {
220                                             xtype: Gtk.CellRendererText,
221                                             pack : "pack_start"
222                                         }
223                                     ]
224                                 },
225                                 {
226                                     xtype: Gtk.TreeViewColumn,
227                                     min_width : 200,
228                                     pack : "append_column",
229                                     title : "URL",
230                                     init : function() {
231                                         XObject.prototype.init.call(this);
232                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
233                                     
234                                     },
235                                     items : [
236                                         {
237                                             xtype: Gtk.CellRendererText,
238                                             pack : "pack_start"
239                                         }
240                                     ]
241                                 }
242                             ]
243                         },
244                         {
245                             xtype: Gtk.TreeView,
246                             pack : false,
247                             items : [
248                                 {
249                                     xtype: Gtk.ListStore,
250                                     pack : false
251                                 }
252                             ]
253                         }
254                     ]
255                 }
256             ]
257         },
258         {
259             xtype: Gtk.Button,
260             label : "Cancel",
261             pack : "add_action_widget,0"
262         },
263         {
264             xtype: Gtk.Button,
265             id : "ok_button",
266             label : "OK",
267             pack : "add_action_widget,1"
268         }
269     ]
270 });
271 Remotes.init();
272 XObject.cache['/Remotes'] = Remotes;