-
Notifications
You must be signed in to change notification settings - Fork 364
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b581929
Make all features switchable
e08b3b9
Remove ServiceProvider property, use Package itself instead.
f8c0d65
Use built-in helper class VSColorTheme for theme changed notification.
e555c4c
Ensure cleanup active code feature always works in current solution.
96ac18e
Ensure Spade inside event handlers register only when feature on
7558960
Disable Spade auto show as sometimes it shows but the feature is off.
c987670
Fix review problems
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,4 +95,4 @@ private static CodeItemMethod CreateExplicitMethod(string interfaceName, string | |
return method; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
andFeature_SettingCleanupOnSave
features on.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.