mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #2796 from Flow-Launcher/fix-custom-shortcuts-not-working-after-settings-split
Settings: fix creating/editing custom shortcuts
This commit is contained in:
commit
c65ac7be99
2 changed files with 20 additions and 10 deletions
|
|
@ -1,31 +1,34 @@
|
||||||
using Flow.Launcher.Core.Resource;
|
using Flow.Launcher.Core.Resource;
|
||||||
using Flow.Launcher.ViewModel;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Flow.Launcher.SettingPages.ViewModels;
|
||||||
|
|
||||||
namespace Flow.Launcher
|
namespace Flow.Launcher
|
||||||
{
|
{
|
||||||
public partial class CustomShortcutSetting : Window
|
public partial class CustomShortcutSetting : Window
|
||||||
{
|
{
|
||||||
|
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
|
||||||
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; init; } = null;
|
private string originalKey { get; } = null;
|
||||||
private string originalValue { get; init; } = null;
|
private string originalValue { get; } = null;
|
||||||
private bool update { get; init; } = false;
|
private bool update { get; } = false;
|
||||||
|
|
||||||
public CustomShortcutSetting(SettingWindowViewModel vm)
|
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
|
||||||
{
|
{
|
||||||
|
_hotkeyVm = vm;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomShortcutSetting(string key, string value)
|
public CustomShortcutSetting(string key, string value, SettingsPaneHotkeyViewModel vm)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
Value = value;
|
Value = value;
|
||||||
originalKey = key;
|
originalKey = key;
|
||||||
originalValue = value;
|
originalValue = value;
|
||||||
update = true;
|
update = true;
|
||||||
|
_hotkeyVm = vm;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +46,7 @@ namespace Flow.Launcher
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check if key is modified or adding a new one
|
// Check if key is modified or adding a new one
|
||||||
if ((update && originalKey != Key) || !update)
|
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
|
||||||
{
|
{
|
||||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Windows;
|
using System.Linq;
|
||||||
|
using System.Windows;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Flow.Launcher.Core.Resource;
|
using Flow.Launcher.Core.Resource;
|
||||||
using Flow.Launcher.Helper;
|
using Flow.Launcher.Helper;
|
||||||
|
|
@ -114,7 +115,7 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var window = new CustomShortcutSetting(item.Key, item.Value);
|
var window = new CustomShortcutSetting(item.Key, item.Value, this);
|
||||||
if (window.ShowDialog() is not true) return;
|
if (window.ShowDialog() is not true) return;
|
||||||
|
|
||||||
var index = Settings.CustomShortcuts.IndexOf(item);
|
var index = Settings.CustomShortcuts.IndexOf(item);
|
||||||
|
|
@ -124,11 +125,17 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private void CustomShortcutAdd()
|
private void CustomShortcutAdd()
|
||||||
{
|
{
|
||||||
var window = new CustomShortcutSetting(null);
|
var window = new CustomShortcutSetting(this);
|
||||||
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);
|
||||||
Settings.CustomShortcuts.Add(shortcut);
|
Settings.CustomShortcuts.Add(shortcut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal bool DoesShortcutExist(string key)
|
||||||
|
{
|
||||||
|
return Settings.CustomShortcuts.Any(v => v.Key == key) ||
|
||||||
|
Settings.BuiltinShortcuts.Any(v => v.Key == key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue