Add global hotkey support (#724)

Design:

Use the plain string for both config and hotkey parsing
and make use of KeyConverter, ModifierKeysConverter
to make it more rubust.

Find corresponding label (to display operation result) and callback (to do the real work) based on textbox name. In this case, they should be named as `<Feature-Name><Control-Name>`.

ShowLogsTextBox,
ShowLogsLabel,
ShowLogsCallback.

If this requirement doesn't meet, throw an exception at runtime.

Logic:

How to input keys:
1. put focus in the corresponding textbox
2. press the key combination you want to use
3. when you think it is ready, release all keys
4. the textbox shows your input

How to change keys:
1. put focus in the corresponding textbox
2. press BackSpace to clear content
3. re-input new one

How to deactivate:
1. clear content in the textbox
2. press OK button

Meaning of label color:
- Green: this combination is not occupied by other programs and register successfully
- Yellow: this combination is occupied by other programs and you have to change to another one
- Transparent without color: initial status

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
Syrone Wong
2016-09-16 23:42:16 -05:00
committed by GitHub
parent 6e6be823ad
commit 99bdec334c
17 changed files with 1294 additions and 7 deletions
@@ -49,10 +49,12 @@ namespace Shadowsocks.View
private MenuItem editOnlinePACItem;
private MenuItem autoCheckUpdatesToggleItem;
private MenuItem proxyItem;
private MenuItem hotKeyItem;
private MenuItem VerboseLoggingToggleItem;
private ConfigForm configForm;
private ProxyForm proxyForm;
private LogForm logForm;
private HotkeySettingsForm hotkeySettingsForm;
private string _urlToOpen;
public MenuViewController(ShadowsocksController controller)
@@ -276,6 +278,7 @@ namespace Shadowsocks.View
new MenuItem("-"),
CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)),
this.VerboseLoggingToggleItem = CreateMenuItem( "Verbose Logging", new EventHandler(this.VerboseLoggingToggleItem_Click) ),
this.hotKeyItem = CreateMenuItem("Edit Hotkeys...", new EventHandler(this.hotKeyItem_Click)),
CreateMenuGroup("Updates...", new MenuItem[] {
CreateMenuItem("Check for Updates...", new EventHandler(this.checkUpdatesItem_Click)),
new MenuItem("-"),
@@ -466,6 +469,21 @@ namespace Shadowsocks.View
}
}
private void ShowHotKeySettingsForm()
{
if (hotkeySettingsForm != null)
{
hotkeySettingsForm.Activate();
}
else
{
hotkeySettingsForm = new HotkeySettingsForm(controller);
hotkeySettingsForm.Show();
hotkeySettingsForm.Activate();
hotkeySettingsForm.FormClosed += hotkeySettingsForm_FormClosed;
}
}
private void ShowLogForm()
{
if (logForm != null)
@@ -505,6 +523,12 @@ namespace Shadowsocks.View
Utils.ReleaseMemory(true);
}
void hotkeySettingsForm_FormClosed(object sender, FormClosedEventArgs e)
{
hotkeySettingsForm = null;
Utils.ReleaseMemory(true);
}
private void Config_Click(object sender, EventArgs e)
{
ShowConfigForm();
@@ -811,9 +835,19 @@ namespace Shadowsocks.View
ShowProxyForm();
}
private void hotKeyItem_Click(object sender, EventArgs e)
{
ShowHotKeySettingsForm();
}
private void ShowLogItem_Click(object sender, EventArgs e)
{
ShowLogForm();
}
public void ShowLogForm_HotKey()
{
ShowLogForm();
}
}
}