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

Fixed submenu ordering. #8377

Merged
merged 1 commit into from
Aug 14, 2020
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 @@ -21,6 +21,10 @@ const SampleCommand: Command = {
id: 'sample-command',
label: 'Sample Command'
};
const SampleCommand2: Command = {
id: 'sample-command2',
label: 'Sample Command2'
};

@injectable()
export class SampleCommandContribution implements CommandContribution {
Expand All @@ -30,6 +34,11 @@ export class SampleCommandContribution implements CommandContribution {
alert('This is a sample command!');
}
});
commands.registerCommand(SampleCommand2, {
execute: () => {
alert('This is sample command2!');
}
});
}

}
Expand All @@ -42,7 +51,22 @@ export class SampleMenuContribution implements MenuContribution {
order: '2' // that should put the menu right next to the File menu
});
menus.registerMenuAction(subMenuPath, {
commandId: SampleCommand.id
commandId: SampleCommand.id,
order: '0'
});
menus.registerMenuAction(subMenuPath, {
commandId: SampleCommand2.id,
order: '2'
});
const subSubMenuPath = [...subMenuPath, 'sample-sub-menu'];
menus.registerSubmenu(subSubMenuPath, 'Sample sub menu', { order: '1' });
menus.registerMenuAction(subSubMenuPath, {
commandId: SampleCommand.id,
order: '0'
});
menus.registerMenuAction(subSubMenuPath, {
commandId: SampleCommand2.id,
order: '2'
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/common/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export class MenuModelRegistry {
const index = menuPath.length - 1;
const menuId = menuPath[index];
const groupPath = index === 0 ? [] : menuPath.slice(0, index);
const parent = this.findGroup(groupPath);
let groupNode = this.findSubMenu(parent, menuId);
const parent = this.findGroup(groupPath, options);
let groupNode = this.findSubMenu(parent, menuId, options);
if (!groupNode) {
groupNode = new CompositeMenuNode(menuId, label, options);
return parent.addNode(groupNode);
Expand Down Expand Up @@ -155,23 +155,23 @@ export class MenuModelRegistry {
recurse(this.root);
}

protected findGroup(menuPath: MenuPath): CompositeMenuNode {
protected findGroup(menuPath: MenuPath, options?: SubMenuOptions): CompositeMenuNode {
let currentMenu = this.root;
for (const segment of menuPath) {
currentMenu = this.findSubMenu(currentMenu, segment);
currentMenu = this.findSubMenu(currentMenu, segment, options);
}
return currentMenu;
}

protected findSubMenu(current: CompositeMenuNode, menuId: string): CompositeMenuNode {
protected findSubMenu(current: CompositeMenuNode, menuId: string, options?: SubMenuOptions): CompositeMenuNode {
const sub = current.children.find(e => e.id === menuId);
if (sub instanceof CompositeMenuNode) {
return sub;
}
if (sub) {
throw new Error(`'${menuId}' is not a menu group.`);
}
const newSub = new CompositeMenuNode(menuId);
const newSub = new CompositeMenuNode(menuId, undefined, options);
current.addNode(newSub);
return newSub;
}
Expand Down