-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Description
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
-
Primary actions
- Provide using
getActions
- Register to ViewContainerTitle menu with
navigation
group - Register to ViewTitle menu with
navigation
group
- Provide using
-
Secondary actions
- Provide using
getSecondaryActions
- Register to ViewContainerTitle menu
- Register to ViewTitle menu
- Provide using
-
Context menu actions
- Provide using
getContextMenuActions
- Register to ViewContainerTitleContext menu
- Register to ViewTitleContext menu
- Provide using
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:
vscode/src/vs/workbench/contrib/markers/browser/markersView.ts
Lines 852 to 857 in af29768
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:
vscode/src/vs/workbench/contrib/outline/browser/outlinePane.ts
Lines 641 to 660 in 56e35cf
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
-
Search - @roblourens
getActions(): IAction[] {
-
Terminal - @Tyriar @meganrogge
public getActions(): IAction[] {