Skip to content

Commit d3d1029

Browse files
author
Benjamin Pasero
committed
macOS: window not correctly restored in some cases
1 parent 3807229 commit d3d1029

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ export class WindowsManager implements IWindowsMainService {
223223
this.lifecycleService.onBeforeWindowUnload(e => this.onBeforeWindowUnload(e));
224224
this.lifecycleService.onBeforeWindowClose(win => this.onBeforeWindowClose(win as CodeWindow));
225225
this.lifecycleService.onBeforeQuit(() => this.onBeforeQuit());
226+
this.onWindowsCountChanged(e => {
227+
if (e.newCount - e.oldCount > 0) {
228+
// clear last closed window state when a new window opens. this helps on macOS where
229+
// otherwise closing the last window, opening a new window and then quitting would
230+
// use the state of the previously closed window when restarting.
231+
this.lastClosedWindowState = void 0;
232+
}
233+
});
226234
}
227235

228236
// Note that onBeforeQuit() and onBeforeWindowClose() are fired in different order depending on the OS:
@@ -232,6 +240,36 @@ export class WindowsManager implements IWindowsMainService {
232240
// user interaction: closing the last window will first trigger onBeforeWindowClose()
233241
// and then onBeforeQuit(). Using the quit action however will first issue onBeforeQuit()
234242
// and then onBeforeWindowClose().
243+
//
244+
// Here is the behaviour on different OS dependig on action taken (Electron 1.7.x):
245+
//
246+
// Legend
247+
// - quit(N): quit application with N windows opened
248+
// - close(1): close one window via the window close button
249+
// - closeAll: close all windows via the taskbar command
250+
// - onBeforeQuit(N): number of windows reported in this event handler
251+
// - onBeforeWindowClose(N, M): number of windows reported and quitRequested boolean in this event handler
252+
//
253+
// macOS
254+
// - quit(1): onBeforeQuit(1), onBeforeWindowClose(1, true)
255+
// - quit(2): onBeforeQuit(2), onBeforeWindowClose(2, true), onBeforeWindowClose(2, true)
256+
// - quit(0): onBeforeQuit(0)
257+
// - close(1): onBeforeWindowClose(1, false)
258+
//
259+
// Windows
260+
// - quit(1): onBeforeQuit(1), onBeforeWindowClose(1, true)
261+
// - quit(2): onBeforeQuit(2), onBeforeWindowClose(2, true), onBeforeWindowClose(2, true)
262+
// - close(1): onBeforeWindowClose(2, false)[not last window]
263+
// - close(1): onBeforeWindowClose(1, false), onBeforequit(0)[last window]
264+
// - closeAll(2): onBeforeWindowClose(2, false), onBeforeWindowClose(2, false), onBeforeQuit(0)
265+
//
266+
// Linux
267+
// - quit(1): onBeforeQuit(1), onBeforeWindowClose(1, true)
268+
// - quit(2): onBeforeQuit(2), onBeforeWindowClose(2, true), onBeforeWindowClose(2, true)
269+
// - close(1): onBeforeWindowClose(2, false)[not last window]
270+
// - close(1): onBeforeWindowClose(1, false), onBeforequit(0)[last window]
271+
// - closeAll(2): onBeforeWindowClose(2, false), onBeforeWindowClose(2, false), onBeforeQuit(0)
272+
//
235273
private onBeforeQuit(): void {
236274
const currentWindowsState: ILegacyWindowsState = {
237275
openedWindows: [],

src/vs/workbench/parts/files/browser/views/explorerViewer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,9 @@ export class FileDragAndDrop implements IDragAndDrop {
886886

887887
// If we are in single-folder context, ask for confirmation to create a workspace
888888
const result = this.messageService.confirm({
889-
message: nls.localize('dropFolders', "Do you want to add the folders to the workspace?"),
889+
message: folders.length > 1 ? nls.localize('dropFolders', "Do you want to add the folders to the workspace?") : nls.localize('dropFolder', "Do you want to add the folder to the workspace?"),
890890
type: 'question',
891-
primaryButton: nls.localize('create', "&&Add Folders")
891+
primaryButton: folders.length > 1 ? nls.localize('addFolders', "&&Add Folders") : nls.localize('addFolder', "&&Add Folder")
892892
});
893893

894894
if (result) {

0 commit comments

Comments
 (0)