mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Finalize data file reading API (#152127)
Fixes #147481 Also reverts #150963 since the `kind` field is not being finalized
This commit is contained in:
parent
d132489cd0
commit
354e1a0595
|
@ -7,7 +7,6 @@
|
|||
"src/**/*",
|
||||
"../../src/vscode-dts/vscode.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.textEditorDrop.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.dataTransferFiles.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.documentPaste.d.ts"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -37,14 +37,14 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
|
|||
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTreeViews);
|
||||
}
|
||||
|
||||
async $registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: string[]; dragMimeTypes: string[]; hasHandleDrag: boolean; hasHandleDrop: boolean; supportsFileDataTransfers: boolean }): Promise<void> {
|
||||
async $registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: string[]; dragMimeTypes: string[]; hasHandleDrag: boolean; hasHandleDrop: boolean }): Promise<void> {
|
||||
this.logService.trace('MainThreadTreeViews#$registerTreeViewDataProvider', treeViewId, options);
|
||||
|
||||
this.extensionService.whenInstalledExtensionsRegistered().then(() => {
|
||||
const dataProvider = new TreeViewDataProvider(treeViewId, this._proxy, this.notificationService);
|
||||
this._dataProviders.set(treeViewId, dataProvider);
|
||||
const dndController = (options.hasHandleDrag || options.hasHandleDrop)
|
||||
? new TreeViewDragAndDropController(treeViewId, options.dropMimeTypes, options.dragMimeTypes, options.hasHandleDrag, options.supportsFileDataTransfers, this._proxy) : undefined;
|
||||
? new TreeViewDragAndDropController(treeViewId, options.dropMimeTypes, options.dragMimeTypes, options.hasHandleDrag, this._proxy) : undefined;
|
||||
const viewer = this.getTreeView(treeViewId);
|
||||
if (viewer) {
|
||||
// Order is important here. The internal tree isn't created until the dataProvider is set.
|
||||
|
@ -201,7 +201,6 @@ class TreeViewDragAndDropController implements ITreeViewDragAndDropController {
|
|||
readonly dropMimeTypes: string[],
|
||||
readonly dragMimeTypes: string[],
|
||||
readonly hasWillDrop: boolean,
|
||||
readonly supportsFileDataTransfers: boolean,
|
||||
private readonly _proxy: ExtHostTreeViewsShape) { }
|
||||
|
||||
async handleDrop(dataTransfer: VSDataTransfer, targetTreeItem: ITreeItem | undefined, token: CancellationToken,
|
||||
|
|
|
@ -1327,7 +1327,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
TextSearchCompleteMessageType: TextSearchCompleteMessageType,
|
||||
DataTransfer: extHostTypes.DataTransfer,
|
||||
DataTransferItem: extHostTypes.DataTransferItem,
|
||||
DataTransferItemKind: extHostTypes.DataTransferItemKind,
|
||||
CoveredCount: extHostTypes.CoveredCount,
|
||||
FileCoverage: extHostTypes.FileCoverage,
|
||||
StatementCoverage: extHostTypes.StatementCoverage,
|
||||
|
|
|
@ -258,7 +258,7 @@ export interface MainThreadTextEditorsShape extends IDisposable {
|
|||
}
|
||||
|
||||
export interface MainThreadTreeViewsShape extends IDisposable {
|
||||
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: readonly string[]; dragMimeTypes: readonly string[]; hasHandleDrag: boolean; hasHandleDrop: boolean; supportsFileDataTransfers: boolean }): Promise<void>;
|
||||
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: readonly string[]; dragMimeTypes: readonly string[]; hasHandleDrag: boolean; hasHandleDrop: boolean }): Promise<void>;
|
||||
$refresh(treeViewId: string, itemsToRefresh?: { [treeItemHandle: string]: ITreeItem }): Promise<void>;
|
||||
$reveal(treeViewId: string, itemInfo: { item: ITreeItem; parentChain: ITreeItem[] } | undefined, options: IRevealOptions): Promise<void>;
|
||||
$setMessage(treeViewId: string, message: string): void;
|
||||
|
|
|
@ -24,7 +24,7 @@ import { IMarkdownString } from 'vs/base/common/htmlContent';
|
|||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { Command } from 'vs/editor/common/languages';
|
||||
import { ITreeViewsService, TreeviewsService } from 'vs/workbench/services/views/common/treeViewsService';
|
||||
import { checkProposedApiEnabled, isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
|
||||
type TreeItemHandle = string;
|
||||
|
||||
|
@ -92,8 +92,7 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
|
|||
const dragMimeTypes = options.dragAndDropController?.dragMimeTypes ?? [];
|
||||
const hasHandleDrag = !!options.dragAndDropController?.handleDrag;
|
||||
const hasHandleDrop = !!options.dragAndDropController?.handleDrop;
|
||||
const supportsFileDataTransfers = isProposedApiEnabled(extension, 'dataTransferFiles');
|
||||
const registerPromise = this._proxy.$registerTreeViewDataProvider(viewId, { showCollapseAll: !!options.showCollapseAll, canSelectMany: !!options.canSelectMany, dropMimeTypes, dragMimeTypes, hasHandleDrag, hasHandleDrop, supportsFileDataTransfers });
|
||||
const registerPromise = this._proxy.$registerTreeViewDataProvider(viewId, { showCollapseAll: !!options.showCollapseAll, canSelectMany: !!options.canSelectMany, dropMimeTypes, dragMimeTypes, hasHandleDrag, hasHandleDrop });
|
||||
const treeView = this.createExtHostTreeView(viewId, options, extension);
|
||||
return {
|
||||
get onDidCollapseElement() { return treeView.onDidCollapseElement; },
|
||||
|
|
|
@ -1953,8 +1953,6 @@ export namespace DataTransferItem {
|
|||
const file = item.fileData;
|
||||
if (file) {
|
||||
return new class extends types.DataTransferItem {
|
||||
override get kind() { return types.DataTransferItemKind.File; }
|
||||
|
||||
override asFile(): vscode.DataTransferFile {
|
||||
return {
|
||||
name: file.name,
|
||||
|
|
|
@ -2428,16 +2428,9 @@ export enum TreeItemCollapsibleState {
|
|||
Expanded = 2
|
||||
}
|
||||
|
||||
export enum DataTransferItemKind {
|
||||
String = 1,
|
||||
File = 2,
|
||||
}
|
||||
|
||||
@es5ClassCompat
|
||||
export class DataTransferItem {
|
||||
|
||||
get kind(): DataTransferItemKind { return DataTransferItemKind.String; }
|
||||
|
||||
async asString(): Promise<string> {
|
||||
return typeof this.value === 'string' ? this.value : JSON.stringify(this.value);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ suite('MainThreadHostTreeView', function () {
|
|||
}
|
||||
drain(): any { return null; }
|
||||
}, new TestViewsService(), new TestNotificationService(), testExtensionService, new NullLogService());
|
||||
mainThreadTreeViews.$registerTreeViewDataProvider(testTreeViewId, { showCollapseAll: false, canSelectMany: false, dropMimeTypes: [], dragMimeTypes: [], hasHandleDrag: false, hasHandleDrop: false, supportsFileDataTransfers: false });
|
||||
mainThreadTreeViews.$registerTreeViewDataProvider(testTreeViewId, { showCollapseAll: false, canSelectMany: false, dropMimeTypes: [], dragMimeTypes: [], hasHandleDrag: false, hasHandleDrop: false });
|
||||
await testExtensionService.whenInstalledExtensionsRegistered();
|
||||
});
|
||||
|
||||
|
|
|
@ -1528,9 +1528,7 @@ export class CustomTreeViewDragAndDrop implements ITreeDragAndDrop<ITreeItem> {
|
|||
const file = dataItem.getAsFile();
|
||||
if (file) {
|
||||
uris.push(URI.file(file.path));
|
||||
if (dndController.supportsFileDataTransfers) {
|
||||
treeDataTransfer.append(type, createFileDataTransferItemFromFile(file));
|
||||
}
|
||||
treeDataTransfer.append(type, createFileDataTransferItemFromFile(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -831,7 +831,6 @@ export interface ITreeViewDataProvider {
|
|||
export interface ITreeViewDragAndDropController {
|
||||
readonly dropMimeTypes: string[];
|
||||
readonly dragMimeTypes: string[];
|
||||
readonly supportsFileDataTransfers: boolean;
|
||||
handleDrag(sourceTreeItemHandles: string[], operationUuid: string, token: CancellationToken): Promise<VSDataTransfer | undefined>;
|
||||
handleDrop(elements: VSDataTransfer, target: ITreeItem | undefined, token: CancellationToken, operationUuid?: string, sourceTreeId?: string, sourceTreeItemHandles?: string[]): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ export const allApiProposals = Object.freeze({
|
|||
contribViewsRemote: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribViewsRemote.d.ts',
|
||||
contribViewsWelcome: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribViewsWelcome.d.ts',
|
||||
customEditorMove: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.customEditorMove.d.ts',
|
||||
dataTransferFiles: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.dataTransferFiles.d.ts',
|
||||
diffCommand: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.diffCommand.d.ts',
|
||||
documentFiltersExclusive: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.documentFiltersExclusive.d.ts',
|
||||
documentPaste: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.documentPaste.d.ts',
|
||||
|
|
31
src/vscode-dts/vscode.d.ts
vendored
31
src/vscode-dts/vscode.d.ts
vendored
|
@ -10054,7 +10054,28 @@ declare module 'vscode' {
|
|||
* `true` if the {@link TreeView tree view} is visible otherwise `false`.
|
||||
*/
|
||||
readonly visible: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A file associated with a {@linkcode DataTransferItem}.
|
||||
*/
|
||||
export interface DataTransferFile {
|
||||
/**
|
||||
* The name of the file.
|
||||
*/
|
||||
readonly name: string;
|
||||
|
||||
/**
|
||||
* The full file path of the file.
|
||||
*
|
||||
* May be `undefined` on web.
|
||||
*/
|
||||
readonly uri?: Uri;
|
||||
|
||||
/**
|
||||
* The full file contents of the file.
|
||||
*/
|
||||
data(): Thenable<Uint8Array>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10068,6 +10089,16 @@ declare module 'vscode' {
|
|||
*/
|
||||
asString(): Thenable<string>;
|
||||
|
||||
/**
|
||||
* Try getting the {@link DataTransferFile file} associated with this data transfer item.
|
||||
*
|
||||
* Note that the file object is only valid for the scope of the drag and drop operation.
|
||||
*
|
||||
* @returns The file for the data transfer or `undefined` if the item is either not a file or the
|
||||
* file data cannot be accessed.
|
||||
*/
|
||||
asFile(): DataTransferFile | undefined;
|
||||
|
||||
/**
|
||||
* Custom data stored on this item.
|
||||
*
|
||||
|
|
|
@ -1,71 +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' {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/147481
|
||||
|
||||
/**
|
||||
* A file associated with a {@linkcode DataTransferItem}.
|
||||
*/
|
||||
interface DataTransferFile {
|
||||
/**
|
||||
* The name of the file.
|
||||
*/
|
||||
readonly name: string;
|
||||
|
||||
/**
|
||||
* The full file path of the file.
|
||||
*
|
||||
* May be undefined on web.
|
||||
*/
|
||||
readonly uri?: Uri;
|
||||
|
||||
/**
|
||||
* The full file contents of the file.
|
||||
*/
|
||||
data(): Thenable<Uint8Array>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies the kind of a {@link DataTransferItem}. May either be {@linkcode DataTransferItemKind.String String} or {@linkcode DataTransferItemKind.File File}.
|
||||
*/
|
||||
enum DataTransferItemKind {
|
||||
|
||||
/**
|
||||
* The {@link DataTransferItem} is a string.
|
||||
*
|
||||
* Use {@link DataTransferItem.asString} to get a string representation of this item or
|
||||
* {@link DataTransferItem.value} to access the original value if them item was created
|
||||
* by an extension.
|
||||
*/
|
||||
String = 1,
|
||||
|
||||
/**
|
||||
* The {@link DataTransferItem} is for a file.
|
||||
*
|
||||
* Use {@link DataTransferItem.asFile} to get the underlying file data.
|
||||
*/
|
||||
File = 2,
|
||||
}
|
||||
|
||||
export interface DataTransferItem {
|
||||
|
||||
/**
|
||||
* The kind of the {@link DataTransferItem}.
|
||||
*/
|
||||
readonly kind: DataTransferItemKind;
|
||||
|
||||
/**
|
||||
* Try getting the file associated with this data transfer item.
|
||||
*
|
||||
* Note that the file object is only valid for the scope of the drag and drop operation.
|
||||
*
|
||||
* @returns The file for the data transfer or `undefined` if the item is either not a file or the
|
||||
* file data cannot be accessed.
|
||||
*/
|
||||
asFile(): DataTransferFile | undefined;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue