Add check for invalid query shortcuts

This commit is contained in:
Jack251970 2025-07-02 15:17:18 +08:00
parent d0fc344b54
commit c4ce8fe580
3 changed files with 13 additions and 2 deletions

View file

@ -43,12 +43,14 @@ namespace Flow.Launcher
App.API.ShowMsgBox(App.API.GetTranslation("emptyShortcut"));
return;
}
// Check if key is modified or adding a new one
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
{
App.API.ShowMsgBox(App.API.GetTranslation("duplicateShortcut"));
return;
}
DialogResult = !update || originalKey != Key || originalValue != Value;
Close();
}

View file

@ -446,6 +446,7 @@
</system:String>
<system:String x:Key="duplicateShortcut">Shortcut already exists, please enter a new Shortcut or edit the existing one.</system:String>
<system:String x:Key="emptyShortcut">Shortcut and/or its expansion is empty.</system:String>
<system:String x:Key="invalidShortcut">Shortcut is invalid</system:String>
<!-- Common Action -->
<system:String x:Key="commonSave">Save</system:String>

View file

@ -107,10 +107,18 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
return;
}
var window = new CustomShortcutSetting(item.Key, item.Value, this);
var settingItem = Settings.CustomShortcuts.FirstOrDefault(o =>
o.Key == item.Key && o.Value == item.Value);
if (settingItem == null)
{
App.API.ShowMsgBox(App.API.GetTranslation("invalidShortcut"));
return;
}
var window = new CustomShortcutSetting(settingItem.Key, settingItem.Value, this);
if (window.ShowDialog() is not true) return;
var index = Settings.CustomShortcuts.IndexOf(item);
var index = Settings.CustomShortcuts.IndexOf(settingItem);
Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value);
}