How to let Widget open automatically?

I registied my Widget by coding:

registerCommands(commands: CommandRegistry): void {
super.registerCommands(commands);
commands.registerCommand(HilensCommand, {
isEnabled: widget => this.withWidget(widget, () => true),
isVisible: widget => this.withWidget(widget, () => true),
isToggled: widget => this.withWidget(widget, () => true),
execute: () => super.openView({ activate: true, reveal: true })
});
}

The Widget is actived automatically while i open the IDE, but it just folds by the side, not open automatically.

[original thread by AlwaysMing]

FrontendApplicationContribution.onDidInitializeLayout is a hook which should be to configure the default layout. If your widget contribution implements it you can call this.openView() from there.

Iā€™m interested. How exactly would I let my widget contribution implement it?

@vincent for your use-case what exactly do you want to achieve? Are you interested in adding the widget to the default layout (which happens when a workspace is opened for the first time), or would you like to open your widget always when the application is started?

I would like the widget to be available in the left sidebar every time the app is started. At the moment, I have to use the menu contribution to make the icon appear in the left area.

@vincent your custom contribution should implement FrontendApplicationContribution by implementing initializeLayout (adds the view as part of the default layout), and onStart (to open the view when the application is started).

An example of onStart can be seen with the getting-started widget which opens when the application starts without a workspace (in your case you want to open without the check):

An example of initializeLayout:

2 Likes

Thank you, this worked a charm!

1 Like