| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Moq;
- using Perspex.Controls.Presenters;
- using Perspex.Controls.Templates;
- using Perspex.Input;
- using Perspex.Platform;
- using Perspex.Styling;
- using Xunit;
- namespace Perspex.Controls.UnitTests.Utils
- {
- public class HotKeyManagerTests
- {
- [Fact]
- public void HotKeyManager_Should_Register_And_Unregister_Key_Binding()
- {
- using (PerspexLocator.EnterScope())
- {
- var windowImpl = new Mock<IWindowImpl>();
- var styler = new Mock<Styler>();
- PerspexLocator.CurrentMutable
- .Bind<IWindowImpl>().ToConstant(windowImpl.Object)
- .Bind<IStyler>().ToConstant(styler.Object);
- var gesture1 = new KeyGesture {Key = Key.A, Modifiers = InputModifiers.Control};
- var gesture2 = new KeyGesture {Key = Key.B, Modifiers = InputModifiers.Control};
- var tl = new Window();
- var button = new Button();
- tl.Content = button;
- tl.Template = CreateWindowTemplate();
- tl.ApplyTemplate();
- HotKeyManager.SetHotKey(button, gesture1);
- Assert.Equal(gesture1, tl.KeyBindings[0].Gesture);
- HotKeyManager.SetHotKey(button, gesture2);
- Assert.Equal(gesture2, tl.KeyBindings[0].Gesture);
- tl.Content = null;
- tl.Presenter.ApplyTemplate();
- Assert.Empty(tl.KeyBindings);
- tl.Content = button;
- tl.Presenter.ApplyTemplate();
- Assert.Equal(gesture2, tl.KeyBindings[0].Gesture);
- HotKeyManager.SetHotKey(button, null);
- Assert.Empty(tl.KeyBindings);
- }
- }
- private FuncControlTemplate CreateWindowTemplate()
- {
- return new FuncControlTemplate<Window>(parent =>
- {
- return new ContentPresenter
- {
- Name = "contentPresenter",
- [~ContentPresenter.ContentProperty] = parent[~ContentControl.ContentProperty],
- };
- });
- }
- }
- }
|