Closed axetroy closed 6 years ago
@axetroy contextValue
on TreeNode
does not refers to the menu location view/item/context
/**
* Context value of the tree item. This can be used to contribute item specific actions in the tree.
* For example, a tree item is given a context value as `folder`. When contributing actions to `view/item/context`
* using `menus` extension point, you can specify context value for key `viewItem` in `when` expression like `viewItem == folder`.
* ```
* "contributes": {
* "menus": {
* "view/item/context": [
* {
* "command": "extension.deleteFolder",
* "when": "viewItem == folder"
* }
* ]
* }
* }
* ```
* This will show action `extension.deleteFolder` only for items with `contextValue` is `folder`.
*/
contextValue?: string;
As mentioned in the documentation, contextValue
is the value your provide in the when
property. In the above example folder
is the contextValue
@sandy081
contextValue is the value your provide in the when property. In the above example folder is the contextValue
I knew it. but contextValue
is only accept string type. isn't it?
How about support an object?
contextValue is always a string and is used internally and in extensions.
What is the purpose of supporting an object?
@sandy081
What is the purpose of supporting an object?
For more complicated conditions, control the command/context when to show.
and support an object, should be more scalable
@axetroy Can you please be more specific about complicated conditions? Currently and
, not
and regex
conditions are supported.
I some case, I need to custom when the context for treeItem should show.
Here are 2 contexts for
star
andunstar
when star project,
star context
hide,unstar context
show when unstar project,unstar context
hide,star context
showHere is what I define in
view/item/context
But unfortunately,
contextValue?: string;
not support object