mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 2b0b9136329c181a9e381463a1f7dc3a2d105a34 (#4880)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { hasWorkspaceFileExtension, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { normalize } from 'vs/base/common/path';
|
||||
import { basename } from 'vs/base/common/resources';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
@@ -79,7 +79,7 @@ export function extractResources(e: DragEvent, externalOnly?: boolean): Array<ID
|
||||
const rawEditorsData = e.dataTransfer.getData(CodeDataTransfers.EDITORS);
|
||||
if (rawEditorsData) {
|
||||
try {
|
||||
const draggedEditors = JSON.parse(rawEditorsData) as ISerializedDraggedEditor[];
|
||||
const draggedEditors: ISerializedDraggedEditor[] = JSON.parse(rawEditorsData);
|
||||
draggedEditors.forEach(draggedEditor => {
|
||||
resources.push({ resource: URI.parse(draggedEditor.resource), backupResource: draggedEditor.backupResource ? URI.parse(draggedEditor.backupResource) : undefined, viewState: draggedEditor.viewState, isExternal: false });
|
||||
});
|
||||
@@ -105,7 +105,7 @@ export function extractResources(e: DragEvent, externalOnly?: boolean): Array<ID
|
||||
// Check for native file transfer
|
||||
if (e.dataTransfer && e.dataTransfer.files) {
|
||||
for (let i = 0; i < e.dataTransfer.files.length; i++) {
|
||||
const file = e.dataTransfer.files[i] as { path: string };
|
||||
const file = e.dataTransfer.files[i];
|
||||
if (file && file.path && !resources.some(r => r.resource.fsPath === file.path) /* prevent duplicates */) {
|
||||
try {
|
||||
resources.push({ resource: URI.file(file.path), isExternal: true });
|
||||
@@ -120,7 +120,7 @@ export function extractResources(e: DragEvent, externalOnly?: boolean): Array<ID
|
||||
const rawCodeFiles = e.dataTransfer.getData(CodeDataTransfers.FILES);
|
||||
if (rawCodeFiles) {
|
||||
try {
|
||||
const codeFiles = JSON.parse(rawCodeFiles) as string[];
|
||||
const codeFiles: string[] = JSON.parse(rawCodeFiles);
|
||||
codeFiles.forEach(codeFile => {
|
||||
if (!resources.some(r => r.resource.fsPath === codeFile) /* prevent duplicates */) {
|
||||
resources.push({ resource: URI.file(codeFile), isExternal: true });
|
||||
@@ -254,16 +254,14 @@ export class ResourcesDropHandler {
|
||||
}
|
||||
|
||||
private handleWorkspaceFileDrop(fileOnDiskResources: URI[]): Promise<boolean> {
|
||||
const workspaceResources: { workspaces: IURIToOpen[], folders: IURIToOpen[] } = {
|
||||
workspaces: [],
|
||||
folders: []
|
||||
};
|
||||
const urisToOpen: IURIToOpen[] = [];
|
||||
const folderURIs: IWorkspaceFolderCreationData[] = [];
|
||||
|
||||
return Promise.all(fileOnDiskResources.map(fileOnDiskResource => {
|
||||
|
||||
// Check for Workspace
|
||||
if (hasWorkspaceFileExtension(fileOnDiskResource.fsPath)) {
|
||||
workspaceResources.workspaces.push({ uri: fileOnDiskResource, typeHint: 'file' });
|
||||
urisToOpen.push({ workspaceUri: fileOnDiskResource });
|
||||
|
||||
return undefined;
|
||||
}
|
||||
@@ -271,14 +269,14 @@ export class ResourcesDropHandler {
|
||||
// Check for Folder
|
||||
return this.fileService.resolve(fileOnDiskResource).then(stat => {
|
||||
if (stat.isDirectory) {
|
||||
workspaceResources.folders.push({ uri: stat.resource, typeHint: 'folder' });
|
||||
urisToOpen.push({ folderUri: stat.resource });
|
||||
folderURIs.push({ uri: stat.resource });
|
||||
}
|
||||
}, error => undefined);
|
||||
})).then(_ => {
|
||||
const { workspaces, folders } = workspaceResources;
|
||||
|
||||
// Return early if no external resource is a folder or workspace
|
||||
if (workspaces.length === 0 && folders.length === 0) {
|
||||
if (urisToOpen.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -286,12 +284,12 @@ export class ResourcesDropHandler {
|
||||
this.windowService.focusWindow();
|
||||
|
||||
// Open in separate windows if we drop workspaces or just one folder
|
||||
if (workspaces.length > 0 || folders.length === 1) {
|
||||
return this.windowService.openWindow([...workspaces, ...folders], { forceReuseWindow: true }).then(_ => true);
|
||||
if (urisToOpen.length > folderURIs.length || folderURIs.length === 1) {
|
||||
return this.windowService.openWindow(urisToOpen, { forceReuseWindow: true }).then(_ => true);
|
||||
}
|
||||
|
||||
// folders.length > 1: Multiple folders: Create new workspace with folders and open
|
||||
return this.workspaceEditingService.createAndEnterWorkspace(folders).then(_ => true);
|
||||
return this.workspaceEditingService.createAndEnterWorkspace(folderURIs).then(_ => true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user