improve ENTER key handle

This commit is contained in:
Paddy Xu
2017-05-27 19:37:18 +03:00
parent 16f20dc79d
commit 6471125a0b
3 changed files with 23 additions and 13 deletions

View File

@@ -24,7 +24,7 @@ namespace QuickLook
if (e.Modifiers != Keys.None) if (e.Modifiers != Keys.None)
return; return;
ViewWindowManager.GetInstance().InvokeRoutine(e.KeyCode); ViewWindowManager.GetInstance().InvokeRoutine(e);
} }
private void InstallKeyHook(KeyEventHandler handler) private void InstallKeyHook(KeyEventHandler handler)

View File

@@ -42,12 +42,12 @@ namespace QuickLook
OpenWithAssocApp(); OpenWithAssocApp();
};*/ };*/
buttonOpenWith.Click += (sender, e) => OpenWithAssocApp(); buttonOpenWith.Click += (sender, e) => RunAndClose();
} }
public ContextObject ContextObject { get; private set; } public ContextObject ContextObject { get; private set; }
internal void OpenWithAssocApp() internal void RunAndClose()
{ {
if (string.IsNullOrEmpty(_path)) if (string.IsNullOrEmpty(_path))
return; return;

View File

@@ -27,40 +27,48 @@ namespace QuickLook
_currentMainWindow = _viewWindowTransparentTransparent; _currentMainWindow = _viewWindowTransparentTransparent;
} }
internal void InvokeRoutine(Keys key) internal void InvokeRoutine(KeyEventArgs kea)
{ {
Debug.WriteLine(key); Debug.WriteLine(kea.KeyCode);
switch (key) switch (kea.KeyCode)
{ {
case Keys.Up: case Keys.Up:
case Keys.Down: case Keys.Down:
case Keys.Left: case Keys.Left:
case Keys.Right: case Keys.Right:
SwitchPreviewToAnotherFile(); SwitchPreview(kea);
break; break;
case Keys.Space: case Keys.Space:
TogglePreview(); TogglePreview(kea);
break; break;
case Keys.Escape: case Keys.Escape:
ClosePreview(kea, false);
break;
case Keys.Enter: case Keys.Enter:
ClosePreview(); ClosePreview(kea, true);
break; break;
default: default:
break; break;
} }
} }
private void ClosePreview() private void ClosePreview(KeyEventArgs kea, bool runBeforeClose)
{ {
if (!WindowHelper.IsFocusedControlExplorerItem() && !WindowHelper.IsFocusedWindowSelf()) if (!WindowHelper.IsFocusedControlExplorerItem() && !WindowHelper.IsFocusedWindowSelf())
return; return;
if (_currentMainWindow.Visibility == Visibility.Visible) if (_currentMainWindow.Visibility != Visibility.Visible)
return;
if (runBeforeClose)
_currentMainWindow.RunAndClose();
else
_currentMainWindow.BeginHide(); _currentMainWindow.BeginHide();
kea.Handled = true;
} }
private void TogglePreview() private void TogglePreview(KeyEventArgs kea)
{ {
if (!WindowHelper.IsFocusedControlExplorerItem() && !WindowHelper.IsFocusedWindowSelf()) if (!WindowHelper.IsFocusedControlExplorerItem() && !WindowHelper.IsFocusedWindowSelf())
return; return;
@@ -69,9 +77,10 @@ namespace QuickLook
_currentMainWindow.BeginHide(); _currentMainWindow.BeginHide();
else else
InvokeViewer(GetCurrentSelection()); InvokeViewer(GetCurrentSelection());
kea.Handled = true;
} }
private void SwitchPreviewToAnotherFile() private void SwitchPreview(KeyEventArgs kea)
{ {
if (_currentMainWindow.Visibility != Visibility.Visible) if (_currentMainWindow.Visibility != Visibility.Visible)
return; return;
@@ -81,6 +90,7 @@ namespace QuickLook
_currentMainWindow.UnloadPlugin(); _currentMainWindow.UnloadPlugin();
InvokeViewer(GetCurrentSelection()); InvokeViewer(GetCurrentSelection());
kea.Handled = false;
} }
internal void InvokeViewer(string path) internal void InvokeViewer(string path)