Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all features switchable #525

Merged
merged 7 commits into from
Mar 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CodeMaid.UnitTests/CodeMaid.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<Compile Include="Formatting\ListFormattingTests.cs" />
<Compile Include="Helpers\CodeItemTypeComparerTests.cs" />
<Compile Include="Helpers\CodeMaidPackageHelper.cs" />
<Compile Include="Helpers\SettingsMonitorTests.cs" />
<Compile Include="Helpers\UIShellServiceMock.cs" />
<Compile Include="Helpers\WindowFrameMock.cs" />
<Compile Include="CodeMaidPackageTest.cs" />
Expand Down
2 changes: 1 addition & 1 deletion CodeMaid.UnitTests/Helpers/CodeItemTypeComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ private static CodeItemMethod CreateExplicitMethod(string interfaceName, string
return method;
}
}
}
}
125 changes: 125 additions & 0 deletions CodeMaid.UnitTests/Helpers/SettingsMonitorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SteveCadwallader.CodeMaid.Helpers;
using SteveCadwallader.CodeMaid.Properties;
using System.Linq;

namespace SteveCadwallader.CodeMaid.UnitTests.Helpers
{
[TestClass]
public class SettingsMonitorTests
{
[TestInitialize]
public void TestInitialize()
{
Settings.Default.Reset();
}

[TestMethod]
public void CallbackShouldBeCalledAtOnce()
{
var monitor = new SettingsMonitor<Settings>(Settings.Default);

int callbackTimes = 0;
monitor.Watch(s => s.Feature_CleanupAllCode, _ => callbackTimes++);

Assert.AreEqual(/*Initial Call Times*/1, callbackTimes);
}

[TestMethod]
public void CallbackShouldNotBeCalledIfSettingNotChanged()
{
Settings.Default.Feature_CleanupAllCode = false;
var monitor = new SettingsMonitor<Settings>(Settings.Default);

bool? value = null;
int callbackTimes = 0;
monitor.Watch(s => s.Feature_CleanupAllCode, v =>
{
value = v;
callbackTimes++;
});

Settings.Default.Feature_CleanupAllCode = false;
Settings.Default.Save();

Assert.AreEqual(/*Initial Call Times*/1 + 0, callbackTimes);
Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value);
}

[TestMethod]
public void CallbackShouldBeCalledOnceSettingChanged()
{
Settings.Default.Feature_CleanupAllCode = false;
var monitor = new SettingsMonitor<Settings>(Settings.Default);

bool? value = null;
int callbackTimes = 0;
monitor.Watch(s => s.Feature_CleanupAllCode, v =>
{
value = v;
callbackTimes++;
});

Settings.Default.Feature_CleanupAllCode = true;
Settings.Default.Save();

Assert.AreEqual(/*Initial Call Times*/ 1 + 1, callbackTimes);
Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value);
}

[TestMethod]
public void AllCallbacksShouldBeCalledOnceSettingChanged()
{
Settings.Default.Feature_CleanupAllCode = false;
var monitor = new SettingsMonitor<Settings>(Settings.Default);

bool? value1 = null, value2 = null;
int callbackTimes1 = 0, callbackTimes2 = 0;
monitor.Watch(s => s.Feature_CleanupAllCode, v =>
{
value1 = v;
callbackTimes1++;
});
monitor.Watch(s => s.Feature_CleanupAllCode, v =>
{
value2 = v;
callbackTimes2++;
});

Settings.Default.Feature_CleanupAllCode = true;
Settings.Default.Save();

Assert.AreEqual(/*Initial Call Times*/1 + 1, callbackTimes1);
Assert.AreEqual(/*Initial Call Times*/1 + 1, callbackTimes2);
Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value1);
Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value2);
}

[TestMethod]
public void CallbackShouldBeCalledOnceAnyWatchedSettingChanged()
{
Settings.Default.Feature_CleanupAllCode = false;
Settings.Default.Feature_CleanupOpenCode = false;
Settings.Default.Feature_CleanupSelectedCode = true;
var monitor = new SettingsMonitor<Settings>(Settings.Default);

bool[] values = null;
int callbackTimes = 0;
monitor.Watch<bool>(new[]{
nameof(Settings.Default.Feature_CleanupAllCode),
nameof(Settings.Default.Feature_CleanupOpenCode),
nameof(Settings.Default.Feature_CleanupSelectedCode)
}, v =>
{
values = v;
callbackTimes++;
});

Settings.Default.Feature_CleanupSelectedCode = false;
Settings.Default.Save();

Assert.AreEqual(/*Initial Call Times*/1 + 1, callbackTimes);
Assert.IsTrue(values.All(v => v == false));
}
}
}
6 changes: 6 additions & 0 deletions CodeMaid.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<setting name="Reorganizing_RunAtStartOfCleanup" serializeAs="String">
<value>False</value>
</setting>
<setting name="Feature_CleanupActiveCode" serializeAs="String">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these features added here, but not all the other ones? I think perhaps they could be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I see you force auto cleanup on file save for this repo, this feature requires Feature_CleanupActiveCode and Feature_SettingCleanupOnSave features on.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see, so you're trying to ensure those features are present in case someone normally has them disabled in their user-level settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

<value>True</value>
</setting>
<setting name="Feature_SettingCleanupOnSave" serializeAs="String">
<value>True</value>
</setting>
</SteveCadwallader.CodeMaid.Properties.Settings>
</userSettings>
</configuration>
8 changes: 7 additions & 1 deletion CodeMaid/CodeMaid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<Compile Include="Helpers\MemberTypeSettingHelper.cs" />
<Compile Include="Helpers\ProjectItemExtensions.cs" />
<Compile Include="Helpers\RegexNullSafe.cs" />
<Compile Include="Helpers\SettingsMonitor.cs" />
<Compile Include="Helpers\SettingsContextHelper.cs" />
<Compile Include="Helpers\RegionHelper.cs" />
<Compile Include="Helpers\TextDocumentExtensions.cs" />
Expand All @@ -197,6 +198,7 @@
<Compile Include="Integration\Commands\SortLinesCommand.cs" />
<Compile Include="Integration\Commands\SpadeContextInsertRegionCommand.cs" />
<Compile Include="Integration\Commands\SpadeSearchCommand.cs" />
<Compile Include="Integration\ISwitchableFeature.cs" />
<Compile Include="Logic\Cleaning\FileHeaderLogic.cs" />
<Compile Include="Logic\Cleaning\RemoveRegionLogic.cs" />
<Compile Include="Logic\Formatting\CommentFormatLogic.cs" />
Expand Down Expand Up @@ -254,7 +256,6 @@
<Compile Include="Integration\Events\BuildProgressEventListener.cs" />
<Compile Include="Integration\Events\DocumentEventListener.cs" />
<Compile Include="Integration\Events\RunningDocumentTableEventListener.cs" />
<Compile Include="Integration\Events\ShellEventListener.cs" />
<Compile Include="Integration\Events\SolutionEventListener.cs" />
<Compile Include="Integration\Events\TextEditorEventListener.cs" />
<Compile Include="Integration\Events\WindowEventListener.cs" />
Expand Down Expand Up @@ -350,6 +351,7 @@
<Compile Include="UI\Dialogs\Options\Finding\FindingViewModel.cs" />
<Compile Include="UI\Dialogs\Options\Formatting\FormattingViewModel.cs" />
<Compile Include="UI\Dialogs\Options\Collapsing\CollapsingViewModel.cs" />
<Compile Include="UI\Dialogs\Options\General\FeaturesViewModel.cs" />
<Compile Include="UI\Dialogs\Options\ISettingToOptionMapping.cs" />
<Compile Include="UI\Dialogs\Options\SettingToOptionMapping.cs" />
<Compile Include="UI\Dialogs\Options\SettingsToOptionsList.cs" />
Expand Down Expand Up @@ -681,6 +683,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UI\Dialogs\Options\General\FeaturesDataTemplate.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UI\Dialogs\Options\ThirdParty\ThirdPartyDataTemplate.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
48 changes: 25 additions & 23 deletions CodeMaid/CodeMaid.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,16 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidBuildProgressToolWindow" priority="0x0100" type="Button">
<Icon guid="GuidImageProgress" id="IconProgress" />
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Build Progress</ButtonText>
</Strings>
</Button>

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidCleanupActiveCode" priority="0x0100" type="Button">
<Icon guid="GuidImageCleanup" id="IconCleanup" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<Strings>
Expand All @@ -312,7 +314,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidCleanupAllCode" priority="0x0100" type="Button">
<Icon guid="GuidImageCleanupAll" id="IconCleanupAll" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Cleanup &amp;All Code...</ButtonText>
Expand All @@ -321,7 +323,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidCleanupOpenCode" priority="0x0100" type="Button">
<Icon guid="GuidImageCleanup" id="IconCleanup" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Cleanup Open Code</ButtonText>
Expand All @@ -330,7 +332,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidCleanupSelectedCode" priority="0x0100" type="Button">
<Icon guid="GuidImageCleanup" id="IconCleanup" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Cleanup Selected Code</ButtonText>
Expand All @@ -339,7 +341,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidCloseAllReadOnly" priority="0x0100" type="Button">
<Icon guid="GuidImageCloseLocked" id="IconCloseLocked" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Close All &amp;Read-Only</ButtonText>
Expand All @@ -348,7 +350,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidCollapseAllSolutionExplorer" priority="0x0100" type="Button">
<Icon guid="GuidImageCollapse" id="IconCollapse" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Co&amp;llapse All Recursively</ButtonText>
Expand All @@ -357,7 +359,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidCollapseSelectedSolutionExplorer" priority="0x0100" type="Button">
<Icon guid="GuidImageCollapse" id="IconCollapse" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Co&amp;llapse Recursively</ButtonText>
Expand All @@ -366,7 +368,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidCommentFormat" priority="0x0100" type="Button">
<Icon guid="GuidImageCommentFormat" id="IconCommentFormat" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Format Comme&amp;nt</ButtonText>
Expand All @@ -375,7 +377,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidFindInSolutionExplorer" priority="0x0100" type="Button">
<Icon guid="GuidImageFind" id="IconFind" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Find In Solution Explorer</ButtonText>
Expand All @@ -384,7 +386,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidJoinLines" priority="0x0100" type="Button">
<Icon guid="GuidImageJoin" id="IconJoin" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Join Lines</ButtonText>
Expand All @@ -400,7 +402,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidReadOnlyToggle" priority="0x0100" type="Button">
<Icon guid="GuidImageUnlock" id="IconUnlock" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Read-Only Toggle</ButtonText>
Expand All @@ -409,7 +411,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidRemoveRegion" priority="0x0100" type="Button">
<Icon guid="GuidImageRemoveRegion" id="IconRemoveRegion" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<Strings>
Expand All @@ -419,7 +421,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidReorganizeActiveCode" priority="0x0100" type="Button">
<Icon guid="GuidImageReorganize" id="IconReorganize" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<Strings>
Expand All @@ -429,6 +431,8 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidSettingCleanupOnSave" priority="0x0100" type="Button">
<Icon guid="GuidImageOptions" id="IconOptions" />
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<Strings>
<ButtonText>&amp;Automatic Cleanup On Save</ButtonText>
Expand All @@ -437,7 +441,7 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidSortLines" priority="0x0100" type="Button">
<Icon guid="GuidImageSortAlpha" id="IconSortAlpha" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Sort Lines</ButtonText>
Expand Down Expand Up @@ -515,14 +519,16 @@

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidSpadeToolWindow" priority="0x0100" type="Button">
<Icon guid="GuidImageSpade" id="IconSpade" />
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>&amp;Spade</ButtonText>
</Strings>
</Button>

<Button guid="GuidCodeMaidMenuSet" id="CmdIDCodeMaidSwitchFile" priority="0x0100" type="Button">
<Icon guid="GuidImageSwitch" id="IconSwitch" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<Strings>
Expand Down Expand Up @@ -987,18 +993,14 @@
<GuidSymbol name="GuidCodeMaidPackage" value="{4c82e17d-927e-42d2-8460-b473ac7df316}" />

<!-- These are the tool window guids -->
<GuidSymbol name="GuidCodeMaidToolWindowBuildProgress" value="{260978c3-582c-487d-ab12-c1fdde07c578}">
</GuidSymbol>
<GuidSymbol name="GuidCodeMaidToolWindowSpade" value="{75d09b86-471e-4b30-8720-362d13ad0a45}">
</GuidSymbol>
<GuidSymbol name="GuidCodeMaidToolWindowBuildProgress" value="{260978c3-582c-487d-ab12-c1fdde07c578}" />
<GuidSymbol name="GuidCodeMaidToolWindowSpade" value="{75d09b86-471e-4b30-8720-362d13ad0a45}" />

<!-- This is the output pane guid -->
<GuidSymbol name="GuidCodeMaidOutputPane" value="{4e7ba904-9311-4dd0-abe5-a61c1739780f}">
</GuidSymbol>
<GuidSymbol name="GuidCodeMaidOutputPane" value="{4e7ba904-9311-4dd0-abe5-a61c1739780f}" />

<!-- These are the symbols for all menu items provided by CodeMaid -->
<GuidSymbol name="GuidCodeMaidMenuSet" value="{369b04df-0688-4074-911d-d0d6c6a31632}">

<!-- This is the id used to group the menu commands together -->
<IDSymbol name="GroupIDCodeMaidMenuBaseGroup" value="0x1020" />

Expand Down Expand Up @@ -1045,7 +1047,7 @@
<!-- This is the command set for the document tab context menu -->
<IDSymbol name="GroupIDCodeMaidContextDocumentTabGroup" value="0x1070" />

<!-- These are the command sets for the document context menu groups -->
<!-- These are the command sets for the document context menu groups -->
<IDSymbol name="GroupIDCodeMaidContextASPXWindowGroup" value="0x1080" />
<IDSymbol name="GroupIDCodeMaidContextASPXCodeWindowGroup" value="0x1081" />
<IDSymbol name="GroupIDCodeMaidContextCodeWindowGroup" value="0x1082" />
Expand Down
Loading