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

« back to all changes in this revision

Viewing changes to src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitConfigurationDialog.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
// 
 
2
// GitConfigurationDialog.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using Gtk;
 
29
using MonoDevelop.Core;
 
30
using MonoDevelop.Ide;
 
31
using MonoDevelop.Components;
 
32
 
 
33
namespace MonoDevelop.VersionControl.Git
 
34
{
 
35
        public partial class GitConfigurationDialog : Gtk.Dialog
 
36
        {
 
37
                GitRepository repo;
 
38
                ListStore storeBranches;
 
39
                TreeStore storeRemotes;
 
40
                
 
41
                public GitConfigurationDialog (GitRepository repo)
 
42
                {
 
43
                        this.Build ();
 
44
                        this.repo = repo;
 
45
                        this.HasSeparator = false;
 
46
                        
 
47
                        // Branches list
 
48
                        
 
49
                        storeBranches = new ListStore (typeof(Branch), typeof(string), typeof(string), typeof(string));
 
50
                        listBranches.Model = storeBranches;
 
51
                        listBranches.HeadersVisible = true;
 
52
                        
 
53
                        listBranches.AppendColumn (GettextCatalog.GetString ("Branch"), new CellRendererText (), "markup", 1);
 
54
                        listBranches.AppendColumn (GettextCatalog.GetString ("Tracking"), new CellRendererText (), "text", 2);
 
55
                        
 
56
                        // Sources tree
 
57
                        
 
58
                        storeRemotes = new TreeStore (typeof(RemoteSource), typeof(string), typeof(string), typeof(string), typeof(string));
 
59
                        treeRemotes.Model = storeRemotes;
 
60
                        treeRemotes.HeadersVisible = true;
 
61
                        
 
62
                        treeRemotes.AppendColumn ("Remote Source / Branch", new CellRendererText (), "markup", 1);
 
63
                        treeRemotes.AppendColumn ("Url", new CellRendererText (), "text", 2);
 
64
                        
 
65
                        // Fill data
 
66
                        
 
67
                        FillBranches ();
 
68
                        FillRemotes ();
 
69
                }
 
70
                
 
71
                void FillBranches ()
 
72
                {
 
73
                        TreeViewState state = new TreeViewState (listBranches, 3);
 
74
                        state.Save ();
 
75
                        storeBranches.Clear ();
 
76
                        string currentBranch = repo.GetCurrentBranch ();
 
77
                        foreach (Branch branch in repo.GetBranches ()) {
 
78
                                string text = branch.Name == currentBranch ? "<b>" + branch.Name + "</b>" : branch.Name;
 
79
                                storeBranches.AppendValues (branch, text, branch.Tracking, branch.Name);
 
80
                        }
 
81
                        state.Load ();
 
82
                }
 
83
                
 
84
                void FillRemotes ()
 
85
                {
 
86
                        TreeViewState state = new TreeViewState (treeRemotes, 4);
 
87
                        state.Save ();
 
88
                        storeRemotes.Clear ();
 
89
                        string currentRemote = repo.GetCurrentRemote ();
 
90
                        foreach (RemoteSource remote in repo.GetRemotes ()) {
 
91
                                string text = remote.Name == currentRemote ? "<b>" + remote.Name + "</b>" : remote.Name;
 
92
                                string url;
 
93
                                if (remote.FetchUrl == remote.PushUrl)
 
94
                                        url = remote.FetchUrl;
 
95
                                else
 
96
                                        url = remote.FetchUrl + " (fetch)\n" + remote.PushUrl + " (push)";
 
97
                                TreeIter it = storeRemotes.AppendValues (remote, text, url, null, remote.Name);
 
98
                                foreach (string branch in repo.GetRemoteBranches (remote.Name))
 
99
                                        storeRemotes.AppendValues (it, null, branch, null, branch, remote.Name + "/" + branch);
 
100
                        }
 
101
                        state.Load ();
 
102
                }
 
103
                
 
104
                protected virtual void OnButtonAddBranchClicked (object sender, System.EventArgs e)
 
105
                {
 
106
                        var dlg = new EditBranchDialog (repo, null, true);
 
107
                        try {
 
108
                                if (MessageService.RunCustomDialog (dlg) == (int) ResponseType.Ok) {
 
109
                                        repo.CreateBranch (dlg.BranchName, dlg.TrackSource);
 
110
                                        FillBranches ();
 
111
                                }
 
112
                        } finally {
 
113
                                dlg.Destroy ();
 
114
                        }
 
115
                }
 
116
                
 
117
                protected virtual void OnButtonEditBranchClicked (object sender, System.EventArgs e)
 
118
                {
 
119
                        TreeIter it;
 
120
                        if (!listBranches.Selection.GetSelected (out it))
 
121
                                return;
 
122
                        Branch b = (Branch) storeBranches.GetValue (it, 0);
 
123
                        var dlg = new EditBranchDialog (repo, b, false);
 
124
                        try {
 
125
                                if (MessageService.RunCustomDialog (dlg) == (int) ResponseType.Ok) {
 
126
                                        if (dlg.BranchName != b.Name) {
 
127
                                                try {
 
128
                                                        repo.RenameBranch (b.Name, dlg.BranchName);
 
129
                                                } catch (Exception ex) {
 
130
                                                        MessageService.ShowException (ex, GettextCatalog.GetString ("The branch could not be renamed"));
 
131
                                                }
 
132
                                        }
 
133
                                        repo.SetBranchTrackSource (dlg.BranchName, dlg.TrackSource);
 
134
                                        FillBranches ();
 
135
                                }
 
136
                        } finally {
 
137
                                dlg.Destroy ();
 
138
                        }
 
139
                }
 
140
                
 
141
                protected virtual void OnButtonRemoveBranchClicked (object sender, System.EventArgs e)
 
142
                {
 
143
                        TreeIter it;
 
144
                        if (!listBranches.Selection.GetSelected (out it))
 
145
                                return;
 
146
                        Branch b = (Branch) storeBranches.GetValue (it, 0);
 
147
                        string txt = null;
 
148
                        if (!repo.IsBranchMerged (b.Name))
 
149
                                txt = GettextCatalog.GetString ("WARNING: The branch has not yet been merged to HEAD");
 
150
                        if (MessageService.Confirm (GettextCatalog.GetString ("Are you sure you want to delete the branch '{0}'?", b.Name), txt, AlertButton.Delete)) {
 
151
                                try {
 
152
                                        repo.RemoveBranch (b.Name);
 
153
                                        FillBranches ();
 
154
                                } catch (Exception ex) {
 
155
                                        MessageService.ShowException (ex, GettextCatalog.GetString ("The branch could not be deleted"));
 
156
                                }
 
157
                        }
 
158
                }
 
159
                
 
160
                protected virtual void OnButtonSetDefaultBranchClicked (object sender, System.EventArgs e)
 
161
                {
 
162
                        TreeIter it;
 
163
                        if (!listBranches.Selection.GetSelected (out it))
 
164
                                return;
 
165
                        Branch b = (Branch) storeBranches.GetValue (it, 0);
 
166
                        GitService.SwitchToBranch (repo, b.Name);
 
167
                        FillBranches ();
 
168
                }
 
169
                
 
170
                protected virtual void OnButtonAddRemoteClicked (object sender, System.EventArgs e)
 
171
                {
 
172
                        var remote = new RemoteSource ();
 
173
                        var dlg = new EditRemoteDialog (remote, true);
 
174
                        try {
 
175
                                if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
 
176
                                        repo.AddRemote (remote, dlg.ImportTags);
 
177
                                        FillRemotes ();
 
178
                                }
 
179
                        } finally {
 
180
                                dlg.Destroy ();
 
181
                        }
 
182
                }
 
183
                
 
184
                protected virtual void OnButtonEditRemoteClicked (object sender, System.EventArgs e)
 
185
                {
 
186
                        TreeIter it;
 
187
                        if (!treeRemotes.Selection.GetSelected (out it))
 
188
                                return;
 
189
                        
 
190
                        RemoteSource remote = (RemoteSource) storeRemotes.GetValue (it, 0);
 
191
                        string oldName = remote.Name;
 
192
                        
 
193
                        var dlg = new EditRemoteDialog (remote, false);
 
194
                        try {
 
195
                                if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
 
196
                                        if (remote.Name != oldName)
 
197
                                                repo.RenameRemote (oldName, remote.Name);
 
198
                                        repo.UpdateRemote (remote);
 
199
                                        FillRemotes ();
 
200
                                }
 
201
                        } finally {
 
202
                                dlg.Destroy ();
 
203
                        }
 
204
                }
 
205
                
 
206
                protected virtual void OnButtonRemoveRemoteClicked (object sender, System.EventArgs e)
 
207
                {
 
208
                        TreeIter it;
 
209
                        if (!treeRemotes.Selection.GetSelected (out it))
 
210
                                return;
 
211
                        RemoteSource remote = (RemoteSource) storeRemotes.GetValue (it, 0);
 
212
                        if (MessageService.Confirm (GettextCatalog.GetString ("Are you sure you want to delete the remote '{0}'?", remote.Name), AlertButton.Delete)) {
 
213
                                repo.RemoveRemote (remote.Name);
 
214
                                FillRemotes ();
 
215
                        }
 
216
                }
 
217
                
 
218
                void UpdateRemoteButtons ()
 
219
                {
 
220
                        TreeIter it;
 
221
                        if (!treeRemotes.Selection.GetSelected (out it)) {
 
222
                                buttonAddRemote.Sensitive = buttonEditRemote.Sensitive = buttonRemoveRemote.Sensitive = buttonTrackRemote.Sensitive = false;
 
223
                                return;
 
224
                        }
 
225
                        RemoteSource remote = (RemoteSource) storeRemotes.GetValue (it, 0);
 
226
                        buttonTrackRemote.Sensitive = remote == null;
 
227
                        buttonAddRemote.Sensitive = buttonEditRemote.Sensitive = buttonRemoveRemote.Sensitive = remote != null;
 
228
                }
 
229
                
 
230
                protected virtual void OnButtonTrackRemoteClicked (object sender, System.EventArgs e)
 
231
                {
 
232
                        TreeIter it;
 
233
                        if (!treeRemotes.Selection.GetSelected (out it))
 
234
                                return;
 
235
                        string branchName = (string) storeRemotes.GetValue (it, 3);
 
236
                        if (branchName == null)
 
237
                                return;
 
238
                        
 
239
                        storeRemotes.IterParent (out it, it);
 
240
                        RemoteSource remote = (RemoteSource) storeRemotes.GetValue (it, 0);
 
241
                        
 
242
                        Branch b = new Branch ();
 
243
                        b.Name = branchName;
 
244
                        b.Tracking = remote.Name + "/" + branchName;
 
245
                        
 
246
                        var dlg = new EditBranchDialog (repo, b, true);
 
247
                        try {
 
248
                                if (MessageService.RunCustomDialog (dlg) == (int) ResponseType.Ok) {
 
249
                                        repo.CreateBranch (dlg.BranchName, dlg.TrackSource);
 
250
                                        FillBranches ();
 
251
                                }
 
252
                        } finally {
 
253
                                dlg.Destroy ();
 
254
                        }
 
255
                }
 
256
        }
 
257
}
 
258