mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
put DND handler for editors into editor control
This commit is contained in:
parent
77336664ff
commit
86175ecaee
|
@ -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)), <HTMLElement>e.toElement).done(null, errors.onUnexpectedError);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private openFromDrop(resources: URI[], target: HTMLElement): TPromise<any> {
|
||||
|
||||
// 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<IWorkbenchEditorConfiguration>().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<IWorkbenchEditorConfiguration>().workbench.showEditorTabs;
|
||||
|
||||
|
|
|
@ -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 = [(<uri>arg1).fsPath];
|
||||
pathsToOpen = [(<URI>arg1).fsPath];
|
||||
}
|
||||
|
||||
ipc.send('vscode:windowOpen', pathsToOpen); // handled from browser process
|
||||
|
|
Loading…
Reference in a new issue