Skip to content

Commit

Permalink
Fix shadowsocks#2458 Unexpected delete server behavior (shadowsocks#2459
Browse files Browse the repository at this point in the history
)

* Fix shadowsocks/shadowsocks-windows/shadowsocks#2458

* Servers List Box position adjustment is consistent with the v4.1.6 version
  • Loading branch information
Stzx authored and celeron533 committed Jul 14, 2019
1 parent 72678c4 commit b708927
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions shadowsocks-csharp/View/ConfigForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using Shadowsocks.Controller;
using Shadowsocks.Model;
Expand Down Expand Up @@ -89,12 +88,6 @@ private void ConfigValueChanged(object sender, EventArgs e)
ApplyButton.Enabled = true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void UpdateIndexToEnd()
{
_lastSelectedIndex = (ServersListBox.SelectedIndex = (_modifiedConfiguration.configs.Count - 1));
}

private bool ValidateAndSaveSelectedServerDetails(bool isSave = false, bool isCopy = false)
{
try
Expand Down Expand Up @@ -157,8 +150,11 @@ private bool GetServerDetailsFromUI(out Server server, bool isSave = false, bool
_modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex);
ServersListBox.SelectedIndexChanged -= ServersListBox_SelectedIndexChanged;

int lastIndex = ServersListBox.SelectedIndex;

LoadServerNameListToUI(_modifiedConfiguration);
UpdateIndexToEnd();

_lastSelectedIndex = (ServersListBox.SelectedIndex = lastIndex);

ServersListBox.SelectedIndexChanged += ServersListBox_SelectedIndexChanged;
return true;
Expand Down Expand Up @@ -453,7 +449,7 @@ private void AddButton_Click(object sender, EventArgs e)
{
Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
LoadServerNameListToUI(_modifiedConfiguration);
UpdateIndexToEnd();
_lastSelectedIndex = (ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1);
}
}

Expand All @@ -462,9 +458,9 @@ private void DuplicateButton_Click(object sender, EventArgs e)
if (ValidateAndSaveSelectedServerDetails(isCopy: true))
{
Server currServer = _modifiedConfiguration.configs[_lastSelectedIndex];
Configuration.AddDefaultServerOrServer(_modifiedConfiguration, currServer);
Configuration.AddDefaultServerOrServer(_modifiedConfiguration, currServer, _lastSelectedIndex + 1);
LoadServerNameListToUI(_modifiedConfiguration);
UpdateIndexToEnd();
_lastSelectedIndex = (ServersListBox.SelectedIndex = (_lastSelectedIndex + 1));
}
}

Expand All @@ -478,7 +474,11 @@ private void DeleteButton_Click(object sender, EventArgs e)
}

LoadServerNameListToUI(_modifiedConfiguration);
UpdateIndexToEnd();
ServersListBox.SelectedIndexChanged -= ServersListBox_SelectedIndexChanged;

_lastSelectedIndex = (ServersListBox.SelectedIndex = (_lastSelectedIndex >= _modifiedConfiguration.configs.Count ? (_modifiedConfiguration.configs.Count - 1) : _lastSelectedIndex));

ServersListBox.SelectedIndexChanged += ServersListBox_SelectedIndexChanged;
LoadSelectedServerDetails();

UpdateButtons();
Expand Down

0 comments on commit b708927

Please sign in to comment.