Skip to content

Commit f5fccbd

Browse files
authored
Finalize tree checkbox API (microsoft#185846)
* Finalize tree checkbox API Fixes microsoft#116141 * Remove TODO
1 parent 42457bd commit f5fccbd

File tree

6 files changed

+76
-98
lines changed

6 files changed

+76
-98
lines changed

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
14621462
ThemeColor: extHostTypes.ThemeColor,
14631463
ThemeIcon: extHostTypes.ThemeIcon,
14641464
TreeItem: extHostTypes.TreeItem,
1465-
TreeItem2: extHostTypes.TreeItem,
14661465
TreeItemCheckboxState: extHostTypes.TreeItemCheckboxState,
14671466
TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState,
14681467
TypeHierarchyItem: extHostTypes.TypeHierarchyItem,

src/vs/workbench/api/common/extHostTreeViews.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
2222
import { MarkdownString, ViewBadge, DataTransfer } from 'vs/workbench/api/common/extHostTypeConverters';
2323
import { IMarkdownString } from 'vs/base/common/htmlContent';
2424
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
25-
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
2625
import { ITreeViewsDnDService, TreeViewsDnDService } from 'vs/editor/common/services/treeViewsDnd';
2726
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
2827

@@ -103,7 +102,6 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
103102
get visible() { return treeView.visible; },
104103
get onDidChangeVisibility() { return treeView.onDidChangeVisibility; },
105104
get onDidChangeCheckboxState() {
106-
checkProposedApiEnabled(extension, 'treeItemCheckbox');
107105
return treeView.onDidChangeCheckboxState;
108106
},
109107
get message() { return treeView.message; },
@@ -500,7 +498,7 @@ class ExtHostTreeView<T> extends Disposable {
500498
}
501499

502500
async setCheckboxState(checkboxUpdates: CheckboxUpdate[]) {
503-
type CheckboxUpdateWithItem = { extensionItem: NonNullable<T>; treeItem: vscode.TreeItem2; newState: TreeItemCheckboxState };
501+
type CheckboxUpdateWithItem = { extensionItem: NonNullable<T>; treeItem: vscode.TreeItem; newState: TreeItemCheckboxState };
504502
const items = (await Promise.all(checkboxUpdates.map(async checkboxUpdate => {
505503
const extensionItem = this.getExtensionElement(checkboxUpdate.treeItemHandle);
506504
if (extensionItem) {
@@ -763,7 +761,7 @@ class ExtHostTreeView<T> extends Disposable {
763761
return command ? { ...this.commands.toInternal(command, disposable), originalId: command.command } : undefined;
764762
}
765763

766-
private getCheckbox(extensionTreeItem: vscode.TreeItem2): ITreeItemCheckboxState | undefined {
764+
private getCheckbox(extensionTreeItem: vscode.TreeItem): ITreeItemCheckboxState | undefined {
767765
if (extensionTreeItem.checkboxState === undefined) {
768766
return undefined;
769767
}

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { FileSystemProviderErrorCode, markAsFileSystemProviderError } from 'vs/p
1818
import { RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver';
1919
import { IRelativePatternDto } from 'vs/workbench/api/common/extHost.protocol';
2020
import { CellEditType, ICellMetadataEdit, IDocumentMetadataEdit, isTextStreamMime } from 'vs/workbench/contrib/notebook/common/notebookCommon';
21-
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
2221
import type * as vscode from 'vscode';
2322

2423
/**
@@ -2542,10 +2541,9 @@ export class TreeItem {
25422541
checkboxState?: vscode.TreeItemCheckboxState;
25432542

25442543
static isTreeItem(thing: any, extension: IExtensionDescription): thing is TreeItem {
2545-
const treeItemThing = thing as vscode.TreeItem2;
2544+
const treeItemThing = thing as vscode.TreeItem;
25462545

25472546
if (treeItemThing.checkboxState !== undefined) {
2548-
checkProposedApiEnabled(extension, 'treeItemCheckbox');
25492547
const checkbox = isNumber(treeItemThing.checkboxState) ? treeItemThing.checkboxState :
25502548
isObject(treeItemThing.checkboxState) && isNumber(treeItemThing.checkboxState.state) ? treeItemThing.checkboxState.state : undefined;
25512549
const tooltip = !isNumber(treeItemThing.checkboxState) && isObject(treeItemThing.checkboxState) ? treeItemThing.checkboxState.tooltip : undefined;

src/vs/workbench/services/extensions/common/extensionsApiProposals.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export const allApiProposals = Object.freeze({
9191
textSearchProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textSearchProvider.d.ts',
9292
timeline: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.timeline.d.ts',
9393
tokenInformation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tokenInformation.d.ts',
94-
treeItemCheckbox: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.treeItemCheckbox.d.ts',
9594
treeViewReveal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.treeViewReveal.d.ts',
9695
tunnels: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tunnels.d.ts',
9796
windowActivity: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.windowActivity.d.ts',

src/vscode-dts/vscode.d.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10392,6 +10392,44 @@ declare module 'vscode' {
1039210392
* An optional interface to implement drag and drop in the tree view.
1039310393
*/
1039410394
dragAndDropController?: TreeDragAndDropController<T>;
10395+
10396+
/**
10397+
* 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.
10398+
* If the tree item is collapsed by default (meaning that the children haven't yet been fetched) then child checkboxes will not be updated.
10399+
* To override this behavior and manage child and parent checkbox state in the extension, set this to `true`.
10400+
*
10401+
* Examples where {@link TreeViewOptions.manageCheckboxStateManually} is false, the default behavior:
10402+
*
10403+
* 1. A tree item is checked, then its children are fetched. The children will be checked.
10404+
*
10405+
* 2. A tree item's parent is checked. The tree item and all of it's siblings will be checked.
10406+
* - [ ] Parent
10407+
* - [ ] Child 1
10408+
* - [ ] Child 2
10409+
* When the user checks Parent, the tree will look like this:
10410+
* - [x] Parent
10411+
* - [x] Child 1
10412+
* - [x] Child 2
10413+
*
10414+
* 3. A tree item and all of it's siblings are checked. The parent will be checked.
10415+
* - [ ] Parent
10416+
* - [ ] Child 1
10417+
* - [ ] Child 2
10418+
* When the user checks Child 1 and Child 2, the tree will look like this:
10419+
* - [x] Parent
10420+
* - [x] Child 1
10421+
* - [x] Child 2
10422+
*
10423+
* 4. A tree item is unchecked. The parent will be unchecked.
10424+
* - [x] Parent
10425+
* - [x] Child 1
10426+
* - [x] Child 2
10427+
* When the user unchecks Child 1, the tree will look like this:
10428+
* - [ ] Parent
10429+
* - [ ] Child 1
10430+
* - [x] Child 2
10431+
*/
10432+
manageCheckboxStateManually?: boolean;
1039510433
}
1039610434

1039710435
/**
@@ -10608,6 +10646,16 @@ declare module 'vscode' {
1060810646
readonly value: number;
1060910647
}
1061010648

10649+
/**
10650+
* An event describing the change in a tree item's checkbox state.
10651+
*/
10652+
export interface TreeCheckboxChangeEvent<T> {
10653+
/**
10654+
* The items that were checked or unchecked.
10655+
*/
10656+
readonly items: ReadonlyArray<[T, TreeItemCheckboxState]>;
10657+
}
10658+
1061110659
/**
1061210660
* Represents a Tree view
1061310661
*/
@@ -10643,6 +10691,11 @@ declare module 'vscode' {
1064310691
*/
1064410692
readonly onDidChangeVisibility: Event<TreeViewVisibilityChangeEvent>;
1064510693

10694+
/**
10695+
* An event to signal that an element or root has either been checked or unchecked.
10696+
*/
10697+
readonly onDidChangeCheckboxState: Event<TreeCheckboxChangeEvent<T>>;
10698+
1064610699
/**
1064710700
* An optional human-readable message that will be rendered in the view.
1064810701
* Setting the message to null, undefined, or empty string will remove the message from the view.
@@ -10824,6 +10877,12 @@ declare module 'vscode' {
1082410877
*/
1082510878
accessibilityInformation?: AccessibilityInformation;
1082610879

10880+
/**
10881+
* {@link TreeItemCheckboxState TreeItemCheckboxState} of the tree item.
10882+
* {@link TreeDataProvider.onDidChangeTreeData onDidChangeTreeData} should be fired when {@link TreeItem.checkboxState checkboxState} changes.
10883+
*/
10884+
checkboxState?: TreeItemCheckboxState | { readonly state: TreeItemCheckboxState; readonly tooltip?: string; readonly accessibilityInformation?: AccessibilityInformation };
10885+
1082710886
/**
1082810887
* @param label A human-readable string describing this item
1082910888
* @param collapsibleState {@link TreeItemCollapsibleState} of the tree item. Default is {@link TreeItemCollapsibleState.None}
@@ -10872,6 +10931,20 @@ declare module 'vscode' {
1087210931
highlights?: [number, number][];
1087310932
}
1087410933

10934+
/**
10935+
* Checkbox state of the tree item
10936+
*/
10937+
export enum TreeItemCheckboxState {
10938+
/**
10939+
* Determines an item is unchecked
10940+
*/
10941+
Unchecked = 0,
10942+
/**
10943+
* Determines an item is checked
10944+
*/
10945+
Checked = 1
10946+
}
10947+
1087510948
/**
1087610949
* Value-object describing what options a terminal should use.
1087710950
*/

src/vscode-dts/vscode.proposed.treeItemCheckbox.d.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)