|
|
@@ -18,7 +18,7 @@ namespace Shadowsocks.View |
|
|
|
|
|
|
|
// this is a copy of configuration that we are working on
|
|
|
|
private Configuration _modifiedConfiguration;
|
|
|
|
private int _oldSelectedIndex = -1;
|
|
|
|
private int _lastSelectedIndex = -1;
|
|
|
|
|
|
|
|
public ConfigForm(ShadowsocksController controller)
|
|
|
|
{
|
|
|
@@ -72,7 +72,7 @@ namespace Shadowsocks.View |
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (_oldSelectedIndex == -1 || _oldSelectedIndex >= _modifiedConfiguration.configs.Count)
|
|
|
|
if (_lastSelectedIndex == -1 || _lastSelectedIndex >= _modifiedConfiguration.configs.Count)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
@@ -87,7 +87,7 @@ namespace Shadowsocks.View |
|
|
|
int localPort = int.Parse(ProxyPortTextBox.Text);
|
|
|
|
Configuration.CheckServer(server);
|
|
|
|
Configuration.CheckLocalPort(localPort);
|
|
|
|
_modifiedConfiguration.configs[_oldSelectedIndex] = server;
|
|
|
|
_modifiedConfiguration.configs[_lastSelectedIndex] = server;
|
|
|
|
_modifiedConfiguration.localPort = localPort;
|
|
|
|
|
|
|
|
return true;
|
|
|
@@ -131,12 +131,12 @@ namespace Shadowsocks.View |
|
|
|
{
|
|
|
|
_modifiedConfiguration = controller.GetConfigurationCopy();
|
|
|
|
LoadConfiguration(_modifiedConfiguration);
|
|
|
|
_oldSelectedIndex = _modifiedConfiguration.index;
|
|
|
|
if (_oldSelectedIndex < 0)
|
|
|
|
_lastSelectedIndex = _modifiedConfiguration.index;
|
|
|
|
if (_lastSelectedIndex < 0)
|
|
|
|
{
|
|
|
|
_oldSelectedIndex = 0;
|
|
|
|
_lastSelectedIndex = 0;
|
|
|
|
}
|
|
|
|
ServersListBox.SelectedIndex = _oldSelectedIndex;
|
|
|
|
ServersListBox.SelectedIndex = _lastSelectedIndex;
|
|
|
|
UpdateMoveUpAndDownButton();
|
|
|
|
LoadSelectedServer();
|
|
|
|
}
|
|
|
@@ -148,7 +148,7 @@ namespace Shadowsocks.View |
|
|
|
|
|
|
|
private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (_oldSelectedIndex == ServersListBox.SelectedIndex)
|
|
|
|
if (_lastSelectedIndex == ServersListBox.SelectedIndex)
|
|
|
|
{
|
|
|
|
// we are moving back to oldSelectedIndex or doing a force move
|
|
|
|
return;
|
|
|
@@ -156,12 +156,12 @@ namespace Shadowsocks.View |
|
|
|
if (!SaveOldSelectedServer())
|
|
|
|
{
|
|
|
|
// why this won't cause stack overflow?
|
|
|
|
ServersListBox.SelectedIndex = _oldSelectedIndex;
|
|
|
|
ServersListBox.SelectedIndex = _lastSelectedIndex;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UpdateMoveUpAndDownButton();
|
|
|
|
LoadSelectedServer();
|
|
|
|
_oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
_lastSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AddButton_Click(object sender, EventArgs e)
|
|
|
@@ -174,24 +174,24 @@ namespace Shadowsocks.View |
|
|
|
_modifiedConfiguration.configs.Add(server);
|
|
|
|
LoadConfiguration(_modifiedConfiguration);
|
|
|
|
ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1;
|
|
|
|
_oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
_lastSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DeleteButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
_oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
if (_oldSelectedIndex >= 0 && _oldSelectedIndex < _modifiedConfiguration.configs.Count)
|
|
|
|
_lastSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
if (_lastSelectedIndex >= 0 && _lastSelectedIndex < _modifiedConfiguration.configs.Count)
|
|
|
|
{
|
|
|
|
_modifiedConfiguration.configs.RemoveAt(_oldSelectedIndex);
|
|
|
|
_modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex);
|
|
|
|
}
|
|
|
|
if (_oldSelectedIndex >= _modifiedConfiguration.configs.Count)
|
|
|
|
if (_lastSelectedIndex >= _modifiedConfiguration.configs.Count)
|
|
|
|
{
|
|
|
|
// can be -1
|
|
|
|
_oldSelectedIndex = _modifiedConfiguration.configs.Count - 1;
|
|
|
|
_lastSelectedIndex = _modifiedConfiguration.configs.Count - 1;
|
|
|
|
}
|
|
|
|
ServersListBox.SelectedIndex = _oldSelectedIndex;
|
|
|
|
ServersListBox.SelectedIndex = _lastSelectedIndex;
|
|
|
|
LoadConfiguration(_modifiedConfiguration);
|
|
|
|
ServersListBox.SelectedIndex = _oldSelectedIndex;
|
|
|
|
ServersListBox.SelectedIndex = _lastSelectedIndex;
|
|
|
|
LoadSelectedServer();
|
|
|
|
}
|
|
|
|
|
|
|
@@ -238,7 +238,7 @@ namespace Shadowsocks.View |
|
|
|
_modifiedConfiguration.index += step;
|
|
|
|
|
|
|
|
ServersListBox.BeginUpdate();
|
|
|
|
_oldSelectedIndex = index + step;
|
|
|
|
_lastSelectedIndex = index + step;
|
|
|
|
ServersListBox.Items.Remove(item);
|
|
|
|
ServersListBox.Items.Insert(index + step, item);
|
|
|
|
ServersListBox.SelectedIndex = index + step;
|
|
|
@@ -282,6 +282,5 @@ namespace Shadowsocks.View |
|
|
|
MoveConfigItem(+1); // +1 means move forward
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|