wss
2 August 2023 08:26
#1
Hi,
I want to bind a custom default toolbar as SampleToolbarDefaultsOverride do
but I get an error
If I directly rebind it, it says can not unbind
there is only one ToolbarDefaultsFactory rebind in my application, it is ok in theia 1.32.0. after I migrated to 1.39.0, this error come, it is strange
@wss thank you for the discussion, it works correctly in my case:
custom-toolbar-defaults.ts
import { DeflatedToolbarTree, ToolbarAlignment } from '@theia/toolbar/lib/browser/toolbar-interfaces';
export const CustomToolbarDefaultsOverride: () => DeflatedToolbarTree = () => ({
items: {
[ToolbarAlignment.LEFT]: [
[
{
id: 'workbench.action.splitEditorRight',
command: 'workbench.action.splitEditor',
icon: 'codicon codicon-split-horizontal',
},
],
],
[ToolbarAlignment.CENTER]: [[]],
[ToolbarAlignment.RIGHT]: [[]]
},
});
custom-toolbar-module.ts
import { ContainerModule } from '@theia/core/shared/inversify';
import { CustomToolbarDefaultsOverride } from './custom-toolbar-defaults';
import { ToolbarDefaultsFactory } from '@theia/toolbar/lib/browser/toolbar-defaults';
export default new ContainerModule((_bind, _unbind, _isBound, rebind) => {
rebind(ToolbarDefaultsFactory).toConstantValue(CustomToolbarDefaultsOverride);
});
The application will correctly use the overriden defaults (ex: only the split-editor
to the left):