Skip to content

Commit 79ce505

Browse files
committed
Settings: fix creating/editing custom shortcuts
1 parent a26cdc4 commit 79ce505

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Flow.Launcher/CustomShortcutSetting.xaml.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
using Flow.Launcher.Core.Resource;
2-
using Flow.Launcher.ViewModel;
32
using System;
43
using System.Windows;
54
using System.Windows.Input;
5+
using Flow.Launcher.SettingPages.ViewModels;
66

77
namespace Flow.Launcher
88
{
99
public partial class CustomShortcutSetting : Window
1010
{
11+
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
1112
public string Key { get; set; } = String.Empty;
1213
public string Value { get; set; } = String.Empty;
13-
private string originalKey { get; init; } = null;
14-
private string originalValue { get; init; } = null;
15-
private bool update { get; init; } = false;
14+
private string originalKey { get; } = null;
15+
private string originalValue { get; } = null;
16+
private bool update { get; } = false;
1617

17-
public CustomShortcutSetting(SettingWindowViewModel vm)
18+
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
1819
{
20+
_hotkeyVm = vm;
1921
InitializeComponent();
2022
}
2123

22-
public CustomShortcutSetting(string key, string value)
24+
public CustomShortcutSetting(string key, string value, SettingsPaneHotkeyViewModel vm)
2325
{
2426
Key = key;
2527
Value = value;
2628
originalKey = key;
2729
originalValue = value;
2830
update = true;
31+
_hotkeyVm = vm;
2932
InitializeComponent();
3033
}
3134

@@ -43,7 +46,7 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
4346
return;
4447
}
4548
// Check if key is modified or adding a new one
46-
if ((update && originalKey != Key) || !update)
49+
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
4750
{
4851
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
4952
return;

Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows;
1+
using System.Linq;
2+
using System.Windows;
23
using CommunityToolkit.Mvvm.Input;
34
using Flow.Launcher.Core.Resource;
45
using Flow.Launcher.Helper;
@@ -114,7 +115,7 @@ private void CustomShortcutEdit()
114115
return;
115116
}
116117

117-
var window = new CustomShortcutSetting(item.Key, item.Value);
118+
var window = new CustomShortcutSetting(item.Key, item.Value, this);
118119
if (window.ShowDialog() is not true) return;
119120

120121
var index = Settings.CustomShortcuts.IndexOf(item);
@@ -124,11 +125,17 @@ private void CustomShortcutEdit()
124125
[RelayCommand]
125126
private void CustomShortcutAdd()
126127
{
127-
var window = new CustomShortcutSetting(null);
128+
var window = new CustomShortcutSetting(this);
128129
if (window.ShowDialog() is true)
129130
{
130131
var shortcut = new CustomShortcutModel(window.Key, window.Value);
131132
Settings.CustomShortcuts.Add(shortcut);
132133
}
133134
}
135+
136+
internal bool DoesShortcutExist(string key)
137+
{
138+
return Settings.CustomShortcuts.Any(v => v.Key == key) ||
139+
Settings.BuiltinShortcuts.Any(v => v.Key == key);
140+
}
134141
}

0 commit comments

Comments
 (0)