Skip to content

Commit

Permalink
Short title for command contribution.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed May 20, 2021
1 parent 29c6157 commit af0c01b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type Icon = { dark?: URI; light?: URI; } | ThemeIcon;
export interface ICommandAction {
id: string;
title: string | ICommandActionTitle;
shortTitle?: string | ICommandActionTitle;
category?: string | ILocalizedString;
tooltip?: string;
icon?: Icon;
Expand Down Expand Up @@ -179,6 +180,7 @@ export class MenuId {
export interface IMenuActionOptions {
arg?: any;
shouldForwardArgs?: boolean;
renderShortTitle?: boolean;
}

export interface IMenu extends IDisposable {
Expand Down Expand Up @@ -388,7 +390,9 @@ export class MenuItemAction implements IAction {
@ICommandService private _commandService: ICommandService
) {
this.id = item.id;
this.label = typeof item.title === 'string' ? item.title : item.title.value;
this.label = options?.renderShortTitle && item.shortTitle
? (typeof item.shortTitle === 'string' ? item.shortTitle : item.shortTitle.value)
: (typeof item.title === 'string' ? item.title : item.title.value);
this.tooltip = item.tooltip ?? '';
this.enabled = !item.precondition || contextKeyService.contextMatchesRules(item.precondition);
this.checked = false;
Expand Down
11 changes: 10 additions & 1 deletion src/vs/workbench/api/common/menusExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ namespace schema {
export interface IUserFriendlyCommand {
command: string;
title: string | ILocalizedString;
shortTitle?: string | ILocalizedString;
enablement?: string;
category?: string | ILocalizedString;
icon?: IUserFriendlyIcon;
Expand All @@ -457,6 +458,9 @@ namespace schema {
if (!isValidLocalizedString(command.title, collector, 'title')) {
return false;
}
if (command.shortTitle && !isValidLocalizedString(command.shortTitle, collector, 'shortTitle')) {
return false;
}
if (command.enablement && typeof command.enablement !== 'string') {
collector.error(localize('optstring', "property `{0}` can be omitted or must be of type `string`", 'precondition'));
return false;
Expand Down Expand Up @@ -510,6 +514,10 @@ namespace schema {
description: localize('vscode.extension.contributes.commandType.title', 'Title by which the command is represented in the UI'),
type: 'string'
},
shortTitle: {
description: localize('vscode.extension.contributes.commandType.shortTitle', 'Short title by which the command is represented in the UI'),
type: 'string'
},
category: {
description: localize('vscode.extension.contributes.commandType.category', '(Optional) Category string by the command is grouped in the UI'),
type: 'string'
Expand Down Expand Up @@ -567,7 +575,7 @@ commandsExtensionPoint.setHandler(extensions => {
return;
}

const { icon, enablement, category, title, command } = userFriendlyCommand;
const { icon, enablement, category, title, shortTitle, command } = userFriendlyCommand;

let absoluteIcon: { dark: URI; light?: URI; } | ThemeIcon | undefined;
if (icon) {
Expand All @@ -588,6 +596,7 @@ commandsExtensionPoint.setHandler(extensions => {
bucket.push({
id: command,
title,
shortTitle,
category,
precondition: ContextKeyExpr.deserialize(enablement),
icon: absoluteIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class NotebookEditorToolbar extends Disposable {
this.domNode.style.display = 'none';
} else {
this._notebookLeftToolbar.setActions([], []);
const groups = this._notebookGlobalActionsMenu.getActions({ shouldForwardArgs: true });
const groups = this._notebookGlobalActionsMenu.getActions({ shouldForwardArgs: true, renderShortTitle: true });
this.domNode.style.display = 'flex';
const primaryLeftGroups = groups.filter(group => /^navigation/.test(group[0]));
let primaryActions: IAction[] = [];
Expand Down

0 comments on commit af0c01b

Please sign in to comment.