mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Fix custom hotkey preview issue
This commit is contained in:
parent
08931347b0
commit
d73f3a165b
7 changed files with 33 additions and 23 deletions
|
|
@ -7,20 +7,23 @@ using System.Windows;
|
|||
using System.Windows.Input;
|
||||
using System.Windows.Controls;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
public partial class CustomQueryHotkeySetting : Window
|
||||
{
|
||||
private SettingWindow _settingWidow;
|
||||
private readonly Settings _settings;
|
||||
private readonly MainViewModel _mainViewModel;
|
||||
private bool update;
|
||||
private CustomPluginHotkey updateCustomHotkey;
|
||||
public Settings Settings { get; }
|
||||
|
||||
public CustomQueryHotkeySetting(SettingWindow settingWidow, Settings settings)
|
||||
public CustomQueryHotkeySetting(SettingWindow settingWidow, Settings settings, MainViewModel mainVM)
|
||||
{
|
||||
_settingWidow = settingWidow;
|
||||
Settings = settings;
|
||||
_settings = settings;
|
||||
_mainViewModel = mainVM;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
@ -33,13 +36,13 @@ namespace Flow.Launcher
|
|||
{
|
||||
if (!update)
|
||||
{
|
||||
Settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
|
||||
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
|
||||
|
||||
var pluginHotkey = new CustomPluginHotkey
|
||||
{
|
||||
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
|
||||
};
|
||||
Settings.CustomPluginHotkeys.Add(pluginHotkey);
|
||||
_settings.CustomPluginHotkeys.Add(pluginHotkey);
|
||||
|
||||
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
|
||||
}
|
||||
|
|
@ -59,7 +62,7 @@ namespace Flow.Launcher
|
|||
|
||||
public void UpdateItem(CustomPluginHotkey item)
|
||||
{
|
||||
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
|
||||
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
|
||||
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
|
||||
if (updateCustomHotkey == null)
|
||||
{
|
||||
|
|
@ -77,8 +80,7 @@ namespace Flow.Launcher
|
|||
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.API.ChangeQuery(tbAction.Text);
|
||||
Application.Current.MainWindow.Show();
|
||||
Application.Current.MainWindow.Opacity = 1;
|
||||
_mainViewModel.Show(false);
|
||||
Application.Current.MainWindow.Focus();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,21 +4,24 @@ using System.Windows;
|
|||
using System.Windows.Input;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
public partial class CustomShortcutSetting : Window
|
||||
{
|
||||
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
|
||||
private readonly MainViewModel _mainViewModel;
|
||||
public string Key { get; set; } = String.Empty;
|
||||
public string Value { get; set; } = String.Empty;
|
||||
private string originalKey { get; } = null;
|
||||
private string originalValue { get; } = null;
|
||||
private bool update { get; } = false;
|
||||
|
||||
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
|
||||
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm, MainViewModel mainVM)
|
||||
{
|
||||
_hotkeyVm = vm;
|
||||
_mainViewModel = mainVM;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
@ -65,8 +68,7 @@ namespace Flow.Launcher
|
|||
private void BtnTestShortcut_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.API.ChangeQuery(tbExpand.Text);
|
||||
Application.Current.MainWindow.Show();
|
||||
Application.Current.MainWindow.Opacity = 1;
|
||||
_mainViewModel.Show(false);
|
||||
Application.Current.MainWindow.Focus();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ namespace Flow.Launcher
|
|||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsVM);
|
||||
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsVM, _mainVM);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,14 @@ using Flow.Launcher.Infrastructure.Hotkey;
|
|||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.ViewModels;
|
||||
|
||||
public partial class SettingsPaneHotkeyViewModel : BaseModel
|
||||
{
|
||||
public Settings Settings { get; }
|
||||
private MainViewModel MainVM { get; }
|
||||
|
||||
public CustomPluginHotkey SelectedCustomPluginHotkey { get; set; }
|
||||
public CustomShortcutModel SelectedCustomShortcut { get; set; }
|
||||
|
|
@ -25,9 +27,10 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
|
|||
$"{KeyConstant.Ctrl}+{KeyConstant.Alt}"
|
||||
};
|
||||
|
||||
public SettingsPaneHotkeyViewModel(Settings settings)
|
||||
public SettingsPaneHotkeyViewModel(Settings settings, MainViewModel mainVM)
|
||||
{
|
||||
Settings = settings;
|
||||
MainVM = mainVM;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
|
@ -71,7 +74,7 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
|
|||
return;
|
||||
}
|
||||
|
||||
var window = new CustomQueryHotkeySetting(null, Settings);
|
||||
var window = new CustomQueryHotkeySetting(null, Settings, MainVM);
|
||||
window.UpdateItem(item);
|
||||
window.ShowDialog();
|
||||
}
|
||||
|
|
@ -79,7 +82,7 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
|
|||
[RelayCommand]
|
||||
private void CustomHotkeyAdd()
|
||||
{
|
||||
new CustomQueryHotkeySetting(null, Settings).ShowDialog();
|
||||
new CustomQueryHotkeySetting(null, Settings, MainVM).ShowDialog();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
|
@ -126,7 +129,7 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
|
|||
[RelayCommand]
|
||||
private void CustomShortcutAdd()
|
||||
{
|
||||
var window = new CustomShortcutSetting(this);
|
||||
var window = new CustomShortcutSetting(this, MainVM);
|
||||
if (window.ShowDialog() is true)
|
||||
{
|
||||
var shortcut = new CustomShortcutModel(window.Key, window.Value);
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ public partial class SettingsPaneHotkey
|
|||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings })
|
||||
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, MainViewModel: { } mainVM })
|
||||
throw new ArgumentException("Settings are required for SettingsPaneHotkey.");
|
||||
_viewModel = new SettingsPaneHotkeyViewModel(settings);
|
||||
_viewModel = new SettingsPaneHotkeyViewModel(settings, mainVM);
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,14 @@ public partial class SettingWindow
|
|||
private readonly IPublicAPI _api;
|
||||
private readonly Settings _settings;
|
||||
private readonly SettingWindowViewModel _viewModel;
|
||||
private readonly MainViewModel _mainVM;
|
||||
|
||||
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
|
||||
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel, MainViewModel mainVM)
|
||||
{
|
||||
_settings = viewModel.Settings;
|
||||
DataContext = viewModel;
|
||||
_viewModel = viewModel;
|
||||
_mainVM = mainVM;
|
||||
_api = api;
|
||||
InitializePosition();
|
||||
InitializeComponent();
|
||||
|
|
@ -160,7 +162,7 @@ public partial class SettingWindow
|
|||
|
||||
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
|
||||
{
|
||||
var paneData = new PaneData(_settings, _viewModel.Updater, _viewModel.Portable);
|
||||
var paneData = new PaneData(_settings, _viewModel.Updater, _viewModel.Portable, _mainVM);
|
||||
if (args.IsSettingsSelected)
|
||||
{
|
||||
ContentFrame.Navigate(typeof(SettingsPaneGeneral), paneData);
|
||||
|
|
@ -206,5 +208,5 @@ public partial class SettingWindow
|
|||
NavView.SelectedItem ??= NavView.MenuItems[0]; /* Set First Page */
|
||||
}
|
||||
|
||||
public record PaneData(Settings Settings, Updater Updater, IPortable Portable);
|
||||
public record PaneData(Settings Settings, Updater Updater, IPortable Portable, MainViewModel MainViewModel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1359,7 +1359,7 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
public void Show()
|
||||
public void Show(bool invokeEvent = true)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
|
|
@ -1368,7 +1368,8 @@ namespace Flow.Launcher.ViewModel
|
|||
MainWindowOpacity = 1;
|
||||
|
||||
MainWindowVisibilityStatus = true;
|
||||
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
|
||||
if (invokeEvent)
|
||||
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue