Flow.Launcher/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs

63 lines
1.7 KiB
C#
Raw Normal View History

2022-10-13 12:14:32 +00:00
using System;
2022-10-08 08:33:39 +00:00
using System.Text.Json.Serialization;
namespace Flow.Launcher.Infrastructure.UserSettings
{
2022-10-13 11:49:44 +00:00
public class CustomShortcutModel
{
public string Key { get; set; }
2022-10-13 11:49:44 +00:00
public string Value { get; set; }
2022-10-13 12:14:32 +00:00
[JsonIgnore]
public bool CanBeEdited { get; private set; } // Can be edited by user from settings window
2022-10-08 08:33:39 +00:00
[JsonIgnore]
public Func<string> Expand { get; set; } = () => { return ""; };
2022-10-13 12:14:32 +00:00
[JsonConstructorAttribute]
2022-10-13 11:49:44 +00:00
public CustomShortcutModel(string key, string value)
{
2022-10-13 11:49:44 +00:00
Key = key;
Value = value;
CanBeEdited = true;
Expand = () => { return Value; };
}
2022-10-13 11:49:44 +00:00
public CustomShortcutModel(string key, string description, Func<string> expand)
{
2022-10-13 11:49:44 +00:00
Key = key;
Value = description;
CanBeEdited = false;
Expand = expand;
2022-10-08 08:33:39 +00:00
}
2022-10-13 11:49:44 +00:00
public override bool Equals(object obj)
2022-10-08 08:33:39 +00:00
{
2022-10-13 11:49:44 +00:00
return obj is CustomShortcutModel other &&
Key == other.Key;
2022-10-08 08:33:39 +00:00
}
2022-10-13 11:49:44 +00:00
public override int GetHashCode()
2022-10-08 08:33:39 +00:00
{
2022-10-13 11:49:44 +00:00
return HashCode.Combine(Key);
}
public void Deconstruct(out string key, out string value)
{
key = Key;
2022-10-13 16:42:05 +00:00
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);
}
}
}