Menu

[38707f]: / UserControlRemotesEdit.cs  Maximize  Restore  History

Download this file

174 lines (147 with data), 6.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Windows.Forms;
namespace GitForce
{
public partial class RemotesEdit : UserControl
{
/// <summary>
/// Local cache of the repo that we are editing
/// </summary>
private ClassRepo _repo;
/// <summary>
/// Currently selected remote repo in our editing listbox
/// </summary>
private ClassRemotes.Remote _current;
public RemotesEdit()
{
InitializeComponent();
}
public void SetRepo(ClassRepo repo)
{
_repo = repo;
ListRefresh();
// Select the first item, if there is any
if (listRemotes.Items.Count > 0)
listRemotes.SelectedIndex = 0;
}
private void ListRefresh()
{
_repo.Remotes.Refresh(_repo);
// Populate the list box
userControlRemoteEdit.Clear();
listRemotes.BeginUpdate();
listRemotes.Items.Clear();
// Get the list of names from remotes class and iteratively add them to the listbox
foreach (var r in _repo.Remotes.GetListNames())
listRemotes.Items.Add(r);
listRemotes.EndUpdate();
}
private void ListRemotesSelectedIndexChanged(object sender, EventArgs e)
{
if (listRemotes.SelectedIndex >= 0)
{
string name = listRemotes.SelectedItem.ToString();
_current = _repo.Remotes.Get(name);
userControlRemoteEdit.Set(_current);
btEdit.Enabled = btRename.Enabled = btDelete.Enabled = true;
}
else
btEdit.Enabled = btRename.Enabled = btDelete.Enabled = false;
}
/// <summary>
/// Add new remote repository
/// </summary>
private void BtAddClick(object sender, EventArgs e)
{
ClassRemotes.Remote remote = new ClassRemotes.Remote();
FormRemoteAddEdit remoteAddEdit = new FormRemoteAddEdit();
remoteAddEdit.Prepare(FormRemoteAddEdit.Function.Add, remote);
if (remoteAddEdit.ShowDialog() == DialogResult.OK)
{
remote = remoteAddEdit.Get();
ExecResult result = _repo.Run("remote add " + remote.Name + " " + remote.UrlFetch);
if (result.Success())
{
_repo.Remotes.SetPassword(remote.Name, remote.Password);
_repo.Remotes.SetPushCmd(remote.Name, remote.PushCmd);
SetRepo(_repo);
}
else
{
MessageBox.Show("Git is unable to add this remote repository.", "Add remote repository", MessageBoxButtons.OK, MessageBoxIcon.Error);
App.PrintStatusMessage(result.stderr, MessageType.Error);
}
}
}
/// <summary>
/// Edit selected remote repository
/// </summary>
private void BtEditClick(object sender, EventArgs e)
{
ClassRemotes.Remote remote;
FormRemoteAddEdit remoteAddEdit = new FormRemoteAddEdit();
remoteAddEdit.Prepare(FormRemoteAddEdit.Function.Edit, _current);
if (remoteAddEdit.ShowDialog() == DialogResult.OK)
{
// Get new values and start comparing what changed
remote = remoteAddEdit.Get();
if (remote.UrlFetch != _current.UrlFetch)
{
// Change the fetch URL
_repo.Run("remote set-url " + remote.Name + " " + remote.UrlFetch);
// However, this will also change the push URL, so reset it
if (_current.UrlPush != "")
_repo.Run("remote set-url --push " + remote.Name + " " + _current.UrlPush);
}
if (remote.UrlPush != _current.UrlPush)
{
// Change the push URL
_repo.Run("remote set-url --push " + remote.Name + " " + remote.UrlPush);
}
if (remote.Password != _current.Password)
{
// Change the password
_repo.Remotes.SetPassword(remote.Name, remote.Password);
}
if (remote.PushCmd != _current.PushCmd)
{
// Change the push command
_repo.Remotes.SetPushCmd(remote.Name, remote.PushCmd);
}
SetRepo(_repo);
}
}
/// <summary>
/// Rename selected remote repository
/// </summary>
private void BtRenameClick(object sender, EventArgs e)
{
ClassRemotes.Remote remote;
FormRemoteAddEdit remoteAddEdit = new FormRemoteAddEdit();
remoteAddEdit.Prepare(FormRemoteAddEdit.Function.Rename, _current);
if (remoteAddEdit.ShowDialog() == DialogResult.OK)
{
// Get new name and change it
remote = remoteAddEdit.Get();
if (remote.Name != _current.Name)
{
_repo.Run("remote rename " + _current.Name + " " + remote.Name);
SetRepo(_repo);
}
}
}
/// <summary>
/// Delete selected remote repository
/// </summary>
private void BtDeleteClick(object sender, EventArgs e)
{
if (MessageBox.Show("This will delete reference to a remote repository '" + _current.Name + "'\nProceed?", "Delete", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
_repo.Run("remote rm " + _current.Name);
btEdit.Enabled = btRename.Enabled = btDelete.Enabled = false;
// Refresh and select the next item, if any
SetRepo(_repo);
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.