Assign Setting to Welcome Page

This commit is contained in:
Kevin Zhang 2021-12-01 20:53:54 -06:00
parent 7e2a3bc115
commit 05c1466b8b
9 changed files with 109 additions and 90 deletions

View file

@ -31,7 +31,7 @@ namespace Flow.Launcher
tbMsg.Visibility = Visibility.Hidden; tbMsg.Visibility = Visibility.Hidden;
//when alt is pressed, the real key should be e.SystemKey //when alt is pressed, the real key should be e.SystemKey
Key key = (e.Key == Key.System ? e.SystemKey : e.Key); Key key = e.Key == Key.System ? e.SystemKey : e.Key;
SpecialKeyState specialKeyState = GlobalHotkey.Instance.CheckModifiers(); SpecialKeyState specialKeyState = GlobalHotkey.Instance.CheckModifiers();

View file

@ -241,7 +241,7 @@ namespace Flow.Launcher
private void OpenWelcomeWindow() private void OpenWelcomeWindow()
{ {
Flow.Launcher.WelcomeWindow WelcomeWindow = new Flow.Launcher.WelcomeWindow(); Flow.Launcher.WelcomeWindow WelcomeWindow = new WelcomeWindow(_settings);
WelcomeWindow.Show(); WelcomeWindow.Show();
} }
private void ToggleGameMode() private void ToggleGameMode()

View file

@ -1,12 +1,12 @@
<Page <Page x:Class="Flow.Launcher.Resources.Pages.WelcomePage1"
x:Class="Flow.Launcher.Resources.Pages.WelcomePage1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Flow.Launcher.Resources.Pages"
xmlns:local="clr-namespace:Flow.Launcher.Resources.Pages" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Title="WelcomePage1"
Title="WelcomePage1" DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<Style x:Key="StyleImageFadeIn" TargetType="{x:Type Image}"> <Style x:Key="StyleImageFadeIn" TargetType="{x:Type Image}">
<Setter Property="Opacity" Value="0" /> <Setter Property="Opacity" Value="0" />
@ -17,10 +17,7 @@
<BeginStoryboard> <BeginStoryboard>
<BeginStoryboard.Storyboard> <BeginStoryboard.Storyboard>
<Storyboard x:Name="FadeIn"> <Storyboard x:Name="FadeIn">
<DoubleAnimation <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:2" />
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0:0:2" />
</Storyboard> </Storyboard>
</BeginStoryboard.Storyboard> </BeginStoryboard.Storyboard>
</BeginStoryboard> </BeginStoryboard>
@ -47,17 +44,15 @@
</Border.Background> </Border.Background>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal"> <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Image <Image Name="Logo"
Name="Logo" Width="60"
Width="60" Height="60"
Height="60" Source="../../images/app.png"
Source="../../images/app.png" Style="{DynamicResource StyleImageFadeIn}" />
Style="{DynamicResource StyleImageFadeIn}" /> <TextBlock Margin="12,0,0,0"
<TextBlock VerticalAlignment="Center"
Margin="12,0,0,0" FontSize="30"
VerticalAlignment="Center" Foreground="White">
FontSize="30"
Foreground="White">
Flow Launcher Flow Launcher
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
@ -65,32 +60,25 @@
<StackPanel Grid.Row="1" Margin="24,20,24,20"> <StackPanel Grid.Row="1" Margin="24,20,24,20">
<StackPanel> <StackPanel>
<TextBlock <TextBlock FontSize="20" FontWeight="SemiBold" Text="{DynamicResource Welcome_Page1_Title}" />
FontSize="20" <TextBlock Margin="0,10,0,0"
FontWeight="SemiBold" FontSize="14"
Text="{DynamicResource Welcome_Page1_Title}" /> Text="{DynamicResource Welcome_Page1_Text01}"
<TextBlock TextWrapping="WrapWithOverflow" />
Margin="0,10,0,0" <TextBlock Margin="0,10,0,0"
FontSize="14" FontSize="14"
Text="{DynamicResource Welcome_Page1_Text01}" Text="{DynamicResource Welcome_Page1_Text02}"
TextWrapping="WrapWithOverflow" /> TextWrapping="WrapWithOverflow" />
<TextBlock <TextBlock Margin="0,30,0,0"
Margin="0,10,0,0" FontSize="14"
FontSize="14" FontWeight="SemiBold"
Text="{DynamicResource Welcome_Page1_Text02}" Text="{DynamicResource language}" />
TextWrapping="WrapWithOverflow" /> <ComboBox Width="200"
<TextBlock Margin="0,10,0,0"
Margin="0,30,0,0" DisplayMemberPath="Display"
FontSize="14" ItemsSource="{Binding Languages}"
FontWeight="SemiBold" SelectedValue="{Binding CustomLanguage, Mode=TwoWay}"
Text="{DynamicResource language}" /> SelectedValuePath="LanguageCode" />
<ComboBox
Width="200"
Margin="0,10,0,0"
DisplayMemberPath="Display"
ItemsSource="{Binding Languages}"
SelectedValue="{Binding Language}"
SelectedValuePath="LanguageCode" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>

View file

@ -18,7 +18,7 @@ using System.Windows.Interop;
using Microsoft.Win32; using Microsoft.Win32;
using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure;
using Flow.Launcher.ViewModel; using Flow.Launcher.ViewModel;
using Flow.Launcher.Core.Resource;
namespace Flow.Launcher.Resources.Pages namespace Flow.Launcher.Resources.Pages
{ {
@ -27,10 +27,31 @@ namespace Flow.Launcher.Resources.Pages
/// </summary> /// </summary>
public partial class WelcomePage1 : Page public partial class WelcomePage1 : Page
{ {
public WelcomePage1()
{
public WelcomePage1(Settings settings)
{
Settings = settings;
InitializeComponent(); InitializeComponent();
} }
private Internationalization _translater => InternationalizationManager.Instance;
public List<Language> Languages => _translater.LoadAvailableLanguages();
public Settings Settings { get; }
public string CustomLanguage
{
get
{
return Settings.Language;
}
set
{
InternationalizationManager.Instance.ChangeLanguage(value);
if (InternationalizationManager.Instance.PromptShouldUsePinyin(value))
Settings.ShouldUsePinyin = true;
}
}
} }
} }

View file

@ -9,7 +9,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019" xmlns:ui="http://schemas.modernwpf.com/2019"
Title="WelcomePage2" Title="WelcomePage2"
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}"
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<converters:BorderClipConverter x:Key="BorderClipConverter" /> <converters:BorderClipConverter x:Key="BorderClipConverter" />

View file

@ -1,4 +1,6 @@
using System; using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.UserSettings;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -20,9 +22,21 @@ namespace Flow.Launcher.Resources.Pages
/// </summary> /// </summary>
public partial class WelcomePage2 : Page public partial class WelcomePage2 : Page
{ {
public WelcomePage2() private readonly Settings settings;
public WelcomePage2(Settings settings)
{ {
InitializeComponent(); InitializeComponent();
this.settings = settings;
HotkeyControl.HotkeyChanged += (_, _) =>
{
if (HotkeyControl.CurrentHotkeyAvailable)
{
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey);
HotKeyMapper.RemoveHotkey(settings.Hotkey);
settings.Hotkey = HotkeyControl.CurrentHotkey.ToString();
}
};
} }
} }
} }

View file

@ -27,9 +27,12 @@ namespace Flow.Launcher.Resources.Pages
public partial class WelcomePage5 : Page public partial class WelcomePage5 : Page
{ {
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"; private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
public WelcomePage5() private readonly Settings settings;
public WelcomePage5(Settings settings)
{ {
InitializeComponent(); InitializeComponent();
this.settings = settings;
} }
private void OnAutoStartupChecked(object sender, RoutedEventArgs e) private void OnAutoStartupChecked(object sender, RoutedEventArgs e)
@ -46,11 +49,13 @@ namespace Flow.Launcher.Resources.Pages
{ {
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true); using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
key?.DeleteValue(Constant.FlowLauncher, false); key?.DeleteValue(Constant.FlowLauncher, false);
settings.StartFlowLauncherOnSystemStartup = false;
} }
public static void SetStartup() public void SetStartup()
{ {
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true); using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath); key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath);
settings.StartFlowLauncherOnSystemStartup = true;
} }

View file

@ -132,7 +132,6 @@ namespace Flow.Launcher
{ {
if (HotkeyControl.CurrentHotkeyAvailable) if (HotkeyControl.CurrentHotkeyAvailable)
{ {
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey); HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey);
HotKeyMapper.RemoveHotkey(settings.Hotkey); HotKeyMapper.RemoveHotkey(settings.Hotkey);
settings.Hotkey = HotkeyControl.CurrentHotkey.ToString(); settings.Hotkey = HotkeyControl.CurrentHotkey.ToString();
@ -277,7 +276,7 @@ namespace Flow.Launcher
private void OpenWelcomeWindow(object sender, RoutedEventArgs e) private void OpenWelcomeWindow(object sender, RoutedEventArgs e)
{ {
Flow.Launcher.WelcomeWindow WelcomeWindow = new Flow.Launcher.WelcomeWindow(); Flow.Launcher.WelcomeWindow WelcomeWindow = new Flow.Launcher.WelcomeWindow(settings);
WelcomeWindow.Show(); WelcomeWindow.Show();
} }
private void OpenLogFolder(object sender, RoutedEventArgs e) private void OpenLogFolder(object sender, RoutedEventArgs e)

View file

@ -12,19 +12,31 @@ using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Resources.Pages;
using ModernWpf.Media.Animation; using ModernWpf.Media.Animation;
using Page = ModernWpf.Controls.Page;
using WelcomePages = Flow.Launcher.Resources.Pages;
namespace Flow.Launcher namespace Flow.Launcher
{ {
public partial class WelcomeWindow : Window public partial class WelcomeWindow : Window
{ {
public WelcomeWindow() private readonly List<Page> pages;
private readonly Settings settings;
public WelcomeWindow(Settings settings)
{ {
InitializeComponent(); InitializeComponent();
ContentFrame.Navigate(typeof(WelcomePages.WelcomePage1));
BackButton.IsEnabled = false; BackButton.IsEnabled = false;
this.settings = settings;
pages = new()
{
new WelcomePage1(settings),
new WelcomePage2(settings),
new WelcomePage3(),
new WelcomePage4(),
new WelcomePage5(settings),
};
ContentFrame.Navigate(pages[0]);
} }
private int page; private int page;
private int MaxPage = 5; private int MaxPage = 5;
@ -41,7 +53,7 @@ namespace Flow.Launcher
BackButton.IsEnabled = true; BackButton.IsEnabled = true;
NextButton.IsEnabled = false; NextButton.IsEnabled = false;
} }
else else
{ {
BackButton.IsEnabled = true; BackButton.IsEnabled = true;
NextButton.IsEnabled = true; NextButton.IsEnabled = true;
@ -49,39 +61,20 @@ namespace Flow.Launcher
} }
private NavigationTransitionInfo _transitionInfo = new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromRight }; private NavigationTransitionInfo _transitionInfo = new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromRight };
Storyboard sb = new Storyboard(); Storyboard sb = new Storyboard();
private static Type PageSelector(int a)
{
switch (a)
{
case 0:
return typeof(WelcomePages.WelcomePage1);
case 1:
return typeof(WelcomePages.WelcomePage2);
case 2:
return typeof(WelcomePages.WelcomePage3);
case 3:
return typeof(WelcomePages.WelcomePage4);
case 4:
return typeof(WelcomePages.WelcomePage5);
default:
return typeof(WelcomePages.WelcomePage1);
}
}
private void ForwardButton_Click(object sender, RoutedEventArgs e) private void ForwardButton_Click(object sender, RoutedEventArgs e)
{ {
page = page + 1; page = page + 1;
ButtonDisabler(); ButtonDisabler();
var pageToNavigateTo = PageSelector(page); var pageToNavigateTo = pages[page];
ContentFrame.Navigate(pageToNavigateTo, null, _transitionInfo);
ContentFrame.Navigate(pageToNavigateTo, _transitionInfo);
} }
private void BackwardButton_Click(object sender, RoutedEventArgs e) private void BackwardButton_Click(object sender, RoutedEventArgs e)
{ {
if (page > 0) if (page > 0)
{ {
page = page - 1; page--;
ButtonDisabler(); ButtonDisabler();
ContentFrame.GoBack(); ContentFrame.GoBack();
} }