2
// GitConfigurationDialog.cs
5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
29
using MonoDevelop.Core;
30
using MonoDevelop.Ide;
31
using MonoDevelop.Components;
33
namespace MonoDevelop.VersionControl.Git
35
public partial class GitConfigurationDialog : Gtk.Dialog
38
ListStore storeBranches;
39
TreeStore storeRemotes;
41
public GitConfigurationDialog (GitRepository repo)
45
this.HasSeparator = false;
49
storeBranches = new ListStore (typeof(Branch), typeof(string), typeof(string), typeof(string));
50
listBranches.Model = storeBranches;
51
listBranches.HeadersVisible = true;
53
listBranches.AppendColumn (GettextCatalog.GetString ("Branch"), new CellRendererText (), "markup", 1);
54
listBranches.AppendColumn (GettextCatalog.GetString ("Tracking"), new CellRendererText (), "text", 2);
58
storeRemotes = new TreeStore (typeof(RemoteSource), typeof(string), typeof(string), typeof(string), typeof(string));
59
treeRemotes.Model = storeRemotes;
60
treeRemotes.HeadersVisible = true;
62
treeRemotes.AppendColumn ("Remote Source / Branch", new CellRendererText (), "markup", 1);
63
treeRemotes.AppendColumn ("Url", new CellRendererText (), "text", 2);
73
TreeViewState state = new TreeViewState (listBranches, 3);
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);
86
TreeViewState state = new TreeViewState (treeRemotes, 4);
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;
93
if (remote.FetchUrl == remote.PushUrl)
94
url = remote.FetchUrl;
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);
104
protected virtual void OnButtonAddBranchClicked (object sender, System.EventArgs e)
106
var dlg = new EditBranchDialog (repo, null, true);
108
if (MessageService.RunCustomDialog (dlg) == (int) ResponseType.Ok) {
109
repo.CreateBranch (dlg.BranchName, dlg.TrackSource);
117
protected virtual void OnButtonEditBranchClicked (object sender, System.EventArgs e)
120
if (!listBranches.Selection.GetSelected (out it))
122
Branch b = (Branch) storeBranches.GetValue (it, 0);
123
var dlg = new EditBranchDialog (repo, b, false);
125
if (MessageService.RunCustomDialog (dlg) == (int) ResponseType.Ok) {
126
if (dlg.BranchName != b.Name) {
128
repo.RenameBranch (b.Name, dlg.BranchName);
129
} catch (Exception ex) {
130
MessageService.ShowException (ex, GettextCatalog.GetString ("The branch could not be renamed"));
133
repo.SetBranchTrackSource (dlg.BranchName, dlg.TrackSource);
141
protected virtual void OnButtonRemoveBranchClicked (object sender, System.EventArgs e)
144
if (!listBranches.Selection.GetSelected (out it))
146
Branch b = (Branch) storeBranches.GetValue (it, 0);
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)) {
152
repo.RemoveBranch (b.Name);
154
} catch (Exception ex) {
155
MessageService.ShowException (ex, GettextCatalog.GetString ("The branch could not be deleted"));
160
protected virtual void OnButtonSetDefaultBranchClicked (object sender, System.EventArgs e)
163
if (!listBranches.Selection.GetSelected (out it))
165
Branch b = (Branch) storeBranches.GetValue (it, 0);
166
GitService.SwitchToBranch (repo, b.Name);
170
protected virtual void OnButtonAddRemoteClicked (object sender, System.EventArgs e)
172
var remote = new RemoteSource ();
173
var dlg = new EditRemoteDialog (remote, true);
175
if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
176
repo.AddRemote (remote, dlg.ImportTags);
184
protected virtual void OnButtonEditRemoteClicked (object sender, System.EventArgs e)
187
if (!treeRemotes.Selection.GetSelected (out it))
190
RemoteSource remote = (RemoteSource) storeRemotes.GetValue (it, 0);
191
string oldName = remote.Name;
193
var dlg = new EditRemoteDialog (remote, false);
195
if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
196
if (remote.Name != oldName)
197
repo.RenameRemote (oldName, remote.Name);
198
repo.UpdateRemote (remote);
206
protected virtual void OnButtonRemoveRemoteClicked (object sender, System.EventArgs e)
209
if (!treeRemotes.Selection.GetSelected (out it))
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);
218
void UpdateRemoteButtons ()
221
if (!treeRemotes.Selection.GetSelected (out it)) {
222
buttonAddRemote.Sensitive = buttonEditRemote.Sensitive = buttonRemoveRemote.Sensitive = buttonTrackRemote.Sensitive = false;
225
RemoteSource remote = (RemoteSource) storeRemotes.GetValue (it, 0);
226
buttonTrackRemote.Sensitive = remote == null;
227
buttonAddRemote.Sensitive = buttonEditRemote.Sensitive = buttonRemoveRemote.Sensitive = remote != null;
230
protected virtual void OnButtonTrackRemoteClicked (object sender, System.EventArgs e)
233
if (!treeRemotes.Selection.GetSelected (out it))
235
string branchName = (string) storeRemotes.GetValue (it, 3);
236
if (branchName == null)
239
storeRemotes.IterParent (out it, it);
240
RemoteSource remote = (RemoteSource) storeRemotes.GetValue (it, 0);
242
Branch b = new Branch ();
244
b.Tracking = remote.Name + "/" + branchName;
246
var dlg = new EditBranchDialog (repo, b, true);
248
if (MessageService.RunCustomDialog (dlg) == (int) ResponseType.Ok) {
249
repo.CreateBranch (dlg.BranchName, dlg.TrackSource);