Skip to content

Commit 8bd339f

Browse files
author
Benjamin Pasero
committed
💄
1 parent 7a9a71c commit 8bd339f

2 files changed

Lines changed: 45 additions & 31 deletions

File tree

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

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IBackupMainService } from 'vs/platform/backup/common/backup';
1414
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
1515
import { IStorageService } from 'vs/platform/storage/node/storage';
1616
import { CodeWindow, IWindowState as ISingleWindowState, defaultWindowState, WindowMode } from 'vs/code/electron-main/window';
17-
import { ipcMain as ipc, app, screen, BrowserWindow, dialog } from 'electron';
17+
import { ipcMain as ipc, screen, BrowserWindow, dialog } from 'electron';
1818
import { IPathWithLineAndColumn, parseLineAndColumnAware } from 'vs/code/node/paths';
1919
import { ILifecycleService, UnloadReason } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
2020
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -231,15 +231,15 @@ export class WindowsManager implements IWindowsMainService {
231231
let foldersToRestore = (openConfig.initialStartup && !openConfig.cli.extensionDevelopmentPath) ? this.backupService.getWorkspaceBackupPaths() : [];
232232
let filesToOpen: IPath[] = [];
233233
let filesToDiff: IPath[] = [];
234+
let filesToCreate = pathsToOpen.filter(iPath => !!iPath.filePath && iPath.createFilePath);
234235
let emptyToOpen = pathsToOpen.filter(iPath => !iPath.workspacePath && !iPath.filePath);
235236
let emptyToRestore = (openConfig.initialStartup && !openConfig.cli.extensionDevelopmentPath) ? this.backupService.getEmptyWorkspaceBackupPaths() : [];
236-
let filesToCreate = pathsToOpen.filter(iPath => !!iPath.filePath && iPath.createFilePath);
237237

238238
// Diff mode needs special care
239-
const candidates = pathsToOpen.filter(iPath => !!iPath.filePath && !iPath.createFilePath);
239+
const filesToOpenCandidates = pathsToOpen.filter(iPath => !!iPath.filePath && !iPath.createFilePath);
240240
if (openConfig.diffMode) {
241-
if (candidates.length === 2) {
242-
filesToDiff = candidates;
241+
if (filesToOpenCandidates.length === 2) {
242+
filesToDiff = filesToOpenCandidates;
243243
} else {
244244
emptyToOpen = [Object.create(null)]; // improper use of diffMode, open empty
245245
}
@@ -248,34 +248,16 @@ export class WindowsManager implements IWindowsMainService {
248248
foldersToRestore = []; // diff is always in empty workspace
249249
filesToCreate = []; // diff ignores other files that do not exist
250250
} else {
251-
filesToOpen = candidates;
251+
filesToOpen = filesToOpenCandidates;
252252
}
253253

254-
// let the user settings override how folders are open in a new window or same window unless we are forced
255-
const windowConfig = this.configurationService.getConfiguration<IWindowSettings>('window');
256-
let openFolderInNewWindow = (openConfig.preferNewWindow || openConfig.forceNewWindow) && !openConfig.forceReuseWindow;
257-
if (!openConfig.forceNewWindow && !openConfig.forceReuseWindow && windowConfig && (windowConfig.openFoldersInNewWindow === 'on' || windowConfig.openFoldersInNewWindow === 'off')) {
258-
openFolderInNewWindow = (windowConfig.openFoldersInNewWindow === 'on');
259-
}
254+
// Settings can decide if files/folders open in new window or not
255+
let { openFolderInNewWindow, openFilesInNewWindow } = this.shouldOpenNewWindow(openConfig);
260256

261257
// Handle files to open/diff or to create when we dont open a folder and we do not restore any folder/untitled from hot-exit
262258
const usedWindows: CodeWindow[] = [];
263259
if (!foldersToOpen.length && !foldersToRestore.length && !emptyToRestore.length && (filesToOpen.length > 0 || filesToCreate.length > 0 || filesToDiff.length > 0)) {
264260

265-
// let the user settings override how files are open in a new window or same window unless we are forced (not for extension development though)
266-
let openFilesInNewWindow: boolean;
267-
if (openConfig.forceNewWindow || openConfig.forceReuseWindow) {
268-
openFilesInNewWindow = openConfig.forceNewWindow && !openConfig.forceReuseWindow;
269-
} else {
270-
if (openConfig.context === OpenContext.DOCK) {
271-
openFilesInNewWindow = true; // only on macOS do we allow to open files in a new window if this is triggered via DOCK context
272-
}
273-
274-
if (!openConfig.cli.extensionDevelopmentPath && windowConfig && (windowConfig.openFilesInNewWindow === 'on' || windowConfig.openFilesInNewWindow === 'off')) {
275-
openFilesInNewWindow = (windowConfig.openFilesInNewWindow === 'on');
276-
}
277-
}
278-
279261
// Open Files in last instance if any and flag tells us so
280262
const fileToCheck = filesToOpen[0] || filesToCreate[0] || filesToDiff[0];
281263
const windowOrFolder = findBestWindowOrFolder({
@@ -286,6 +268,7 @@ export class WindowsManager implements IWindowsMainService {
286268
filePath: fileToCheck && fileToCheck.filePath,
287269
userHome: this.environmentService.userHome
288270
});
271+
289272
if (windowOrFolder instanceof CodeWindow) {
290273
windowOrFolder.focus();
291274
const files = { filesToOpen, filesToCreate, filesToDiff }; // copy to object because they get reset shortly after
@@ -328,6 +311,7 @@ export class WindowsManager implements IWindowsMainService {
328311
if (windowsOnWorkspacePath.length > 0) {
329312
const browserWindow = windowsOnWorkspacePath[0];
330313
browserWindow.focus(); // just focus one of them
314+
331315
const files = { filesToOpen, filesToCreate, filesToDiff }; // copy to object because they get reset shortly after
332316
browserWindow.ready().then(readyWindow => {
333317
readyWindow.send('vscode:openFiles', files);
@@ -418,7 +402,6 @@ export class WindowsManager implements IWindowsMainService {
418402

419403
pathsToOpen.forEach(iPath => {
420404
if (iPath.filePath || iPath.workspacePath) {
421-
app.addRecentDocument(iPath.filePath || iPath.workspacePath);
422405
recentPaths.push({ path: iPath.filePath || iPath.workspacePath, isFile: !!iPath.filePath });
423406
}
424407
});
@@ -576,6 +559,32 @@ export class WindowsManager implements IWindowsMainService {
576559
return null;
577560
}
578561

562+
private shouldOpenNewWindow(openConfig: IOpenConfiguration): { openFolderInNewWindow: boolean; openFilesInNewWindow: boolean; } {
563+
564+
// let the user settings override how folders are open in a new window or same window unless we are forced
565+
const windowConfig = this.configurationService.getConfiguration<IWindowSettings>('window');
566+
let openFolderInNewWindow = (openConfig.preferNewWindow || openConfig.forceNewWindow) && !openConfig.forceReuseWindow;
567+
if (!openConfig.forceNewWindow && !openConfig.forceReuseWindow && windowConfig && (windowConfig.openFoldersInNewWindow === 'on' || windowConfig.openFoldersInNewWindow === 'off')) {
568+
openFolderInNewWindow = (windowConfig.openFoldersInNewWindow === 'on');
569+
}
570+
571+
// let the user settings override how files are open in a new window or same window unless we are forced (not for extension development though)
572+
let openFilesInNewWindow: boolean;
573+
if (openConfig.forceNewWindow || openConfig.forceReuseWindow) {
574+
openFilesInNewWindow = openConfig.forceNewWindow && !openConfig.forceReuseWindow;
575+
} else {
576+
if (openConfig.context === OpenContext.DOCK) {
577+
openFilesInNewWindow = true; // only on macOS do we allow to open files in a new window if this is triggered via DOCK context
578+
}
579+
580+
if (!openConfig.cli.extensionDevelopmentPath && windowConfig && (windowConfig.openFilesInNewWindow === 'on' || windowConfig.openFilesInNewWindow === 'off')) {
581+
openFilesInNewWindow = (windowConfig.openFilesInNewWindow === 'on');
582+
}
583+
}
584+
585+
return { openFolderInNewWindow, openFilesInNewWindow };
586+
}
587+
579588
public openExtensionDevelopmentHostWindow(openConfig: IOpenConfiguration): void {
580589

581590
// Reload an existing extension development host window on the same path

src/vs/platform/history/electron-main/historyMainService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
'use strict';
77

88
import * as path from 'path';
9-
import * as platform from 'vs/base/common/platform';
109
import * as nls from 'vs/nls';
1110
import * as arrays from 'vs/base/common/arrays';
1211
import { trim } from 'vs/base/common/strings';
@@ -17,6 +16,7 @@ import { getPathLabel } from 'vs/base/common/labels';
1716
import { IPath } from 'vs/platform/windows/common/windows';
1817
import CommonEvent, { Emitter } from 'vs/base/common/event';
1918
import { createDecorator } from "vs/platform/instantiation/common/instantiation";
19+
import { isWindows, isMacintosh, isLinux } from "vs/base/common/platform";
2020

2121
export const IHistoryMainService = createDecorator<IHistoryMainService>('historyMainService');
2222

@@ -69,15 +69,20 @@ export class HistoryMainService implements IHistoryMainService {
6969

7070
if (isFile) {
7171
mru.files.unshift(path);
72-
mru.files = arrays.distinct(mru.files, (f) => platform.isLinux ? f : f.toLowerCase());
72+
mru.files = arrays.distinct(mru.files, (f) => isLinux ? f : f.toLowerCase());
7373
} else {
7474
mru.folders.unshift(path);
75-
mru.folders = arrays.distinct(mru.folders, (f) => platform.isLinux ? f : f.toLowerCase());
75+
mru.folders = arrays.distinct(mru.folders, (f) => isLinux ? f : f.toLowerCase());
7676
}
7777

7878
// Make sure its bounded
7979
mru.folders = mru.folders.slice(0, HistoryMainService.MAX_TOTAL_RECENT_ENTRIES);
8080
mru.files = mru.files.slice(0, HistoryMainService.MAX_TOTAL_RECENT_ENTRIES);
81+
82+
// Add to recent documents (Windows/macOS only)
83+
if (isMacintosh || isWindows) {
84+
app.addRecentDocument(path);
85+
}
8186
});
8287

8388
this.storageService.setItem(HistoryMainService.recentPathsListStorageKey, mru);
@@ -157,7 +162,7 @@ export class HistoryMainService implements IHistoryMainService {
157162
}
158163

159164
public updateWindowsJumpList(): void {
160-
if (!platform.isWindows) {
165+
if (!isWindows) {
161166
return; // only on windows
162167
}
163168

0 commit comments

Comments
 (0)