Browse Source

Minor updates on Hotkeys form

tags/4.1.0
celeron533 7 years ago
parent
commit
66cdd13144
2 changed files with 30 additions and 22 deletions
  1. +5
    -0
      shadowsocks-csharp/Controller/System/Hotkeys/Hotkeys.cs
  2. +25
    -22
      shadowsocks-csharp/View/HotkeySettingsForm.cs

+ 5
- 0
shadowsocks-csharp/Controller/System/Hotkeys/Hotkeys.cs View File

@@ -59,6 +59,9 @@ namespace Shadowsocks.Controller.Hotkeys
return false; return false;
} }
} }

#region Converters

public static string HotKey2Str( HotKey key ) public static string HotKey2Str( HotKey key )
{ {
if (key == null) throw new ArgumentNullException(nameof(key)); if (key == null) throw new ArgumentNullException(nameof(key));
@@ -112,6 +115,8 @@ namespace Shadowsocks.Controller.Hotkeys
} }
} }


#endregion

public static bool Register(HotKey key, HotKeyCallBackHandler callBack) public static bool Register(HotKey key, HotKeyCallBackHandler callBack)
{ {
if (key == null) if (key == null)


+ 25
- 22
shadowsocks-csharp/View/HotkeySettingsForm.cs View File

@@ -62,10 +62,10 @@ namespace Shadowsocks.View
private void LoadCurrentConfiguration() private void LoadCurrentConfiguration()
{ {
_modifiedHotkeyConfig = _controller.GetConfigurationCopy().hotkey; _modifiedHotkeyConfig = _controller.GetConfigurationCopy().hotkey;
LoadConfiguration(_modifiedHotkeyConfig);
SetConfigToUI(_modifiedHotkeyConfig);
} }
private void LoadConfiguration(HotkeyConfig config)
private void SetConfigToUI(HotkeyConfig config)
{ {
SwitchSystemProxyTextBox.Text = config.SwitchSystemProxy; SwitchSystemProxyTextBox.Text = config.SwitchSystemProxy;
SwitchProxyModeTextBox.Text = config.SwitchSystemProxyMode; SwitchProxyModeTextBox.Text = config.SwitchSystemProxyMode;
@@ -75,6 +75,25 @@ namespace Shadowsocks.View
ServerMoveDownTextBox.Text = config.ServerMoveDown; ServerMoveDownTextBox.Text = config.ServerMoveDown;
} }
private void SaveConfig()
{
_modifiedHotkeyConfig = GetConfigFromUI();
_controller.SaveHotkeyConfig(_modifiedHotkeyConfig);
}
private HotkeyConfig GetConfigFromUI()
{
return new HotkeyConfig
{
SwitchSystemProxy = SwitchSystemProxyTextBox.Text,
SwitchSystemProxyMode = SwitchProxyModeTextBox.Text,
SwitchAllowLan = SwitchAllowLanTextBox.Text,
ShowLogs = ShowLogsTextBox.Text,
ServerMoveUp = ServerMoveUpTextBox.Text,
ServerMoveDown = ServerMoveDownTextBox.Text
};
}
/// <summary> /// <summary>
/// Capture hotkey - Press key /// Capture hotkey - Press key
/// </summary> /// </summary>
@@ -160,7 +179,7 @@ namespace Shadowsocks.View
private void OKButton_Click(object sender, EventArgs e) private void OKButton_Click(object sender, EventArgs e)
{ {
// try to register, notify to change settings if failed // try to register, notify to change settings if failed
if (!RegisterAllHotkeys(out _)) // declare out as an inline discard variable
if (!RegisterAllHotkeys())
{ {
MessageBox.Show(I18N.GetString("Register hotkey failed")); MessageBox.Show(I18N.GetString("Register hotkey failed"));
} }
@@ -172,13 +191,12 @@ namespace Shadowsocks.View
private void RegisterAllButton_Click(object sender, EventArgs e) private void RegisterAllButton_Click(object sender, EventArgs e)
{ {
RegisterAllHotkeys(out _); // declare out as an inline discard variable
RegisterAllHotkeys();
} }
private bool RegisterAllHotkeys(out string failureInfoStr)
private bool RegisterAllHotkeys()
{ {
bool isSuccess = true; bool isSuccess = true;
StringBuilder failureInfo = new StringBuilder();
foreach (var tb in _allTextBoxes) foreach (var tb in _allTextBoxes)
{ {
if (tb.Text.IsNullOrEmpty()) if (tb.Text.IsNullOrEmpty())
@@ -188,10 +206,8 @@ namespace Shadowsocks.View
if (!TryRegHotkey(tb)) if (!TryRegHotkey(tb))
{ {
isSuccess = false; isSuccess = false;
failureInfo.AppendLine(tb.Text);
} }
} }
failureInfoStr = failureInfo.ToString();
return isSuccess; return isSuccess;
} }
@@ -238,23 +254,10 @@ namespace Shadowsocks.View
} }
} }
private void SaveConfig()
{
_modifiedHotkeyConfig.SwitchSystemProxy = SwitchSystemProxyTextBox.Text;
_modifiedHotkeyConfig.SwitchSystemProxyMode = SwitchProxyModeTextBox.Text;
_modifiedHotkeyConfig.SwitchAllowLan = SwitchAllowLanTextBox.Text;
_modifiedHotkeyConfig.ShowLogs = ShowLogsTextBox.Text;
_modifiedHotkeyConfig.ServerMoveUp = ServerMoveUpTextBox.Text;
_modifiedHotkeyConfig.ServerMoveDown = ServerMoveDownTextBox.Text;
_controller.SaveHotkeyConfig(_modifiedHotkeyConfig);
}
#region Prepare hotkey #region Prepare hotkey
/// <summary> /// <summary>
/// Find correct callback and corresponding label
/// Find correct callback and corresponding label by textBox
/// </summary> /// </summary>
/// <param name="tb"></param> /// <param name="tb"></param>
/// <param name="cb"></param> /// <param name="cb"></param>


Loading…
Cancel
Save