diff --git a/packages/commands/src/index.ts b/packages/commands/src/index.ts index 37833e630..fd25e9d98 100644 --- a/packages/commands/src/index.ts +++ b/packages/commands/src/index.ts @@ -12,7 +12,7 @@ import { } from '@lumino/algorithm'; import { - JSONExt, ReadonlyPartialJSONObject + JSONExt, ReadonlyJSONObject, ReadonlyPartialJSONObject } from '@lumino/coreutils'; import { @@ -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. * @@ -797,6 +812,20 @@ namespace CommandRegistry { */ isToggled?: CommandFunc; + /** + * 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. * @@ -1211,6 +1240,7 @@ namespace Private { readonly dataset: CommandFunc; readonly isEnabled: CommandFunc; readonly isToggled: CommandFunc; + readonly isToggleable: boolean; readonly isVisible: CommandFunc; } @@ -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 }; }