diff --git a/shadowsocks-csharp/Controller/System/Hotkeys/Hotkeys.cs b/shadowsocks-csharp/Controller/System/Hotkeys/Hotkeys.cs index 00393c46..bfb10166 100644 --- a/shadowsocks-csharp/Controller/System/Hotkeys/Hotkeys.cs +++ b/shadowsocks-csharp/Controller/System/Hotkeys/Hotkeys.cs @@ -59,6 +59,9 @@ namespace Shadowsocks.Controller.Hotkeys return false; } } + + #region Converters + public static string HotKey2Str( HotKey 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) { if (key == null) diff --git a/shadowsocks-csharp/View/HotkeySettingsForm.cs b/shadowsocks-csharp/View/HotkeySettingsForm.cs index 1c75a664..ee3def67 100644 --- a/shadowsocks-csharp/View/HotkeySettingsForm.cs +++ b/shadowsocks-csharp/View/HotkeySettingsForm.cs @@ -62,10 +62,10 @@ namespace Shadowsocks.View private void LoadCurrentConfiguration() { _modifiedHotkeyConfig = _controller.GetConfigurationCopy().hotkey; - LoadConfiguration(_modifiedHotkeyConfig); + SetConfigToUI(_modifiedHotkeyConfig); } - private void LoadConfiguration(HotkeyConfig config) + private void SetConfigToUI(HotkeyConfig config) { SwitchSystemProxyTextBox.Text = config.SwitchSystemProxy; SwitchProxyModeTextBox.Text = config.SwitchSystemProxyMode; @@ -75,6 +75,25 @@ namespace Shadowsocks.View 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 + }; + } + /// /// Capture hotkey - Press key /// @@ -160,7 +179,7 @@ namespace Shadowsocks.View private void OKButton_Click(object sender, EventArgs e) { // 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")); } @@ -172,13 +191,12 @@ namespace Shadowsocks.View 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; - StringBuilder failureInfo = new StringBuilder(); foreach (var tb in _allTextBoxes) { if (tb.Text.IsNullOrEmpty()) @@ -188,10 +206,8 @@ namespace Shadowsocks.View if (!TryRegHotkey(tb)) { isSuccess = false; - failureInfo.AppendLine(tb.Text); } } - failureInfoStr = failureInfo.ToString(); 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 /// - /// Find correct callback and corresponding label + /// Find correct callback and corresponding label by textBox /// /// ///