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

`-w` doesn't work when there are no windows open (fixes #4150)

上级 373426f1
...@@ -12,6 +12,7 @@ import {assign} from 'vs/base/common/objects'; ...@@ -12,6 +12,7 @@ import {assign} from 'vs/base/common/objects';
import platform = require('vs/base/common/platform'); import platform = require('vs/base/common/platform');
import env = require('vs/workbench/electron-main/env'); import env = require('vs/workbench/electron-main/env');
import windows = require('vs/workbench/electron-main/windows'); import windows = require('vs/workbench/electron-main/windows');
import window = require('vs/workbench/electron-main/window');
import lifecycle = require('vs/workbench/electron-main/lifecycle'); import lifecycle = require('vs/workbench/electron-main/lifecycle');
import menu = require('vs/workbench/electron-main/menus'); import menu = require('vs/workbench/electron-main/menus');
import settings = require('vs/workbench/electron-main/settings'); import settings = require('vs/workbench/electron-main/settings');
...@@ -28,20 +29,22 @@ export class LaunchService { ...@@ -28,20 +29,22 @@ export class LaunchService {
env.log('Received data from other instance', args); env.log('Received data from other instance', args);
let killOtherInstance = args.waitForWindowClose; let killOtherInstance = args.waitForWindowClose;
let usedWindows: window.VSCodeWindow[];
// Otherwise handle in windows manager // Otherwise handle in windows manager
if (!!args.extensionDevelopmentPath) { if (!!args.extensionDevelopmentPath) {
windows.manager.openPluginDevelopmentHostWindow({ cli: args, userEnv: userEnv }); windows.manager.openPluginDevelopmentHostWindow({ cli: args, userEnv: userEnv });
} else if (args.pathArguments.length === 0 && args.openNewWindow) { } else if (args.pathArguments.length === 0 && args.openNewWindow) {
windows.manager.open({ cli: args, userEnv: userEnv, forceNewWindow: true, forceEmpty: true }); usedWindows = windows.manager.open({ cli: args, userEnv: userEnv, forceNewWindow: true, forceEmpty: true });
} else if (args.pathArguments.length === 0) { } else if (args.pathArguments.length === 0) {
windows.manager.focusLastActive(args); usedWindows = [windows.manager.focusLastActive(args)];
} else { } else {
let usedWindows = windows.manager.open({ cli: args, userEnv: userEnv, forceNewWindow: args.waitForWindowClose || args.openNewWindow, preferNewWindow: !args.openInSameWindow }); usedWindows = windows.manager.open({ cli: args, userEnv: userEnv, forceNewWindow: args.waitForWindowClose || args.openNewWindow, preferNewWindow: !args.openInSameWindow });
}
// If the other instance is waiting to be killed, we hook up a window listener if one window // If the other instance is waiting to be killed, we hook up a window listener if one window
// is being used and kill the other instance when that window is being closed // is being used and kill the other instance when that window is being closed
if (args.waitForWindowClose && usedWindows && usedWindows.length === 1) { if (args.waitForWindowClose && usedWindows && usedWindows.length === 1 && usedWindows[0]) {
let windowToObserve = usedWindows[0]; let windowToObserve = usedWindows[0];
killOtherInstance = false; // only scenario where the "-w" switch is supported and makes sense killOtherInstance = false; // only scenario where the "-w" switch is supported and makes sense
...@@ -52,7 +55,6 @@ export class LaunchService { ...@@ -52,7 +55,6 @@ export class LaunchService {
} }
}); });
} }
}
if (killOtherInstance) { if (killOtherInstance) {
process.kill(otherInstancePid); process.kill(otherInstancePid);
......
...@@ -964,17 +964,19 @@ export class WindowsManager { ...@@ -964,17 +964,19 @@ export class WindowsManager {
}); });
} }
public focusLastActive(cli: env.ICommandLineArguments): void { public focusLastActive(cli: env.ICommandLineArguments): window.VSCodeWindow {
let lastActive = this.getLastActiveWindow(); let lastActive = this.getLastActiveWindow();
if (lastActive) { if (lastActive) {
lastActive.focus(); lastActive.focus();
return lastActive;
} }
// No window - open new one // No window - open new one
else {
this.windowsState.openedFolders = []; // make sure we do not open too much this.windowsState.openedFolders = []; // make sure we do not open too much
this.open({ cli: cli }); const res = this.open({ cli: cli });
}
return res && res[0];
} }
public getLastActiveWindow(): window.VSCodeWindow { public getLastActiveWindow(): window.VSCodeWindow {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册