Skip to content

Commit fd57be7

Browse files
author
Yair Aichenbaum
committed
Moved some shortcuts to ProHome.xaml.cs
1 parent b1a81c0 commit fd57be7

File tree

3 files changed

+73
-106
lines changed

3 files changed

+73
-106
lines changed

Files/App.xaml.cs

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -85,107 +85,6 @@ private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
8585
}
8686
}
8787

88-
private async void CoreWindow_KeyDown(CoreWindow sender, KeyEventArgs args)
89-
{
90-
var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
91-
var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift);
92-
var alt = Window.Current.CoreWindow.GetKeyState(VirtualKey.Menu);
93-
if (App.CurrentInstance != null)
94-
{
95-
if (ctrl.HasFlag(CoreVirtualKeyStates.Down))
96-
{
97-
if (shift.HasFlag(CoreVirtualKeyStates.Down))
98-
{
99-
if (App.CurrentInstance.ContentPage != null)
100-
{
101-
switch (args.VirtualKey)
102-
{
103-
case VirtualKey.N:
104-
Window.Current.CoreWindow.KeyDown -= CoreWindow_KeyDown;
105-
await App.addItemDialog.ShowAsync();
106-
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
107-
break;
108-
}
109-
}
110-
}
111-
else
112-
{
113-
if (App.CurrentInstance.ContentPage != null)
114-
{
115-
switch (args.VirtualKey)
116-
{
117-
case VirtualKey.C:
118-
App.CurrentInstance.InteractionOperations.CopyItem_ClickAsync(null, null);
119-
break;
120-
case VirtualKey.X:
121-
App.CurrentInstance.InteractionOperations.CutItem_Click(null, null);
122-
break;
123-
case VirtualKey.V:
124-
App.CurrentInstance.InteractionOperations.PasteItem_ClickAsync(null, null);
125-
break;
126-
case VirtualKey.A:
127-
App.CurrentInstance.InteractionOperations.SelectAllItems();
128-
break;
129-
}
130-
}
131-
132-
switch (args.VirtualKey)
133-
{
134-
case VirtualKey.N:
135-
var filesUWPUri = new Uri("files-uwp:");
136-
await Launcher.LaunchUriAsync(filesUWPUri);
137-
break;
138-
case VirtualKey.W:
139-
if (((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.TabItems.Count == 1)
140-
{
141-
Application.Current.Exit();
142-
}
143-
else if (((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.TabItems.Count > 1)
144-
{
145-
((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.TabItems.RemoveAt(((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.SelectedIndex);
146-
}
147-
break;
148-
}
149-
}
150-
}
151-
else if (ctrl.HasFlag(CoreVirtualKeyStates.None) && alt.HasFlag(CoreVirtualKeyStates.None))
152-
{
153-
if (App.CurrentInstance.ContentPage != null)
154-
{
155-
switch (args.VirtualKey)
156-
{
157-
case VirtualKey.Delete:
158-
App.CurrentInstance.InteractionOperations.DeleteItem_Click(null, null);
159-
break;
160-
case VirtualKey.Enter:
161-
if ((App.CurrentInstance.ContentPage).IsQuickLookEnabled)
162-
{
163-
App.CurrentInstance.InteractionOperations.ToggleQuickLook();
164-
}
165-
else
166-
{
167-
App.CurrentInstance.InteractionOperations.List_ItemClick(null, null);
168-
}
169-
break;
170-
}
171-
172-
if (App.CurrentInstance.CurrentPageType == typeof(PhotoAlbum))
173-
{
174-
switch (args.VirtualKey)
175-
{
176-
case VirtualKey.F2:
177-
if((App.CurrentInstance.ContentPage).SelectedItems.Count > 0)
178-
{
179-
App.CurrentInstance.InteractionOperations.RenameItem_Click(null, null);
180-
}
181-
break;
182-
}
183-
}
184-
}
185-
}
186-
}
187-
}
188-
18988
public static INavigationControlItem rightClickedItem;
19089

19190
public static async void FlyoutItem_Click(object sender, RoutedEventArgs e)
@@ -308,7 +207,6 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
308207

309208
// Ensure the current window is active
310209
Window.Current.Activate();
311-
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
312210
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
313211
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
314212

@@ -369,7 +267,6 @@ protected override void OnActivated(IActivatedEventArgs args)
369267
}
370268
// Ensure the current window is active.
371269
Window.Current.Activate();
372-
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
373270
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
374271
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
375272
return;
@@ -395,7 +292,6 @@ protected override void OnActivated(IActivatedEventArgs args)
395292

396293
// Ensure the current window is active.
397294
Window.Current.Activate();
398-
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
399295
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
400296
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
401297

@@ -404,7 +300,6 @@ protected override void OnActivated(IActivatedEventArgs args)
404300
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
405301
// Ensure the current window is active.
406302
Window.Current.Activate();
407-
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
408303
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
409304
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
410305
return;
@@ -418,7 +313,6 @@ protected override void OnActivated(IActivatedEventArgs args)
418313

419314
// Ensure the current window is active.
420315
Window.Current.Activate();
421-
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
422316
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
423317
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
424318
}

Files/ProHome.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
1515
x:Name="ProHomeInstance"
1616
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
17+
KeyUp="ProHomeInstance_KeyUp"
1718
Loaded="Page_Loaded"
1819
NavigationCacheMode="Disabled"
1920
mc:Ignorable="d">

Files/ProHome.xaml.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Drawing;
2222
using Files.View_Models;
2323
using Files.Controls;
24+
using Windows.UI.Core;
2425

2526
namespace Files
2627
{
@@ -273,6 +274,77 @@ public void UpdateProgressFlyout(InteractionOperationType operationType, int amo
273274
UnloadObject(ProgressFlyout);
274275
}
275276
}
277+
278+
private async void ProHomeInstance_KeyUp(object sender, KeyRoutedEventArgs e)
279+
{
280+
var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
281+
var alt = Window.Current.CoreWindow.GetKeyState(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
282+
var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
283+
var tabInstance = App.CurrentInstance != null;
284+
285+
switch (c: ctrl, s: shift, a: alt, t: tabInstance, k: e.Key)
286+
{
287+
case (true, true, false, true, VirtualKey.N):
288+
await App.addItemDialog.ShowAsync();
289+
break;
290+
case (true, false, false, true, VirtualKey.C):
291+
App.CurrentInstance.InteractionOperations.CopyItem_ClickAsync(null, null);
292+
break;
293+
case (true, false, false, true, VirtualKey.V):
294+
App.CurrentInstance.InteractionOperations.PasteItem_ClickAsync(null, null);
295+
break;
296+
case (true, false, false, true, VirtualKey.X):
297+
App.CurrentInstance.InteractionOperations.CutItem_Click(null, null);
298+
break;
299+
case (true, false, false, true, VirtualKey.A):
300+
App.CurrentInstance.InteractionOperations.SelectAllItems();
301+
break;
302+
case (true, false, false, true, VirtualKey.N):
303+
LaunchNewWindow();
304+
break;
305+
case (true, false, false, true, VirtualKey.W):
306+
CloseTab();
307+
break;
308+
case (false, false, false, true, VirtualKey.Delete):
309+
App.CurrentInstance.InteractionOperations.DeleteItem_Click(null, null);
310+
break;
311+
case (false, false, false, true, VirtualKey.Enter):
312+
App.CurrentInstance.InteractionOperations.List_ItemClick(null, null);
313+
break;
314+
};
315+
316+
if (App.CurrentInstance.CurrentPageType == typeof(PhotoAlbum))
317+
{
318+
switch (e.Key)
319+
{
320+
case VirtualKey.F2:
321+
if ((App.CurrentInstance.ContentPage).SelectedItems.Count > 0)
322+
{
323+
App.CurrentInstance.InteractionOperations.RenameItem_Click(null, null);
324+
}
325+
break;
326+
}
327+
}
328+
}
329+
330+
private void CloseTab()
331+
{
332+
if (((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.TabItems.Count == 1)
333+
{
334+
Application.Current.Exit();
335+
}
336+
else if (((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.TabItems.Count > 1)
337+
{
338+
((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.TabItems.RemoveAt(((Window.Current.Content as Frame).Content as InstanceTabsView).TabStrip.SelectedIndex);
339+
}
340+
}
341+
342+
private async void LaunchNewWindow()
343+
{
344+
var filesUWPUri = new Uri("files-uwp:");
345+
await Launcher.LaunchUriAsync(filesUWPUri);
346+
}
347+
276348
}
277349

278350
public enum InteractionOperationType

0 commit comments

Comments
 (0)