Hi all,
I have a widget MyTestWidget
that is derived from TreeWidget
from theia core.
How can I attach a context menu to MyTestWidget
? Any sample would be very helpful.
Thanks in advance.
I referred to the Debug Watch widget implementation in theia:
packages/debug/src/browser/view/debug-watch-widget.ts
.
This seems like a good example.
However, in my widget (that is derived from TreeWidget
), during initialization of ContainerModule, i’m setting the context menu as shown below:
{
const child = createTreeContainer(parent);
/*other init code*/
child.rebind(TreeProps).toConstantValue(TEST_VIEW_PROPS);
/*more initialization*/
}
export const TEST_VIEW_PROPS = <TreeProps>{
...defaultTreeProps,
contextMenuPath: TestViewMenus.TEST_VIEW_CONTEXT_MENU,
multiSelect: true,
search: true,
globalSelection: true
};
export class TestViewMenus {
static TEST_VIEW_CONTEXT_MENU: MenuPath = ['TEST-view-context-menu'];
static TEST_VIEW = [...TestViewMenus.TEST_VIEW_CONTEXT_MENU, 'TEST-view'];
};
and in frontend-contribution class:
registerCommands(registry: CommandRegistry): void {
super.registerCommands(registry);
registry.registerCommand(TestViewCommands.OPEN, {
isEnabled: () => true,
execute: () => this.open()
});
registry.registerCommand(TestViewCommands.DELETE, {
isEnabled: () => true,
execute: () => this.delete()
});
}
registerMenus(menus: MenuModelRegistry): void {
super.registerMenus(menus);
menus.registerMenuAction(TestViewMenus.TEST_VIEW, {
commandId: TestViewCommands.OPEN.id,
order: '0'
});
menus.registerMenuAction(TestViewMenus.TEST_VIEW, {
commandId: TestViewCommands.DELETE.id,
order: '1'
});
}
But, when I right click the an item in the tree view, no context menu appears… Pls help.
Snippets which you shared looks good. It is hard to say without running.