提交 b106857f 编写于 作者: B Benjamin Pasero

multi root: allow target extension development window to be a workspace too

上级 4f074abe
......@@ -72,15 +72,12 @@ export class CodeWindow implements ICodeWindow {
private static MIN_WIDTH = 200;
private static MIN_HEIGHT = 120;
private options: IWindowCreationOptions;
private hiddenTitleBarStyle: boolean;
private showTimeoutHandle: any;
private _id: number;
private _win: Electron.BrowserWindow;
private _lastFocusTime: number;
private _readyState: ReadyState;
private _extensionDevelopmentPath: string;
private _isExtensionTestHost: boolean;
private windowState: IWindowState;
private currentMenuBarVisibility: MenuBarVisibility;
private toDispose: IDisposable[];
......@@ -99,11 +96,8 @@ export class CodeWindow implements ICodeWindow {
@IStorageService private storageService: IStorageService,
@IWorkspacesMainService private workspaceService: IWorkspacesMainService
) {
this.options = config;
this._lastFocusTime = -1;
this._readyState = ReadyState.NONE;
this._extensionDevelopmentPath = config.extensionDevelopmentPath;
this._isExtensionTestHost = config.isExtensionTestHost;
this.whenReadyCallbacks = [];
this.toDispose = [];
......@@ -207,15 +201,15 @@ export class CodeWindow implements ICodeWindow {
}
public get isExtensionDevelopmentHost(): boolean {
return !!this._extensionDevelopmentPath;
return !!this.config.extensionDevelopmentPath;
}
public get isExtensionTestHost(): boolean {
return this._isExtensionTestHost;
return !!this.config.extensionTestsPath;
}
public get extensionDevelopmentPath(): string {
return this._extensionDevelopmentPath;
return this.config.extensionDevelopmentPath;
}
public get config(): IWindowConfiguration {
......
......@@ -20,7 +20,7 @@ import { ILifecycleService, UnloadReason, IWindowUnloadEvent } from 'vs/platform
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
import { IWindowSettings, OpenContext, IPath, IWindowConfiguration, INativeOpenDialogOptions } from 'vs/platform/windows/common/windows';
import { getLastActiveWindow, findBestWindowOrFolderForFile, findWindowOnWorkspace } from 'vs/code/node/windowsFinder';
import { getLastActiveWindow, findBestWindowOrFolderForFile, findWindowOnWorkspace, findWindowOnExtensionDevelopmentPath, findWindowOnWorkspaceOrFolderPath } from 'vs/code/node/windowsFinder';
import CommonEvent, { Emitter } from 'vs/base/common/event';
import product from 'vs/platform/node/product';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
......@@ -888,28 +888,26 @@ export class WindowsManager implements IWindowsMainService {
// Reload an existing extension development host window on the same path
// We currently do not allow more than one extension development window
// on the same extension path.
let res = WindowsManager.WINDOWS.filter(w => w.config && isEqual(w.config.extensionDevelopmentPath, openConfig.cli.extensionDevelopmentPath, !isLinux /* ignorecase */));
if (res && res.length === 1) {
this.reload(res[0], openConfig.cli);
res[0].focus(); // make sure it gets focus and is restored
const existingWindow = findWindowOnExtensionDevelopmentPath(WindowsManager.WINDOWS, openConfig.cli.extensionDevelopmentPath);
if (existingWindow) {
this.reload(existingWindow, openConfig.cli);
existingWindow.focus(); // make sure it gets focus and is restored
return;
}
// Fill in previously opened folder unless an explicit path is provided and we are not unit testing
// Fill in previously opened workspace unless an explicit path is provided and we are not unit testing
if (openConfig.cli._.length === 0 && !openConfig.cli.extensionTestsPath) {
const folderToOpen = this.windowsState.lastPluginDevelopmentHostWindow && this.windowsState.lastPluginDevelopmentHostWindow.folderPath;
if (folderToOpen) {
openConfig.cli._ = [folderToOpen];
const extensionDevelopmentWindowState = this.windowsState.lastPluginDevelopmentHostWindow;
const workspaceToOpen = extensionDevelopmentWindowState && (extensionDevelopmentWindowState.workspace || extensionDevelopmentWindowState.folderPath);
if (workspaceToOpen) {
openConfig.cli._ = [isSingleFolderWorkspaceIdentifier(workspaceToOpen) ? workspaceToOpen : workspaceToOpen.configPath];
}
}
// Make sure we are not asked to open a path that is already opened
if (openConfig.cli._.length > 0) {
res = WindowsManager.WINDOWS.filter(w => w.openedFolderPath && openConfig.cli._.indexOf(w.openedFolderPath) >= 0);
if (res.length) {
openConfig.cli._ = [];
}
// Make sure we are not asked to open a workspace or folder that is already opened
if (openConfig.cli._.some(path => !!findWindowOnWorkspaceOrFolderPath(WindowsManager.WINDOWS, path))) {
openConfig.cli._ = [];
}
// Open it
......
......@@ -112,43 +112,57 @@ function hasCodeSettings(folder: string, normalizedUserHome?: string, codeSettin
}
export function getLastActiveWindow<W extends ISimpleWindow>(windows: W[]): W {
if (windows.length) {
const lastFocussedDate = Math.max.apply(Math, windows.map(w => w.lastFocusTime));
const res = windows.filter(w => w.lastFocusTime === lastFocussedDate);
if (res && res.length) {
return res[0];
}
}
const lastFocussedDate = Math.max.apply(Math, windows.map(window => window.lastFocusTime));
return null;
return windows.filter(window => window.lastFocusTime === lastFocussedDate)[0];
}
export function findWindowOnWorkspace<W extends ISimpleWindow>(windows: W[], workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)): W {
if (windows.length) {
const res = windows.filter(w => {
// match on folder
if (isSingleFolderWorkspaceIdentifier(workspace)) {
if (typeof w.openedFolderPath === 'string' && (paths.isEqual(w.openedFolderPath, workspace, !platform.isLinux /* ignorecase */))) {
return true;
}
return windows.filter(window => {
// match on folder
if (isSingleFolderWorkspaceIdentifier(workspace)) {
if (typeof window.openedFolderPath === 'string' && (paths.isEqual(window.openedFolderPath, workspace, !platform.isLinux /* ignorecase */))) {
return true;
}
}
// match on workspace
else {
if (w.openedWorkspace && w.openedWorkspace.id === workspace.id) {
return true;
}
// match on workspace
else {
if (window.openedWorkspace && window.openedWorkspace.id === workspace.id) {
return true;
}
}
return false;
})[0];
}
return false;
});
export function findWindowOnExtensionDevelopmentPath<W extends ISimpleWindow>(windows: W[], extensionDevelopmentPath: string): W {
return windows.filter(window => {
if (res && res.length) {
return res[0];
// match on extension development path
if (paths.isEqual(window.extensionDevelopmentPath, extensionDevelopmentPath, !platform.isLinux /* ignorecase */)) {
return true;
}
}
return null;
return false;
})[0];
}
export function findWindowOnWorkspaceOrFolderPath<W extends ISimpleWindow>(windows: W[], path: string): W {
return windows.filter(window => {
// check for workspace config path
if (window.openedWorkspace && paths.isEqual(window.openedWorkspace.configPath, path, !platform.isLinux /* ignorecase */)) {
return true;
}
// check for folder path
if (window.openedFolderPath && paths.isEqual(window.openedFolderPath, path, !platform.isLinux /* ignorecase */)) {
return true;
}
return false;
})[0];
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册