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