diff --git a/packages/commands/src/index.ts b/packages/commands/src/index.ts index 5e356be58..fbf08046a 100644 --- a/packages/commands/src/index.ts +++ b/packages/commands/src/index.ts @@ -313,6 +313,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. * @@ -759,6 +774,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. * @@ -1147,6 +1176,7 @@ namespace Private { readonly dataset: CommandFunc; readonly isEnabled: CommandFunc; readonly isToggled: CommandFunc; + readonly isToggleable: boolean; readonly isVisible: CommandFunc; } @@ -1167,6 +1197,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 }; }