Skip to content

Commit

Permalink
Finalize tree checkbox API (#185846)
Browse files Browse the repository at this point in the history
* Finalize tree checkbox API
Fixes #116141

* Remove TODO
  • Loading branch information
alexr00 authored Jun 22, 2023
1 parent 42457bd commit f5fccbd
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 98 deletions.
1 change: 0 additions & 1 deletion src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions src/vs/workbench/api/common/extHostTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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; },
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
73 changes: 73 additions & 0 deletions src/vscode-dts/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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.
*/
Expand Down
89 changes: 0 additions & 89 deletions src/vscode-dts/vscode.proposed.treeItemCheckbox.d.ts

This file was deleted.

0 comments on commit f5fccbd

Please sign in to comment.