Skip to content

Commit

Permalink
Fix selection of contributed menu action argument adapters (#14132)
Browse files Browse the repository at this point in the history
Fixes #14072

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>om>
  • Loading branch information
tsmaeder authored Sep 5, 2024
1 parent 0a1c174 commit 19556f4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { NAVIGATION, RenderedToolbarItem } from './tab-bar-toolbar-types';
export const TOOLBAR_WRAPPER_ID_SUFFIX = '-as-tabbar-toolbar-item';

export class ToolbarMenuNodeWrapper implements RenderedToolbarItem {
constructor(protected readonly menuNode: MenuNode, readonly group?: string, readonly menuPath?: MenuPath) { }
constructor(protected readonly menuNode: MenuNode, readonly group: string | undefined, readonly delegateMenuPath: MenuPath, readonly menuPath?: MenuPath) { }
get id(): string { return this.menuNode.id + TOOLBAR_WRAPPER_ID_SUFFIX; }
get command(): string { return this.menuNode.command ?? ''; };
get icon(): string | undefined { return this.menuNode.icon; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ export class TabBarToolbarRegistry implements FrontendApplicationContribution {
for (const grandchild of child.children) {
if (!grandchild.when || this.contextKeyService.match(grandchild.when, widget.node)) {
const menuPath = this.menuRegistry.getPath(grandchild);
result.push(new ToolbarMenuNodeWrapper(grandchild, child.id, menuPath));
result.push(new ToolbarMenuNodeWrapper(grandchild, child.id, delegate.menuPath, menuPath));
}
}
} else if (child.command) {
result.push(new ToolbarMenuNodeWrapper(child, ''));
const menuPath = this.menuRegistry.getPath(child);
result.push(new ToolbarMenuNodeWrapper(child, undefined, delegate.menuPath, menuPath));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export interface TabBarToolbarItemBase {
* If no command is present, this menu will be opened.
*/
menuPath?: MenuPath;
/**
* The path of the menu delegate that contributed this toolbar item
*/
delegateMenuPath?: MenuPath;
contextKeyOverlays?: Record<string, string>;
/**
* Optional ordering string for placing the item within its group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ export class TabBarToolbar extends ReactWidget {
return;
}

if (item.command && item.menuPath) {
this.menuCommandExecutor.executeCommand(item.menuPath, item.command, this.current);
if (item.command && item.delegateMenuPath) {
this.menuCommandExecutor.executeCommand(item.delegateMenuPath, item.command, this.current);
} else if (item.command) {
this.commands.executeCommand(item.command, this.current);
} else if (item.menuPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,27 @@ export class PluginMenuCommandAdapter implements MenuCommandAdapter {
}

protected getArgumentAdapterForMenu(menuPath: MenuPath): ArgumentAdapter | undefined {
return this.argumentAdapters.get(menuPath.join(this.separator));
let result;
let length = 0;
for (const [key, value] of this.argumentAdapters.entries()) {
const candidate = key.split(this.separator);
if (this.isPrefixOf(candidate, menuPath) && candidate.length > length) {
result = value;
length = candidate.length;
}
}
return result;
}
isPrefixOf(candidate: string[], menuPath: MenuPath): boolean {
if (candidate.length > menuPath.length) {
return false;
}
for (let i = 0; i < candidate.length; i++) {
if (candidate[i] !== menuPath[i]) {
return false;
}
}
return true;
}

protected addArgumentAdapter(menuPath: MenuPath, adapter: ArgumentAdapter): void {
Expand Down

0 comments on commit 19556f4

Please sign in to comment.