Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public App()
.AddSingleton<IPublicAPI, PublicAPIInstance>()
.AddSingleton<MainViewModel>()
.AddSingleton<Theme>()
.AddSingleton<WelcomeViewModel>()
).Build();
Ioc.Default.ConfigureServices(host.Services);
}
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/CustomQueryHotkeySetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
HorizontalAlignment="Left"
VerticalAlignment="Center"
HorizontalContentAlignment="Left"
HotkeySettings="{Binding Settings}"
DefaultHotkey="" />
<TextBlock
Grid.Row="1"
Expand Down
139 changes: 118 additions & 21 deletions Flow.Launcher/HotkeyControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.UserSettings;

namespace Flow.Launcher
{
public partial class HotkeyControl
{
public IHotkeySettings HotkeySettings {
get { return (IHotkeySettings)GetValue(HotkeySettingsProperty); }
set { SetValue(HotkeySettingsProperty, value); }
}

public static readonly DependencyProperty HotkeySettingsProperty = DependencyProperty.Register(
nameof(HotkeySettings),
typeof(IHotkeySettings),
typeof(HotkeyControl),
new PropertyMetadata()
);
public string WindowTitle {
get { return (string)GetValue(WindowTitleProperty); }
set { SetValue(WindowTitleProperty, value); }
Expand Down Expand Up @@ -71,8 +62,7 @@ private static void OnHotkeyChanged(DependencyObject d, DependencyPropertyChange
return;
}

hotkeyControl.SetKeysToDisplay(new HotkeyModel(hotkeyControl.Hotkey));
hotkeyControl.CurrentHotkey = new HotkeyModel(hotkeyControl.Hotkey);
hotkeyControl.RefreshHotkeyInterface(hotkeyControl.Hotkey);
}


Expand All @@ -90,25 +80,132 @@ public ICommand? ChangeHotkey
}


public static readonly DependencyProperty HotkeyProperty = DependencyProperty.Register(
nameof(Hotkey),
typeof(string),
public static readonly DependencyProperty TypeProperty = DependencyProperty.Register(
nameof(Type),
typeof(HotkeyType),
typeof(HotkeyControl),
new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHotkeyChanged)
new FrameworkPropertyMetadata(HotkeyType.Hotkey, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHotkeyChanged)
);

public HotkeyType Type
{
get { return (HotkeyType)GetValue(TypeProperty); }
set { SetValue(TypeProperty, value); }
}

public enum HotkeyType
{
Hotkey,
PreviewHotkey,
OpenContextMenuHotkey,
SettingWindowHotkey,
CycleHistoryUpHotkey,
CycleHistoryDownHotkey,
SelectPrevPageHotkey,
SelectNextPageHotkey,
AutoCompleteHotkey,
AutoCompleteHotkey2,
SelectPrevItemHotkey,
SelectPrevItemHotkey2,
SelectNextItemHotkey,
SelectNextItemHotkey2
}

// We can initialize settings in static field because it has been constructed in App constuctor
// and it will not construct settings instances twice
private static readonly Settings _settings = Ioc.Default.GetRequiredService<Settings>();

public string Hotkey
{
get { return (string)GetValue(HotkeyProperty); }
set { SetValue(HotkeyProperty, value); }
get
{
return Type switch
{
HotkeyType.Hotkey => _settings.Hotkey,
HotkeyType.PreviewHotkey => _settings.PreviewHotkey,
HotkeyType.OpenContextMenuHotkey => _settings.OpenContextMenuHotkey,
HotkeyType.SettingWindowHotkey => _settings.SettingWindowHotkey,
HotkeyType.CycleHistoryUpHotkey => _settings.CycleHistoryUpHotkey,
HotkeyType.CycleHistoryDownHotkey => _settings.CycleHistoryDownHotkey,
HotkeyType.SelectPrevPageHotkey => _settings.SelectPrevPageHotkey,
HotkeyType.SelectNextPageHotkey => _settings.SelectNextPageHotkey,
HotkeyType.AutoCompleteHotkey => _settings.AutoCompleteHotkey,
HotkeyType.AutoCompleteHotkey2 => _settings.AutoCompleteHotkey2,
HotkeyType.SelectPrevItemHotkey => _settings.SelectPrevItemHotkey,
HotkeyType.SelectPrevItemHotkey2 => _settings.SelectPrevItemHotkey2,
HotkeyType.SelectNextItemHotkey => _settings.SelectNextItemHotkey,
HotkeyType.SelectNextItemHotkey2 => _settings.SelectNextItemHotkey2,
_ => string.Empty
};
}
set
{
switch (Type)
{
case HotkeyType.Hotkey:
_settings.Hotkey = value;
break;
case HotkeyType.PreviewHotkey:
_settings.PreviewHotkey = value;
break;
case HotkeyType.OpenContextMenuHotkey:
_settings.OpenContextMenuHotkey = value;
break;
case HotkeyType.SettingWindowHotkey:
_settings.SettingWindowHotkey = value;
break;
case HotkeyType.CycleHistoryUpHotkey:
_settings.CycleHistoryUpHotkey = value;
break;
case HotkeyType.CycleHistoryDownHotkey:
_settings.CycleHistoryDownHotkey = value;
break;
case HotkeyType.SelectPrevPageHotkey:
_settings.SelectPrevPageHotkey = value;
break;
case HotkeyType.SelectNextPageHotkey:
_settings.SelectNextPageHotkey = value;
break;
case HotkeyType.AutoCompleteHotkey:
_settings.AutoCompleteHotkey = value;
break;
case HotkeyType.AutoCompleteHotkey2:
_settings.AutoCompleteHotkey2 = value;
break;
case HotkeyType.SelectPrevItemHotkey:
_settings.SelectPrevItemHotkey = value;
break;
case HotkeyType.SelectNextItemHotkey:
_settings.SelectNextItemHotkey = value;
break;
case HotkeyType.SelectPrevItemHotkey2:
_settings.SelectPrevItemHotkey2 = value;
break;
case HotkeyType.SelectNextItemHotkey2:
_settings.SelectNextItemHotkey2 = value;
break;
default:
return;
}

// After setting the hotkey, we need to refresh the interface
RefreshHotkeyInterface(Hotkey);
}
}

public HotkeyControl()
{
InitializeComponent();

HotkeyList.ItemsSource = KeysToDisplay;
SetKeysToDisplay(CurrentHotkey);

RefreshHotkeyInterface(Hotkey);
}

private void RefreshHotkeyInterface(string hotkey)
{
SetKeysToDisplay(new HotkeyModel(Hotkey));
CurrentHotkey = new HotkeyModel(Hotkey);
}

private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) =>
Expand All @@ -133,7 +230,7 @@ private async Task OpenHotkeyDialog()
HotKeyMapper.RemoveHotkey(Hotkey);
}

var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, HotkeySettings, WindowTitle);
var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, WindowTitle);
await dialog.ShowAsync();
switch (dialog.ResultType)
{
Expand Down
7 changes: 4 additions & 3 deletions Flow.Launcher/HotkeyControlDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Windows;
using System.Windows.Input;
using ChefKeys;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using ModernWpf.Controls;

Expand All @@ -16,7 +18,7 @@ namespace Flow.Launcher;

public partial class HotkeyControlDialog : ContentDialog
{
private IHotkeySettings _hotkeySettings;
private static readonly IHotkeySettings _hotkeySettings = Ioc.Default.GetRequiredService<Settings>();
private Action? _overwriteOtherHotkey;
private string DefaultHotkey { get; }
public string WindowTitle { get; }
Expand All @@ -36,7 +38,7 @@ public enum EResultType

private static bool isOpenFlowHotkey;

public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings hotkeySettings, string windowTitle = "")
public HotkeyControlDialog(string hotkey, string defaultHotkey, string windowTitle = "")
{
WindowTitle = windowTitle switch
{
Expand All @@ -45,7 +47,6 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings
};
DefaultHotkey = defaultHotkey;
CurrentHotkey = new HotkeyModel(hotkey);
_hotkeySettings = hotkeySettings;
SetKeysToDisplay(CurrentHotkey);

InitializeComponent();
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private void CheckFirstLaunch()

private void OpenWelcomeWindow()
{
var WelcomeWindow = new WelcomeWindow(_settings);
var WelcomeWindow = new WelcomeWindow();
WelcomeWindow.Show();
}

Expand Down
15 changes: 8 additions & 7 deletions Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
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
{
public partial class WelcomePage1
{
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.ExtraData is Settings settings)
Settings = settings;
else
throw new ArgumentException("Unexpected Navigation Parameter for Settings");
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;
Expand All @@ -37,4 +38,4 @@ public string CustomLanguage
}

}
}
}
3 changes: 1 addition & 2 deletions Flow.Launcher/Resources/Pages/WelcomePage2.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@
Margin="0,8,0,0"
ChangeHotkey="{Binding SetTogglingHotkeyCommand}"
DefaultHotkey="Alt+Space"
Hotkey="{Binding Settings.Hotkey}"
HotkeySettings="{Binding Settings}"
Type="Hotkey"
ValidateKeyGesture="True"
WindowTitle="{DynamicResource flowlauncherHotkey}" />
</StackPanel>
Expand Down
11 changes: 5 additions & 6 deletions Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.UserSettings;
using System;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.ViewModel;
using System.Windows.Media;
using CommunityToolkit.Mvvm.DependencyInjection;

namespace Flow.Launcher.Resources.Pages
{
Expand All @@ -15,11 +15,10 @@ public partial class WelcomePage2

protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.ExtraData is Settings settings)
Settings = settings;
else
throw new ArgumentException("Unexpected Parameter setting.");

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();
}

Expand Down
13 changes: 7 additions & 6 deletions Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System;
using System.Windows.Navigation;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.ViewModel;

namespace Flow.Launcher.Resources.Pages
{
public partial class WelcomePage3
{
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.ExtraData is Settings settings)
Settings = settings;
else if(Settings is null)
throw new ArgumentException("Unexpected Navigation Parameter for Settings");
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();
}

Expand Down
13 changes: 7 additions & 6 deletions Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Flow.Launcher.Infrastructure.UserSettings;
using System;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.ViewModel;
using System.Windows.Navigation;

namespace Flow.Launcher.Resources.Pages
Expand All @@ -8,10 +9,10 @@ public partial class WelcomePage4
{
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.ExtraData is Settings settings)
Settings = settings;
else
throw new ArgumentException("Unexpected Navigation Parameter for Settings");
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();
}

Expand Down
13 changes: 7 additions & 6 deletions Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Windows;
using System.Windows;
using System.Windows.Navigation;
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
{
Expand All @@ -15,10 +16,10 @@ public partial class WelcomePage5

protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.ExtraData is Settings settings)
Settings = settings;
else
throw new ArgumentException("Unexpected Navigation Parameter for Settings");
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();
}

Expand Down
Loading
Loading