mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
reuse code to extract resources from DND
This commit is contained in:
parent
11e5950dda
commit
93b0a04aa5
|
@ -6,6 +6,7 @@
|
|||
'use strict';
|
||||
|
||||
import {$} from 'vs/base/browser/builder';
|
||||
import URI from 'vs/base/common/uri';
|
||||
|
||||
/**
|
||||
* A helper that will execute a provided function when the provided HTMLElement receives
|
||||
|
@ -39,4 +40,35 @@ export class DelayedDragHandler {
|
|||
public dispose(): void {
|
||||
this.clearDragTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
export function extractResources(e: DragEvent): URI[] {
|
||||
const resources: URI[] = [];
|
||||
if (e.dataTransfer.types.length > 0) {
|
||||
|
||||
// Check for in-app DND
|
||||
const rawData = e.dataTransfer.getData(e.dataTransfer.types[0]);
|
||||
if (rawData) {
|
||||
try {
|
||||
resources.push(URI.parse(rawData));
|
||||
} catch (error) {
|
||||
// Invalid URI
|
||||
}
|
||||
}
|
||||
|
||||
// Check for native file transfer
|
||||
if (e.dataTransfer && e.dataTransfer.files) {
|
||||
for (let i = 0; i < e.dataTransfer.files.length; i++) {
|
||||
if (e.dataTransfer.files[i] && e.dataTransfer.files[i].path) {
|
||||
try {
|
||||
resources.push(URI.file(e.dataTransfer.files[i].path));
|
||||
} catch (error) {
|
||||
// Invalid URI
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resources;
|
||||
}
|
|
@ -34,6 +34,7 @@ import {TabsTitleControl} from 'vs/workbench/browser/parts/editor/tabsTitleContr
|
|||
import {NoTabsTitleControl} from 'vs/workbench/browser/parts/editor/noTabsTitleControl';
|
||||
import {IEditorStacksModel, IStacksModelChangeEvent, IWorkbenchEditorConfiguration} from 'vs/workbench/common/editor';
|
||||
import {ITitleAreaControl} from 'vs/workbench/browser/parts/editor/titleControl';
|
||||
import {extractResources} from 'vs/base/browser/dnd';
|
||||
|
||||
export enum Rochade {
|
||||
NONE,
|
||||
|
@ -762,28 +763,7 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
|
|||
node.addEventListener(DOM.EventType.DROP, (e: DragEvent) => {
|
||||
DOM.EventHelper.stop(e);
|
||||
|
||||
const droppedResources: URI[] = [];
|
||||
if (e.dataTransfer.types.length > 0) {
|
||||
|
||||
// Check for in-app DND
|
||||
const rawData = e.dataTransfer.getData(e.dataTransfer.types[0]);
|
||||
if (rawData) {
|
||||
const resource = URI.parse(rawData);
|
||||
if (resource.scheme === 'file' || resource.scheme === 'untitled') {
|
||||
droppedResources.push(resource);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for native file transfer
|
||||
if (e.dataTransfer && e.dataTransfer.files) {
|
||||
for (let i = 0; i < e.dataTransfer.files.length; i++) {
|
||||
if (e.dataTransfer.files[i] && e.dataTransfer.files[i].path) {
|
||||
droppedResources.push(URI.file(e.dataTransfer.files[i].path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const droppedResources = extractResources(e).filter(r => r.scheme === 'file' || r.scheme === 'untitled');
|
||||
if (droppedResources.length) {
|
||||
window.focus(); // make sure this window has focus so that the open call reaches the right window!
|
||||
this.openFromDrop(droppedResources, <HTMLElement>e.toElement).done(null, errors.onUnexpectedError);
|
||||
|
|
|
@ -11,7 +11,6 @@ import {IAction} from 'vs/base/common/actions';
|
|||
import {prepareActions} from 'vs/workbench/browser/actionBarRegistry';
|
||||
import arrays = require('vs/base/common/arrays');
|
||||
import errors = require('vs/base/common/errors');
|
||||
import URI from 'vs/base/common/uri';
|
||||
import DOM = require('vs/base/browser/dom');
|
||||
import {isMacintosh} from 'vs/base/common/platform';
|
||||
import {MIME_BINARY} from 'vs/base/common/mime';
|
||||
|
@ -33,6 +32,7 @@ import {TitleControl} from 'vs/workbench/browser/parts/editor/titleControl';
|
|||
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
|
||||
import {ScrollableElement} from 'vs/base/browser/ui/scrollbar/scrollableElement';
|
||||
import {ScrollbarVisibility} from 'vs/base/browser/ui/scrollbar/scrollableElementOptions';
|
||||
import {extractResources} from 'vs/base/browser/dnd';
|
||||
|
||||
export class TabsTitleControl extends TitleControl {
|
||||
|
||||
|
@ -472,31 +472,7 @@ export class TabsTitleControl extends TitleControl {
|
|||
}
|
||||
|
||||
private handleExternalDrop(e: DragEvent, targetPosition: Position, targetIndex: number): void {
|
||||
let resources: URI[] = [];
|
||||
|
||||
if (e.dataTransfer.types.length > 0) {
|
||||
|
||||
// Check for in-app DND
|
||||
const rawData = e.dataTransfer.getData(e.dataTransfer.types[0]);
|
||||
if (rawData) {
|
||||
const resource = URI.parse(rawData);
|
||||
if (resource.scheme === 'file' || resource.scheme === 'untitled') {
|
||||
resources.push(resource);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for external app DND
|
||||
else if (e.dataTransfer && e.dataTransfer.files) {
|
||||
let thepaths: string[] = [];
|
||||
for (let i = 0; i < e.dataTransfer.files.length; i++) {
|
||||
if (e.dataTransfer.files[i] && (e.dataTransfer.files[i]).path) {
|
||||
thepaths.push(e.dataTransfer.files[i].path);
|
||||
}
|
||||
}
|
||||
|
||||
resources = thepaths.map(p => URI.file(p));
|
||||
}
|
||||
}
|
||||
const resources = extractResources(e).filter(r => r.scheme === 'file' || r.scheme === 'untitled');
|
||||
|
||||
// Open resources if found
|
||||
if (resources.length) {
|
||||
|
|
Loading…
Reference in a new issue