Skip to content

Commit

Permalink
chore: Ability to use mouse 4 and mouse 5 to navigate backward and fo…
Browse files Browse the repository at this point in the history
…rward
  • Loading branch information
Jorixon committed Nov 11, 2023
1 parent 38ec6ec commit d3647d4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ namespace GIMI_ModManager.WinUI.Contracts.Services;
public interface INavigationService
{
event NavigatedEventHandler Navigated;

bool CanGoForward { get; }
bool CanGoBack { get; }

Frame? Frame { get; set; }

bool NavigateTo(string pageKey, object? parameter = null, bool clearNavigation = false);
bool GoForward();

bool GoBack();
void SetListDataItemForNextConnectedAnimation(object item);
Expand Down
20 changes: 20 additions & 0 deletions src/GIMI-ModManager.WinUI/Services/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public Frame? Frame
[MemberNotNullWhen(true, nameof(Frame), nameof(_frame))]
public bool CanGoBack => Frame != null && Frame.CanGoBack;

[MemberNotNullWhen(true, nameof(Frame), nameof(_frame))]
public bool CanGoForward => Frame != null && Frame.CanGoForward;

public NavigationService(IPageService pageService)
{
_pageService = pageService;
Expand All @@ -63,6 +66,23 @@ private void UnregisterFrameEvents()
}
}

public bool GoForward()
{
if (CanGoForward)
{
var vmBeforeNavigation = _frame.GetPageViewModel();
_frame.GoForward();
if (vmBeforeNavigation is INavigationAware navigationAware)
{
navigationAware.OnNavigatedFrom();
}

return true;
}

return false;
}

public bool GoBack()
{
if (CanGoBack)
Expand Down
25 changes: 25 additions & 0 deletions src/GIMI-ModManager.WinUI/Views/ShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using GIMI_ModManager.WinUI.Contracts.Services;
using GIMI_ModManager.WinUI.Helpers;
using GIMI_ModManager.WinUI.ViewModels;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
Expand Down Expand Up @@ -36,6 +37,7 @@ public ShellPage(ShellViewModel viewModel)
AppTitleBarText.Text += " - DEBUG";
#endif
KeyDown += GlobalKeyHandler_Invoked;
PointerPressed += GlobalMouseHandler_Invoked;

Loaded += (sender, args) =>
{
Expand Down Expand Up @@ -64,6 +66,29 @@ public ShellPage(ShellViewModel viewModel)
#endif
}

private void GlobalMouseHandler_Invoked(object sender, PointerRoutedEventArgs e)
{
if (!IsEnabled)
return;

// Check if mouse 4 or 5 is clicked
var mouseButton = e.GetCurrentPoint(this).Properties.PointerUpdateKind;

if (mouseButton is not (PointerUpdateKind.XButton1Pressed or PointerUpdateKind.XButton2Pressed)) return;

var navigationService = App.GetService<INavigationService>();

switch (mouseButton)
{
case PointerUpdateKind.XButton1Pressed when navigationService.CanGoBack:
navigationService.GoBack();
break;
case PointerUpdateKind.XButton2Pressed when navigationService.CanGoForward:
navigationService.GoForward();
break;
}
}


private void OnLoaded(object sender, RoutedEventArgs e)
{
Expand Down

0 comments on commit d3647d4

Please sign in to comment.