~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/UrlBasedRepositoryEditor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
using System;
 
3
using MonoDevelop.Ide;
 
4
using System.Linq;
 
5
using System.Collections.Generic;
3
6
 
4
7
namespace MonoDevelop.VersionControl
5
8
{
6
 
        public partial class UrlBasedRepositoryEditor : Gtk.Bin
 
9
        public partial class UrlBasedRepositoryEditor : Gtk.Bin, IRepositoryEditor
7
10
        {
8
11
                UrlBasedRepository repo;
9
12
                bool updating;
10
 
                string[] protocols;
 
13
                List<string> protocols = new List<string> ();
 
14
                int altProtocolIndex;
11
15
                
12
 
                public UrlBasedRepositoryEditor (UrlBasedRepository repo, string[] supportedProtocols)
 
16
                public UrlBasedRepositoryEditor (UrlBasedRepository repo)
13
17
                {
14
18
                        Build ();
15
 
                        protocols = supportedProtocols;
 
19
                        protocols = new List<string> (repo.SupportedProtocols);
 
20
                        altProtocolIndex = protocols.Count;
 
21
                        protocols.AddRange (repo.SupportedNonUrlProtocols);
16
22
                                
17
23
                        this.repo = repo;
18
24
                        foreach (string p in protocols)
25
31
                        updating = false;
26
32
                }
27
33
                
 
34
                Gtk.Widget IRepositoryEditor.Widget {
 
35
                        get { return this; }
 
36
                }
 
37
                
 
38
                public bool Validate ()
 
39
                {
 
40
                        if (!repo.IsUrlValid (repositoryUrlEntry.Text)) {
 
41
                                labelError.Show ();
 
42
                                return false;
 
43
                        } else {
 
44
                                return true;
 
45
                        }
 
46
                }
 
47
                
28
48
                void Fill ()
29
49
                {
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);
 
58
                        } else {
 
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 + "://"));
 
62
                                if (prot != null) {
 
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);
 
68
                                }
 
69
                                else
 
70
                                        comboProtocol.Active = protocols.IndexOf (repo.Protocol);
 
71
                        }
38
72
                }
39
73
 
40
74
                protected virtual void OnRepositoryUrlEntryChanged(object sender, System.EventArgs e)
43
77
                                updating = true;
44
78
                                repo.Url = repositoryUrlEntry.Text;
45
79
                                Fill ();
 
80
                                UpdateControls ();
 
81
                                labelError.Hide ();
46
82
                                updating = false;
47
83
                        }
48
84
                }
51
87
                {
52
88
                        updating = true;
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;
56
92
                        updating = false;
57
93
                }
58
94
                
59
95
                void UpdateControls ()
60
96
                {
61
 
                        switch (Protocol) {
62
 
                                case "svn":
63
 
                                case "svn+ssh":
64
 
                                case "http":
65
 
                                case "https":
66
 
                                        repositoryServerEntry.Sensitive = true;
67
 
                                        repositoryUserEntry.Sensitive = true;
68
 
                                        repositoryPassEntry.Sensitive = true;
69
 
                                        repositoryPortSpin.Sensitive = true;
70
 
                                        break;
71
 
                                case "file":
72
 
                                        repositoryServerEntry.Sensitive = false;
73
 
                                        repositoryUserEntry.Sensitive = false;
74
 
                                        repositoryPassEntry.Sensitive = false;
75
 
                                        repositoryPortSpin.Sensitive = false;
76
 
                                        break;
77
 
                        }
 
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;
 
103
                        } else {
 
104
                                repositoryPathEntry.Sensitive = false;
 
105
                                repositoryServerEntry.Sensitive = false;
 
106
                                repositoryUserEntry.Sensitive = false;
 
107
                                repositoryPortSpin.Sensitive = false;
 
108
                        }
 
109
                }
 
110
                
 
111
                void SetRepoUrl ()
 
112
                {
 
113
                        if (!repo.SupportedProtocols.Contains (Protocol)) {
 
114
                                repo.Url = string.Empty;
 
115
                                return;
 
116
                        }
 
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 ();
78
124
                }
79
125
 
80
126
                protected virtual void OnRepositoryServerEntryChanged(object sender, System.EventArgs e)
81
127
                {
82
128
                        if (updating) return;
83
 
                        if (repo.Name == repo.Server)
84
 
                                repo.Name = repositoryServerEntry.Text;
85
 
                        repo.Server = repositoryServerEntry.Text;
 
129
                        SetRepoUrl ();
86
130
                        UpdateUrl ();
87
131
                }
88
132
 
89
133
                protected virtual void OnRepositoryPathEntryChanged(object sender, System.EventArgs e)
90
134
                {
91
135
                        if (updating) return;
92
 
                        repo.Dir = repositoryPathEntry.Text;
 
136
                        SetRepoUrl ();
93
137
                        UpdateUrl ();
94
138
                }
95
139
 
96
140
                protected virtual void OnRepositoryUserEntryChanged(object sender, System.EventArgs e)
97
141
                {
98
142
                        if (updating) return;
99
 
                        repo.User = repositoryUserEntry.Text;
100
 
                        UpdateUrl ();
101
 
                }
102
 
 
103
 
                protected virtual void OnRepositoryPassEntryChanged(object sender, System.EventArgs e)
104
 
                {
105
 
                        if (updating) return;
106
 
                        repo.Pass = repositoryPassEntry.Text;
 
143
                        SetRepoUrl ();
107
144
                        UpdateUrl ();
108
145
                }
109
146
 
110
147
                protected virtual void OnComboProtocolChanged(object sender, System.EventArgs e)
111
148
                {
112
149
                        if (updating) return;
113
 
                        repo.Method = Protocol;
 
150
                        SetRepoUrl ();
114
151
                        UpdateUrl ();
115
152
                        UpdateControls ();
116
153
                }
118
155
                protected virtual void OnRepositoryPortSpinValueChanged (object sender, System.EventArgs e)
119
156
                {
120
157
                        if (updating) return;
121
 
                        repo.Port = (int) repositoryPortSpin.Value;
 
158
                        SetRepoUrl ();
122
159
                        UpdateUrl ();
123
160
                }
124
161
                
125
162
                string Protocol {
126
163
                        get {
127
 
                                return protocols [comboProtocol.Active];
 
164
                                return comboProtocol.Active != -1 ? protocols [comboProtocol.Active] : null;
128
165
                        }
129
166
                }
130
167
        }