mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-11 17:18:13 +01:00
Finalize tree checkbox API (#185846)
* Finalize tree checkbox API Fixes #116141 * Remove TODO
This commit is contained in:
@@ -1462,7 +1462,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
ThemeColor: extHostTypes.ThemeColor,
|
||||
ThemeIcon: extHostTypes.ThemeIcon,
|
||||
TreeItem: extHostTypes.TreeItem,
|
||||
TreeItem2: extHostTypes.TreeItem,
|
||||
TreeItemCheckboxState: extHostTypes.TreeItemCheckboxState,
|
||||
TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState,
|
||||
TypeHierarchyItem: extHostTypes.TypeHierarchyItem,
|
||||
|
||||
@@ -22,7 +22,6 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
|
||||
import { MarkdownString, ViewBadge, DataTransfer } from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import { IMarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { ITreeViewsDnDService, TreeViewsDnDService } from 'vs/editor/common/services/treeViewsDnd';
|
||||
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
|
||||
|
||||
@@ -103,7 +102,6 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
|
||||
get visible() { return treeView.visible; },
|
||||
get onDidChangeVisibility() { return treeView.onDidChangeVisibility; },
|
||||
get onDidChangeCheckboxState() {
|
||||
checkProposedApiEnabled(extension, 'treeItemCheckbox');
|
||||
return treeView.onDidChangeCheckboxState;
|
||||
},
|
||||
get message() { return treeView.message; },
|
||||
@@ -500,7 +498,7 @@ class ExtHostTreeView<T> extends Disposable {
|
||||
}
|
||||
|
||||
async setCheckboxState(checkboxUpdates: CheckboxUpdate[]) {
|
||||
type CheckboxUpdateWithItem = { extensionItem: NonNullable<T>; treeItem: vscode.TreeItem2; newState: TreeItemCheckboxState };
|
||||
type CheckboxUpdateWithItem = { extensionItem: NonNullable<T>; treeItem: vscode.TreeItem; newState: TreeItemCheckboxState };
|
||||
const items = (await Promise.all(checkboxUpdates.map(async checkboxUpdate => {
|
||||
const extensionItem = this.getExtensionElement(checkboxUpdate.treeItemHandle);
|
||||
if (extensionItem) {
|
||||
@@ -763,7 +761,7 @@ class ExtHostTreeView<T> extends Disposable {
|
||||
return command ? { ...this.commands.toInternal(command, disposable), originalId: command.command } : undefined;
|
||||
}
|
||||
|
||||
private getCheckbox(extensionTreeItem: vscode.TreeItem2): ITreeItemCheckboxState | undefined {
|
||||
private getCheckbox(extensionTreeItem: vscode.TreeItem): ITreeItemCheckboxState | undefined {
|
||||
if (extensionTreeItem.checkboxState === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import { FileSystemProviderErrorCode, markAsFileSystemProviderError } from 'vs/p
|
||||
import { RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver';
|
||||
import { IRelativePatternDto } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { CellEditType, ICellMetadataEdit, IDocumentMetadataEdit, isTextStreamMime } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import type * as vscode from 'vscode';
|
||||
|
||||
/**
|
||||
@@ -2542,10 +2541,9 @@ export class TreeItem {
|
||||
checkboxState?: vscode.TreeItemCheckboxState;
|
||||
|
||||
static isTreeItem(thing: any, extension: IExtensionDescription): thing is TreeItem {
|
||||
const treeItemThing = thing as vscode.TreeItem2;
|
||||
const treeItemThing = thing as vscode.TreeItem;
|
||||
|
||||
if (treeItemThing.checkboxState !== undefined) {
|
||||
checkProposedApiEnabled(extension, 'treeItemCheckbox');
|
||||
const checkbox = isNumber(treeItemThing.checkboxState) ? treeItemThing.checkboxState :
|
||||
isObject(treeItemThing.checkboxState) && isNumber(treeItemThing.checkboxState.state) ? treeItemThing.checkboxState.state : undefined;
|
||||
const tooltip = !isNumber(treeItemThing.checkboxState) && isObject(treeItemThing.checkboxState) ? treeItemThing.checkboxState.tooltip : undefined;
|
||||
|
||||
@@ -91,7 +91,6 @@ export const allApiProposals = Object.freeze({
|
||||
textSearchProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textSearchProvider.d.ts',
|
||||
timeline: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.timeline.d.ts',
|
||||
tokenInformation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tokenInformation.d.ts',
|
||||
treeItemCheckbox: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.treeItemCheckbox.d.ts',
|
||||
treeViewReveal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.treeViewReveal.d.ts',
|
||||
tunnels: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tunnels.d.ts',
|
||||
windowActivity: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.windowActivity.d.ts',
|
||||
|
||||
Vendored
+73
@@ -10392,6 +10392,44 @@ declare module 'vscode' {
|
||||
* An optional interface to implement drag and drop in the tree view.
|
||||
*/
|
||||
dragAndDropController?: TreeDragAndDropController<T>;
|
||||
|
||||
/**
|
||||
* By default, when the children of a tree item have already been fetched, child checkboxes are automatically managed based on the checked state of the parent tree item.
|
||||
* If the tree item is collapsed by default (meaning that the children haven't yet been fetched) then child checkboxes will not be updated.
|
||||
* To override this behavior and manage child and parent checkbox state in the extension, set this to `true`.
|
||||
*
|
||||
* Examples where {@link TreeViewOptions.manageCheckboxStateManually} is false, the default behavior:
|
||||
*
|
||||
* 1. A tree item is checked, then its children are fetched. The children will be checked.
|
||||
*
|
||||
* 2. A tree item's parent is checked. The tree item and all of it's siblings will be checked.
|
||||
* - [ ] Parent
|
||||
* - [ ] Child 1
|
||||
* - [ ] Child 2
|
||||
* When the user checks Parent, the tree will look like this:
|
||||
* - [x] Parent
|
||||
* - [x] Child 1
|
||||
* - [x] Child 2
|
||||
*
|
||||
* 3. A tree item and all of it's siblings are checked. The parent will be checked.
|
||||
* - [ ] Parent
|
||||
* - [ ] Child 1
|
||||
* - [ ] Child 2
|
||||
* When the user checks Child 1 and Child 2, the tree will look like this:
|
||||
* - [x] Parent
|
||||
* - [x] Child 1
|
||||
* - [x] Child 2
|
||||
*
|
||||
* 4. A tree item is unchecked. The parent will be unchecked.
|
||||
* - [x] Parent
|
||||
* - [x] Child 1
|
||||
* - [x] Child 2
|
||||
* When the user unchecks Child 1, the tree will look like this:
|
||||
* - [ ] Parent
|
||||
* - [ ] Child 1
|
||||
* - [x] Child 2
|
||||
*/
|
||||
manageCheckboxStateManually?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -10608,6 +10646,16 @@ declare module 'vscode' {
|
||||
readonly value: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* An event describing the change in a tree item's checkbox state.
|
||||
*/
|
||||
export interface TreeCheckboxChangeEvent<T> {
|
||||
/**
|
||||
* The items that were checked or unchecked.
|
||||
*/
|
||||
readonly items: ReadonlyArray<[T, TreeItemCheckboxState]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a Tree view
|
||||
*/
|
||||
@@ -10643,6 +10691,11 @@ declare module 'vscode' {
|
||||
*/
|
||||
readonly onDidChangeVisibility: Event<TreeViewVisibilityChangeEvent>;
|
||||
|
||||
/**
|
||||
* An event to signal that an element or root has either been checked or unchecked.
|
||||
*/
|
||||
readonly onDidChangeCheckboxState: Event<TreeCheckboxChangeEvent<T>>;
|
||||
|
||||
/**
|
||||
* An optional human-readable message that will be rendered in the view.
|
||||
* Setting the message to null, undefined, or empty string will remove the message from the view.
|
||||
@@ -10824,6 +10877,12 @@ declare module 'vscode' {
|
||||
*/
|
||||
accessibilityInformation?: AccessibilityInformation;
|
||||
|
||||
/**
|
||||
* {@link TreeItemCheckboxState TreeItemCheckboxState} of the tree item.
|
||||
* {@link TreeDataProvider.onDidChangeTreeData onDidChangeTreeData} should be fired when {@link TreeItem.checkboxState checkboxState} changes.
|
||||
*/
|
||||
checkboxState?: TreeItemCheckboxState | { readonly state: TreeItemCheckboxState; readonly tooltip?: string; readonly accessibilityInformation?: AccessibilityInformation };
|
||||
|
||||
/**
|
||||
* @param label A human-readable string describing this item
|
||||
* @param collapsibleState {@link TreeItemCollapsibleState} of the tree item. Default is {@link TreeItemCollapsibleState.None}
|
||||
@@ -10872,6 +10931,20 @@ declare module 'vscode' {
|
||||
highlights?: [number, number][];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox state of the tree item
|
||||
*/
|
||||
export enum TreeItemCheckboxState {
|
||||
/**
|
||||
* Determines an item is unchecked
|
||||
*/
|
||||
Unchecked = 0,
|
||||
/**
|
||||
* Determines an item is checked
|
||||
*/
|
||||
Checked = 1
|
||||
}
|
||||
|
||||
/**
|
||||
* Value-object describing what options a terminal should use.
|
||||
*/
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module 'vscode' {
|
||||
|
||||
export class TreeItem2 extends TreeItem {
|
||||
/**
|
||||
* {@link TreeItemCheckboxState TreeItemCheckboxState} of the tree item.
|
||||
* {@link TreeDataProvider.onDidChangeTreeData onDidChangeTreeData} should be fired when {@link TreeItem2.checkboxState checkboxState} changes.
|
||||
*/
|
||||
checkboxState?: TreeItemCheckboxState | { readonly state: TreeItemCheckboxState; readonly tooltip?: string; readonly accessibilityInformation?: AccessibilityInformation };
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox state of the tree item
|
||||
*/
|
||||
export enum TreeItemCheckboxState {
|
||||
/**
|
||||
* Determines an item is unchecked
|
||||
*/
|
||||
Unchecked = 0,
|
||||
/**
|
||||
* Determines an item is checked
|
||||
*/
|
||||
Checked = 1
|
||||
}
|
||||
|
||||
/**
|
||||
* A data provider that provides tree data
|
||||
*/
|
||||
export interface TreeView<T> {
|
||||
/**
|
||||
* An event to signal that an element or root has either been checked or unchecked.
|
||||
*/
|
||||
onDidChangeCheckboxState: Event<TreeCheckboxChangeEvent<T>>;
|
||||
}
|
||||
|
||||
export interface TreeCheckboxChangeEvent<T> {
|
||||
/**
|
||||
* The items that were checked or unchecked.
|
||||
*/
|
||||
readonly items: ReadonlyArray<[T, TreeItemCheckboxState]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for creating a {@link TreeView}
|
||||
*/
|
||||
export interface TreeViewOptions<T> {
|
||||
/**
|
||||
* By default, when the children of a tree item have already been fetched, child checkboxes are automatically managed based on the checked state of the parent tree item.
|
||||
* If the tree item is collapsed by default (meaning that the children haven't yet been fetched) then child checkboxes will not be updated.
|
||||
* To override this behavior and manage child and parent checkbox state in the extension, set this to `true`.
|
||||
*
|
||||
* Examples where {@link TreeViewOptions.manageCheckboxStateManually} is false, the default behavior:
|
||||
*
|
||||
* 1. A tree item is checked, then its children are fetched. The children will be checked. TODO @alexr00 there's a bug here
|
||||
*
|
||||
* 2. A tree item's parent is checked. The tree item and all of it's siblings will be checked.
|
||||
* - [ ] Parent
|
||||
* - [ ] Child 1
|
||||
* - [ ] Child 2
|
||||
* When the user checks Parent, the tree will look like this:
|
||||
* - [x] Parent
|
||||
* - [x] Child 1
|
||||
* - [x] Child 2
|
||||
*
|
||||
* 3. A tree item and all of it's siblings are checked. The parent will be checked.
|
||||
* - [ ] Parent
|
||||
* - [ ] Child 1
|
||||
* - [ ] Child 2
|
||||
* When the user checks Child 1 and Child 2, the tree will look like this:
|
||||
* - [x] Parent
|
||||
* - [x] Child 1
|
||||
* - [x] Child 2
|
||||
*
|
||||
* 4. A tree item is unchecked. The parent will be unchecked. TODO @alexr00 there's a bug here
|
||||
* - [x] Parent
|
||||
* - [x] Child 1
|
||||
* - [x] Child 2
|
||||
* When the user unchecks Child 1, the tree will look like this:
|
||||
* - [ ] Parent
|
||||
* - [ ] Child 1
|
||||
* - [x] Child 2
|
||||
*/
|
||||
manageCheckboxStateManually?: boolean;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user