From 514bb02098933c8a08095564c7c6fc545a8a5fe2 Mon Sep 17 00:00:00 2001 From: Syrone Wong Date: Sun, 4 Sep 2016 07:57:35 +0800 Subject: [PATCH] Fix config selection User wants to use that server after selected it in the ConfigForm. If user deletes the server in use, we can't find its index, then the previous logic will revert to index 0, which is not expected behaviour. Since we handled 'ServersListBox.SelectedIndex' in various event handlers, we can trust it all the time. Signed-off-by: Syrone Wong --- shadowsocks-csharp/View/ConfigForm.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index 6bf861aa..f2a190da 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -230,7 +230,6 @@ namespace Shadowsocks.View private void OKButton_Click(object sender, EventArgs e) { - Server server = controller.GetCurrentServer(); if (!SaveOldSelectedServer()) { return; @@ -241,7 +240,10 @@ namespace Shadowsocks.View return; } controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort); - controller.SelectServerIndex(_modifiedConfiguration.configs.IndexOf(server)); + // SelectedIndex remains valid + // We handled this in event handlers, e.g. Add/DeleteButton, SelectedIndexChanged + // and move operations + controller.SelectServerIndex(ServersListBox.SelectedIndex); this.Close(); }