Files
vscode-extension-samples/tree-view-sample/USAGE.md

40 lines
1.5 KiB
Markdown
Raw Normal View History

# Contributing a View
2016-11-16 15:49:54 -08:00
* Contribute a view using the [views](https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributesviews) extension point.
* Register a data provider for the view using the [TreeDataProvider](https://code.visualstudio.com/docs/extensionAPI/vscode-api#_TreeDataProvider) API.
* Contribute actions to the view using `view/title` and `view/item/context` locations in [menus](https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributesmenus) extension point.
2016-11-16 15:49:54 -08:00
# contributes.views extension point
2016-11-16 15:49:54 -08:00
You must specify an identifier and name for the view. You can contribute to following locations
2016-11-16 15:49:54 -08:00
- `explorer`: Explorer view in the Side bar
- `debug`: Debug view in the Side bar
2016-11-16 15:49:54 -08:00
When the user opens the view, VS Code will then emit an activationEvent `onView:${viewId}` (e.g. `onView:nodeDependencies` for the example below). You can also control the visibility of the view by providing the `when` context value.
2016-11-16 15:49:54 -08:00
```json
"contributes": {
"views": {
"explorer": [
{
"id": "nodeDependencies",
"name": "Node Dependencies",
"when": "workspaceHasPackageJSON"
}
]
2016-11-16 15:49:54 -08:00
}
}
```
# TreeDataProvider
2016-11-16 15:49:54 -08:00
2017-09-25 16:22:19 +02:00
Extension writers should register a [provider](/docs/extensionAPI/vscode-api.md#TreeDataProvider) programmatically to populate data in the view.
2016-11-16 15:49:54 -08:00
```typescript
vscode.window.registerTreeDataProvider('nodeDependencies', new DepNodeProvider());
2016-11-16 15:49:54 -08:00
```
See [nodeDependencies.ts](src/nodeDependencies.ts) for the implementation.