Overview

A command set is a set of commands, often with predefined properties set on them. For example there is a command for simulating a key press on the keyboard, but the media command set takes this one step further by defining a command that plays or pauses media via a key press command for the play/pause keyboard key. Gestures can only be mapped to commands that are exposed through command sets.

Included Command Sets

  • Generic Commands - Exposes many primitive commands such as key press, mouse move, and mouse click.
  • Media Commands - Exposes commands for manipulating the media player such as play/pause, track forward, track backward, and mute.
  • Browser Commands - Exposes commands for manipulating the browser such as navigate backward, navigate forward, and switch browser tabs.

Extending Command Sets

To create a command set you must inherit from the command set abstract class and decorate the class with the CommandSetAttribute. Commands are exposed via properties of type CommandDescriptor. The command descriptor must supply a factory method to create commands. To hide user properties from the gui set the AllowsUserProperties property of the command to false within the factory method.

Sample

[CommandSet("Browser Commands", "BrowserCommandSet")]
public class BrowserCommandSet : CommandSet
{
CommandDescriptor _backCommand;
CommandDescriptor _forwardCommand;
CommandDescriptor _switchTabCommand;

public CommandDescriptor BackCommand { get { return _backCommand; } }
public CommandDescriptor ForwardCommand { get { return _forwardCommand; } }
public CommandDescriptor SwitchTabCommand { get { return _switchTabCommand; } }

public BrowserCommandSet()
{
    _backCommand = new CommandDescriptor()
    {
        CreateCommandInstance = () => new KeyPressCommand() 
            { 
                Key = System.Windows.Forms.Keys.BrowserBack, 
                AllowUserProperties = false 
            },
        ActionText = "Browse Back"
    };

    _forwardCommand = new CommandDescriptor()
    {
        CreateCommandInstance = () => new KeyPressCommand() 
            { 
                Key = System.Windows.Forms.Keys.BrowserForward, 
                AllowUserProperties = false 
            },
        ActionText = "Browse Forward"
    };

    _switchTabCommand = new CommandDescriptor()
    {
        CreateCommandInstance = () => new SwitchCommand() 
        {   
            SwitchKey = System.Windows.Forms.Keys.Tab,
            ModifierKey = System.Windows.Forms.Keys.ControlKey,
            ReverseModifierKey = System.Windows.Forms.Keys.ShiftKey,
            AllowUserProperties = false 
        },

        ActionText = "Switch Tabs"
    };
}

Last edited Nov 20, 2009 at 7:41 PM by PhilipB, version 3

Comments

No comments yet.