Fix #5560 - Gitlive - branching wip
[gitlive] / old_seed_version / RemoteEdit.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 RemoteEdit=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 : 150,
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.get('/remoteURL').el.get_child().set_text('');
51         this.get('/remoteName').el.set_text('');
52         
53         
54         this.el.show_all();
55         
56         var run_ret = this.el.run();
57         if (run_ret < 1 ) {
58             return false;
59         }
60         var ret=  {
61             url :  this.get('/remoteURL').el.get_child().get_text(),
62             name :  this.get('/remoteName').el.get_text()
63         };
64         
65         return ret;
66         
67         
68         
69     },
70     items : [
71         {
72             xtype: Gtk.VBox,
73             pack : function(p,e) {
74                     p.el.get_content_area().pack_start(e.el,true,true,10);
75                 },
76             items : [
77                 {
78                     xtype: Gtk.HBox,
79                     pack : "pack_start,false,true,10",
80                     items : [
81                         {
82                             xtype: Gtk.Label,
83                             label : "URL :",
84                             pack : "pack_start,false,false,10",
85                             width_request : 50
86                         },
87                         {
88                             xtype: Gtk.ComboBox,
89                             listeners : {
90                                 changed : function (self) {
91                                    var val = this.el.get_child().get_text();
92                                    print(JSON.stringify(val));
93                                    if (!val.length) {
94                                        return;
95                                    }
96                                    
97                                    var name = this.get('/remoteName').el.get_text();
98                                    if (name.length) {
99                                        return;
100                                    }
101                                    // fill in name
102                                    var val = imports.Scm.Git.Repo.Repo.parseURL(val);
103                                    if ((typeof(val.host) != 'undefined') && val.host.length) {
104                                        var host = val.host;
105                                        // need to add github owner...
106                                         if (host.match(/github.com$/)) {
107                                           host += '.' + val.path.split('/').shift();
108                                         }
109                                    
110                                    
111                                         this.get('/remoteName').el.set_text(host);
112                                    }
113                                     
114                                    
115                                 }
116                             },
117                             id : "remoteURL",
118                             init : function() {
119                                 this.el = new Gtk.ComboBox.with_entry();
120                                 
121                                 
122                                 this.model  = new XObject(this.model);
123                                 this.model.init();
124                                 this.el.set_model(this.model.el);
125                                 this.el.set_entry_text_column (0);
126                                  XObject.prototype.init.call(this);
127                                 
128                             },
129                             load : function(tr)
130                             {
131                                 //this.insert(citer,iter,0);
132                                 this.model.el.clear();
133                                 
134                                 var master = false;
135                                 var working = false;
136                                 
137                                 for(var i =0 ; i < tr.length; i++) {
138                                     var ret = {  };
139                                     this.model.el.append(ret);
140                                     //print(JSON.stringify(ret,null,4));
141                                     if (tr[i].name == 'master') {
142                                         master = i;
143                                     }
144                                     if (tr[i].name == 'working') {
145                                         working = i;
146                                     }          
147                                     this.model.el.set_value(ret.iter, 0, '' + tr[i].name );
148                                     this.model.el.set_value(ret.iter, 1, '' + tr[i].rev  );
149                              
150                                     
151                                 }     
152                                 if (master !== false) {
153                                     this.el.set_active(master);
154                                 }
155                                 if (working !== false) {
156                                     this.el.set_active(working);
157                                 }
158                                 
159                             },
160                             model : {
161                                 xtype: Gtk.ListStore,
162                                 init : function() {
163                                     XObject.prototype.init.call(this);
164                                     this.el.set_column_types ( 3, [
165                                            GObject.TYPE_STRING, // file  
166                                           GObject.TYPE_STRING, // added
167                                           GObject.TYPE_STRING, // removed
168                                       ] );
169                                 }
170                             }
171                         }
172                     ]
173                 },
174                 {
175                     xtype: Gtk.HBox,
176                     pack : "pack_start,false,true,10",
177                     items : [
178                         {
179                             xtype: Gtk.Label,
180                             label : "Name : ",
181                             pack : "pack_start,false,false,10",
182                             width_request : 50,
183                             xalign : 1
184                         },
185                         {
186                             xtype: Gtk.Entry,
187                             id : "remoteName"
188                         }
189                     ]
190                 }
191             ]
192         },
193         {
194             xtype: Gtk.Button,
195             label : "Cancel",
196             pack : "add_action_widget,0"
197         },
198         {
199             xtype: Gtk.Button,
200             id : "ok_button",
201             label : "Add",
202             pack : "add_action_widget,1"
203         }
204     ]
205 });
206 RemoteEdit.init();
207 XObject.cache['/RemoteEdit'] = RemoteEdit;