diff --git a/src/vs/workbench/browser/parts/editor/sideBySideEditorControl.ts b/src/vs/workbench/browser/parts/editor/sideBySideEditorControl.ts index f668a640f6c..cc2a70b7f06 100644 --- a/src/vs/workbench/browser/parts/editor/sideBySideEditorControl.ts +++ b/src/vs/workbench/browser/parts/editor/sideBySideEditorControl.ts @@ -7,6 +7,7 @@ import 'vs/css!./media/sidebyside'; import arrays = require('vs/base/common/arrays'); +import {TPromise} from 'vs/base/common/winjs.base'; import Event, {Emitter} from 'vs/base/common/event'; import {StandardMouseEvent} from 'vs/base/browser/mouseEvent'; import {isWindows} from 'vs/base/common/platform'; @@ -16,6 +17,8 @@ import {Sash, ISashEvent, IVerticalSashLayoutProvider} from 'vs/base/browser/ui/ import {ProgressBar} from 'vs/base/browser/ui/progressbar/progressbar'; import {BaseEditor} from 'vs/workbench/browser/parts/editor/baseEditor'; import DOM = require('vs/base/browser/dom'); +import errors = require('vs/base/common/errors'); +import URI from 'vs/base/common/uri'; import {IWorkbenchEditorService, GroupArrangement} from 'vs/workbench/services/editor/common/editorService'; import {IContextMenuService} from 'vs/platform/contextview/browser/contextView'; import {Position, POSITIONS} from 'vs/platform/editor/common/editor'; @@ -704,6 +707,9 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti private create(parent: Builder): void { + // Allow to drop into container to open + this.enableDropTarget(parent.getHTMLElement()); + // Left Container this.containers[Position.LEFT] = $(parent).div({ class: 'one-editor-container editor-left monaco-editor-background' }); @@ -750,6 +756,54 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti } } + private enableDropTarget(node: HTMLElement): void { + + // Let a dropped file open inside Code (only if dropped over editor area) + node.addEventListener(DOM.EventType.DROP, (e: DragEvent) => { + DOM.EventHelper.stop(e); + + // Check for native file transfer + 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); + } + } + + if (thepaths.length) { + window.focus(); // make sure this window has focus so that the open call reaches the right window! + this.openFromDrop(thepaths.map(p => URI.file(p)), e.toElement).done(null, errors.onUnexpectedError); + } + } + }); + } + + private openFromDrop(resources: URI[], target: HTMLElement): TPromise { + + // Find target position by looking at target DOM node + let position = Position.LEFT; + this.containers.forEach((container, index) => { + if (DOM.isAncestor(target, container.getHTMLElement())) { + position = index; + } + }); + + // One resource to open: always pick position of the drop + if (resources.length === 1) { + return this.editorService.openEditor({ resource: resources[0], options: { pinned: true } }, position); + } + + // Multiple resources to open with tabs: open them all in target position + const showsTabs = this.configurationService.getConfiguration().workbench.showEditorTabs; + if (showsTabs) { + return this.editorService.openEditors(resources.map(resource => { return { input: { resource, options: { pinned: true } }, position }; })).then(() => this.editorGroupService.focusGroup(position)); + } + + // Multiple resources without tabs: open them side by side + return this.editorService.openEditors(resources.map((resource, index) => { return { input: { resource, options: { pinned: true } }, position: Math.min(index, Position.RIGHT) }; })); + } + private createTitleControl(position: Position): void { const useTabs = !!this.configurationService.getConfiguration().workbench.showEditorTabs; diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts index 6ef967567a5..a0b67f9d966 100644 --- a/src/vs/workbench/electron-browser/window.ts +++ b/src/vs/workbench/electron-browser/window.ts @@ -6,12 +6,11 @@ 'use strict'; import platform = require('vs/base/common/platform'); -import uri from 'vs/base/common/uri'; -import {Identifiers} from 'vs/workbench/common/constants'; +import URI from 'vs/base/common/uri'; +import DOM = require('vs/base/browser/dom'); import workbenchEditorCommon = require('vs/workbench/common/editor'); import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; -import dom = require('vs/base/browser/dom'); import {IStorageService} from 'vs/platform/storage/common/storage'; import {IEventService} from 'vs/platform/event/common/event'; import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace'; @@ -65,32 +64,8 @@ export class ElectronWindow { } // Prevent a dropped file from opening as application - window.document.body.addEventListener('dragover', (e: DragEvent) => { - e.preventDefault(); - }); - - // Let a dropped file open inside Code (only if dropped over editor area) - window.document.body.addEventListener('drop', (e: DragEvent) => { - e.preventDefault(); - - let editorArea = window.document.getElementById(Identifiers.EDITOR_PART); - if (dom.isAncestor(e.toElement, editorArea)) { - - // Check for native file transfer - 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); - } - } - - if (thepaths.length) { - this.focus(); // make sure this window has focus so that the open call reaches the right window! - this.open(thepaths); - } - } - } + window.document.body.addEventListener(DOM.EventType.DRAG_OVER, (e: DragEvent) => { + DOM.EventHelper.stop(e); }); // Handle window.open() calls @@ -103,14 +78,14 @@ export class ElectronWindow { // Patch focus to also focus the entire window const originalFocus = window.focus; const $this = this; - window.focus = function() { + window.focus = function () { originalFocus.call(this, arguments); $this.focus(); }; } public open(pathsToOpen: string[]): void; - public open(fileResource: uri): void; + public open(fileResource: URI): void; public open(pathToOpen: string): void; public open(arg1: any): void { let pathsToOpen: string[]; @@ -119,7 +94,7 @@ export class ElectronWindow { } else if (typeof arg1 === 'string') { pathsToOpen = [arg1]; } else { - pathsToOpen = [(arg1).fsPath]; + pathsToOpen = [(arg1).fsPath]; } ipc.send('vscode:windowOpen', pathsToOpen); // handled from browser process