Browse Source

HotKey property landed to button and menuitem

pull/227/head
Nikita Tsukanov 11 years ago
parent
commit
23896f772d
  1. 12
      src/Perspex.Controls/Button.cs
  2. 13
      src/Perspex.Controls/MenuItem.cs
  3. 45
      src/Perspex.Input/HotkeyManager.cs
  4. 1
      src/Perspex.Input/Perspex.Input.csproj

12
src/Perspex.Controls/Button.cs

@ -44,6 +44,9 @@ namespace Perspex.Controls
public static readonly PerspexProperty<ICommand> CommandProperty = public static readonly PerspexProperty<ICommand> CommandProperty =
PerspexProperty.Register<Button, ICommand>(nameof(Command)); PerspexProperty.Register<Button, ICommand>(nameof(Command));
public static readonly PerspexProperty<KeyGesture> HotKeyProperty =
HotKeyManager.HotKeyProperty.AddOwner<Button>();
/// <summary> /// <summary>
/// Defines the <see cref="CommandParameter"/> property. /// Defines the <see cref="CommandParameter"/> property.
/// </summary> /// </summary>
@ -100,6 +103,15 @@ namespace Perspex.Controls
set { SetValue(CommandProperty, value); } set { SetValue(CommandProperty, value); }
} }
/// <summary>
/// Gets or sets an <see cref="KeyGesture"/> associated with this control
/// </summary>
public KeyGesture HotKey
{
get { return GetValue(HotKeyProperty); }
set { SetValue(HotKeyProperty, value); }
}
/// <summary> /// <summary>
/// Gets or sets a parameter to be passed to the <see cref="Command"/>. /// Gets or sets a parameter to be passed to the <see cref="Command"/>.
/// </summary> /// </summary>

13
src/Perspex.Controls/MenuItem.cs

@ -28,6 +28,9 @@ namespace Perspex.Controls
public static readonly PerspexProperty<ICommand> CommandProperty = public static readonly PerspexProperty<ICommand> CommandProperty =
Button.CommandProperty.AddOwner<MenuItem>(); Button.CommandProperty.AddOwner<MenuItem>();
public static readonly PerspexProperty<KeyGesture> HotKeyProperty =
HotKeyManager.HotKeyProperty.AddOwner<Button>();
/// <summary> /// <summary>
/// Defines the <see cref="CommandParameter"/> property. /// Defines the <see cref="CommandParameter"/> property.
/// </summary> /// </summary>
@ -130,6 +133,16 @@ namespace Perspex.Controls
set { SetValue(CommandProperty, value); } set { SetValue(CommandProperty, value); }
} }
/// <summary>
/// Gets or sets an <see cref="KeyGesture"/> associated with this control
/// </summary>
public KeyGesture HotKey
{
get { return GetValue(HotKeyProperty); }
set { SetValue(HotKeyProperty, value); }
}
/// <summary> /// <summary>
/// Gets or sets the parameter to pass to the <see cref="Command"/> property of a /// Gets or sets the parameter to pass to the <see cref="Command"/> property of a
/// <see cref="MenuItem"/>. /// <see cref="MenuItem"/>.

45
src/Perspex.Input/HotkeyManager.cs

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Perspex.Input
{
public class HotkeyManager
{
public static PerspexProperty<KeyGesture> HotKey
= PerspexProperty.RegisterAttached<Visual, KeyGesture>("HotKey", typeof (HotkeyManager));
class HotkeyCommandWrapper : ICommand
{
public Visual Visual;
public PerspexProperty Property;
ICommand GetCommand() => (ICommand) Visual.GetValue(Property);
public bool CanExecute(object parameter) => GetCommand()?.CanExecute(parameter) ?? false;
public void Execute(object parameter) => GetCommand()?.Execute(parameter);
//Implementation isn't needed in this case
public event EventHandler CanExecuteChanged;
}
static HotkeyManager()
{
HotKey.Changed.Subscribe(args =>
{
if (args.OldValue != null)
{
}
});
}
}
}

1
src/Perspex.Input/Perspex.Input.csproj

@ -66,7 +66,6 @@
</Compile> </Compile>
<Compile Include="Cursors.cs" /> <Compile Include="Cursors.cs" />
<Compile Include="AccessKeyHandler.cs" /> <Compile Include="AccessKeyHandler.cs" />
<Compile Include="HotkeyManager.cs" />
<Compile Include="KeyBinding.cs" /> <Compile Include="KeyBinding.cs" />
<Compile Include="KeyGesture.cs" /> <Compile Include="KeyGesture.cs" />
<Compile Include="Platform\IClipboard.cs" /> <Compile Include="Platform\IClipboard.cs" />

Loading…
Cancel
Save