Skip to content

Commit 16eb3d0

Browse files
authored
Merge pull request #2307 from marticliment/better-keyboard-navigation
Keyboard navigation
2 parents 0fc55a0 + 1ea44dd commit 16eb3d0

File tree

6 files changed

+116
-41
lines changed

6 files changed

+116
-41
lines changed

src/UniGetUI/Interface/MainView.xaml.cs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.UI.Xaml.Documents;
66
using Microsoft.UI.Xaml.Media;
77
using UniGetUI.Core.Data;
8+
using UniGetUI.Core.Logging;
89
using UniGetUI.Core.SettingsEngine;
910
using UniGetUI.Core.Tools;
1011
using UniGetUI.Interface.Dialogs;
@@ -92,23 +93,47 @@ public MainView()
9293

9394
KeyUp += (s, e) =>
9495
{
95-
if (e.Key == Windows.System.VirtualKey.Tab && InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down))
96+
bool IS_CONTROL_PRESSED = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
97+
bool IS_SHIFT_PRESSED = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
98+
99+
if (e.Key == Windows.System.VirtualKey.Tab && IS_CONTROL_PRESSED)
96100
{
97101
if (CurrentPage != null)
98-
if (!InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down))
102+
{
103+
if (!IS_SHIFT_PRESSED)
99104
{
100-
if (NextPageReference.ContainsKey(CurrentPage))
101-
NextPageReference[CurrentPage].ForceClick();
102-
else
103-
DiscoverNavButton.ForceClick();
105+
if (NextPageReference.ContainsKey(CurrentPage)) NextPageReference[CurrentPage].ForceClick();
106+
else DiscoverNavButton.ForceClick();
104107
}
105108
else
106109
{
107-
if (NextPageReference.ContainsKey(CurrentPage))
108-
PreviousTabReference[CurrentPage].ForceClick();
109-
else
110-
DiscoverNavButton.ForceClick();
110+
if (PreviousTabReference.ContainsKey(CurrentPage)) PreviousTabReference[CurrentPage].ForceClick();
111+
else DiscoverNavButton.ForceClick();
111112
}
113+
}
114+
}
115+
else if (e.Key == Windows.System.VirtualKey.F1)
116+
{
117+
HelpMenu_Click(s, e);
118+
}
119+
else if (IS_CONTROL_PRESSED && (e.Key == Windows.System.VirtualKey.Q || e.Key == Windows.System.VirtualKey.W))
120+
{
121+
MainApp.Instance.MainWindow.Close();
122+
}
123+
else if(CurrentPage is IPageWithKeyboardShortcuts)
124+
{
125+
if (e.Key == Windows.System.VirtualKey.F5 || (IS_CONTROL_PRESSED && e.Key == Windows.System.VirtualKey.R))
126+
{
127+
(CurrentPage as IPageWithKeyboardShortcuts)?.ReloadTriggered();
128+
}
129+
else if (IS_CONTROL_PRESSED && e.Key == Windows.System.VirtualKey.F)
130+
{
131+
(CurrentPage as IPageWithKeyboardShortcuts)?.SearchTriggered();
132+
}
133+
else if (IS_CONTROL_PRESSED && e.Key == Windows.System.VirtualKey.A)
134+
{
135+
(CurrentPage as IPageWithKeyboardShortcuts)?.SelectAllTriggered();
136+
}
112137
}
113138
};
114139
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Windows.ApplicationModel.VoiceCommands;
7+
8+
namespace UniGetUI.Interface.Pages
9+
{
10+
interface IPageWithKeyboardShortcuts
11+
{
12+
public void SearchTriggered();
13+
14+
public void ReloadTriggered();
15+
16+
public void SelectAllTriggered();
17+
}
18+
}

src/UniGetUI/Interface/Pages/LogPage.xaml.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public enum Logger_LogType
2828
OperationHistory
2929
}
3030

31-
public sealed partial class Logger_LogPage : Page
31+
public sealed partial class Logger_LogPage : Page, IPageWithKeyboardShortcuts
3232
{
3333
private int LOG_LEVEL = 4;
3434
public Logger_LogType Logger_LogType;
@@ -66,6 +66,19 @@ public Logger_LogPage(Logger_LogType logger_LogType = Logger_LogType.UniGetUILog
6666
}
6767
}
6868

69+
public void ReloadTriggered()
70+
{
71+
LoadLog();
72+
}
73+
74+
public void SelectAllTriggered()
75+
{
76+
LogTextBox.SelectAll();
77+
}
78+
79+
public void SearchTriggered()
80+
{ }
81+
6982
public void SetText(string body)
7083
{
7184
Paragraph paragraph = new();

src/UniGetUI/Interface/SoftwarePages/AbstractPackagesPage.xaml.cs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using UniGetUI.Core.SettingsEngine;
99
using UniGetUI.Core.Tools;
1010
using UniGetUI.Interface.Enums;
11+
using UniGetUI.Interface.Pages;
1112
using UniGetUI.Interface.Widgets;
1213
using UniGetUI.PackageEngine.Classes.Manager.ManagerHelpers;
1314
using UniGetUI.PackageEngine.Enums;
@@ -22,7 +23,7 @@
2223
namespace UniGetUI.Interface
2324
{
2425

25-
public abstract partial class AbstractPackagesPage : Page
26+
public abstract partial class AbstractPackagesPage : Page, IPageWithKeyboardShortcuts
2627
{
2728
protected bool DISABLE_AUTOMATIC_PACKAGE_LOAD_ON_START = false;
2829
protected bool MEGA_QUERY_BOX_ENABLED = false;
@@ -233,40 +234,25 @@ public AbstractPackagesPage()
233234

234235
PackageList.KeyUp += (s, e) =>
235236
{
237+
bool IS_CONTROL_PRESSED = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
238+
bool IS_SHIFT_PRESSED = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
239+
bool IS_ALT_PRESSED = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
240+
236241
if (e.Key == Windows.System.VirtualKey.Enter && PackageList.SelectedItem != null)
237242
{
238-
if (InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down))
243+
if (IS_ALT_PRESSED)
239244
ShowInstallationOptionsForPackage(PackageList.SelectedItem as Package);
240-
else if (InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down))
245+
else if (IS_CONTROL_PRESSED)
241246
PerformMainPackageAction(PackageList.SelectedItem as Package);
242247
else
243248
ShowDetailsForPackage(PackageList.SelectedItem as Package);
244-
}
245-
else if (e.Key == Windows.System.VirtualKey.A && InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down))
246-
{
247-
if (AllSelected)
248-
ClearItemSelection();
249-
else
250-
SelectAllItems();
251-
}
252-
else if (e.Key == Windows.System.VirtualKey.Space && PackageList.SelectedItem != null)
249+
}
250+
else if (e.Key == Windows.System.VirtualKey.Space)
253251
{
254252
Package? package = PackageList.SelectedItem as Package;
255253
if(package != null)
256254
package.IsChecked = !package.IsChecked;
257255
}
258-
else if (e.Key == Windows.System.VirtualKey.F5)
259-
{
260-
_ = LoadPackages(ReloadReason.Manual);
261-
}
262-
else if (e.Key == Windows.System.VirtualKey.F1)
263-
{
264-
MainApp.Instance.MainWindow.NavigationPage.ShowHelp();
265-
}
266-
else if (e.Key == Windows.System.VirtualKey.F && InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down))
267-
{
268-
QueryBlock.Focus(FocusState.Programmatic);
269-
}
270256
};
271257

272258
int width = 250;
@@ -289,6 +275,24 @@ public AbstractPackagesPage()
289275
MegaQueryBlock.PlaceholderText = CoreTools.Translate("Search for packages");
290276
}
291277

278+
public void SearchTriggered()
279+
{
280+
QueryBlock.Focus(FocusState.Pointer);
281+
}
282+
283+
public void ReloadTriggered()
284+
{
285+
_ = LoadPackages(ReloadReason.Manual);
286+
}
287+
288+
public void SelectAllTriggered()
289+
{
290+
if (AllSelected)
291+
ClearItemSelection();
292+
else
293+
SelectAllItems();
294+
}
295+
292296
protected void AddPackageToSourcesList(Package package)
293297
{
294298
if (!Initialized)

src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using UniGetUI.Core.Logging;
1313
using UniGetUI.Core.SettingsEngine;
1414
using UniGetUI.Core.Tools;
15+
using UniGetUI.Interface.Pages;
1516
using UniGetUI.Interface.Widgets;
1617
using UniGetUI.PackageEngine.Classes;
1718
using UniGetUI.PackageEngine.Classes.Manager.ManagerHelpers;
@@ -26,7 +27,7 @@
2627

2728
namespace UniGetUI.Interface
2829
{
29-
public partial class PackageBundlePage : Page
30+
public partial class PackageBundlePage : Page, IPageWithKeyboardShortcuts
3031
{
3132
public ObservableCollection<BundledPackage> Packages = new();
3233
public SortableObservableCollection<BundledPackage> FilteredPackages = new() { SortingSelector = (a) => (a.Package.Name) };
@@ -139,10 +140,6 @@ public PackageBundlePage()
139140
{
140141
MainApp.Instance.MainWindow.NavigationPage.ShowHelp();
141142
}
142-
else if (e.Key == Windows.System.VirtualKey.F && InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down))
143-
{
144-
QueryBlock.Focus(FocusState.Programmatic);
145-
}
146143
};
147144

148145
int width = 250;
@@ -163,6 +160,24 @@ public PackageBundlePage()
163160
}
164161

165162

163+
public void SearchTriggered()
164+
{
165+
QueryBlock.Focus(FocusState.Pointer);
166+
}
167+
168+
public void ReloadTriggered()
169+
{
170+
}
171+
172+
public void SelectAllTriggered()
173+
{
174+
if (AllSelected)
175+
ClearItemSelection();
176+
else
177+
SelectAllItems();
178+
}
179+
180+
166181
protected void AddPackageToSourcesList(Package package)
167182
{
168183
if (!Initialized)

src/UniGetUI/UniGetUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.0.240109" />
7878
<PackageReference Include="CommunityToolkit.WinUI.Notifications" Version="7.1.2" />
7979
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.0.131" />
80-
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
80+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240607001" />
8181
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
8282
<PackageReference Include="Nancy" Version="2.0.0" />
8383
<PackageReference Include="Nancy.Hosting.Self" Version="2.0.0">

0 commit comments

Comments
 (0)