mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Fix page number issue when navigating with keyboard
This commit is contained in:
parent
c68a764dcf
commit
8ce4bd92e2
9 changed files with 132 additions and 47 deletions
|
|
@ -64,6 +64,7 @@ namespace Flow.Launcher
|
|||
.AddSingleton<IPublicAPI, PublicAPIInstance>()
|
||||
.AddSingleton<MainViewModel>()
|
||||
.AddSingleton<Theme>()
|
||||
.AddSingleton<WelcomeViewModel>()
|
||||
).Build();
|
||||
Ioc.Default.ConfigureServices(host.Services);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Windows.Navigation;
|
|||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher.Resources.Pages
|
||||
{
|
||||
|
|
@ -11,6 +12,9 @@ namespace Flow.Launcher.Resources.Pages
|
|||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 1;
|
||||
InitializeComponent();
|
||||
}
|
||||
private Internationalization _translater => InternationalizationManager.Instance;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ namespace Flow.Launcher.Resources.Pages
|
|||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 2;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher.Resources.Pages
|
||||
{
|
||||
|
|
@ -9,6 +10,9 @@ namespace Flow.Launcher.Resources.Pages
|
|||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace Flow.Launcher.Resources.Pages
|
||||
|
|
@ -9,6 +10,9 @@ namespace Flow.Launcher.Resources.Pages
|
|||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 4;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using Flow.Launcher.Infrastructure.UserSettings;
|
|||
using Microsoft.Win32;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher.Resources.Pages
|
||||
{
|
||||
|
|
@ -16,6 +17,9 @@ namespace Flow.Launcher.Resources.Pages
|
|||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 5;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
|
|||
68
Flow.Launcher/ViewModel/WelcomeViewModel.cs
Normal file
68
Flow.Launcher/ViewModel/WelcomeViewModel.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.ViewModel
|
||||
{
|
||||
public partial class WelcomeViewModel : BaseModel
|
||||
{
|
||||
public const int MaxPageNum = 5;
|
||||
|
||||
public string PageDisplay => $"{PageNum}/5";
|
||||
|
||||
private int _pageNum = 1;
|
||||
public int PageNum
|
||||
{
|
||||
get => _pageNum;
|
||||
set
|
||||
{
|
||||
if (_pageNum != value)
|
||||
{
|
||||
_pageNum = value;
|
||||
OnPropertyChanged();
|
||||
UpdateView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _backEnabled = false;
|
||||
public bool BackEnabled
|
||||
{
|
||||
get => _backEnabled;
|
||||
set
|
||||
{
|
||||
_backEnabled = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _nextEnabled = true;
|
||||
public bool NextEnabled
|
||||
{
|
||||
get => _nextEnabled;
|
||||
set
|
||||
{
|
||||
_nextEnabled = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateView()
|
||||
{
|
||||
OnPropertyChanged(nameof(PageDisplay));
|
||||
if (PageNum == 1)
|
||||
{
|
||||
BackEnabled = false;
|
||||
NextEnabled = true;
|
||||
}
|
||||
else if (PageNum == MaxPageNum)
|
||||
{
|
||||
BackEnabled = true;
|
||||
NextEnabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
BackEnabled = true;
|
||||
NextEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
xmlns:local="clr-namespace:Flow.Launcher"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.modernwpf.com/2019"
|
||||
xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
|
||||
Name="FlowWelcomeWindow"
|
||||
Title="{DynamicResource Welcome_Page1_Title}"
|
||||
Width="550"
|
||||
|
|
@ -14,8 +15,10 @@
|
|||
MinHeight="650"
|
||||
MaxWidth="550"
|
||||
MaxHeight="650"
|
||||
d:DataContext="{d:DesignInstance Type=vm:WelcomeViewModel}"
|
||||
Activated="OnActivated"
|
||||
Background="{DynamicResource Color00B}"
|
||||
Closed="Window_Closed"
|
||||
Foreground="{DynamicResource PopupTextColor}"
|
||||
MouseDown="window_MouseDown"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
|
|
@ -41,12 +44,12 @@
|
|||
Grid.Column="0"
|
||||
Width="16"
|
||||
Height="16"
|
||||
Margin="10,4,4,4"
|
||||
Margin="10 4 4 4"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
Source="/Images/app.png" />
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="4,0,0,0"
|
||||
Margin="4 0 0 0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="12"
|
||||
Foreground="{DynamicResource Color05B}"
|
||||
|
|
@ -95,7 +98,7 @@
|
|||
Grid.Row="1"
|
||||
Background="{DynamicResource Color00B}"
|
||||
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
|
||||
BorderThickness="0,1,0,0">
|
||||
BorderThickness="0 1 0 0">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="130" />
|
||||
|
|
@ -109,11 +112,11 @@
|
|||
VerticalAlignment="Center">
|
||||
<TextBlock
|
||||
Name="PageNavigation"
|
||||
Margin="0,2,0,0"
|
||||
Margin="0 2 0 0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="14"
|
||||
Text="{Binding PageDisplay, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
|
||||
Text="{Binding PageDisplay, Mode=OneWay}"
|
||||
TextAlignment="Center" />
|
||||
</StackPanel>
|
||||
|
||||
|
|
@ -122,25 +125,26 @@
|
|||
Grid.Column="0"
|
||||
Width="100"
|
||||
Height="40"
|
||||
Margin="20,5,0,5"
|
||||
Margin="20 5 0 5"
|
||||
Click="BtnCancel_OnClick"
|
||||
Content="{DynamicResource Skip}"
|
||||
DockPanel.Dock="Right"
|
||||
FontSize="14" />
|
||||
<DockPanel
|
||||
Grid.Column="2"
|
||||
Margin="0,0,20,0"
|
||||
Margin="0 0 20 0"
|
||||
VerticalAlignment="Stretch">
|
||||
<Button
|
||||
x:Name="NextButton"
|
||||
Width="40"
|
||||
Height="40"
|
||||
Margin="8,5,0,5"
|
||||
Margin="8 5 0 5"
|
||||
Click="ForwardButton_Click"
|
||||
Content=""
|
||||
DockPanel.Dock="Right"
|
||||
FontFamily="/Resources/#Segoe Fluent Icons"
|
||||
FontSize="18" />
|
||||
FontSize="18"
|
||||
IsEnabled="{Binding NextEnabled, Mode=OneWay}" />
|
||||
<Button
|
||||
x:Name="BackButton"
|
||||
Width="40"
|
||||
|
|
@ -149,7 +153,8 @@
|
|||
Content=""
|
||||
DockPanel.Dock="Right"
|
||||
FontFamily="/Resources/#Segoe Fluent Icons"
|
||||
FontSize="18" />
|
||||
FontSize="18"
|
||||
IsEnabled="{Binding BackEnabled, Mode=OneWay}" />
|
||||
<StackPanel />
|
||||
</DockPanel>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,69 +4,55 @@ using System.Windows.Input;
|
|||
using System.Windows.Controls;
|
||||
using Flow.Launcher.Resources.Pages;
|
||||
using ModernWpf.Media.Animation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
public partial class WelcomeWindow : Window
|
||||
{
|
||||
public WelcomeWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
BackButton.IsEnabled = false;
|
||||
}
|
||||
private readonly WelcomeViewModel _viewModel;
|
||||
|
||||
private NavigationTransitionInfo _transitionInfo = new SlideNavigationTransitionInfo()
|
||||
private readonly NavigationTransitionInfo _forwardTransitionInfo = new SlideNavigationTransitionInfo()
|
||||
{
|
||||
Effect = SlideNavigationTransitionEffect.FromRight
|
||||
};
|
||||
private NavigationTransitionInfo _backTransitionInfo = new SlideNavigationTransitionInfo()
|
||||
private readonly NavigationTransitionInfo _backTransitionInfo = new SlideNavigationTransitionInfo()
|
||||
{
|
||||
Effect = SlideNavigationTransitionEffect.FromLeft
|
||||
};
|
||||
|
||||
private int pageNum = 1;
|
||||
private int MaxPage = 5;
|
||||
public string PageDisplay => $"{pageNum}/5";
|
||||
|
||||
private void UpdateView()
|
||||
public WelcomeWindow()
|
||||
{
|
||||
PageNavigation.Text = PageDisplay;
|
||||
if (pageNum == 1)
|
||||
{
|
||||
BackButton.IsEnabled = false;
|
||||
NextButton.IsEnabled = true;
|
||||
}
|
||||
else if (pageNum == MaxPage)
|
||||
{
|
||||
BackButton.IsEnabled = true;
|
||||
NextButton.IsEnabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
BackButton.IsEnabled = true;
|
||||
NextButton.IsEnabled = true;
|
||||
}
|
||||
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ForwardButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
pageNum++;
|
||||
UpdateView();
|
||||
|
||||
ContentFrame.Navigate(PageTypeSelector(pageNum), null, _transitionInfo);
|
||||
if (_viewModel.PageNum < WelcomeViewModel.MaxPageNum)
|
||||
{
|
||||
_viewModel.PageNum++;
|
||||
ContentFrame.Navigate(PageTypeSelector(_viewModel.PageNum), null, _forwardTransitionInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
_viewModel.NextEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void BackwardButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (pageNum > 1)
|
||||
if (_viewModel.PageNum > 1)
|
||||
{
|
||||
pageNum--;
|
||||
UpdateView();
|
||||
ContentFrame.Navigate(PageTypeSelector(pageNum), null, _backTransitionInfo);
|
||||
_viewModel.PageNum--;
|
||||
ContentFrame.Navigate(PageTypeSelector(_viewModel.PageNum), null, _backTransitionInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
BackButton.IsEnabled = false;
|
||||
_viewModel.BackEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,5 +93,11 @@ namespace Flow.Launcher
|
|||
{
|
||||
ContentFrame.Navigate(PageTypeSelector(1)); /* Set First Page */
|
||||
}
|
||||
|
||||
private void Window_Closed(object sender, EventArgs e)
|
||||
{
|
||||
// Save settings when window is closed
|
||||
Ioc.Default.GetRequiredService<Settings>().Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue