-
-
Notifications
You must be signed in to change notification settings - Fork 363
/
Copy pathCustomShortcutModel.cs
106 lines (84 loc) · 2.79 KB
/
CustomShortcutModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Flow.Launcher.Infrastructure.UserSettings
{
#region Base
public abstract class ShortcutBaseModel
{
public string Key { get; set; }
public override bool Equals(object obj)
{
return obj is ShortcutBaseModel other &&
Key == other.Key;
}
public override int GetHashCode()
{
return Key.GetHashCode();
}
}
public class BaseCustomShortcutModel : ShortcutBaseModel
{
public string Value { get; set; }
public BaseCustomShortcutModel(string key, string value)
{
Key = key;
Value = value;
}
public void Deconstruct(out string key, out string value)
{
key = Key;
value = Value;
}
public static implicit operator (string Key, string Value)(BaseCustomShortcutModel shortcut)
{
return (shortcut.Key, shortcut.Value);
}
public static implicit operator BaseCustomShortcutModel((string Key, string Value) shortcut)
{
return new BaseCustomShortcutModel(shortcut.Key, shortcut.Value);
}
}
public class BaseBuiltinShortcutModel : ShortcutBaseModel
{
public string Description { get; set; }
public BaseBuiltinShortcutModel(string key, string description)
{
Key = key;
Description = description;
}
}
#endregion
#region Custom Shortcut
public class CustomShortcutModel : BaseCustomShortcutModel
{
[JsonIgnore]
public Func<string> Expand { get; set; } = () => { return string.Empty; };
[JsonConstructor]
public CustomShortcutModel(string key, string value) : base(key, value)
{
Expand = () => { return Value; };
}
}
#endregion
#region Builtin Shortcut
public class BuiltinShortcutModel : BaseBuiltinShortcutModel
{
[JsonIgnore]
public Func<string> Expand { get; set; } = () => { return string.Empty; };
public BuiltinShortcutModel(string key, string description, Func<string> expand) : base(key, description)
{
Expand = expand ?? (() => { return string.Empty; });
}
}
public class AsyncBuiltinShortcutModel : BaseBuiltinShortcutModel
{
[JsonIgnore]
public Func<Task<string>> ExpandAsync { get; set; } = () => { return Task.FromResult(string.Empty); };
public AsyncBuiltinShortcutModel(string key, string description, Func<Task<string>> expandAsync) : base(key, description)
{
ExpandAsync = expandAsync ?? (() => { return Task.FromResult(string.Empty); });
}
}
#endregion
}