Skip to content

Commit 3937e57

Browse files
authored
add window.openWithoutArgumentsInNewWindow (microsoft#45322)
* add window.openWithoutArgumentsInNewWindow * remove relaunch command
1 parent 5ab754e commit 3937e57

4 files changed

Lines changed: 59 additions & 18 deletions

File tree

src/vs/code/electron-main/launch.ts

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import { TPromise } from 'vs/base/common/winjs.base';
99
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
1010
import { ILogService } from 'vs/platform/log/common/log';
1111
import { IURLService } from 'vs/platform/url/common/url';
12-
import { IProcessEnvironment } from 'vs/base/common/platform';
12+
import { IProcessEnvironment, isMacintosh } from 'vs/base/common/platform';
1313
import { ParsedArgs, IEnvironmentService } from 'vs/platform/environment/common/environment';
1414
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
15-
import { OpenContext } from 'vs/platform/windows/common/windows';
15+
import { OpenContext, IWindowSettings } from 'vs/platform/windows/common/windows';
1616
import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-main/windows';
1717
import { whenDeleted } from 'vs/base/node/pfs';
1818
import { IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces';
1919
import { Schemas } from 'vs/base/common/network';
20+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2021

2122
export const ID = 'launchService';
2223
export const ILaunchService = createDecorator<ILaunchService>(ID);
@@ -110,7 +111,8 @@ export class LaunchService implements ILaunchService {
110111
@IWindowsMainService private windowsMainService: IWindowsMainService,
111112
@IURLService private urlService: IURLService,
112113
@IWorkspacesMainService private workspacesMainService: IWorkspacesMainService,
113-
@IEnvironmentService private readonly environmentService: IEnvironmentService
114+
@IEnvironmentService private readonly environmentService: IEnvironmentService,
115+
@IConfigurationService private readonly configurationService: IConfigurationService
114116
) { }
115117

116118
public start(args: ParsedArgs, userEnv: IProcessEnvironment): TPromise<void> {
@@ -140,13 +142,51 @@ export class LaunchService implements ILaunchService {
140142
private startOpenWindow(args: ParsedArgs, userEnv: IProcessEnvironment): TPromise<void> {
141143
const context = !!userEnv['VSCODE_CLI'] ? OpenContext.CLI : OpenContext.DESKTOP;
142144
let usedWindows: ICodeWindow[];
145+
146+
// Special case extension development
143147
if (!!args.extensionDevelopmentPath) {
144148
this.windowsMainService.openExtensionDevelopmentHostWindow({ context, cli: args, userEnv });
145-
} else if (args._.length === 0 && (args['new-window'] || args['unity-launch'])) {
146-
usedWindows = this.windowsMainService.open({ context, cli: args, userEnv, forceNewWindow: true, forceEmpty: true });
147-
} else if (args._.length === 0) {
148-
usedWindows = [this.windowsMainService.focusLastActive(args, context)];
149-
} else {
149+
}
150+
151+
// Start without file/folder arguments
152+
else if (args._.length === 0) {
153+
let openNewWindow = false;
154+
155+
// Force new window
156+
if (args['new-window'] || args['unity-launch']) {
157+
openNewWindow = true;
158+
}
159+
160+
// Force reuse window
161+
else if (args['reuse-window']) {
162+
openNewWindow = false;
163+
}
164+
165+
// Otherwise check for settings
166+
else {
167+
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
168+
const openWithoutArgumentsInNewWindowConfig = (windowConfig && windowConfig.openWithoutArgumentsInNewWindow) || 'default' /* default */;
169+
switch (openWithoutArgumentsInNewWindowConfig) {
170+
case 'on':
171+
openNewWindow = true;
172+
break;
173+
case 'off':
174+
openNewWindow = false;
175+
break;
176+
default:
177+
openNewWindow = !isMacintosh; // prefer to restore running instance on macOS
178+
}
179+
}
180+
181+
if (openNewWindow) {
182+
usedWindows = this.windowsMainService.open({ context, cli: args, userEnv, forceNewWindow: true, forceEmpty: true });
183+
} else {
184+
usedWindows = [this.windowsMainService.focusLastActive(args, context)];
185+
}
186+
}
187+
188+
// Start with file/folder arguments
189+
else {
150190
usedWindows = this.windowsMainService.open({
151191
context,
152192
cli: args,

src/vs/code/electron-main/window.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,6 @@ export class CodeWindow implements ICodeWindow {
215215
this._win.setSheetOffset(22); // offset dialogs by the height of the custom title bar if we have any
216216
}
217217

218-
// Set relaunch command
219-
if (isWindows && product.win32AppUserModelId && typeof this._win.setAppDetails === 'function') {
220-
this._win.setAppDetails({
221-
appId: product.win32AppUserModelId,
222-
relaunchCommand: `"${process.execPath}" -n`,
223-
relaunchDisplayName: product.nameLong
224-
});
225-
}
226-
227218
if (isFullscreenOrMaximized) {
228219
this._win.maximize();
229220

src/vs/platform/windows/common/windows.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export interface IWindowsConfiguration {
213213
export interface IWindowSettings {
214214
openFilesInNewWindow: 'on' | 'off' | 'default';
215215
openFoldersInNewWindow: 'on' | 'off' | 'default';
216+
openWithoutArgumentsInNewWindow: 'on' | 'off';
216217
restoreWindows: 'all' | 'folders' | 'one' | 'none';
217218
restoreFullscreen: boolean;
218219
zoomLevel: number;

src/vs/workbench/electron-browser/main.contribution.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ configurationRegistry.registerConfiguration({
302302
isMacintosh ?
303303
nls.localize('openFilesInNewWindowMac', "Controls if files should open in a new window.\n- default: files will open in the window with the files' folder open or the last active window unless opened via the Dock or from Finder\n- on: files will open in a new window\n- off: files will open in the window with the files' folder open or the last active window\nNote that there can still be cases where this setting is ignored (e.g. when using the -new-window or -reuse-window command line option).") :
304304
nls.localize('openFilesInNewWindow', "Controls if files should open in a new window.\n- default: files will open in a new window unless picked from within the application (e.g. via the File menu)\n- on: files will open in a new window\n- off: files will open in the window with the files' folder open or the last active window\nNote that there can still be cases where this setting is ignored (e.g. when using the -new-window or -reuse-window command line option).")
305-
306305
},
307306
'window.openFoldersInNewWindow': {
308307
'type': 'string',
@@ -315,6 +314,16 @@ configurationRegistry.registerConfiguration({
315314
'default': 'default',
316315
'description': nls.localize('openFoldersInNewWindow', "Controls if folders should open in a new window or replace the last active window.\n- default: folders will open in a new window unless a folder is picked from within the application (e.g. via the File menu)\n- on: folders will open in a new window\n- off: folders will replace the last active window\nNote that there can still be cases where this setting is ignored (e.g. when using the -new-window or -reuse-window command line option).")
317316
},
317+
'window.openWithoutArgumentsInNewWindow': {
318+
'type': 'string',
319+
'enum': ['on', 'off'],
320+
'enumDescriptions': [
321+
nls.localize('window.openWithoutArgumentsInNewWindow.on', "Open a new empty window"),
322+
nls.localize('window.openWithoutArgumentsInNewWindow.off', "Focus the last active running instance")
323+
],
324+
'default': isMacintosh ? 'off' : 'on',
325+
'description': nls.localize('openWithoutArgumentsInNewWindow', "Controls if a new empty window should open when starting a second instance without arguments or if the last running instance should get focus.\n- on: open a new empty window\n- off: the last active running instance will get focus\nNote that there can still be cases where this setting is ignored (e.g. when using the -new-window or -reuse-window command line option).")
326+
},
318327
'window.restoreWindows': {
319328
'type': 'string',
320329
'enum': ['all', 'folders', 'one', 'none'],

0 commit comments

Comments
 (0)