|
|
@@ -18,8 +18,8 @@ namespace Shadowsocks.View |
|
|
|
{
|
|
|
|
private readonly ShadowsocksController _controller;
|
|
|
|
|
|
|
|
// this is a copy of configuration that we are working on
|
|
|
|
private HotkeyConfig _modifiedConfig;
|
|
|
|
// this is a copy of hotkey configuration that we are working on
|
|
|
|
private HotkeyConfig _modifiedHotkeyConfig;
|
|
|
|
|
|
|
|
private readonly IEnumerable<TextBox> _allTextBoxes;
|
|
|
|
|
|
|
@@ -39,6 +39,21 @@ namespace Shadowsocks.View |
|
|
|
if (!_allTextBoxes.Any()) throw new Exception("Cannot get all textboxes");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateTexts()
|
|
|
|
{
|
|
|
|
// I18N stuff
|
|
|
|
SwitchSystemProxyLabel.Text = I18N.GetString("Switch system proxy");
|
|
|
|
SwitchProxyModeLabel.Text = I18N.GetString("Switch system proxy mode");
|
|
|
|
SwitchAllowLanLabel.Text = I18N.GetString("Switch share over LAN");
|
|
|
|
ShowLogsLabel.Text = I18N.GetString("Show Logs");
|
|
|
|
ServerMoveUpLabel.Text = I18N.GetString("Switch to prev server");
|
|
|
|
ServerMoveDownLabel.Text = I18N.GetString("Switch to next server");
|
|
|
|
btnOK.Text = I18N.GetString("OK");
|
|
|
|
btnCancel.Text = I18N.GetString("Cancel");
|
|
|
|
btnRegisterAll.Text = I18N.GetString("Reg All");
|
|
|
|
this.Text = I18N.GetString("Edit Hotkeys...");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void controller_ConfigChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
LoadCurrentConfiguration();
|
|
|
@@ -46,8 +61,8 @@ namespace Shadowsocks.View |
|
|
|
|
|
|
|
private void LoadCurrentConfiguration()
|
|
|
|
{
|
|
|
|
_modifiedConfig = _controller.GetConfigurationCopy().hotkey;
|
|
|
|
LoadConfiguration(_modifiedConfig);
|
|
|
|
_modifiedHotkeyConfig = _controller.GetConfigurationCopy().hotkey;
|
|
|
|
LoadConfiguration(_modifiedHotkeyConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LoadConfiguration(HotkeyConfig config)
|
|
|
@@ -60,21 +75,6 @@ namespace Shadowsocks.View |
|
|
|
ServerMoveDownTextBox.Text = config.ServerMoveDown;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateTexts()
|
|
|
|
{
|
|
|
|
// I18N stuff
|
|
|
|
SwitchSystemProxyLabel.Text = I18N.GetString("Switch system proxy");
|
|
|
|
SwitchProxyModeLabel.Text = I18N.GetString("Switch system proxy mode");
|
|
|
|
SwitchAllowLanLabel.Text = I18N.GetString("Switch share over LAN");
|
|
|
|
ShowLogsLabel.Text = I18N.GetString("Show Logs");
|
|
|
|
ServerMoveUpLabel.Text = I18N.GetString("Switch to prev server");
|
|
|
|
ServerMoveDownLabel.Text = I18N.GetString("Switch to next server");
|
|
|
|
btnOK.Text = I18N.GetString("OK");
|
|
|
|
btnCancel.Text = I18N.GetString("Cancel");
|
|
|
|
btnRegisterAll.Text = I18N.GetString("Reg All");
|
|
|
|
Text = I18N.GetString("Edit Hotkeys...");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Capture hotkey - Press key
|
|
|
|
/// </summary>
|
|
|
@@ -154,40 +154,45 @@ namespace Shadowsocks.View |
|
|
|
|
|
|
|
private void CancelButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OKButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// try to register, notify to change settings if failed
|
|
|
|
foreach (var tb in _allTextBoxes)
|
|
|
|
if (!RegisterAllHotkeys(out _)) // declare out as an inline discard variable
|
|
|
|
{
|
|
|
|
if (tb.Text.IsNullOrEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!TryRegHotkey(tb))
|
|
|
|
{
|
|
|
|
MessageBox.Show(I18N.GetString("Register hotkey failed"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MessageBox.Show(I18N.GetString("Register hotkey failed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// All check passed, saving
|
|
|
|
SaveConfig();
|
|
|
|
Close();
|
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RegisterAllButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
RegisterAllHotkeys(out _); // declare out as an inline discard variable
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool RegisterAllHotkeys(out string failureInfoStr)
|
|
|
|
{
|
|
|
|
bool isSuccess = true;
|
|
|
|
StringBuilder failureInfo = new StringBuilder();
|
|
|
|
foreach (var tb in _allTextBoxes)
|
|
|
|
{
|
|
|
|
if (tb.Text.IsNullOrEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
TryRegHotkey(tb);
|
|
|
|
if (!TryRegHotkey(tb))
|
|
|
|
{
|
|
|
|
isSuccess = false;
|
|
|
|
failureInfo.AppendLine(tb.Text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
failureInfoStr = failureInfo.ToString();
|
|
|
|
return isSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool TryRegHotkey(TextBox tb)
|
|
|
@@ -218,7 +223,7 @@ namespace Shadowsocks.View |
|
|
|
// or change to another one
|
|
|
|
// Transparent without color: first run or empty config
|
|
|
|
|
|
|
|
bool regResult = HotKeys.Regist(hotkey, callBack);
|
|
|
|
bool regResult = HotKeys.Register(hotkey, callBack);
|
|
|
|
lb.BackColor = regResult ? Color.Green : Color.Yellow;
|
|
|
|
return regResult;
|
|
|
|
}
|
|
|
@@ -229,19 +234,19 @@ namespace Shadowsocks.View |
|
|
|
if (HotKeys.IsCallbackExists(cb, out prevHotKey))
|
|
|
|
{
|
|
|
|
// unregister previous one
|
|
|
|
HotKeys.UnRegist(prevHotKey);
|
|
|
|
HotKeys.Unregister(prevHotKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SaveConfig()
|
|
|
|
{
|
|
|
|
_modifiedConfig.SwitchSystemProxy = SwitchSystemProxyTextBox.Text;
|
|
|
|
_modifiedConfig.SwitchSystemProxyMode = SwitchProxyModeTextBox.Text;
|
|
|
|
_modifiedConfig.SwitchAllowLan = SwitchAllowLanTextBox.Text;
|
|
|
|
_modifiedConfig.ShowLogs = ShowLogsTextBox.Text;
|
|
|
|
_modifiedConfig.ServerMoveUp = ServerMoveUpTextBox.Text;
|
|
|
|
_modifiedConfig.ServerMoveDown = ServerMoveDownTextBox.Text;
|
|
|
|
_controller.SaveHotkeyConfig(_modifiedConfig);
|
|
|
|
_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|