Skip to content

Commit 892b9bf

Browse files
committed
reponse to arrow keys
1 parent 13d6edd commit 892b9bf

File tree

10 files changed

+48
-25
lines changed

10 files changed

+48
-25
lines changed

QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ private void ShowErrorNotification(object sender, MediaErrorRoutedEventArgs e)
5656
mediaElement.Stop();
5757

5858
_context.ShowNotification("", "An error occurred while loading the video.");
59-
60-
throw new Exception();
6159
}
6260

6361
public void LoadAndPlay(string path)

QuickLook/App.xaml.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ public partial class App : Application
1818

1919
protected override void OnStartup(StartupEventArgs e)
2020
{
21-
AppDomain.CurrentDomain.UnhandledException +=
22-
(sender, args) => MessageBox.Show(((Exception) args.ExceptionObject).Message + Environment.NewLine +
23-
((Exception) args.ExceptionObject).StackTrace);
21+
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
22+
{
23+
MessageBox.Show(((Exception) args.ExceptionObject).Message + Environment.NewLine +
24+
((Exception) args.ExceptionObject).StackTrace);
25+
26+
Current.Shutdown();
27+
};
2428

2529
base.OnStartup(e);
2630
}
@@ -68,9 +72,9 @@ private void RunAsListener(StartupEventArgs e)
6872

6973
PidHelper.WritePid();
7074

71-
TrayIcon.GetInstance();
75+
TrayIconManager.GetInstance();
7276
if (!e.Args.Contains("/autorun"))
73-
TrayIcon.GetInstance().ShowNotification("", "QuickLook is running in the background.");
77+
TrayIconManager.GetInstance().ShowNotification("", "QuickLook is running in the background.");
7478

7579
PluginManager.GetInstance();
7680

@@ -79,7 +83,7 @@ private void RunAsListener(StartupEventArgs e)
7983

8084
private void App_OnExit(object sender, ExitEventArgs e)
8185
{
82-
TrayIcon.GetInstance().Dispose();
86+
TrayIconManager.GetInstance().Dispose();
8387
BackgroundListener.GetInstance().Dispose();
8488

8589
PidHelper.DeletePid();

QuickLook/BackgroundListener.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ private void HotkeyEventHandler(object sender, KeyEventArgs e)
2424
if (e.Modifiers != Keys.None)
2525
return;
2626

27-
ViewWindowManager.GetInstance().InvokeRoutine();
27+
ViewWindowManager.GetInstance().InvokeRoutine(e.KeyCode != Keys.Space);
2828
}
2929

3030
private void InstallHook(KeyEventHandler handler)
3131
{
3232
_hook = GlobalKeyboardHook.GetInstance();
3333

3434
_hook.HookedKeys.Add(Keys.Space);
35+
_hook.HookedKeys.Add(Keys.Up);
36+
_hook.HookedKeys.Add(Keys.Down);
37+
_hook.HookedKeys.Add(Keys.Left);
38+
_hook.HookedKeys.Add(Keys.Right);
3539

3640
_hook.KeyUp += handler;
3741
}

QuickLook/GlobalKeyboardHook.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Windows.Forms;
4+
using System.Windows.Input;
45
using QuickLook.NativeMethods;
6+
using KeyEventArgs = System.Windows.Forms.KeyEventArgs;
7+
using KeyEventHandler = System.Windows.Forms.KeyEventHandler;
58

69
namespace QuickLook
710
{
@@ -62,6 +65,8 @@ private int HookProc(int code, int wParam, ref User32.KeyboardHookStruct lParam)
6265
var key = (Keys) lParam.vkCode;
6366
if (HookedKeys.Contains(key))
6467
{
68+
key = AddModifiers(key);
69+
6570
var kea = new KeyEventArgs(key);
6671
if (wParam == User32.WM_KEYDOWN || wParam == User32.WM_SYSKEYDOWN)
6772
KeyDown?.Invoke(this, kea);
@@ -73,5 +78,19 @@ private int HookProc(int code, int wParam, ref User32.KeyboardHookStruct lParam)
7378
}
7479
return User32.CallNextHookEx(_hhook, code, wParam, ref lParam);
7580
}
81+
82+
private Keys AddModifiers(Keys key)
83+
{
84+
//Ctrl
85+
if ((Keyboard.Modifiers & ModifierKeys.Control) != 0) key = key | Keys.Control;
86+
87+
//Shift
88+
if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0) key = key | Keys.Shift;
89+
90+
//Alt
91+
if ((Keyboard.Modifiers & ModifierKeys.Alt) != 0) key = key | Keys.Alt;
92+
93+
return key;
94+
}
7695
}
7796
}

QuickLook/Helpers/AutoStartupHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal static void CreateAutorunShortcut()
2828
}
2929
catch (Exception)
3030
{
31-
TrayIcon.GetInstance().ShowNotification("", "Failed to add QuickLook to Startup folder.");
31+
TrayIconManager.GetInstance().ShowNotification("", "Failed to add QuickLook to Startup folder.");
3232
}
3333
}
3434

QuickLook/MainWindow.xaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ internal MainWindow()
2121

2222
InitializeComponent();
2323

24-
// revert designer changes
25-
windowPanel.Opacity = 0d;
26-
busyIndicatorLayer.Visibility = Visibility.Visible;
27-
busyIndicatorLayer.Opacity = 1d;
28-
2924
// do not set TopMost property if we are now debugging. it makes debugging painful...
3025
if (!Debugger.IsAttached)
3126
Topmost = true;
@@ -59,6 +54,9 @@ private void DragMoveCurrentWindow(object sender, MouseButtonEventArgs e)
5954

6055
private new void Show()
6156
{
57+
// revert UI changes
58+
ContextObject.IsBusy = true;
59+
6260
Height = ContextObject.PreferredSize.Height + titlebar.Height + windowBorder.BorderThickness.Top +
6361
windowBorder.BorderThickness.Bottom;
6462
Width = ContextObject.PreferredSize.Width + windowBorder.BorderThickness.Left +

QuickLook/Plugin/ContextObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void DisposePlugin()
8484
/// <param name="isError">Is this indicates a error?</param>
8585
public void ShowNotification(string title, string content, bool isError = false)
8686
{
87-
TrayIcon.GetInstance().ShowNotification(title, content, isError);
87+
TrayIconManager.GetInstance().ShowNotification(title, content, isError);
8888
}
8989

9090
/// <summary>

QuickLook/QuickLook.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
<Compile Include="Plugin\InfoPanel\WindowsThumbnailProvider.cs" />
122122
<Compile Include="Plugin\IViewer.cs" />
123123
<Compile Include="Helpers\DpiHelpers.cs" />
124-
<Compile Include="TrayIcon.cs" />
124+
<Compile Include="TrayIconManager.cs" />
125125
<Compile Include="Plugin\ContextObject.cs" />
126126
<Compile Include="Helpers\WindowHelper.cs" />
127127
<Compile Include="ViewWindowManager.cs" />
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace QuickLook
99
{
10-
public class TrayIcon : IDisposable
10+
public class TrayIconManager : IDisposable
1111
{
12-
private static TrayIcon _instance;
12+
private static TrayIconManager _instance;
1313

1414
private readonly NotifyIcon _icon;
1515

@@ -22,11 +22,11 @@ public class TrayIcon : IDisposable
2222
AutoStartupHelper.CreateAutorunShortcut();
2323
});
2424

25-
private TrayIcon()
25+
private TrayIconManager()
2626
{
2727
_icon = new NotifyIcon
2828
{
29-
Icon = Resources.app_white,
29+
Icon = Resources.app,
3030
Visible = true,
3131
ContextMenu = new ContextMenu(new[]
3232
{
@@ -50,9 +50,9 @@ public void ShowNotification(string title, string content, bool isError = false)
5050
_icon.ShowBalloonTip(5000, title, content, isError ? ToolTipIcon.Error : ToolTipIcon.Info);
5151
}
5252

53-
internal static TrayIcon GetInstance()
53+
internal static TrayIconManager GetInstance()
5454
{
55-
return _instance ?? (_instance = new TrayIcon());
55+
return _instance ?? (_instance = new TrayIconManager());
5656
}
5757
}
5858
}

QuickLook/ViewWindowManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ internal ViewWindowManager()
2222
_viewWindow = new MainWindow();
2323
}
2424

25-
internal void InvokeRoutine()
25+
internal void InvokeRoutine(bool replaceView = false)
2626
{
2727
if (!WindowHelper.IsFocusedControlExplorerItem())
2828
if (!WindowHelper.IsFocusedWindowSelf())
2929
return;
3030

31-
if (_viewWindow.BeginHide())
31+
if (!replaceView && _viewWindow.BeginHide())
3232
return;
3333

3434
var path = GetCurrentSelection();

0 commit comments

Comments
 (0)