Permalink
Browse files

Fixed the conflicting manager banner

The conflicting manager banner had a bug where it wouldn't respond to
the conflicting button.  Users had to hit Ignore and then select the
Options button to manually bring up the conflicting key manager.
  • Loading branch information...
1 parent 70962e2 commit 47544436af843260732cd8feeefdeb88831d52d6 @jaredpar committed Jun 28, 2012
@@ -416,11 +416,19 @@ public static Mock<IServiceProvider> CreateServiceProvider(MockRepository factor
{
factory = factory ?? new MockRepository(MockBehavior.Strict);
var mock = factory.Create<IServiceProvider>();
- foreach (var tuple in serviceList)
- {
- var localTuple = tuple;
- mock.Setup(x => x.GetService(localTuple.Item1)).Returns(localTuple.Item2);
- }
+ mock
+ .Setup(x => x.GetService(It.IsAny<Type>()))
+ .Returns<Type>(type =>
+ {
+ foreach (var tuple in serviceList)
+ {
+ if (tuple.Item1 == type)
+ {
+ return tuple.Item2;
+ }
+ }
+ return null;
+ });
return mock;
}
@@ -29,13 +29,7 @@ public interface IKeyBindingService
/// Start the check for conflicting key bindings. This method will return immediately but can
/// operate asynchrounously. If the check has already run this method will exit immediately
/// </summary>
- void RunConflictingKeyBindingStateCheck(IVimBuffer buffer, Action<ConflictingKeyBindingState, CommandKeyBindingSnapshot> onComplete);
-
- /// <summary>
- /// Start the check for conflicting key bindings. This method will return immediately but can
- /// operate asynchrounously. If the check has already run this method will exit immediately
- /// </summary>
- void RunConflictingKeyBindingStateCheck(IEnumerable<KeyInput> neededInputs, Action<ConflictingKeyBindingState, CommandKeyBindingSnapshot> onComplete);
+ void RunConflictingKeyBindingStateCheck(IVimBuffer buffer);
/// <summary>
/// Reset the checked state of the key binding service
@@ -28,6 +28,11 @@ internal sealed class KeyBindingService : IKeyBindingService, IVimBufferCreation
private ConflictingKeyBindingState _state;
private CommandKeyBindingSnapshot _snapshot;
+ internal CommandKeyBindingSnapshot CommandKeyBindingSnapshotOptional
+ {
+ get { return _snapshot; }
+ }
+
[ImportingConstructor]
internal KeyBindingService(SVsServiceProvider serviceProvider, IOptionsDialogService service, IProtectedOperations protectedOperations, ILegacySettings legacySettings)
{
@@ -64,24 +69,17 @@ private set
internal event EventHandler ConflictingKeyBindingStateChanged;
- internal void RunConflictingKeyBindingStateCheck(IVimBuffer buffer, Action<ConflictingKeyBindingState, CommandKeyBindingSnapshot> onComplete)
+ internal void RunConflictingKeyBindingStateCheck(IVimBuffer buffer)
{
+ // Create the set of KeyInput values which are handled by VsVim
var needed = buffer.AllModes.Select(x => x.CommandNames).SelectMany(x => x).ToList();
needed.Add(KeyInputSet.NewOneKeyInput(buffer.LocalSettings.GlobalSettings.DisableAllCommand));
- RunConflictingKeyBindingStateCheck(needed.Select(x => x.KeyInputs.First()), onComplete);
- }
+ var set = new HashSet<KeyInput>(needed.Select(x => x.KeyInputs.First()));
- internal void RunConflictingKeyBindingStateCheck(IEnumerable<KeyInput> neededInputs, Action<ConflictingKeyBindingState, CommandKeyBindingSnapshot> onComplete)
- {
- if (_snapshot != null)
- {
- onComplete(_state, _snapshot);
- return;
- }
-
- var set = new HashSet<KeyInput>(neededInputs);
- var snapshot = CreateCommandKeyBindingSnapshot(set);
- ConflictingKeyBindingState = snapshot.Conflicting.Any()
+ // Take a snapshot based on the current state of the DTE commands and store it
+ // and the conflicting state
+ _snapshot = CreateCommandKeyBindingSnapshot(set);
+ ConflictingKeyBindingState = _snapshot.Conflicting.Any()
? ConflictingKeyBindingState.FoundConflicts
: ConflictingKeyBindingState.ConflictsIgnoredOrResolved;
}
@@ -102,14 +100,12 @@ internal void ResolveAnyConflicts()
if (_optionsDialogService.ShowConflictingKeyBindingsDialog(_snapshot))
{
ConflictingKeyBindingState = ConflictingKeyBindingState.ConflictsIgnoredOrResolved;
- _snapshot = null;
}
}
internal void IgnoreAnyConflicts()
{
ConflictingKeyBindingState = ConflictingKeyBindingState.ConflictsIgnoredOrResolved;
- _snapshot = null;
}
/// <summary>
@@ -328,14 +324,9 @@ CommandKeyBindingSnapshot IKeyBindingService.CreateCommandKeyBindingSnapshot(IVi
return CreateCommandKeyBindingSnapshot(vimBuffer);
}
- void IKeyBindingService.RunConflictingKeyBindingStateCheck(IVimBuffer buffer, Action<ConflictingKeyBindingState, CommandKeyBindingSnapshot> onComplete)
- {
- RunConflictingKeyBindingStateCheck(buffer, onComplete);
- }
-
- void IKeyBindingService.RunConflictingKeyBindingStateCheck(IEnumerable<KeyInput> neededInputs, Action<ConflictingKeyBindingState, CommandKeyBindingSnapshot> onComplete)
+ void IKeyBindingService.RunConflictingKeyBindingStateCheck(IVimBuffer buffer)
{
- RunConflictingKeyBindingStateCheck(neededInputs, onComplete);
+ RunConflictingKeyBindingStateCheck(buffer);
}
void IKeyBindingService.ResetConflictingKeyBindingState()
@@ -369,7 +360,7 @@ void IVimBufferCreationListener.VimBufferCreated(IVimBuffer vimBuffer)
}
else
{
- RunConflictingKeyBindingStateCheck(vimBuffer, (x, y) => { });
+ RunConflictingKeyBindingStateCheck(vimBuffer);
}
}
};
@@ -9,13 +9,15 @@
using Vim.UI.Wpf;
using VsVim.Implementation;
using VsVim.UnitTest.Mock;
+using Vim.UnitTest;
namespace VsVim.UnitTest
{
- public sealed class KeyBindingServiceTest
+ public sealed class KeyBindingServiceTest : VimTestBase
{
private Mock<_DTE> _dte;
private Mock<IOptionsDialogService> _optionsDialogService;
+ private Mock<ILegacySettings> _legacySettings;
private KeyBindingService _serviceRaw;
private IKeyBindingService _service;
private CommandsSnapshot _commandsSnapshot;
@@ -28,12 +30,17 @@ private void Create(params string[] args)
Tuple.Create(typeof(SDTE), (object)(_dte.Object)),
Tuple.Create(typeof(SVsShell), (object)(new Mock<IVsShell>(MockBehavior.Strict)).Object));
_optionsDialogService = new Mock<IOptionsDialogService>(MockBehavior.Strict);
+ _legacySettings = new Mock<ILegacySettings>(MockBehavior.Strict);
+ _legacySettings.SetupGet(x => x.IgnoredConflictingKeyBinding).Returns(false);
+ _legacySettings.SetupGet(x => x.HaveUpdatedKeyBindings).Returns(false);
_serviceRaw = new KeyBindingService(
sp.Object,
_optionsDialogService.Object,
new Mock<IProtectedOperations>().Object,
- new Mock<ILegacySettings>().Object);
+ _legacySettings.Object);
_service = _serviceRaw;
+
+ var result = _dte.Object.Commands.Count;
}
private void Create()
@@ -271,5 +278,31 @@ public void ShouldSkip_FunctionKeys()
Create();
Assert.False(_serviceRaw.ShouldSkip(binding));
}
+
+ /// <summary>
+ /// Make sure that after running the conflicting check and there are conflicts that we
+ /// store the information
+ /// </summary>
+ [Fact]
+ public void RunConflictingKeyBindingStateCheck_SetSnapshot()
+ {
+ Create("::d", "::ctrl+h", "::b");
+ var vimBuffer = CreateVimBuffer("");
+ _service.RunConflictingKeyBindingStateCheck(vimBuffer);
+ Assert.NotNull(_serviceRaw.ConflictingKeyBindingState);
+ Assert.Equal(ConflictingKeyBindingState.FoundConflicts, _serviceRaw.ConflictingKeyBindingState);
+ }
+
+ /// <summary>
+ /// Make sure we correctly detect there are no conflicts if there are none
+ /// </summary>
+ [Fact]
+ public void RunConflictingKeyBindingStateCheck_NoConflicts()
+ {
+ Create(new string[] { });
+ var vimBuffer = CreateVimBuffer("");
+ _service.RunConflictingKeyBindingStateCheck(vimBuffer);
+ Assert.Equal(ConflictingKeyBindingState.ConflictsIgnoredOrResolved, _serviceRaw.ConflictingKeyBindingState);
+ }
}
}
@@ -23,31 +23,41 @@ public static Mock<SVsServiceProvider> CreateVsServiceProvider(MockRepository fa
return mock.As<SVsServiceProvider>();
}
- public static IEnumerable<Mock<EnvDTE.Command>> CreateCommandList(params string[] args)
+ public static List<Mock<EnvDTE.Command>> CreateCommandList(params string[] args)
{
+ var list = new List<Mock<EnvDTE.Command>>();
foreach (var binding in args)
{
var localBinding = binding;
var mock = new Mock<EnvDTE.Command>(MockBehavior.Strict);
mock.Setup(x => x.Bindings).Returns(localBinding);
mock.Setup(x => x.Name).Returns("example command");
mock.Setup(x => x.LocalizedName).Returns("example command");
- yield return mock;
+ list.Add(mock);
}
+
+ return list;
}
- public static Mock<EnvDTE.Commands> CreateCommands(IEnumerable<EnvDTE.Command> commands)
+ public static Mock<EnvDTE.Commands> CreateCommands(List<EnvDTE.Command> commands)
{
var mock = new Mock<EnvDTE.Commands>(MockBehavior.Strict);
var enumMock = mock.As<IEnumerable>();
- mock.Setup(x => x.GetEnumerator()).Returns(commands.GetEnumerator());
- enumMock.Setup(x => x.GetEnumerator()).Returns(commands.GetEnumerator());
+ mock.Setup(x => x.GetEnumerator()).Returns(() =>
+ {
+ return commands.GetEnumerator();
+ });
+ mock.SetupGet(x => x.Count).Returns(commands.Count);
+ enumMock.Setup(x => x.GetEnumerator()).Returns(() =>
+ {
+ return commands.GetEnumerator();
+ });
return mock;
}
public static Mock<_DTE> CreateDteWithCommands(params string[] args)
{
- var commandList = CreateCommandList(args).Select(x => x.Object);
+ var commandList = CreateCommandList(args).Select(x => x.Object).ToList();
var commands = CreateCommands(commandList);
var dte = new Mock<_DTE>();
dte.SetupGet(x => x.Commands).Returns(commands.Object);

0 comments on commit 4754443

Please sign in to comment.