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

66 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-15 06:18:54 +00:00
public abstract class ShortcutBaseModel
{
public string Key { get; set; }
2022-10-08 08:33:39 +00:00
[JsonIgnore]
public Func<string> Expand { get; set; } = () => { return ""; };
2022-10-13 11:49:44 +00:00
public override bool Equals(object obj)
2022-10-08 08:33:39 +00:00
{
2022-10-15 06:29:19 +00:00
return obj is ShortcutBaseModel other &&
2022-10-13 11:49:44 +00:00
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-11-03 17:13:29 +00:00
return Key.GetHashCode();
}
2022-10-15 06:18:54 +00:00
}
public class CustomShortcutModel : ShortcutBaseModel
{
public string Value { get; set; }
[JsonConstructorAttribute]
public CustomShortcutModel(string key, string value)
{
Key = key;
Value = value;
Expand = () => { return Value; };
}
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);
}
}
2022-10-15 06:18:54 +00:00
public class BuiltinShortcutModel : ShortcutBaseModel
{
public string Description { get; set; }
public BuiltinShortcutModel(string key, string description, Func<string> expand)
{
Key = key;
Description = description;
2022-11-03 17:44:23 +00:00
Expand = expand ?? (() => { return ""; });
2022-10-15 06:18:54 +00:00
}
}
}