Skip to content

Commit

Permalink
Merge pull request #101 from ManticSic/fix/75/settings-not-saved
Browse files Browse the repository at this point in the history
Create new options page
  • Loading branch information
patrickweegen authored Jan 10, 2020
2 parents 318be16 + 6a1d31c commit 0b6f673
Show file tree
Hide file tree
Showing 10 changed files with 467 additions and 196 deletions.
18 changes: 11 additions & 7 deletions src/Exceptional/Exceptional.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<PackageReference Include="JetBrains.Lifetimes">
<Version>2019.3.0</Version>
</PackageReference>
<PackageReference Include="JetBrains.RdFramework">
<Version>2019.3.0</Version>
</PackageReference>
<PackageReference Include="JetBrains.ReSharper.SDK" Version="2019.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down Expand Up @@ -116,6 +119,13 @@
<Compile Include="Models\ThrownExceptionsReader.cs" />
<Compile Include="Models\TreeElementModelBase.cs" />
<Compile Include="Models\TryStatementModel.cs" />
<Compile Include="Options\AccessorOverridesOptionsPage.cs" />
<Compile Include="Options\ExceptionalOptionsPage.cs" />
<Compile Include="Options\ExceptionTypesAsHintForMethodOrPropertyOptionsPage.cs" />
<Compile Include="Options\ExceptionTypesAsHintOptionsPage.cs" />
<Compile Include="Options\GeneralOptionsPage.cs" />
<Compile Include="Options\InspectionLevelOptionsPage.cs" />
<Compile Include="Options\OptionsLabels.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QuickFixes\AddExceptionDocumentationFix.cs" />
<Compile Include="QuickFixes\AddToOptionalMethodExceptionsFix.cs" />
Expand All @@ -133,9 +143,6 @@
<Compile Include="Settings\OptionalExceptionConfiguration.cs" />
<Compile Include="Settings\OptionalExceptionReplacementType.cs" />
<Compile Include="Settings\OptionalMethodExceptionConfiguration.cs" />
<Compile Include="Settings\Views\SettingsView.xaml.cs">
<DependentUpon>SettingsView.xaml</DependentUpon>
</Compile>
<Compile Include="Utilities\CodeElementFactory.cs" />
<Compile Include="Utilities\NameFactory.cs" />
</ItemGroup>
Expand All @@ -147,10 +154,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Settings\Views\SettingsView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources.resx">
Expand All @@ -159,5 +162,6 @@
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
79 changes: 79 additions & 0 deletions src/Exceptional/Options/AccessorOverridesOptionsPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using JetBrains.Application.Settings;
using JetBrains.Application.UI.Options;
using JetBrains.Application.UI.Options.OptionsDialog;
using JetBrains.DataFlow;
using JetBrains.IDE.UI.Extensions;
using JetBrains.IDE.UI.Options;
using JetBrains.Lifetimes;
using JetBrains.Rd.Base;
using JetBrains.Util;

namespace ReSharper.Exceptional.Options
{
[OptionsPage(Pid, Name, typeof(UnnamedThemedIcons.ExceptionalSettings), ParentId = ExceptionalOptionsPage.Pid, Sequence = 4.0)]
public class AccessorOverridesOptionsPage : BeSimpleOptionsPage
{
public const string Pid = "Exceptional::AccessorOverrides";
public const string Name = "Accessor Overrides";

public AccessorOverridesOptionsPage(Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext, bool wrapInScrollablePanel = true) : base(lifetime, optionsPageContext, optionsSettingsSmartContext, wrapInScrollablePanel)
{
AddText(OptionsLabels.AccessorOverrides.Description);

CreateCheckboxUsePredefined(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);

AddButton(OptionsLabels.AccessorOverrides.ShowPredefined, ShowPredefined);

AddSpacer();

AddText(OptionsLabels.AccessorOverrides.Note);
CreateRichTextAccessorOverrides(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
}

private void ShowPredefined()
{
string content = ReSharper.Exceptional.Settings.ExceptionalSettings.DefaultAccessorOverrides;

MessageBox.ShowInfo(content);
}

private void CreateCheckboxUsePredefined(in Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::AccessorOverrides::UsePredefined");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.UseDefaultAccessorOverrides2));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.UseDefaultAccessorOverrides2, a.New);
});

AddBoolOption((Settings.ExceptionalSettings key) => key.UseDefaultAccessorOverrides2, OptionsLabels.AccessorOverrides.UsePredefined);
}

private void CreateRichTextAccessorOverrides(in Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<string> property = new Property<string>(lifetime, "Exceptional::AccessorOverrides::AccessorOverrides");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.AccessorOverrides2));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.AccessorOverrides2, a.New);
});

var textControl = BeControls.GetTextControl(isReadonly:false);

textControl.Text.SetValue(property.GetValue());
textControl.Text.Change.Advise(lifetime, str =>
{
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.AccessorOverrides2, str);
});

AddControl(textControl);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using JetBrains.Application.Settings;
using JetBrains.Application.UI.Options;
using JetBrains.Application.UI.Options.OptionsDialog;
using JetBrains.DataFlow;
using JetBrains.IDE.UI.Extensions;
using JetBrains.IDE.UI.Options;
using JetBrains.Lifetimes;
using JetBrains.Rd.Base;
using JetBrains.Util;

namespace ReSharper.Exceptional.Options
{
[OptionsPage(Pid, Name, typeof(UnnamedThemedIcons.ExceptionalSettings), ParentId = ExceptionalOptionsPage.Pid, Sequence = 3.0)]
public class ExceptionTypesAsHintForMethodOrPropertyOptionsPage : BeSimpleOptionsPage
{
public const string Pid = "Exceptional::ExceptionTypesAsHintForMethodsOrProperties";
public const string Name = "Optional Exceptions (Methods or Properties)";

public ExceptionTypesAsHintForMethodOrPropertyOptionsPage(Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext, bool wrapInScrollablePanel = true) : base(lifetime, optionsPageContext, optionsSettingsSmartContext, wrapInScrollablePanel)
{
AddText(OptionsLabels.ExceptionTypesAsHintForMethodOrProperty.Description);

CreateCheckboxUsePredefined(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);

AddButton(OptionsLabels.ExceptionTypesAsHintForMethodOrProperty.ShowPredefined, ShowPredefined);

AddSpacer();

AddText(OptionsLabels.ExceptionTypesAsHintForMethodOrProperty.Note);
CreateRichTextExceptionTypesAsHint(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
}

private void ShowPredefined()
{
string content = ReSharper.Exceptional.Settings.ExceptionalSettings.DefaultOptionalMethodExceptions;

MessageBox.ShowInfo(content);
}

private void CreateCheckboxUsePredefined(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::ExceptionTypesAsHintForMethodsOrProperties::UsePredefined");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.UseDefaultOptionalMethodExceptions2));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.UseDefaultOptionalMethodExceptions2, a.New);
});

AddBoolOption((Settings.ExceptionalSettings key) => key.UseDefaultOptionalMethodExceptions2, OptionsLabels.ExceptionTypesAsHintForMethodOrProperty.UsePredefined);
}

private void CreateRichTextExceptionTypesAsHint(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<string> property = new Property<string>(lifetime, "Exceptional::ExceptionTypesAsHintForMethodsOrProperties::ExceptionTypes");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.OptionalMethodExceptions2));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.OptionalMethodExceptions2, a.New);
});

var textControl = BeControls.GetTextControl(isReadonly:false);

textControl.Text.SetValue(property.GetValue());
textControl.Text.Change.Advise(lifetime, str =>
{
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.OptionalMethodExceptions2, str);
});

AddControl(textControl);
}
}
}
78 changes: 78 additions & 0 deletions src/Exceptional/Options/ExceptionTypesAsHintOptionsPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using JetBrains.Application.Settings;
using JetBrains.Application.UI.Options;
using JetBrains.Application.UI.Options.OptionsDialog;
using JetBrains.DataFlow;
using JetBrains.IDE.UI.Extensions;
using JetBrains.IDE.UI.Options;
using JetBrains.Lifetimes;
using JetBrains.Rd.Base;
using JetBrains.Util;

namespace ReSharper.Exceptional.Options
{
[OptionsPage(Pid, Name, typeof(UnnamedThemedIcons.ExceptionalSettings), ParentId = ExceptionalOptionsPage.Pid, Sequence = 2.0)]
public class ExceptionTypesAsHintOptionsPage : BeSimpleOptionsPage
{
public const string Pid = "Exceptional::ExceptionTypesAsHint";
public const string Name = "Optional Exceptions (Global)";

public ExceptionTypesAsHintOptionsPage(Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext) : base(lifetime, optionsPageContext, optionsSettingsSmartContext, true)
{
AddText(OptionsLabels.ExceptionTypesAsHint.Description);

CreateCheckboxUsePredefined(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);

AddButton(OptionsLabels.ExceptionTypesAsHint.ShowPredefined, ShowPredefined);

AddSpacer();

AddText(OptionsLabels.ExceptionTypesAsHint.Note);
CreateRichTextExceptionTypesAsHint(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
}

private void ShowPredefined()
{
string content = ReSharper.Exceptional.Settings.ExceptionalSettings.DefaultOptionalExceptions;

MessageBox.ShowInfo(content);
}

private void CreateCheckboxUsePredefined(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::ExceptionTypesAsHint::UsePredefined");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.UseDefaultOptionalExceptions2));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.UseDefaultOptionalExceptions2, a.New);
});

AddBoolOption((Settings.ExceptionalSettings key) => key.UseDefaultOptionalExceptions2, OptionsLabels.ExceptionTypesAsHint.UsePredefined);
}

private void CreateRichTextExceptionTypesAsHint(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<string> property = new Property<string>(lifetime, "Exceptional::ExceptionTypesAsHint::ExceptionTypes");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.OptionalExceptions2));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.OptionalExceptions2, a.New);
});

var textControl = BeControls.GetTextControl(isReadonly:false);

textControl.Text.SetValue(property.GetValue());
textControl.Text.Change.Advise(lifetime, str =>
{
storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.OptionalExceptions2, str);
});

AddControl(textControl);
}
}
}
12 changes: 12 additions & 0 deletions src/Exceptional/Options/ExceptionalOptionsPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using JetBrains.Application.UI.Options;
using JetBrains.Application.UI.Options.OptionsDialog;

namespace ReSharper.Exceptional.Options
{
[OptionsPage(Pid, Name, null, Sequence = 5.0)]
public class ExceptionalOptionsPage : AEmptyOptionsPage
{
public const string Pid = "Exceptional";
public const string Name = "Exceptional";
}
}
76 changes: 76 additions & 0 deletions src/Exceptional/Options/GeneralOptionsPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using JetBrains.Application.Settings;
using JetBrains.Application.UI.Options;
using JetBrains.Application.UI.Options.OptionsDialog;
using JetBrains.DataFlow;
using JetBrains.IDE.UI.Options;
using JetBrains.Lifetimes;

namespace ReSharper.Exceptional.Options
{
[OptionsPage(Pid, Name, typeof(UnnamedThemedIcons.ExceptionalSettings), ParentId = ExceptionalOptionsPage.Pid, Sequence = 0.0)]
public class GeneralOptionsPage : BeSimpleOptionsPage
{
public const string Pid = "Exceptional::General";
public const string Name = "General";

public GeneralOptionsPage(Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext, bool wrapInScrollablePanel = false) : base(lifetime, optionsPageContext, optionsSettingsSmartContext, wrapInScrollablePanel)
{
CreateCheckboxInspectPublic(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);

CreateDocumentationSection(lifetime, optionsSettingsSmartContext.StoreOptionsTransactionContext);
}

private void CreateCheckboxInspectPublic(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::General::DelegateInvocationsMayThrowSystemException");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.DelegateInvocationsMayThrowExceptions));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.DelegateInvocationsMayThrowExceptions, a.New);
});

AddBoolOption((Settings.ExceptionalSettings key) => key.DelegateInvocationsMayThrowExceptions, OptionsLabels.General.DelegateInvocationsMayThrowSystemException);
}

private void CreateDocumentationSection(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
AddHeader(OptionsLabels.General.DocumentationOfThrownExceptionsSubtypeHeader);

CreateCheckboxIsDocumentationOfExceptionSubtypeSufficientForThrowStatements(lifetime, storeOptionsTransactionContext);
CreateCheckboxIsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions(lifetime, storeOptionsTransactionContext);
}

private void CreateCheckboxIsDocumentationOfExceptionSubtypeSufficientForThrowStatements(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::General::IsDocumentationOfExceptionSubtypeSufficientForThrowStatements");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements, a.New);
});

AddBoolOption((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements, OptionsLabels.General.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements);
}

private void CreateCheckboxIsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions(Lifetime lifetime, IContextBoundSettingsStoreLive storeOptionsTransactionContext)
{
IProperty<bool> property = new Property<bool>(lifetime, "Exceptional::General::IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions");
property.SetValue(storeOptionsTransactionContext.GetValue((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions));

property.Change.Advise(lifetime, a =>
{
if (!a.HasNew) return;

storeOptionsTransactionContext.SetValue((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions, a.New);
});

AddBoolOption((Settings.ExceptionalSettings key) => key.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions, OptionsLabels.General.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions);
}
}
}
Loading

0 comments on commit 0b6f673

Please sign in to comment.