Skip to content

Commit 473626f

Browse files
Fix duplicates when editing
1 parent fc7ed31 commit 473626f

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

Flow.Launcher/CustomShortcutSetting.xaml.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Flow.Launcher.Core.Resource;
22
using Flow.Launcher.Infrastructure.UserSettings;
33
using System;
4+
using System.Linq;
45
using System.Windows;
56
using System.Windows.Input;
67

@@ -12,7 +13,7 @@ public partial class CustomShortcutSetting : Window
1213
private bool update = false;
1314
public string Key { get; set; }
1415
public string Value { get; set; }
15-
public CustomShortcutModel ShortCut => (Key, Value);
16+
public CustomShortcutModel ShortCut;
1617

1718
public CustomShortcutSetting(Settings settings)
1819
{
@@ -24,6 +25,7 @@ public CustomShortcutSetting(CustomShortcutModel shortcut, Settings settings)
2425
{
2526
Key = shortcut.Key;
2627
Value = shortcut.Value;
28+
ShortCut = shortcut;
2729
_settings = settings;
2830
update = true;
2931
InitializeComponent();
@@ -37,17 +39,32 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
3739

3840
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
3941
{
42+
bool modified = false;
4043
if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value))
4144
{
4245
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("emptyShortcut"));
4346
return;
4447
}
45-
if (!update && (_settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)) || _settings.BuiltinShortcuts.Contains(new BuiltinShortcutModel(Key, Value, null))))
48+
if (!update)
4649
{
47-
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("dulplicateShortcut"));
48-
return;
50+
ShortCut = new CustomShortcutModel(Key, Value);
51+
if (_settings.CustomShortcuts.Any(x => x.Key == Key) || _settings.BuiltinShortcuts.Any(x => x.Key == Key))
52+
{
53+
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
54+
return;
55+
}
56+
modified = true;
57+
}
58+
else
59+
{
60+
if (ShortCut.Key != Key && _settings.CustomShortcuts.Any(x => x.Key == Key) || _settings.BuiltinShortcuts.Any(x => x.Key == Key))
61+
{
62+
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut"));
63+
return;
64+
}
65+
modified = ShortCut.Key != Key || ShortCut.Value != Value;
4966
}
50-
DialogResult = true;
67+
DialogResult = modified;
5168
Close();
5269
}
5370

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
<!-- Custom Query Shortcut Dialog -->
249249
<system:String x:Key="customeQueryShortcutTitle">Custom Query Shortcut</system:String>
250250
<system:String x:Key="customeQueryShortcutTips">Enter a shortcut that automatically expands to the specified query.</system:String>
251-
<system:String x:Key="dulplicateShortcut">Shortcut is dulplicate, please enter a new Shortcut or edit the existing one.</system:String>
251+
<system:String x:Key="duplicateShortcut">Shortcut already exists, please enter a new Shortcut or edit the existing one.</system:String>
252252
<system:String x:Key="emptyShortcut">Shortcut and/or its expansion is empty.</system:String>
253253

254254
<!-- Hotkey Control -->

0 commit comments

Comments
 (0)