Move CustomShortcutModel definition to a new file

1. Move CustomShortcutModel definition to a new file
2. Some other minor tweaks
This commit is contained in:
Vic 2022-10-06 02:20:51 +08:00
parent 099b1d6ed1
commit 99d18077f3
4 changed files with 58 additions and 43 deletions

View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flow.Launcher.Infrastructure.UserSettings
{
public class CustomShortcutModel
{
public string Key { get; set; }
public string Value { get; set; }
public CustomShortcutModel(string key, string value)
{
Key = key;
Value = value;
}
public override bool Equals(object obj)
{
return obj is CustomShortcutModel other &&
Key == other.Key &&
Value == other.Value;
}
public override int GetHashCode()
{
return HashCode.Combine(Key, Value);
}
public void Deconstruct(out string key, out string value)
{
key = Key;
value = Value;
}
public static implicit operator (string Key, string Value)(CustomShortcutModel shortcut)
{
return (shortcut.Key, shortcut.Value);
}
public static implicit operator CustomShortcutModel((string Key, string Value) shortcut)
{
return new CustomShortcutModel(shortcut.Key, shortcut.Value);
}
}
}

View file

@ -220,44 +220,4 @@ namespace Flow.Launcher.Infrastructure.UserSettings
Light,
Dark
}
public struct CustomShortcutModel
{
public string Key { get; set; }
public string Value { get; set; }
public CustomShortcutModel(string key, string value)
{
Key = key;
Value = value;
}
public override bool Equals(object obj)
{
return obj is CustomShortcutModel other &&
Key == other.Key &&
Value == other.Value;
}
public override int GetHashCode()
{
return HashCode.Combine(Key, Value);
}
public void Deconstruct(out string key, out string value)
{
key = Key;
value = Value;
}
public static implicit operator (string Key, string Value)(CustomShortcutModel value)
{
return (value.Key, value.Value);
}
public static implicit operator CustomShortcutModel((string Key, string Value) value)
{
return new CustomShortcutModel(value.Key, value.Value);
}
}
}

View file

@ -14,12 +14,12 @@ namespace Flow.Launcher
{
private SettingWindow _settingWidow;
private bool update;
private CustomPluginHotkey updateCustomHotkey;
private Settings _settings;
public string Key { get; set; }
public string Value { get; set; }
public CustomShortcutModel ShortCut => (Key, Value);
public CustomShortcutSetting()
{
InitializeComponent();

View file

@ -365,11 +365,14 @@ namespace Flow.Launcher
restoreButton.Visibility = Visibility.Collapsed;
}
}
private void Window_StateChanged(object sender, EventArgs e)
{
RefreshMaximizeRestoreButton();
}
#region Shortcut
private void OnDeleteCustomShortCutClick(object sender, RoutedEventArgs e)
{
var item = viewModel.SelectedCustomShortcut;
@ -386,15 +389,16 @@ namespace Flow.Launcher
MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
settings.CustomShortcuts.Remove(item.Value);
settings.CustomShortcuts.Remove(item);
}
}
private void OnEditCustomShortCutClick(object sender, RoutedEventArgs e)
{
var item = viewModel.SelectedCustomShortcut;
if (item != null)
{
var shortcutSettingWindow = new CustomShortcutSetting(item.Value);
var shortcutSettingWindow = new CustomShortcutSetting(item);
if (shortcutSettingWindow.ShowDialog() == true)
{
settings.CustomShortcuts[viewModel.SelectCustomShortcutIndex.Value] = shortcutSettingWindow.ShortCut;
@ -414,5 +418,8 @@ namespace Flow.Launcher
settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut);
}
}
#endregion
}
}