Browse Source

Fix #2458 Unexpected delete server behavior (#2459)

* Fix shadowsocks/shadowsocks-windows/#2458

* Servers List Box position adjustment is consistent with the v4.1.6 version
tags/4.1.7.1
Silence Tai Allen Zhu 6 years ago
parent
commit
b7089275f6
1 changed files with 12 additions and 12 deletions
  1. +12
    -12
      shadowsocks-csharp/View/ConfigForm.cs

+ 12
- 12
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms; using System.Windows.Forms;
using Shadowsocks.Controller; using Shadowsocks.Controller;
using Shadowsocks.Model; using Shadowsocks.Model;
@@ -89,12 +88,6 @@ namespace Shadowsocks.View
ApplyButton.Enabled = true; 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) private bool ValidateAndSaveSelectedServerDetails(bool isSave = false, bool isCopy = false)
{ {
try try
@@ -157,8 +150,11 @@ namespace Shadowsocks.View
_modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex); _modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex);
ServersListBox.SelectedIndexChanged -= ServersListBox_SelectedIndexChanged; ServersListBox.SelectedIndexChanged -= ServersListBox_SelectedIndexChanged;
int lastIndex = ServersListBox.SelectedIndex;
LoadServerNameListToUI(_modifiedConfiguration); LoadServerNameListToUI(_modifiedConfiguration);
UpdateIndexToEnd();
_lastSelectedIndex = (ServersListBox.SelectedIndex = lastIndex);
ServersListBox.SelectedIndexChanged += ServersListBox_SelectedIndexChanged; ServersListBox.SelectedIndexChanged += ServersListBox_SelectedIndexChanged;
return true; return true;
@@ -453,7 +449,7 @@ namespace Shadowsocks.View
{ {
Configuration.AddDefaultServerOrServer(_modifiedConfiguration); Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
LoadServerNameListToUI(_modifiedConfiguration); LoadServerNameListToUI(_modifiedConfiguration);
UpdateIndexToEnd();
_lastSelectedIndex = (ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1);
} }
} }
@@ -462,9 +458,9 @@ namespace Shadowsocks.View
if (ValidateAndSaveSelectedServerDetails(isCopy: true)) if (ValidateAndSaveSelectedServerDetails(isCopy: true))
{ {
Server currServer = _modifiedConfiguration.configs[_lastSelectedIndex]; Server currServer = _modifiedConfiguration.configs[_lastSelectedIndex];
Configuration.AddDefaultServerOrServer(_modifiedConfiguration, currServer);
Configuration.AddDefaultServerOrServer(_modifiedConfiguration, currServer, _lastSelectedIndex + 1);
LoadServerNameListToUI(_modifiedConfiguration); LoadServerNameListToUI(_modifiedConfiguration);
UpdateIndexToEnd();
_lastSelectedIndex = (ServersListBox.SelectedIndex = (_lastSelectedIndex + 1));
} }
} }
@@ -478,7 +474,11 @@ namespace Shadowsocks.View
} }
LoadServerNameListToUI(_modifiedConfiguration); LoadServerNameListToUI(_modifiedConfiguration);
UpdateIndexToEnd();
ServersListBox.SelectedIndexChanged -= ServersListBox_SelectedIndexChanged;
_lastSelectedIndex = (ServersListBox.SelectedIndex = (_lastSelectedIndex >= _modifiedConfiguration.configs.Count ? (_modifiedConfiguration.configs.Count - 1) : _lastSelectedIndex));
ServersListBox.SelectedIndexChanged += ServersListBox_SelectedIndexChanged;
LoadSelectedServerDetails(); LoadSelectedServerDetails();
UpdateButtons(); UpdateButtons();


Loading…
Cancel
Save