From 473626f16e07233e1fae9ab133f28dbac0273281 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Fri, 4 Nov 2022 14:28:02 +0800 Subject: [PATCH] Fix duplicates when editing --- Flow.Launcher/CustomShortcutSetting.xaml.cs | 27 +++++++++++++++++---- Flow.Launcher/Languages/en.xaml | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher/CustomShortcutSetting.xaml.cs b/Flow.Launcher/CustomShortcutSetting.xaml.cs index 524ea69ed..45ec8871b 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml.cs +++ b/Flow.Launcher/CustomShortcutSetting.xaml.cs @@ -1,6 +1,7 @@ using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure.UserSettings; using System; +using System.Linq; using System.Windows; using System.Windows.Input; @@ -12,7 +13,7 @@ namespace Flow.Launcher private bool update = false; public string Key { get; set; } public string Value { get; set; } - public CustomShortcutModel ShortCut => (Key, Value); + public CustomShortcutModel ShortCut; public CustomShortcutSetting(Settings settings) { @@ -24,6 +25,7 @@ namespace Flow.Launcher { Key = shortcut.Key; Value = shortcut.Value; + ShortCut = shortcut; _settings = settings; update = true; InitializeComponent(); @@ -37,17 +39,32 @@ namespace Flow.Launcher private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { + bool modified = false; if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value)) { MessageBox.Show(InternationalizationManager.Instance.GetTranslation("emptyShortcut")); return; } - if (!update && (_settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)) || _settings.BuiltinShortcuts.Contains(new BuiltinShortcutModel(Key, Value, null)))) + if (!update) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("dulplicateShortcut")); - return; + ShortCut = new CustomShortcutModel(Key, Value); + if (_settings.CustomShortcuts.Any(x => x.Key == Key) || _settings.BuiltinShortcuts.Any(x => x.Key == Key)) + { + MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut")); + return; + } + modified = true; } - DialogResult = true; + else + { + if (ShortCut.Key != Key && _settings.CustomShortcuts.Any(x => x.Key == Key) || _settings.BuiltinShortcuts.Any(x => x.Key == Key)) + { + MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut")); + return; + } + modified = ShortCut.Key != Key || ShortCut.Value != Value; + } + DialogResult = modified; Close(); } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 94a301ace..ead42c460 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -248,7 +248,7 @@ Custom Query Shortcut Enter a shortcut that automatically expands to the specified query. - Shortcut is dulplicate, please enter a new Shortcut or edit the existing one. + Shortcut already exists, please enter a new Shortcut or edit the existing one. Shortcut and/or its expansion is empty.