forked from KhaosCoders/VSCodeBlockEndTag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CBEOptionPage.cs
264 lines (227 loc) · 8.24 KB
/
CBEOptionPage.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
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
using Microsoft.VisualStudio.Shell;
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Linq;
using Microsoft.VisualStudio.Shell.Settings;
using Microsoft.VisualStudio.Settings;
using System.Windows.Threading;
namespace CodeBlockEndTag
{
[Guid("B009CDB7-6900-47DC-8403-285191252811")]
public class CBEOptionPage : DialogPage
{
// Name of settings collection where bit array is stored
const string collectionName = "CodeBlockEndTag";
public delegate void OptionChangedHandler(object sender);
public event OptionChangedHandler OptionChanged;
public CBEOptionPage()
{
// default: all languages are enabled
SupportedLangActive = _supportedLangs.Select(l => true).ToArray();
}
#region supported languages
// List of all supported languages
// Never remove any! User preferences are stored for each array position
private SupportedLang[] _supportedLangs = new SupportedLang[]
{
new SupportedLang() { Name = "CSharp", DisplayName = "CSharp C#" },
/*
All of these languages don't come with a decent TextStructureNavigator so they can't be used right now
new SupportedLang() { Name = "C/C++", DisplayName = "C/C++" },
new SupportedLang() { Name = "PowerShell", DisplayName = "PowerShell" },
new SupportedLang() { Name = "JavaScript", DisplayName = "JavaScript" },
new SupportedLang() { Name = "CoffeeScript", DisplayName = "CoffeeScript" },
new SupportedLang() { Name = "TypeScript", DisplayName = "TypeScript" },
new SupportedLang() { Name = "SCSS", DisplayName = "SCSS/CSS" },
new SupportedLang() { Name = "LESS", DisplayName = "LESS" },
new SupportedLang() { Name = "SASS", DisplayName = "SASS" },
new SupportedLang() { Name = "HTML", DisplayName = "HTML(JS/CSS)" }
*/
};
/// <summary>
/// Gets an array with all supported languages display names
/// </summary>
public string[] SupportedLangDisplayNames
{
get
{
return _supportedLangs.Select(l => l.DisplayName).ToArray();
}
}
/// <summary>
/// Gets or sets the array storing whether the tagger is enabled for a language or not
/// </summary>
[TypeConverter(typeof(BoolArrayConverter))]
public bool[] SupportedLangActive { get; set; }
/// <summary>
/// Enable or disable a supported language
/// </summary>
public void SetSupportedLangActive(int index, bool active)
{
if (index >= SupportedLangActive.Length)
{
bool[] a = SupportedLangActive;
Array.Resize(ref a, index + 1);
SupportedLangActive = a;
}
SupportedLangActive[index] = active;
}
/// <summary>
/// Returns true if the given language is supported and active
/// </summary>
public bool IsLanguageSupported(string lang)
{
int index = Array.FindIndex(_supportedLangs, sl => sl.Name.Equals(lang));
if (index >= 0 && index < SupportedLangActive.Length)
{
return SupportedLangActive[index];
}
return false;
}
#endregion
#region other settings
/// <summary>
/// Gets or set the option: Enable CodeBlock End Tagger
/// </summary>
public bool CBETaggerEnabled
{
get { return cbeTaggerEnabled; }
set
{
if (cbeTaggerEnabled != value)
{
cbeTaggerEnabled = value;
OptionChanged?.Invoke(this);
}
}
}
private bool cbeTaggerEnabled = true;
/// <summary>
/// Gets or sets the option: Display Mode (Icon&Text / Icon / Text)
/// </summary>
public int CBEDisplayMode
{
get { return cbeDisplayMode; }
set
{
if (cbeDisplayMode != value)
{
cbeDisplayMode = value;
OptionChanged?.Invoke(this);
}
}
}
private int cbeDisplayMode = (int)DisplayModes.IconAndText;
public enum DisplayModes : int
{
Text = 1,
Icon = 2,
IconAndText = 3
}
/// <summary>
/// Gets or sets the option: Navigate on (Single-Click / Double-Click / CTRL+Click)
/// </summary>
public int CBEClickMode
{
get { return cbeClickMode; }
set
{
if (cbeClickMode != value)
{
cbeClickMode = value;
OptionChanged?.Invoke(this);
}
}
}
private int cbeClickMode = (int)ClickMode.SingleClick;
public enum ClickMode : int
{
SingleClick = 1,
DoubleClick = 2,
CtrlClick = 3
}
/// <summary>
/// Gets or sets the option: Show Tags when (Always / Header not visible)
/// </summary>
public int CBEVisibilityMode
{
get { return cbeVisibilityMode; }
set
{
if (cbeVisibilityMode != value)
{
cbeVisibilityMode = value;
OptionChanged?.Invoke(this);
}
}
}
private int cbeVisibilityMode = (int)VisibilityModes.HeaderNotVisible;
public enum VisibilityModes : int
{
Always = 1,
HeaderNotVisible = 2
}
/// <summary>
/// Gets or sets the option: Tag size
/// </summary>
public double CBETagScale
{
get { return cbeTagScale; }
set
{
if (cbeTagScale != value)
{
cbeTagScale = value;
OptionChanged?.Invoke(this);
}
}
}
private double cbeTagScale = 0.8;
#endregion
#region save / load
public override void SaveSettingsToStorage()
{
base.SaveSettingsToStorage();
Dispatcher.CurrentDispatcher.VerifyAccess();
var settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
var userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
if (!userSettingsStore.CollectionExists(collectionName))
userSettingsStore.CreateCollection(collectionName);
var converter = new BoolArrayConverter();
userSettingsStore.SetString(
collectionName,
nameof(SupportedLangActive),
converter.ConvertTo(SupportedLangActive, typeof(string)) as string);
}
public override void LoadSettingsFromStorage()
{
base.LoadSettingsFromStorage();
Dispatcher.CurrentDispatcher.VerifyAccess();
var settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
var userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
if (!userSettingsStore.PropertyExists(collectionName, nameof(SupportedLangActive)))
return;
var converter = new BoolArrayConverter();
SupportedLangActive = converter.ConvertFrom(
userSettingsStore.GetString(collectionName, nameof(SupportedLangActive))) as bool[];
}
#endregion
protected override IWin32Window Window
{
get
{
CBEOptionPageControl page = new CBEOptionPageControl();
page.optionsPage = this;
page.Initialize();
return page;
}
}
}
public struct SupportedLang
{
public string Name { get; set; }
public string DisplayName { get; set; }
}
}