Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isToggleable command state #129

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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