Merge branch 'dev' into velopack

This commit is contained in:
Jeremy Wu 2024-06-21 16:08:52 +10:00 committed by GitHub
commit cb77f8d92f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 11 deletions

View file

@ -1,31 +1,34 @@
using Flow.Launcher.Core.Resource;
using Flow.Launcher.ViewModel;
using System;
using System.Windows;
using System.Windows.Input;
using Flow.Launcher.SettingPages.ViewModels;
namespace Flow.Launcher
{
public partial class CustomShortcutSetting : Window
{
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
public string Key { get; set; } = String.Empty;
public string Value { get; set; } = String.Empty;
private string originalKey { get; init; } = null;
private string originalValue { get; init; } = null;
private bool update { get; init; } = false;
private string originalKey { get; } = null;
private string originalValue { get; } = null;
private bool update { get; } = false;
public CustomShortcutSetting(SettingWindowViewModel vm)
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
{
_hotkeyVm = vm;
InitializeComponent();
}
public CustomShortcutSetting(string key, string value)
public CustomShortcutSetting(string key, string value, SettingsPaneHotkeyViewModel vm)
{
Key = key;
Value = value;
originalKey = key;
originalValue = value;
update = true;
_hotkeyVm = vm;
InitializeComponent();
}
@ -43,7 +46,7 @@ namespace Flow.Launcher
return;
}
// 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"));
return;

View file

@ -93,7 +93,7 @@
<!-- ModernWpfUI v0.9.5 introduced WinRT changes that causes Notification platform unavailable error on some machines -->
<!-- https://github.com/Flow-Launcher/Flow.Launcher/issues/1772#issuecomment-1502440801 -->
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
<PackageReference Include="NHotkey.Wpf" Version="2.1.1" />
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
<PackageReference Include="Velopack" Version="0.0.359" />
<PackageReference Include="SemanticVersioning" Version="3.0.0-beta2" />

View file

@ -1,4 +1,5 @@
using System.Windows;
using System.Linq;
using System.Windows;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
@ -114,7 +115,7 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
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;
var index = Settings.CustomShortcuts.IndexOf(item);
@ -124,11 +125,17 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
[RelayCommand]
private void CustomShortcutAdd()
{
var window = new CustomShortcutSetting(null);
var window = new CustomShortcutSetting(this);
if (window.ShowDialog() is true)
{
var shortcut = new CustomShortcutModel(window.Key, window.Value);
Settings.CustomShortcuts.Add(shortcut);
}
}
internal bool DoesShortcutExist(string key)
{
return Settings.CustomShortcuts.Any(v => v.Key == key) ||
Settings.BuiltinShortcuts.Any(v => v.Key == key);
}
}