Skip to content

Review usage/overrides of get.*Actions on ViewPanes #92038

@sbatten

Description

@sbatten

With the introduction of View Menu Actions its possible for ViewPanes to accidentally override them. We should verify if this is happening and consider if we still want View Menu Actions with DnD for views already introduced.
/cc @eamodio

Updated Description

Currently ViewPanes and ViewPaneContainers can contribute Primary, Secondary and ContextMenu actions in following ways

We would like to move away from get*Actions and use Menu registry because

  • All actions shall be command driven so that user can assign keybindings
  • Facilitates providing customizable menus
  • Improves code quality
    • One consistent way to register actions across workbench
    • Allows removing redundant code if the same action is used at multiple places
    • Helps in removing ambiguity of actions lifecycle and simplifies views as they do not need to maintain actions state

I will be removing the get*Actions method after everyone move away from it. I listed the existing consumers of this and assigned the respective owner. Please adopt using Menu registries.

Here are some tips that might help you while adopting

  • If you have a custom UI for your action, you can override getActionViewItem like before and provide custom implementation.

Example:

public getActionViewItem(action: IAction): IActionViewItem | undefined {
if (action.id === `workbench.actions.treeView.${this.id}.filter`) {
return this.instantiationService.createInstance(MarkersFilterActionViewItem, action, this);
}
return super.getActionViewItem(action);
}

  • If your action needs access to your view's or view container's state, you can use ViewAction or ViewPaneContainerAction. They will pass our view or viewPaneContainer as arg in run method

Example:

registerAction2(class Collapse extends ViewAction<OutlinePane> {
constructor() {
super({
viewId: OutlineViewId,
id: 'outline.collapse',
title: localize('collapse', "Collapse All"),
f1: false,
icon: Codicon.collapseAll,
menu: {
id: MenuId.ViewTitle,
group: 'navigation',
when: ContextKeyEqualsExpr.create('view', OutlineViewId)
}
});
}
runInView(_accessor: ServicesAccessor, view: OutlinePane) {
view.collapseAll();
}
});

To Adopt

Metadata

Metadata

Assignees

Labels

debtCode quality issuesworkbench-viewsWorkbench view issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions