diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs index b8cd8ce6a..4077980b0 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs @@ -56,8 +56,6 @@ private void ShowErrorNotification(object sender, MediaErrorRoutedEventArgs e) mediaElement.Stop(); _context.ShowNotification("", "An error occurred while loading the video."); - - throw new Exception(); } public void LoadAndPlay(string path) diff --git a/QuickLook/App.xaml.cs b/QuickLook/App.xaml.cs index 7466dc954..d9c8a1145 100644 --- a/QuickLook/App.xaml.cs +++ b/QuickLook/App.xaml.cs @@ -18,9 +18,13 @@ public partial class App : Application protected override void OnStartup(StartupEventArgs e) { - AppDomain.CurrentDomain.UnhandledException += - (sender, args) => MessageBox.Show(((Exception) args.ExceptionObject).Message + Environment.NewLine + - ((Exception) args.ExceptionObject).StackTrace); + AppDomain.CurrentDomain.UnhandledException += (sender, args) => + { + MessageBox.Show(((Exception) args.ExceptionObject).Message + Environment.NewLine + + ((Exception) args.ExceptionObject).StackTrace); + + Current.Shutdown(); + }; base.OnStartup(e); } @@ -68,9 +72,9 @@ private void RunAsListener(StartupEventArgs e) PidHelper.WritePid(); - TrayIcon.GetInstance(); + TrayIconManager.GetInstance(); 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(); @@ -79,7 +83,7 @@ private void RunAsListener(StartupEventArgs e) private void App_OnExit(object sender, ExitEventArgs e) { - TrayIcon.GetInstance().Dispose(); + TrayIconManager.GetInstance().Dispose(); BackgroundListener.GetInstance().Dispose(); PidHelper.DeletePid(); diff --git a/QuickLook/BackgroundListener.cs b/QuickLook/BackgroundListener.cs index a63ac0ccb..a45f792c4 100644 --- a/QuickLook/BackgroundListener.cs +++ b/QuickLook/BackgroundListener.cs @@ -24,7 +24,7 @@ private void HotkeyEventHandler(object sender, KeyEventArgs e) if (e.Modifiers != Keys.None) return; - ViewWindowManager.GetInstance().InvokeRoutine(); + ViewWindowManager.GetInstance().InvokeRoutine(e.KeyCode != Keys.Space); } private void InstallHook(KeyEventHandler handler) @@ -32,6 +32,10 @@ private void InstallHook(KeyEventHandler handler) _hook = GlobalKeyboardHook.GetInstance(); _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; } diff --git a/QuickLook/GlobalKeyboardHook.cs b/QuickLook/GlobalKeyboardHook.cs index a6dbfcf54..eac0c2fee 100644 --- a/QuickLook/GlobalKeyboardHook.cs +++ b/QuickLook/GlobalKeyboardHook.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; using System.Windows.Forms; +using System.Windows.Input; using QuickLook.NativeMethods; +using KeyEventArgs = System.Windows.Forms.KeyEventArgs; +using KeyEventHandler = System.Windows.Forms.KeyEventHandler; namespace QuickLook { @@ -62,6 +65,8 @@ private int HookProc(int code, int wParam, ref User32.KeyboardHookStruct lParam) var key = (Keys) lParam.vkCode; if (HookedKeys.Contains(key)) { + key = AddModifiers(key); + var kea = new KeyEventArgs(key); if (wParam == User32.WM_KEYDOWN || wParam == User32.WM_SYSKEYDOWN) KeyDown?.Invoke(this, kea); @@ -73,5 +78,19 @@ private int HookProc(int code, int wParam, ref User32.KeyboardHookStruct 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; + } } } \ No newline at end of file diff --git a/QuickLook/Helpers/AutoStartupHelper.cs b/QuickLook/Helpers/AutoStartupHelper.cs index 63c35b476..c30c48362 100644 --- a/QuickLook/Helpers/AutoStartupHelper.cs +++ b/QuickLook/Helpers/AutoStartupHelper.cs @@ -28,7 +28,7 @@ internal static void CreateAutorunShortcut() } catch (Exception) { - TrayIcon.GetInstance().ShowNotification("", "Failed to add QuickLook to Startup folder."); + TrayIconManager.GetInstance().ShowNotification("", "Failed to add QuickLook to Startup folder."); } } diff --git a/QuickLook/MainWindow.xaml.cs b/QuickLook/MainWindow.xaml.cs index da8e27523..bc2725167 100644 --- a/QuickLook/MainWindow.xaml.cs +++ b/QuickLook/MainWindow.xaml.cs @@ -21,11 +21,6 @@ internal MainWindow() 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... if (!Debugger.IsAttached) Topmost = true; @@ -59,6 +54,9 @@ private void DragMoveCurrentWindow(object sender, MouseButtonEventArgs e) private new void Show() { + // revert UI changes + ContextObject.IsBusy = true; + Height = ContextObject.PreferredSize.Height + titlebar.Height + windowBorder.BorderThickness.Top + windowBorder.BorderThickness.Bottom; Width = ContextObject.PreferredSize.Width + windowBorder.BorderThickness.Left + diff --git a/QuickLook/Plugin/ContextObject.cs b/QuickLook/Plugin/ContextObject.cs index 9bb502dd5..98b776108 100644 --- a/QuickLook/Plugin/ContextObject.cs +++ b/QuickLook/Plugin/ContextObject.cs @@ -84,7 +84,7 @@ public void DisposePlugin() /// Is this indicates a error? public void ShowNotification(string title, string content, bool isError = false) { - TrayIcon.GetInstance().ShowNotification(title, content, isError); + TrayIconManager.GetInstance().ShowNotification(title, content, isError); } /// diff --git a/QuickLook/QuickLook.csproj b/QuickLook/QuickLook.csproj index 32d410aa7..b7170aa97 100644 --- a/QuickLook/QuickLook.csproj +++ b/QuickLook/QuickLook.csproj @@ -121,7 +121,7 @@ - + diff --git a/QuickLook/TrayIcon.cs b/QuickLook/TrayIconManager.cs similarity index 83% rename from QuickLook/TrayIcon.cs rename to QuickLook/TrayIconManager.cs index dc6387074..a14000c72 100644 --- a/QuickLook/TrayIcon.cs +++ b/QuickLook/TrayIconManager.cs @@ -7,9 +7,9 @@ namespace QuickLook { - public class TrayIcon : IDisposable + public class TrayIconManager : IDisposable { - private static TrayIcon _instance; + private static TrayIconManager _instance; private readonly NotifyIcon _icon; @@ -22,11 +22,11 @@ public class TrayIcon : IDisposable AutoStartupHelper.CreateAutorunShortcut(); }); - private TrayIcon() + private TrayIconManager() { _icon = new NotifyIcon { - Icon = Resources.app_white, + Icon = Resources.app, Visible = true, ContextMenu = new ContextMenu(new[] { @@ -50,9 +50,9 @@ public void ShowNotification(string title, string content, bool isError = false) _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()); } } } \ No newline at end of file diff --git a/QuickLook/ViewWindowManager.cs b/QuickLook/ViewWindowManager.cs index 0960780e7..823e3d0fb 100644 --- a/QuickLook/ViewWindowManager.cs +++ b/QuickLook/ViewWindowManager.cs @@ -22,13 +22,13 @@ internal ViewWindowManager() _viewWindow = new MainWindow(); } - internal void InvokeRoutine() + internal void InvokeRoutine(bool replaceView = false) { if (!WindowHelper.IsFocusedControlExplorerItem()) if (!WindowHelper.IsFocusedWindowSelf()) return; - if (_viewWindow.BeginHide()) + if (!replaceView && _viewWindow.BeginHide()) return; var path = GetCurrentSelection();