-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathCmdArgsOptionPage.cs
More file actions
292 lines (254 loc) · 11.2 KB
/
CmdArgsOptionPage.cs
File metadata and controls
292 lines (254 loc) · 11.2 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
using Microsoft.VisualStudio.Shell;
using SmartCmdArgs.Helper;
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace SmartCmdArgs
{
[TypeConverter(typeof(EnumDescriptionTypeConverter))]
public enum RelativePathRootOption
{
[Description("Build Target Directory")]
BuildTargetDirectory,
[Description("Project Directory")]
ProjectDirectory
}
[TypeConverter(typeof(EnumDescriptionTypeConverter))]
public enum InactiveDisableMode
{
[Description("Disabled")]
Disabled,
[Description("In all Projects")]
InAllProjects,
[Description("Only in Startup Projects")]
OnlyInStartupProjects,
}
[TypeConverter(typeof(EnumDescriptionTypeConverter))]
public enum EnableBehaviour
{
[Description("Enable if a *.arg.json file or an entry in the *.suo file is found")]
EnableIfArgJsonOrSuoEntryIsFound,
[Description("Enable if a *.arg.json file is found")]
EnableIfArgJsonIsFound,
[Description("Always ask for new Solutions")]
AlwaysAsk,
[Description("Enable by default (old behaviour)")]
EnableByDefault,
}
[Flags]
[TypeConverter(typeof(EnumDescriptionTypeConverter))]
public enum SetActiveProfileBehavior
{
[Description("Never, due to a bug in virtual profiles you will have to reselect Smart CLI Args every time you open a project")]
Never = 1 << 0,
[Description("On Smart CLI Arg tree changed (ie option checked)")]
OnTreeChanged = 1 << 1,
[Description("On first run/debug")]
OnRun = 1 << 2,
[Description("On Smart CLI Arg option checked or first run/debug")]
OnCheckedOrRun = OnTreeChanged | OnRun
}
public class CmdArgsOptionPage : DialogPage, INotifyPropertyChanged
{
private bool _dontSave = false;
public CmdArgsOptionPage() : base()
{
_dontSave = true;
try
{
ResetSettings();
}
finally
{
_dontSave = false;
}
}
private EnableBehaviour _enableBehaviour;
private SetActiveProfileBehavior _setActiveProfileBehavior;
private RelativePathRootOption _relativePathRoot;
private bool _useMonospaceFont;
private bool _displayTagForCla;
private InactiveDisableMode _disableInactiveItems;
private bool _deleteEmptyFilesAutomatically;
private bool _deleteUnnecessaryFilesAutomatically;
private bool _manageCommandLineArgs;
private bool _manageEnvironmentVars;
private bool _manageWorkingDirectories;
private bool _manageLaunchApplication;
private bool _vcsSupportEnabled;
private bool _useCpsVirtualProfile;
private bool _useSolutionDir;
private bool _macroEvaluationEnabled;
[Category("General")]
[DisplayName("Enable Behaviour")]
[Description("Choose whether the extension should enable automatically or ask the user for permission first.")]
[DefaultValue(EnableBehaviour.EnableIfArgJsonOrSuoEntryIsFound)]
public EnableBehaviour EnableBehaviour
{
get => _enableBehaviour;
set => SetAndNotify(value, ref _enableBehaviour);
}
[Category("Settings Defaults")]
[DisplayName("Set Active Profile Behavior")]
[Description("When we should automatically make ourselves the active profile")]
[DefaultValue(SetActiveProfileBehavior.OnTreeChanged)]
public SetActiveProfileBehavior SetActiveProfileBehavior
{
get => _setActiveProfileBehavior;
set => SetAndNotify(value, ref _setActiveProfileBehavior);
}
[Category("General")]
[DisplayName("Relative path root")]
[Description("Sets the base path that is used to resolve relative paths for the open/reveal file/folder context menu option.")]
[DefaultValue(RelativePathRootOption.BuildTargetDirectory)]
public RelativePathRootOption RelativePathRoot
{
get => _relativePathRoot;
set => SetAndNotify(value, ref _relativePathRoot);
}
[Category("Appearance")]
[DisplayName("Use Monospace Font")]
[Description("If enabled the fontfamily is changed to 'Consolas'.")]
[DefaultValue(false)]
public bool UseMonospaceFont
{
get => _useMonospaceFont;
set => SetAndNotify(value, ref _useMonospaceFont);
}
[Category("Appearance")]
[DisplayName("Display Tags for CLAs")]
[Description("If enabled the item tag 'CLA' is displayed for Command Line Arguments. Normally the tag 'ENV' is only displayed for environment varibales.")]
[DefaultValue(false)]
public bool DisplayTagForCla
{
get => _displayTagForCla;
set => SetAndNotify(value, ref _displayTagForCla);
}
[Category("Appearance")]
[DisplayName("Grey out inactive items")]
[Description("If set to 'Disabled' nothing happens. If set to 'InAllProjects' then CLAs and EnvVars that are not applied in the current scenario are greyed out. E.g. arguments that are in a group for a project configuration that is currently not active or environment variables that are overridden somewhere later in the list. The 'OnlyInStartupProjects' option limits this behaviour only to startup projects.")]
[DefaultValue(InactiveDisableMode.Disabled)]
public InactiveDisableMode DisableInactiveItems
{
get => _disableInactiveItems;
set => SetAndNotify(value, ref _disableInactiveItems);
}
[Category("Cleanup")]
[DisplayName("Delete empty files automatically")]
[Description("If enabled, '*.args.json' files which would contain no arguments will be delete automatically.")]
[DefaultValue(true)]
public bool DeleteEmptyFilesAutomatically
{
get => _deleteEmptyFilesAutomatically;
set => SetAndNotify(value, ref _deleteEmptyFilesAutomatically);
}
[Category("Cleanup")]
[DisplayName("Delete unnecessary files automatically")]
[Description("If enabled, '*.args.json' whcih are unnecessary will be deleted automatically. Such a file is unnecessary if it belongs to a project and 'Use Solution Directory' is enbaled or belongs to a solution and 'Use Solution Directory' is disabled.")]
[DefaultValue(true)]
public bool DeleteUnnecessaryFilesAutomatically
{
get => _deleteUnnecessaryFilesAutomatically;
set => SetAndNotify(value, ref _deleteUnnecessaryFilesAutomatically);
}
[Category("Settings Defaults")]
[DisplayName("Manage Command Line Arguments")]
[Description("If enabled the arguments are set automatically when a project is started/debugged.")]
[DefaultValue(true)]
public bool ManageCommandLineArgs
{
get => _manageCommandLineArgs;
set => SetAndNotify(value, ref _manageCommandLineArgs);
}
[Category("Settings Defaults")]
[DisplayName("Manage Environment Variables")]
[Description("If enabled the environment variables are set automatically when a project is started/debugged.")]
[DefaultValue(false)]
public bool ManageEnvironmentVars
{
get => _manageEnvironmentVars;
set => SetAndNotify(value, ref _manageEnvironmentVars);
}
[Category("Settings Defaults")]
[DisplayName("Manage Working Directories")]
[Description("If enabled the working directories are set automatically when a project is started/debugged.")]
[DefaultValue(false)]
public bool ManageWorkingDirectories
{
get => _manageWorkingDirectories;
set => SetAndNotify(value, ref _manageWorkingDirectories);
}
[Category("Settings Defaults")]
[DisplayName("Manage Launch Application")]
[Description("If enabled the launch application is set automatically when a project is started/debugged.")]
[DefaultValue(false)]
public bool ManageLaunchApplication
{
get => _manageLaunchApplication;
set => SetAndNotify(value, ref _manageLaunchApplication);
}
[Category("Settings Defaults")]
[DisplayName("Enable version control support")]
[Description("If enabled the extension will store the command line arguments into an json file at the same loctation as the related project file. That way the command line arguments might be version controlled by a VCS. If disabled the extension will store everything inside the solutions .suo-file which is usally ignored by version control. The default value for this setting is True.")]
[DefaultValue(true)]
public bool VcsSupportEnabled
{
get => _vcsSupportEnabled;
set => SetAndNotify(value, ref _vcsSupportEnabled);
}
[Category("Settings Defaults")]
[DisplayName("Use CPS Virtual Profile")]
[Description("If enabled a virtual profile is created for CPS projects and only this profile is changed by the extension.")]
[DefaultValue(false)]
public bool UseCpsVirtualProfile
{
get => _useCpsVirtualProfile;
set => SetAndNotify(value, ref _useCpsVirtualProfile);
}
[Category("Settings Defaults")]
[DisplayName("Use Solution Directory")]
[Description("If enabled all arguments of every project will be stored in a single file next to the *.sln file. (Only if version control support is enabled)")]
[DefaultValue(false)]
public bool UseSolutionDir
{
get => _useSolutionDir;
set => SetAndNotify(value, ref _useSolutionDir);
}
[Category("Settings Defaults")]
[DisplayName("Enable Macro evaluation")]
[Description("If enabled Macros like '$(ProjectDir)' will be evaluated and replaced by the corresponding string.")]
[DefaultValue(true)]
public bool MacroEvaluationEnabled
{
get => _macroEvaluationEnabled;
set => SetAndNotify(value, ref _macroEvaluationEnabled);
}
public override void SaveSettingsToStorage()
{
if (_dontSave)
return;
base.SaveSettingsToStorage();
}
public override void ResetSettings()
{
base.ResetSettings();
foreach (var prop in GetType().GetProperties())
{
var attribute = prop.GetCustomAttributes<DefaultValueAttribute>().FirstOrDefault();
if (attribute != null)
{
prop.SetValue(this, attribute.Value);
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void SetAndNotify<T>(T newValue, ref T field, [CallerMemberName] string propertyName = null)
{
if (Equals(newValue, field)) return;
field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}