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

Fix selection of contributed menu action argument adapters #14132

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
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
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
Loading