-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLaunchItem.cs
More file actions
142 lines (123 loc) · 3.62 KB
/
LaunchItem.cs
File metadata and controls
142 lines (123 loc) · 3.62 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Imaging.Interop;
namespace CodingWithCalvin.LaunchyBar.Models;
/// <summary>
/// Represents a single item in the LaunchyBar.
/// </summary>
public sealed class LaunchItem : INotifyPropertyChanged
{
private string _iconPath = string.Empty;
private string _name = string.Empty;
private bool _isActive;
/// <inheritdoc/>
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// Unique identifier for the launch item.
/// </summary>
public string Id { get; set; } = Guid.NewGuid().ToString();
/// <summary>
/// Display name shown in tooltip.
/// </summary>
public string Name
{
get => _name;
set
{
if (_name != value)
{
_name = value;
OnPropertyChanged();
}
}
}
/// <summary>
/// Path to icon file, embedded resource, or VS ImageMoniker name.
/// </summary>
public string IconPath
{
get => _iconPath;
set
{
if (_iconPath != value)
{
_iconPath = value;
OnPropertyChanged();
OnPropertyChanged(nameof(IconMoniker));
}
}
}
/// <summary>
/// The type of action this item performs.
/// </summary>
public LaunchItemType Type { get; set; } = LaunchItemType.VsCommand;
/// <summary>
/// The target of the action: executable path, command ID, or tool window GUID.
/// </summary>
public string Target { get; set; } = string.Empty;
/// <summary>
/// Optional command-line arguments for external programs.
/// </summary>
public string? Arguments { get; set; }
/// <summary>
/// Optional working directory for external programs.
/// </summary>
public string? WorkingDirectory { get; set; }
/// <summary>
/// Where this item appears in the bar.
/// </summary>
public LaunchItemPosition Position { get; set; } = LaunchItemPosition.Top;
/// <summary>
/// Sort order within the position group.
/// </summary>
public int Order { get; set; }
/// <summary>
/// Whether this item is enabled.
/// </summary>
public bool IsEnabled { get; set; } = true;
/// <summary>
/// Whether this item's tool window is currently visible.
/// </summary>
[JsonIgnore]
public bool IsActive
{
get => _isActive;
set
{
if (_isActive != value)
{
_isActive = value;
OnPropertyChanged();
}
}
}
/// <summary>
/// Gets the ImageMoniker for this item's icon.
/// </summary>
[JsonIgnore]
public ImageMoniker IconMoniker => GetIconMoniker();
private ImageMoniker GetIconMoniker()
{
if (string.IsNullOrEmpty(IconPath))
{
return KnownMonikers.QuestionMark;
}
if (IconPath.StartsWith("KnownMonikers."))
{
var monikerName = IconPath.Substring("KnownMonikers.".Length);
var property = typeof(KnownMonikers).GetProperty(monikerName);
if (property != null)
{
return (ImageMoniker)property.GetValue(null)!;
}
}
return KnownMonikers.QuestionMark;
}
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}