5
using System.Collections.Generic;
4
7
namespace MonoDevelop.VersionControl
6
public partial class UrlBasedRepositoryEditor : Gtk.Bin
9
public partial class UrlBasedRepositoryEditor : Gtk.Bin, IRepositoryEditor
8
11
UrlBasedRepository repo;
13
List<string> protocols = new List<string> ();
12
public UrlBasedRepositoryEditor (UrlBasedRepository repo, string[] supportedProtocols)
16
public UrlBasedRepositoryEditor (UrlBasedRepository repo)
15
protocols = supportedProtocols;
19
protocols = new List<string> (repo.SupportedProtocols);
20
altProtocolIndex = protocols.Count;
21
protocols.AddRange (repo.SupportedNonUrlProtocols);
18
24
foreach (string p in protocols)
34
Gtk.Widget IRepositoryEditor.Widget {
38
public bool Validate ()
40
if (!repo.IsUrlValid (repositoryUrlEntry.Text)) {
30
if (repo.Name == repositoryServerEntry.Text)
31
repo.Name = repo.Server;
32
repositoryServerEntry.Text = repo.Server;
33
repositoryPortSpin.Value = repo.Port;
34
repositoryPathEntry.Text = repo.Dir;
35
repositoryUserEntry.Text = repo.User;
36
repositoryPassEntry.Text = repo.Pass;
37
comboProtocol.Active = Array.IndexOf (protocols, repo.Method);
50
if (repo.Uri != null) {
51
if (repo.Name == repositoryServerEntry.Text)
52
repo.Name = repo.Uri.Host;
53
repositoryServerEntry.Text = repo.Uri.Host;
54
repositoryPortSpin.Value = repo.Uri.Port;
55
repositoryPathEntry.Text = repo.Uri.PathAndQuery;
56
repositoryUserEntry.Text = repo.Uri.UserInfo;
57
comboProtocol.Active = protocols.IndexOf (repo.Uri.Scheme);
59
// The url may have a scheme, but it may be an incomplete or incorrect url. Do the best to select
60
// the correct value in the protocol combo
61
string prot = repo.SupportedProtocols.FirstOrDefault (p => repo.Url.StartsWith (p + "://"));
63
repositoryServerEntry.Text = string.Empty;
64
repositoryPortSpin.Value = 0;
65
repositoryPathEntry.Text = string.Empty;
66
repositoryUserEntry.Text = string.Empty;
67
comboProtocol.Active = protocols.IndexOf (prot);
70
comboProtocol.Active = protocols.IndexOf (repo.Protocol);
40
74
protected virtual void OnRepositoryUrlEntryChanged(object sender, System.EventArgs e)
53
89
repositoryUrlEntry.Text = repo.Url;
54
if (repo.Name == repositoryServerEntry.Text)
55
repo.Name = repo.Server;
90
if (repo.Uri != null && repo.Name == repositoryServerEntry.Text)
91
repo.Name = repo.Uri.Host;
59
95
void UpdateControls ()
66
repositoryServerEntry.Sensitive = true;
67
repositoryUserEntry.Sensitive = true;
68
repositoryPassEntry.Sensitive = true;
69
repositoryPortSpin.Sensitive = true;
72
repositoryServerEntry.Sensitive = false;
73
repositoryUserEntry.Sensitive = false;
74
repositoryPassEntry.Sensitive = false;
75
repositoryPortSpin.Sensitive = false;
97
if (repo.Uri != null || repo.SupportedProtocols.Any (p => repositoryUrlEntry.Text.StartsWith (p + "://"))) {
98
repositoryPathEntry.Sensitive = true;
99
bool isUrl = Protocol != "file";
100
repositoryServerEntry.Sensitive = isUrl;
101
repositoryUserEntry.Sensitive = isUrl;
102
repositoryPortSpin.Sensitive = isUrl;
104
repositoryPathEntry.Sensitive = false;
105
repositoryServerEntry.Sensitive = false;
106
repositoryUserEntry.Sensitive = false;
107
repositoryPortSpin.Sensitive = false;
113
if (!repo.SupportedProtocols.Contains (Protocol)) {
114
repo.Url = string.Empty;
117
UriBuilder ub = new UriBuilder ();
118
ub.Host = repositoryServerEntry.Text;
119
ub.Scheme = Protocol;
120
ub.UserName = repositoryUserEntry.Text;
121
ub.Port = (int)repositoryPortSpin.Value;
122
ub.Path = repositoryPathEntry.Text;
123
repo.Url = ub.ToString ();
80
126
protected virtual void OnRepositoryServerEntryChanged(object sender, System.EventArgs e)
82
128
if (updating) return;
83
if (repo.Name == repo.Server)
84
repo.Name = repositoryServerEntry.Text;
85
repo.Server = repositoryServerEntry.Text;
89
133
protected virtual void OnRepositoryPathEntryChanged(object sender, System.EventArgs e)
91
135
if (updating) return;
92
repo.Dir = repositoryPathEntry.Text;
96
140
protected virtual void OnRepositoryUserEntryChanged(object sender, System.EventArgs e)
98
142
if (updating) return;
99
repo.User = repositoryUserEntry.Text;
103
protected virtual void OnRepositoryPassEntryChanged(object sender, System.EventArgs e)
105
if (updating) return;
106
repo.Pass = repositoryPassEntry.Text;
110
147
protected virtual void OnComboProtocolChanged(object sender, System.EventArgs e)
112
149
if (updating) return;
113
repo.Method = Protocol;
115
152
UpdateControls ();