Remotes.js
[gitlive] / 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                                     Remotes.repo.remotes(res);
84                                     
85                                     
86                                 
87                                     
88                                 }
89                             },
90                             label : "Add",
91                             pack : "add"
92                         }
93                     ]
94                 },
95                 {
96                     xtype: Gtk.ScrolledWindow,
97                     init : function() {
98                         XObject.prototype.init.call(this);
99                           this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
100                     },
101                     items : [
102                         {
103                             xtype: Gtk.TreeView,
104                             listeners : {
105                                 cursor_changed : function (self)
106                                 {
107                                 
108                                    return;
109                                   // SEE SELECTION.CHANGED
110                                     if (this.el.get_selection().count_selected_rows() < 1) {
111                                         //nothing? - clea it?
112                                         return;
113                                     }
114                                         var ret = {};         
115                                     var model = this.get('/changedFilesStore');
116                                 
117                                      var s = this.el.get_selection();
118                                      var files = [];
119                                     s.selected_foreach(function(model,p,iter) {
120                                     
121                                        files.push( model.get_value(iter, 0).value.get_string());
122                                      
123                                     });
124                                     this.get('/patchview').showDiff(files); 
125                                     //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();
126                                      //print("OUT?" + value);// id..
127                                     // load the list in the right grid..
128                                      
129                                     return true;
130                                 
131                                 }
132                             },
133                             id : "remotesView",
134                             pack : "add",
135                             init : function() {
136                                 XObject.prototype.init.call(this);
137                                     var description = new Pango.FontDescription.c_new();
138                                description.set_size(8000);
139                                  this.el.modify_font(description);
140                             
141                                  this.selection = this.el.get_selection();
142                                   this.selection.set_mode( Gtk.SelectionMode.MULTIPLE);
143                                 var _this = this;
144                               this.selection.signal['changed'].connect(function() {
145                                  _this.listeners.cursor_changed.apply(
146                                       _this, [ _this, '']
147                                    );
148                                          });
149                               },
150                             items : [
151                                 {
152                                     xtype: Gtk.ListStore,
153                                     id : "remotesStore",
154                                     pack : "set_model",
155                                     init : function() {
156                                         XObject.prototype.init.call(this);
157                                         this.el.set_column_types ( 3, [
158                                            GObject.TYPE_STRING, // file  
159                                           GObject.TYPE_STRING, // added
160                                           GObject.TYPE_STRING, // removed
161                                       ] );
162                                     },
163                                     load : function(tr)
164                                     {
165                                         //this.insert(citer,iter,0);
166                                         this.el.clear();
167                                         
168                                         var tr = Remotes.repo.remotes();
169                                         
170                                         
171                                         for(var i =0 ; i < tr.length; i++) {
172                                             var ret = {  };
173                                            
174                                             this.el.append(ret);
175                                             
176                                             //print(JSON.stringify(ret,null,4));
177                                              
178                                               
179                                             this.el.set_value(ret.iter, 0, ''  +  tr[i].name );
180                                             this.el.set_value(ret.iter, 1, '' + tr[i].url );
181                                            this.el.set_value(ret.iter, 2, '' + tr[i].type );
182                                      
183                                             
184                                         }     
185                                     }
186                                 },
187                                 {
188                                     xtype: Gtk.TreeViewColumn,
189                                     min_width : 70,
190                                     pack : "append_column",
191                                     resizable : true,
192                                     title : "Name",
193                                     init : function() {
194                                         XObject.prototype.init.call(this);
195                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
196                                     
197                                     },
198                                     items : [
199                                         {
200                                             xtype: Gtk.CellRendererText,
201                                             pack : "pack_start"
202                                         }
203                                     ]
204                                 },
205                                 {
206                                     xtype: Gtk.TreeViewColumn,
207                                     min_width : 70,
208                                     pack : "append_column",
209                                     resizable : true,
210                                     title : "Type",
211                                     init : function() {
212                                         XObject.prototype.init.call(this);
213                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
214                                     
215                                     },
216                                     items : [
217                                         {
218                                             xtype: Gtk.CellRendererText,
219                                             pack : "pack_start"
220                                         }
221                                     ]
222                                 },
223                                 {
224                                     xtype: Gtk.TreeViewColumn,
225                                     min_width : 200,
226                                     pack : "append_column",
227                                     title : "URL",
228                                     init : function() {
229                                         XObject.prototype.init.call(this);
230                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
231                                     
232                                     },
233                                     items : [
234                                         {
235                                             xtype: Gtk.CellRendererText,
236                                             pack : "pack_start"
237                                         }
238                                     ]
239                                 }
240                             ]
241                         },
242                         {
243                             xtype: Gtk.TreeView,
244                             pack : false,
245                             items : [
246                                 {
247                                     xtype: Gtk.ListStore,
248                                     pack : false
249                                 }
250                             ]
251                         }
252                     ]
253                 }
254             ]
255         },
256         {
257             xtype: Gtk.Button,
258             label : "Cancel",
259             pack : "add_action_widget,0"
260         },
261         {
262             xtype: Gtk.Button,
263             id : "ok_button",
264             label : "OK",
265             pack : "add_action_widget,1"
266         }
267     ]
268 });
269 Remotes.init();
270 XObject.cache['/Remotes'] = Remotes;