forked from HamidMosalla/VisualStudio-ColorCoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorCoderPackage.cs
More file actions
364 lines (324 loc) · 13.4 KB
/
Copy pathColorCoderPackage.cs
File metadata and controls
364 lines (324 loc) · 13.4 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
using ColorCoder.Classifications;
using ColorCoder.ColorCoderCore;
using ColorCoder.Types;
using Microsoft.VisualStudio.Shell;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using Task = System.Threading.Tasks.Task;
namespace ColorCoder
{
[Guid(Guids.ChangeColorOptionGrid)]
public class ChangeColorOptionGrid : DialogPage
{
private ColorManager _colorManager;
private const string ColorSubCategory = "Colors";
[Category(ColorSubCategory)]
[DisplayName("Class")]
public Color Class
{
get { return _colorManager.Get(ColorCoderClassificationName.Class); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Class, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Delegate")]
public Color Delegate
{
get { return _colorManager.Get(ColorCoderClassificationName.Delegate); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Delegate, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Interface")]
public Color Interface
{
get { return _colorManager.Get(ColorCoderClassificationName.Interface); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Interface, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Struct")]
public Color Struct
{
get { return _colorManager.Get(ColorCoderClassificationName.Struct); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Struct, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Enum")]
public Color Enum
{
get { return _colorManager.Get(ColorCoderClassificationName.Enum); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Enum, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Generic Type Parameter")]
public Color GenericTypeParameter
{
get { return _colorManager.Get(ColorCoderClassificationName.GenericTypeParameter); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.GenericTypeParameter, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Module(VB Only)")]
public Color Module
{
get { return _colorManager.Get(ColorCoderClassificationName.Module); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Module, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Attribute")]
public Color Attribute
{
get { return _colorManager.Get(ColorCoderClassificationName.Attribute); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Attribute, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Local Variable")]
public Color Local
{
get { return _colorManager.Get(ColorCoderClassificationName.LocalVariable); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.LocalVariable, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Enum Member")]
public Color EnumMember
{
get { return _colorManager.Get(ColorCoderClassificationName.EnumMember); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.EnumMember, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Constructor (C# Only)")]
public Color Constructor
{
get { return _colorManager.Get(ColorCoderClassificationName.Constructor); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Constructor, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Field")]
public Color Field
{
get { return _colorManager.Get(ColorCoderClassificationName.Field); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Field, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Namespace")]
public Color Namespace
{
get { return _colorManager.Get(ColorCoderClassificationName.Namespace); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Namespace, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Method")]
public Color Method
{
get { return _colorManager.Get(ColorCoderClassificationName.Method); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Method, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Static Method")]
public Color StaticMethod
{
get { return _colorManager.Get(ColorCoderClassificationName.StaticMethod); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.StaticMethod, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Extension Method")]
public Color ExtensionMethod
{
get { return _colorManager.Get(ColorCoderClassificationName.ExtensionMethod); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.ExtensionMethod, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Property")]
public Color AutomaticProperty
{
get { return _colorManager.Get(ColorCoderClassificationName.Property); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Property, value);
}
}
[Category(ColorSubCategory)]
[DisplayName("Parameter")]
public Color Parameter
{
get { return _colorManager.Get(ColorCoderClassificationName.Parameter); }
set
{
ThreadHelper.ThrowIfNotOnUIThread();
_colorManager.Set(ColorCoderClassificationName.Parameter, value);
}
}
public override void LoadSettingsFromStorage()
{
ThreadHelper.ThrowIfNotOnUIThread();
this._colorManager = new ColorManager(new ColorStorage(this.Site));
_colorManager.Load(
ColorCoderClassificationName.Attribute,
ColorCoderClassificationName.Constructor,
ColorCoderClassificationName.EnumMember,
ColorCoderClassificationName.ExtensionMethod,
ColorCoderClassificationName.Field,
ColorCoderClassificationName.LocalVariable,
ColorCoderClassificationName.Method,
ColorCoderClassificationName.Namespace,
ColorCoderClassificationName.Property,
ColorCoderClassificationName.StaticMethod,
ColorCoderClassificationName.Parameter,
ColorCoderClassificationName.Class,
ColorCoderClassificationName.Interface,
ColorCoderClassificationName.Module,
ColorCoderClassificationName.Struct,
ColorCoderClassificationName.Enum,
ColorCoderClassificationName.Delegate,
ColorCoderClassificationName.GenericTypeParameter
);
}
public override void SaveSettingsToStorage() { }
}
[Guid(Guids.PresetOptionGrid)]
public class PresetOptionGrid : DialogPage
{
private ColorManager _colorManager;
private const string PresetSubCategory = "Presets";
[Category(PresetSubCategory)]
[DisplayName("Preset")]
[Description("Select from one of the available sets of Presets")]
public Preset Preset { get; set; }
public override void LoadSettingsFromStorage()
{
this._colorManager = new ColorManager(new ColorStorage(this.Site));
Preset = Settings.Load().Preset;
}
public override void SaveSettingsToStorage()
{
Settings.Save(new PresetData { Preset = Preset });
if (Preset == Preset.NoPreset) return;
ThreadHelper.ThrowIfNotOnUIThread();
if (Preset == Preset.VisualStudioDefault)
{
var defaultColors = _colorManager.GetDefaultColorsBySelectedThemes();
_colorManager.Save(defaultColors);
}
if (Preset == Preset.ColorCoderBlueThemeDefault)
{
var colors = _colorManager.GetBlueThemeColorCoderDefaultColors();
_colorManager.Save(colors);
}
if (Preset == Preset.ColorCoderDarkThemeDefault)
{
var colors = _colorManager.GetDarkThemeColorCoderDefaultColors();
_colorManager.Save(colors);
}
}
}
/// <summary>
/// This is the class that implements the package exposed by this assembly.
/// </summary>
/// <remarks>
/// <para>
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
/// to do it: it derives from the Package class that provides the implementation of the
/// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell. These attributes tell the pkgdef creation
/// utility what data to put into .pkgdef file.
/// </para>
/// <para>
/// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file.
/// </para>
/// </remarks>
[Guid(Guids.ColorCoderOptionPackage)]
[DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\14.0")]
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[ProvideOptionPage(typeof(ChangeColorOptionGrid), "ColorCoder", "Colors", 1000, 1001, true)]
[ProvideOptionPage(typeof(PresetOptionGrid), "ColorCoder", "Presets", 1000, 1001, true)]
[InstalledProductRegistration("ColorCoder", "Color Coder provides semantic coloring for C# and VB - http://hamidmosalla.com/color-coder/", Vsix.Version, IconResourceID = 400)]
public sealed class ColorCoderPackage : AsyncPackage
{
/// <summary>
/// ColorCoderPackage GUID string.
/// </summary>
public const string PackageGuidString = "b9c81946-7fc5-4544-8f62-881252590edb";
#region Package Members
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
/// <param name="progress">A provider for progress updates.</param>
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
}
#endregion
}
}