Zebra API Doc

zebra.ui.CommandManager Class

Command manager supports short cut keys definition and listening. The shortcuts have to be defined in zebra JSON configuration files. There are two sections:

  • osx to keep shortcuts for Mac OS X platform
  • common to keep shortcuts for all other platforms

The JSON configuration entity has simple structure:

{
  "common": [
       {
          "command"   : "undo_command",
          "args"      : [ true, "test"],
          "key"       : "Ctrl+z"
       },
       {
          "command" : "redo_command",
          "key"     : "Ctrl+Shift+z"
       },
       ...
  ],
  "osx" : [
       {
          "command"   : "undo_command",
          "args"      : [ true, "test"],
          "key"       : "Cmd+z"
       },
       ...
  ]
}

The configuration contains list of shortcuts. Every shortcut is bound to a key combination it is triggered. Every shortcut has a name and an optional list of arguments that have to be passed to a shortcut listener method. The optional arguments can be used to differentiate two shortcuts that are bound to the same command.

On the component level shortcut commands can be listened by implementing method whose name equals to shortcut name. Pay attention to catch shortcut command your component has to be focusable and holds focus at the given time. For instance, to catch "undo_command" do the following:

  var pan = new zebra.ui.Panel([
      function redo_command() {
          // handle shortcut here
      },

      // visualize the component gets focus
      function focused() {
          this.$super();
          this.setBackground(this.hasFocus()?"red":null);
      }
  ]);

  // let our panel to hold focus by setting appropriate property
  pan.canHaveFocus = true;

Constructor

zebra.ui.CommandManager

()

Item Index

Methods

Events

Methods

keyPressed

(
  • e
)

Key pressed event handler.

Parameters:

Events

shortcut

Shortcut event is handled by registering a method handler with shortcut manager. The manager is accessed as "zebra.ui.commandManager" static variable:

   zebra.ui.commandManager.bind(function (e) {
       ...
   });

Event Parameters:

  • e Object

    shortcut event

    • args Array

      shortcut arguments list

    • command String

      shortcut name