Skip to content

Commit 0b6f673

Browse files
Merge pull request #101 from ManticSic/fix/75/settings-not-saved
Create new options page
2 parents 318be16 + 6a1d31c commit 0b6f673

10 files changed

+467
-196
lines changed

src/Exceptional/Exceptional.csproj

+11-7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
<PackageReference Include="JetBrains.Lifetimes">
5858
<Version>2019.3.0</Version>
5959
</PackageReference>
60+
<PackageReference Include="JetBrains.RdFramework">
61+
<Version>2019.3.0</Version>
62+
</PackageReference>
6063
<PackageReference Include="JetBrains.ReSharper.SDK" Version="2019.3.0">
6164
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
6265
<PrivateAssets>all</PrivateAssets>
@@ -116,6 +119,13 @@
116119
<Compile Include="Models\ThrownExceptionsReader.cs" />
117120
<Compile Include="Models\TreeElementModelBase.cs" />
118121
<Compile Include="Models\TryStatementModel.cs" />
122+
<Compile Include="Options\AccessorOverridesOptionsPage.cs" />
123+
<Compile Include="Options\ExceptionalOptionsPage.cs" />
124+
<Compile Include="Options\ExceptionTypesAsHintForMethodOrPropertyOptionsPage.cs" />
125+
<Compile Include="Options\ExceptionTypesAsHintOptionsPage.cs" />
126+
<Compile Include="Options\GeneralOptionsPage.cs" />
127+
<Compile Include="Options\InspectionLevelOptionsPage.cs" />
128+
<Compile Include="Options\OptionsLabels.cs" />
119129
<Compile Include="Properties\AssemblyInfo.cs" />
120130
<Compile Include="QuickFixes\AddExceptionDocumentationFix.cs" />
121131
<Compile Include="QuickFixes\AddToOptionalMethodExceptionsFix.cs" />
@@ -133,9 +143,6 @@
133143
<Compile Include="Settings\OptionalExceptionConfiguration.cs" />
134144
<Compile Include="Settings\OptionalExceptionReplacementType.cs" />
135145
<Compile Include="Settings\OptionalMethodExceptionConfiguration.cs" />
136-
<Compile Include="Settings\Views\SettingsView.xaml.cs">
137-
<DependentUpon>SettingsView.xaml</DependentUpon>
138-
</Compile>
139146
<Compile Include="Utilities\CodeElementFactory.cs" />
140147
<Compile Include="Utilities\NameFactory.cs" />
141148
</ItemGroup>
@@ -147,10 +154,6 @@
147154
<Generator>MSBuild:Compile</Generator>
148155
<SubType>Designer</SubType>
149156
</Page>
150-
<Page Include="Settings\Views\SettingsView.xaml">
151-
<Generator>MSBuild:Compile</Generator>
152-
<SubType>Designer</SubType>
153-
</Page>
154157
</ItemGroup>
155158
<ItemGroup>
156159
<EmbeddedResource Include="Resources.resx">
@@ -159,5 +162,6 @@
159162
<SubType>Designer</SubType>
160163
</EmbeddedResource>
161164
</ItemGroup>
165+
<ItemGroup />
162166
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
163167
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using JetBrains.Application.Settings;
2+
using JetBrains.Application.UI.Options;
3+
using JetBrains.Application.UI.Options.OptionsDialog;
4+
using JetBrains.DataFlow;
5+
using JetBrains.IDE.UI.Extensions;
6+
using JetBrains.IDE.UI.Options;
7+
using JetBrains.Lifetimes;
8+
using JetBrains.Rd.Base;
9+
using JetBrains.Util;
10+
11+
namespace ReSharper.Exceptional.Options
12+
{
13+
[OptionsPage(Pid, Name, typeof(UnnamedThemedIcons.ExceptionalSettings), ParentId = ExceptionalOptionsPage.Pid, Sequence = 4.0)]
14+
public class AccessorOverridesOptionsPage : BeSimpleOptionsPage
15+
{
16+
public const string Pid = "Exceptional::AccessorOverrides";
17+
public const string Name = "Accessor Overrides";
18+
19+
public AccessorOverridesOptionsPage(Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext, bool wrapInScrollablePanel = true) : base(lifetime, optionsPageContext, optionsSettingsSmartContext, wrapInScrollablePanel)
20+
{
21+
AddText(OptionsLabels.AccessorOverrides.Description);
22+
23+
CreateCheckboxUsePredefined(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
24+
25+
AddButton(OptionsLabels.AccessorOverrides.ShowPredefined, ShowPredefined);
26+
27+
AddSpacer();
28+
29+
AddText(OptionsLabels.AccessorOverrides.Note);
30+
CreateRichTextAccessorOverrides(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
31+
}
32+
33+
private void ShowPredefined()
34+
{
35+
string content = ReSharper.Exceptional.Settings.ExceptionalSettings.DefaultAccessorOverrides;
36+
37+
MessageBox.ShowInfo(content);
38+
}
39+
40+
private void CreateCheckboxUsePredefined(in Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
41+
{
42+
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::AccessorOverrides::UsePredefined");
43+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.UseDefaultAccessorOverrides2));
44+
45+
property.Change.Advise(lifetime, a =>
46+
{
47+
if (!a.HasNew) return;
48+
49+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.UseDefaultAccessorOverrides2, a.New);
50+
});
51+
52+
AddBoolOption((Settings.ExceptionalSettings key) => key.UseDefaultAccessorOverrides2, OptionsLabels.AccessorOverrides.UsePredefined);
53+
}
54+
55+
private void CreateRichTextAccessorOverrides(in Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
56+
{
57+
IProperty<string> property = new Property<string>(lifetime, "Exceptional::AccessorOverrides::AccessorOverrides");
58+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.AccessorOverrides2));
59+
60+
property.Change.Advise(lifetime, a =>
61+
{
62+
if (!a.HasNew) return;
63+
64+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.AccessorOverrides2, a.New);
65+
});
66+
67+
var textControl = BeControls.GetTextControl(isReadonly:false);
68+
69+
textControl.Text.SetValue(property.GetValue());
70+
textControl.Text.Change.Advise(lifetime, str =>
71+
{
72+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.AccessorOverrides2, str);
73+
});
74+
75+
AddControl(textControl);
76+
}
77+
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using JetBrains.Application.Settings;
2+
using JetBrains.Application.UI.Options;
3+
using JetBrains.Application.UI.Options.OptionsDialog;
4+
using JetBrains.DataFlow;
5+
using JetBrains.IDE.UI.Extensions;
6+
using JetBrains.IDE.UI.Options;
7+
using JetBrains.Lifetimes;
8+
using JetBrains.Rd.Base;
9+
using JetBrains.Util;
10+
11+
namespace ReSharper.Exceptional.Options
12+
{
13+
[OptionsPage(Pid, Name, typeof(UnnamedThemedIcons.ExceptionalSettings), ParentId = ExceptionalOptionsPage.Pid, Sequence = 3.0)]
14+
public class ExceptionTypesAsHintForMethodOrPropertyOptionsPage : BeSimpleOptionsPage
15+
{
16+
public const string Pid = "Exceptional::ExceptionTypesAsHintForMethodsOrProperties";
17+
public const string Name = "Optional Exceptions (Methods or Properties)";
18+
19+
public ExceptionTypesAsHintForMethodOrPropertyOptionsPage(Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext, bool wrapInScrollablePanel = true) : base(lifetime, optionsPageContext, optionsSettingsSmartContext, wrapInScrollablePanel)
20+
{
21+
AddText(OptionsLabels.ExceptionTypesAsHintForMethodOrProperty.Description);
22+
23+
CreateCheckboxUsePredefined(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
24+
25+
AddButton(OptionsLabels.ExceptionTypesAsHintForMethodOrProperty.ShowPredefined, ShowPredefined);
26+
27+
AddSpacer();
28+
29+
AddText(OptionsLabels.ExceptionTypesAsHintForMethodOrProperty.Note);
30+
CreateRichTextExceptionTypesAsHint(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
31+
}
32+
33+
private void ShowPredefined()
34+
{
35+
string content = ReSharper.Exceptional.Settings.ExceptionalSettings.DefaultOptionalMethodExceptions;
36+
37+
MessageBox.ShowInfo(content);
38+
}
39+
40+
private void CreateCheckboxUsePredefined(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
41+
{
42+
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::ExceptionTypesAsHintForMethodsOrProperties::UsePredefined");
43+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.UseDefaultOptionalMethodExceptions2));
44+
45+
property.Change.Advise(lifetime, a =>
46+
{
47+
if (!a.HasNew) return;
48+
49+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.UseDefaultOptionalMethodExceptions2, a.New);
50+
});
51+
52+
AddBoolOption((Settings.ExceptionalSettings key) => key.UseDefaultOptionalMethodExceptions2, OptionsLabels.ExceptionTypesAsHintForMethodOrProperty.UsePredefined);
53+
}
54+
55+
private void CreateRichTextExceptionTypesAsHint(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
56+
{
57+
IProperty<string> property = new Property<string>(lifetime, "Exceptional::ExceptionTypesAsHintForMethodsOrProperties::ExceptionTypes");
58+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.OptionalMethodExceptions2));
59+
60+
property.Change.Advise(lifetime, a =>
61+
{
62+
if (!a.HasNew) return;
63+
64+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.OptionalMethodExceptions2, a.New);
65+
});
66+
67+
var textControl = BeControls.GetTextControl(isReadonly:false);
68+
69+
textControl.Text.SetValue(property.GetValue());
70+
textControl.Text.Change.Advise(lifetime, str =>
71+
{
72+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.OptionalMethodExceptions2, str);
73+
});
74+
75+
AddControl(textControl);
76+
}
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using JetBrains.Application.Settings;
2+
using JetBrains.Application.UI.Options;
3+
using JetBrains.Application.UI.Options.OptionsDialog;
4+
using JetBrains.DataFlow;
5+
using JetBrains.IDE.UI.Extensions;
6+
using JetBrains.IDE.UI.Options;
7+
using JetBrains.Lifetimes;
8+
using JetBrains.Rd.Base;
9+
using JetBrains.Util;
10+
11+
namespace ReSharper.Exceptional.Options
12+
{
13+
[OptionsPage(Pid, Name, typeof(UnnamedThemedIcons.ExceptionalSettings), ParentId = ExceptionalOptionsPage.Pid, Sequence = 2.0)]
14+
public class ExceptionTypesAsHintOptionsPage : BeSimpleOptionsPage
15+
{
16+
public const string Pid = "Exceptional::ExceptionTypesAsHint";
17+
public const string Name = "Optional Exceptions (Global)";
18+
19+
public ExceptionTypesAsHintOptionsPage(Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext) : base(lifetime, optionsPageContext, optionsSettingsSmartContext, true)
20+
{
21+
AddText(OptionsLabels.ExceptionTypesAsHint.Description);
22+
23+
CreateCheckboxUsePredefined(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
24+
25+
AddButton(OptionsLabels.ExceptionTypesAsHint.ShowPredefined, ShowPredefined);
26+
27+
AddSpacer();
28+
29+
AddText(OptionsLabels.ExceptionTypesAsHint.Note);
30+
CreateRichTextExceptionTypesAsHint(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
31+
}
32+
33+
private void ShowPredefined()
34+
{
35+
string content = ReSharper.Exceptional.Settings.ExceptionalSettings.DefaultOptionalExceptions;
36+
37+
MessageBox.ShowInfo(content);
38+
}
39+
40+
private void CreateCheckboxUsePredefined(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
41+
{
42+
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::ExceptionTypesAsHint::UsePredefined");
43+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.UseDefaultOptionalExceptions2));
44+
45+
property.Change.Advise(lifetime, a =>
46+
{
47+
if (!a.HasNew) return;
48+
49+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.UseDefaultOptionalExceptions2, a.New);
50+
});
51+
52+
AddBoolOption((Settings.ExceptionalSettings key) => key.UseDefaultOptionalExceptions2, OptionsLabels.ExceptionTypesAsHint.UsePredefined);
53+
}
54+
55+
private void CreateRichTextExceptionTypesAsHint(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
56+
{
57+
IProperty<string> property = new Property<string>(lifetime, "Exceptional::ExceptionTypesAsHint::ExceptionTypes");
58+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.OptionalExceptions2));
59+
60+
property.Change.Advise(lifetime, a =>
61+
{
62+
if (!a.HasNew) return;
63+
64+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.OptionalExceptions2, a.New);
65+
});
66+
67+
var textControl = BeControls.GetTextControl(isReadonly:false);
68+
69+
textControl.Text.SetValue(property.GetValue());
70+
textControl.Text.Change.Advise(lifetime, str =>
71+
{
72+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.OptionalExceptions2, str);
73+
});
74+
75+
AddControl(textControl);
76+
}
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JetBrains.Application.UI.Options;
2+
using JetBrains.Application.UI.Options.OptionsDialog;
3+
4+
namespace ReSharper.Exceptional.Options
5+
{
6+
[OptionsPage(Pid, Name, null, Sequence = 5.0)]
7+
public class ExceptionalOptionsPage : AEmptyOptionsPage
8+
{
9+
public const string Pid = "Exceptional";
10+
public const string Name = "Exceptional";
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using JetBrains.Application.Settings;
2+
using JetBrains.Application.UI.Options;
3+
using JetBrains.Application.UI.Options.OptionsDialog;
4+
using JetBrains.DataFlow;
5+
using JetBrains.IDE.UI.Options;
6+
using JetBrains.Lifetimes;
7+
8+
namespace ReSharper.Exceptional.Options
9+
{
10+
[OptionsPage(Pid, Name, typeof(UnnamedThemedIcons.ExceptionalSettings), ParentId = ExceptionalOptionsPage.Pid, Sequence = 0.0)]
11+
public class GeneralOptionsPage : BeSimpleOptionsPage
12+
{
13+
public const string Pid = "Exceptional::General";
14+
public const string Name = "General";
15+
16+
public GeneralOptionsPage(Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext, bool wrapInScrollablePanel = false) : base(lifetime, optionsPageContext, optionsSettingsSmartContext, wrapInScrollablePanel)
17+
{
18+
CreateCheckboxInspectPublic(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
19+
20+
CreateDocumentationSection(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
21+
}
22+
23+
private void CreateCheckboxInspectPublic(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
24+
{
25+
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::General::DelegateInvocationsMayThrowSystemException");
26+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.DelegateInvocationsMayThrowExceptions));
27+
28+
property.Change.Advise(lifetime, a =>
29+
{
30+
if (!a.HasNew) return;
31+
32+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.DelegateInvocationsMayThrowExceptions, a.New);
33+
});
34+
35+
AddBoolOption((Settings.ExceptionalSettings key) => key.DelegateInvocationsMayThrowExceptions, OptionsLabels.General.DelegateInvocationsMayThrowSystemException);
36+
}
37+
38+
private void CreateDocumentationSection(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
39+
{
40+
AddHeader(OptionsLabels.General.DocumentationOfThrownExceptionsSubtypeHeader);
41+
42+
CreateCheckboxIsDocumentationOfExceptionSubtypeSufficientForThrowStatements(lifetime, storeOptionsTransactionContext);
43+
CreateCheckboxIsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions(lifetime, storeOptionsTransactionContext);
44+
}
45+
46+
private void CreateCheckboxIsDocumentationOfExceptionSubtypeSufficientForThrowStatements(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
47+
{
48+
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::General::IsDocumentationOfExceptionSubtypeSufficientForThrowStatements");
49+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements));
50+
51+
property.Change.Advise(lifetime, a =>
52+
{
53+
if (!a.HasNew) return;
54+
55+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements, a.New);
56+
});
57+
58+
AddBoolOption((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements, OptionsLabels.General.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements);
59+
}
60+
61+
private void CreateCheckboxIsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
62+
{
63+
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::General::IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions");
64+
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions));
65+
66+
property.Change.Advise(lifetime, a =>
67+
{
68+
if (!a.HasNew) return;
69+
70+
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions, a.New);
71+
});
72+
73+
AddBoolOption((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions, OptionsLabels.General.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions);
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)