Skip to content

Commit

Permalink
Add isToggleable command state
Browse files Browse the repository at this point in the history
  • Loading branch information
Martha Cryan committed Nov 4, 2020
1 parent 11728c2 commit 536e531
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion packages/commands/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@lumino/algorithm';

import {
JSONExt, ReadonlyPartialJSONObject
JSONExt, ReadonlyJSONObject, ReadonlyPartialJSONObject
} from '@lumino/coreutils';

import {
Expand Down Expand Up @@ -333,6 +333,21 @@ class CommandRegistry {
return cmd ? cmd.isToggled.call(undefined, args) : false;
}

/**
* Test whether a specific command is toggleable.
*
* @param id - The id of the command of interest.
*
* @param args - The arguments for the command.
*
* @returns A boolean indicating whether the command is toggleable,
* or `false` if the command is not registered.
*/
isToggleable(id: string, args: ReadonlyJSONObject = JSONExt.emptyObject): boolean {
let cmd = this._commands[id];
return cmd ? cmd.isToggleable : false;
}

/**
* Test whether a specific command is visible.
*
Expand Down Expand Up @@ -797,6 +812,20 @@ namespace CommandRegistry {
*/
isToggled?: CommandFunc<boolean>;

/**
* A function which indicates whether the command is toggleable.
*
* #### Notes
* Visual representations may use this value to display a toggled command in
* a different form, such as a check box for a menu item or a depressed
* state for a toggle button. This attribute also allows for accessible
* interfaces to notify the user that the command corresponds to some state.
*
* The default value is `true` if an `isToggled` function is given, `false`
* otherwise.
*/
isToggleable?: boolean;

/**
* A function which indicates whether the command is visible.
*
Expand Down Expand Up @@ -1211,6 +1240,7 @@ namespace Private {
readonly dataset: CommandFunc<Dataset>;
readonly isEnabled: CommandFunc<boolean>;
readonly isToggled: CommandFunc<boolean>;
readonly isToggleable: boolean;
readonly isVisible: CommandFunc<boolean>;
}

Expand Down Expand Up @@ -1250,6 +1280,7 @@ namespace Private {
dataset: asFunc(options.dataset, emptyDatasetFunc),
isEnabled: options.isEnabled || trueFunc,
isToggled: options.isToggled || falseFunc,
isToggleable: options.isToggleable || !!options.isToggled,
isVisible: options.isVisible || trueFunc
};
}
Expand Down

0 comments on commit 536e531

Please sign in to comment.