From f5fccbdfe84df3344e8eb9d711e2eed9913f9b05 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 22 Jun 2023 15:28:11 +0200 Subject: [PATCH] Finalize tree checkbox API (#185846) * Finalize tree checkbox API Fixes #116141 * Remove TODO --- .../workbench/api/common/extHost.api.impl.ts | 1 - .../workbench/api/common/extHostTreeViews.ts | 6 +- src/vs/workbench/api/common/extHostTypes.ts | 4 +- .../common/extensionsApiProposals.ts | 1 - src/vscode-dts/vscode.d.ts | 73 +++++++++++++++ .../vscode.proposed.treeItemCheckbox.d.ts | 89 ------------------- 6 files changed, 76 insertions(+), 98 deletions(-) delete mode 100644 src/vscode-dts/vscode.proposed.treeItemCheckbox.d.ts diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 74d589602383a..49d7ce7999053 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -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, diff --git a/src/vs/workbench/api/common/extHostTreeViews.ts b/src/vs/workbench/api/common/extHostTreeViews.ts index a33110de6cbcc..c6accd54fe98b 100644 --- a/src/vs/workbench/api/common/extHostTreeViews.ts +++ b/src/vs/workbench/api/common/extHostTreeViews.ts @@ -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 extends Disposable { } async setCheckboxState(checkboxUpdates: CheckboxUpdate[]) { - type CheckboxUpdateWithItem = { extensionItem: NonNullable; treeItem: vscode.TreeItem2; newState: TreeItemCheckboxState }; + type CheckboxUpdateWithItem = { extensionItem: NonNullable; 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 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; } diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index c1b61ceafc71e..b7c7df1f577a6 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -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; diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index 0c7d40f6e97da..ed18b53ce4f9d 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -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', diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index 8c72191f57e4a..d819f00fa1c8f 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -10392,6 +10392,44 @@ declare module 'vscode' { * An optional interface to implement drag and drop in the tree view. */ dragAndDropController?: TreeDragAndDropController; + + /** + * 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 { + /** + * 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; + /** + * An event to signal that an element or root has either been checked or unchecked. + */ + readonly onDidChangeCheckboxState: Event>; + /** * 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. */ diff --git a/src/vscode-dts/vscode.proposed.treeItemCheckbox.d.ts b/src/vscode-dts/vscode.proposed.treeItemCheckbox.d.ts deleted file mode 100644 index 436c69babdfe0..0000000000000 --- a/src/vscode-dts/vscode.proposed.treeItemCheckbox.d.ts +++ /dev/null @@ -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 { - /** - * An event to signal that an element or root has either been checked or unchecked. - */ - onDidChangeCheckboxState: Event>; - } - - export interface TreeCheckboxChangeEvent { - /** - * The items that were checked or unchecked. - */ - readonly items: ReadonlyArray<[T, TreeItemCheckboxState]>; - } - - /** - * Options for creating a {@link TreeView} - */ - export interface TreeViewOptions { - /** - * 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; - } -}