Merge pull request #290 from NLick47/main

feat: 新增导航对鼠标回退键的支持
This commit is contained in:
yaobiao131
2025-05-13 20:43:12 +08:00
committed by GitHub
18 changed files with 54 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Threading;
using DownKyi.Core.Settings;
using DownKyi.Events;
@@ -17,6 +19,10 @@ public class MainWindowViewModel : BindableBase
{
private readonly IEventAggregator _eventAggregator;
private readonly IRegionManager _regionManager;
private const string ContentRegion = nameof(ContentRegion);
private ClipboardListener? _clipboardListener;
private bool _messageVisibility;
@@ -50,6 +56,9 @@ public class MainWindowViewModel : BindableBase
public DelegateCommand ClosingCommand => _closingCommand ??= _closingCommand = new DelegateCommand(ExecuteClosingCommand);
public DelegateCommand<PointerPressedEventArgs> PointerPressedCommand =>
new (ExecutePointerPressed);
private void ExecuteClosingCommand()
{
if (_clipboardListener == null) return;
@@ -57,11 +66,29 @@ public class MainWindowViewModel : BindableBase
_clipboardListener.Dispose();
}
private void ExecutePointerPressed(PointerPressedEventArgs e)
{
var point = e.GetCurrentPoint(null);
var updateKind = point.Properties.PointerUpdateKind;
if (updateKind == PointerUpdateKind.XButton1Pressed)
{
var v = GetCurrentUserControl()?.DataContext;
if (v is ViewModelBase vm)
{
vm.ExecuteBackSpace();
e.Handled = true;
}
}
}
private UserControl? GetCurrentUserControl() => _regionManager
.Regions[ContentRegion].ActiveViews
.FirstOrDefault() as UserControl;
public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
_regionManager = regionManager;
#region MyRegion
_eventAggregator.GetEvent<NavigationEvent>().Subscribe(view =>
@@ -71,7 +98,7 @@ public class MainWindowViewModel : BindableBase
{ "Parent", view.ParentViewName },
{ "Parameter", view.Parameter }
};
regionManager.RequestNavigate("ContentRegion", view.ViewName, param);
regionManager.RequestNavigate(ContentRegion, view.ViewName, param);
});
// 订阅消息发送事件

View File

@@ -69,7 +69,7 @@ public class ViewDownloadManagerViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
var parameter = new NavigationParam
{

View File

@@ -76,7 +76,7 @@ namespace DownKyi.ViewModels
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
//InitView();

View File

@@ -55,7 +55,7 @@ public class ViewLoginViewModel : ViewModelBase
public DelegateCommand BackSpaceCommand => _backSpaceCommand ??= new DelegateCommand(ExecuteBackSpace);
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
// 初始化状态
InitStatus();

View File

@@ -34,6 +34,11 @@ public class ViewModelBase : BindableBase, INavigationAware
ParentView = viewName;
}
}
protected internal virtual void ExecuteBackSpace()
{
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
@@ -61,4 +66,5 @@ public class ViewModelBase : BindableBase, INavigationAware
{
Dispatcher.UIThread.Invoke(callback);
}
}

View File

@@ -184,7 +184,7 @@ public class ViewMyBangumiFollowViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
InitView();

View File

@@ -215,7 +215,7 @@ public class ViewMyFavoritesViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
InitView();

View File

@@ -146,7 +146,7 @@ public class ViewMyHistoryViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
InitView();

View File

@@ -330,7 +330,7 @@ public class ViewMySpaceViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
// 结束任务
_tokenSource?.Cancel();

View File

@@ -136,7 +136,7 @@ public class ViewMyToViewVideoViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
InitView();

View File

@@ -165,7 +165,7 @@ public class ViewPublicFavoritesViewModel : ViewModelBase
/// <summary>
/// 返回
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
// 结束任务
_tokenSource?.Cancel();

View File

@@ -173,7 +173,7 @@ namespace DownKyi.ViewModels
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
ArrowBack.Fill = DictionaryResource.GetColor("ColorText");

View File

@@ -164,7 +164,7 @@ public class ViewSeasonsSeriesViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
ArrowBack.Fill = DictionaryResource.GetColor("ColorText");

View File

@@ -75,7 +75,7 @@ public class ViewSettingsViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
var parameter = new NavigationParam
{

View File

@@ -62,7 +62,7 @@ namespace DownKyi.ViewModels
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
var parameter = new NavigationParam
{

View File

@@ -214,7 +214,7 @@ public class ViewUserSpaceViewModel : ViewModelBase
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
var parameter = new NavigationParam
{

View File

@@ -153,7 +153,7 @@ public class ViewVideoDetailViewModel : ViewModelBase
/// <summary>
/// 返回
/// </summary>
private void ExecuteBackSpace()
protected internal override void ExecuteBackSpace()
{
var parameter = new NavigationParam
{

View File

@@ -21,6 +21,10 @@
<EventTriggerBehavior EventName="Opened">
<InvokeCommandAction Command="{Binding LoadedCommand}" />
</EventTriggerBehavior>
<EventTriggerBehavior EventName="PointerPressed">
<InvokeCommandAction Command="{Binding PointerPressedCommand}"
PassEventArgsToCommand="True"/>
</EventTriggerBehavior>
</Interaction.Behaviors>
<Grid RowDefinitions="*">
<ContentControl prism:RegionManager.RegionName="ContentRegion" />