reponse to arrow keys

This commit is contained in:
Paddy Xu
2017-05-16 22:27:14 +03:00
parent 13d6edd2c9
commit 892b9bf4d2
10 changed files with 48 additions and 25 deletions

View File

@@ -56,8 +56,6 @@ namespace QuickLook.Plugin.VideoViewer
mediaElement.Stop(); mediaElement.Stop();
_context.ShowNotification("", "An error occurred while loading the video."); _context.ShowNotification("", "An error occurred while loading the video.");
throw new Exception();
} }
public void LoadAndPlay(string path) public void LoadAndPlay(string path)

View File

@@ -18,9 +18,13 @@ namespace QuickLook
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
AppDomain.CurrentDomain.UnhandledException += AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
(sender, args) => MessageBox.Show(((Exception) args.ExceptionObject).Message + Environment.NewLine + {
((Exception) args.ExceptionObject).StackTrace); MessageBox.Show(((Exception) args.ExceptionObject).Message + Environment.NewLine +
((Exception) args.ExceptionObject).StackTrace);
Current.Shutdown();
};
base.OnStartup(e); base.OnStartup(e);
} }
@@ -68,9 +72,9 @@ namespace QuickLook
PidHelper.WritePid(); PidHelper.WritePid();
TrayIcon.GetInstance(); TrayIconManager.GetInstance();
if (!e.Args.Contains("/autorun")) if (!e.Args.Contains("/autorun"))
TrayIcon.GetInstance().ShowNotification("", "QuickLook is running in the background."); TrayIconManager.GetInstance().ShowNotification("", "QuickLook is running in the background.");
PluginManager.GetInstance(); PluginManager.GetInstance();
@@ -79,7 +83,7 @@ namespace QuickLook
private void App_OnExit(object sender, ExitEventArgs e) private void App_OnExit(object sender, ExitEventArgs e)
{ {
TrayIcon.GetInstance().Dispose(); TrayIconManager.GetInstance().Dispose();
BackgroundListener.GetInstance().Dispose(); BackgroundListener.GetInstance().Dispose();
PidHelper.DeletePid(); PidHelper.DeletePid();

View File

@@ -24,7 +24,7 @@ namespace QuickLook
if (e.Modifiers != Keys.None) if (e.Modifiers != Keys.None)
return; return;
ViewWindowManager.GetInstance().InvokeRoutine(); ViewWindowManager.GetInstance().InvokeRoutine(e.KeyCode != Keys.Space);
} }
private void InstallHook(KeyEventHandler handler) private void InstallHook(KeyEventHandler handler)
@@ -32,6 +32,10 @@ namespace QuickLook
_hook = GlobalKeyboardHook.GetInstance(); _hook = GlobalKeyboardHook.GetInstance();
_hook.HookedKeys.Add(Keys.Space); _hook.HookedKeys.Add(Keys.Space);
_hook.HookedKeys.Add(Keys.Up);
_hook.HookedKeys.Add(Keys.Down);
_hook.HookedKeys.Add(Keys.Left);
_hook.HookedKeys.Add(Keys.Right);
_hook.KeyUp += handler; _hook.KeyUp += handler;
} }

View File

@@ -1,7 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Input;
using QuickLook.NativeMethods; using QuickLook.NativeMethods;
using KeyEventArgs = System.Windows.Forms.KeyEventArgs;
using KeyEventHandler = System.Windows.Forms.KeyEventHandler;
namespace QuickLook namespace QuickLook
{ {
@@ -62,6 +65,8 @@ namespace QuickLook
var key = (Keys) lParam.vkCode; var key = (Keys) lParam.vkCode;
if (HookedKeys.Contains(key)) if (HookedKeys.Contains(key))
{ {
key = AddModifiers(key);
var kea = new KeyEventArgs(key); var kea = new KeyEventArgs(key);
if (wParam == User32.WM_KEYDOWN || wParam == User32.WM_SYSKEYDOWN) if (wParam == User32.WM_KEYDOWN || wParam == User32.WM_SYSKEYDOWN)
KeyDown?.Invoke(this, kea); KeyDown?.Invoke(this, kea);
@@ -73,5 +78,19 @@ namespace QuickLook
} }
return User32.CallNextHookEx(_hhook, code, wParam, ref lParam); return User32.CallNextHookEx(_hhook, code, wParam, ref lParam);
} }
private Keys AddModifiers(Keys key)
{
//Ctrl
if ((Keyboard.Modifiers & ModifierKeys.Control) != 0) key = key | Keys.Control;
//Shift
if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0) key = key | Keys.Shift;
//Alt
if ((Keyboard.Modifiers & ModifierKeys.Alt) != 0) key = key | Keys.Alt;
return key;
}
} }
} }

View File

@@ -28,7 +28,7 @@ namespace QuickLook.Helpers
} }
catch (Exception) catch (Exception)
{ {
TrayIcon.GetInstance().ShowNotification("", "Failed to add QuickLook to Startup folder."); TrayIconManager.GetInstance().ShowNotification("", "Failed to add QuickLook to Startup folder.");
} }
} }

View File

@@ -21,11 +21,6 @@ namespace QuickLook
InitializeComponent(); InitializeComponent();
// revert designer changes
windowPanel.Opacity = 0d;
busyIndicatorLayer.Visibility = Visibility.Visible;
busyIndicatorLayer.Opacity = 1d;
// do not set TopMost property if we are now debugging. it makes debugging painful... // do not set TopMost property if we are now debugging. it makes debugging painful...
if (!Debugger.IsAttached) if (!Debugger.IsAttached)
Topmost = true; Topmost = true;
@@ -59,6 +54,9 @@ namespace QuickLook
private new void Show() private new void Show()
{ {
// revert UI changes
ContextObject.IsBusy = true;
Height = ContextObject.PreferredSize.Height + titlebar.Height + windowBorder.BorderThickness.Top + Height = ContextObject.PreferredSize.Height + titlebar.Height + windowBorder.BorderThickness.Top +
windowBorder.BorderThickness.Bottom; windowBorder.BorderThickness.Bottom;
Width = ContextObject.PreferredSize.Width + windowBorder.BorderThickness.Left + Width = ContextObject.PreferredSize.Width + windowBorder.BorderThickness.Left +

View File

@@ -84,7 +84,7 @@ namespace QuickLook.Plugin
/// <param name="isError">Is this indicates a error?</param> /// <param name="isError">Is this indicates a error?</param>
public void ShowNotification(string title, string content, bool isError = false) public void ShowNotification(string title, string content, bool isError = false)
{ {
TrayIcon.GetInstance().ShowNotification(title, content, isError); TrayIconManager.GetInstance().ShowNotification(title, content, isError);
} }
/// <summary> /// <summary>

View File

@@ -121,7 +121,7 @@
<Compile Include="Plugin\InfoPanel\WindowsThumbnailProvider.cs" /> <Compile Include="Plugin\InfoPanel\WindowsThumbnailProvider.cs" />
<Compile Include="Plugin\IViewer.cs" /> <Compile Include="Plugin\IViewer.cs" />
<Compile Include="Helpers\DpiHelpers.cs" /> <Compile Include="Helpers\DpiHelpers.cs" />
<Compile Include="TrayIcon.cs" /> <Compile Include="TrayIconManager.cs" />
<Compile Include="Plugin\ContextObject.cs" /> <Compile Include="Plugin\ContextObject.cs" />
<Compile Include="Helpers\WindowHelper.cs" /> <Compile Include="Helpers\WindowHelper.cs" />
<Compile Include="ViewWindowManager.cs" /> <Compile Include="ViewWindowManager.cs" />

View File

@@ -7,9 +7,9 @@ using Application = System.Windows.Application;
namespace QuickLook namespace QuickLook
{ {
public class TrayIcon : IDisposable public class TrayIconManager : IDisposable
{ {
private static TrayIcon _instance; private static TrayIconManager _instance;
private readonly NotifyIcon _icon; private readonly NotifyIcon _icon;
@@ -22,11 +22,11 @@ namespace QuickLook
AutoStartupHelper.CreateAutorunShortcut(); AutoStartupHelper.CreateAutorunShortcut();
}); });
private TrayIcon() private TrayIconManager()
{ {
_icon = new NotifyIcon _icon = new NotifyIcon
{ {
Icon = Resources.app_white, Icon = Resources.app,
Visible = true, Visible = true,
ContextMenu = new ContextMenu(new[] ContextMenu = new ContextMenu(new[]
{ {
@@ -50,9 +50,9 @@ namespace QuickLook
_icon.ShowBalloonTip(5000, title, content, isError ? ToolTipIcon.Error : ToolTipIcon.Info); _icon.ShowBalloonTip(5000, title, content, isError ? ToolTipIcon.Error : ToolTipIcon.Info);
} }
internal static TrayIcon GetInstance() internal static TrayIconManager GetInstance()
{ {
return _instance ?? (_instance = new TrayIcon()); return _instance ?? (_instance = new TrayIconManager());
} }
} }
} }

View File

@@ -22,13 +22,13 @@ namespace QuickLook
_viewWindow = new MainWindow(); _viewWindow = new MainWindow();
} }
internal void InvokeRoutine() internal void InvokeRoutine(bool replaceView = false)
{ {
if (!WindowHelper.IsFocusedControlExplorerItem()) if (!WindowHelper.IsFocusedControlExplorerItem())
if (!WindowHelper.IsFocusedWindowSelf()) if (!WindowHelper.IsFocusedWindowSelf())
return; return;
if (_viewWindow.BeginHide()) if (!replaceView && _viewWindow.BeginHide())
return; return;
var path = GetCurrentSelection(); var path = GetCurrentSelection();