提交 1af3873a 编写于 作者: D Daniel Imms

Support file.hotExit: appExitAndWindowClose

上级 08748316
......@@ -11,6 +11,8 @@ import * as platform from 'vs/base/common/platform';
import * as extfs from 'vs/base/node/extfs';
import { IBackupWorkspacesFormat, IBackupMainService } from 'vs/platform/backup/common/backup';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IFilesConfiguration, HotExitConfiguration } from 'vs/platform/files/common/files';
import { TPromise } from 'vs/base/common/winjs.base';
export class BackupMainService implements IBackupMainService {
......@@ -24,7 +26,8 @@ export class BackupMainService implements IBackupMainService {
private mapWindowToBackupFolder: { [windowId: number]: string; };
constructor(
@IEnvironmentService environmentService: IEnvironmentService
@IEnvironmentService environmentService: IEnvironmentService,
@IConfigurationService private configurationService: IConfigurationService
) {
this.backupHome = environmentService.backupHome;
this.workspacesJsonPath = environmentService.backupWorkspacesPath;
......@@ -34,6 +37,12 @@ export class BackupMainService implements IBackupMainService {
}
public getWorkspaceBackupPaths(): string[] {
const config = this.configurationService.getConfiguration<IFilesConfiguration>();
if (config && config.files && config.files.hotExit === HotExitConfiguration.APP_EXIT_AND_WINDOW_CLOSE) {
// Only non-folder windows are restored on main process launch when
// hot exit is configured as appExitAndWindowClose.
return [];
}
return this.backups.folderWorkspaces.slice(0); // return a copy
}
......
......@@ -20,7 +20,7 @@ import { IBackupWorkspacesFormat } from 'vs/platform/backup/common/backup';
class TestBackupMainService extends BackupMainService {
constructor(backupHome: string, backupWorkspacesPath: string) {
super(new EnvironmentService(parseArgs(process.argv), process.execPath));
super(new EnvironmentService(parseArgs(process.argv), process.execPath), null);
this.backupHome = backupHome;
this.workspacesJsonPath = backupWorkspacesPath;
......
......@@ -490,6 +490,12 @@ export const AutoSaveConfiguration = {
ON_WINDOW_CHANGE: 'onWindowChange'
};
export const HotExitConfiguration = {
OFF: 'off',
APP_EXIT: 'appExit',
APP_EXIT_AND_WINDOW_CLOSE: 'appExitAndWindowClose'
};
export const CONTENT_CHANGE_EVENT_BUFFER_DELAY = 1000;
export interface IFilesConfiguration {
......@@ -502,7 +508,7 @@ export interface IFilesConfiguration {
autoSave: string;
autoSaveDelay: number;
eol: string;
hotExit: boolean;
hotExit: string;
};
}
......
......@@ -16,7 +16,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'v
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IEditorRegistry, Extensions as EditorExtensions, IEditorInputFactory, EditorInput, IFileEditorInput } from 'vs/workbench/common/editor';
import { AutoSaveConfiguration, SUPPORTED_ENCODINGS, IFilesConfiguration } from 'vs/platform/files/common/files';
import { AutoSaveConfiguration, HotExitConfiguration, SUPPORTED_ENCODINGS, IFilesConfiguration } from 'vs/platform/files/common/files';
import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { FILE_EDITOR_INPUT_ID, VIEWLET_ID } from 'vs/workbench/parts/files/common/files';
import { FileEditorTracker } from 'vs/workbench/parts/files/common/editors/fileEditorTracker';
......@@ -244,9 +244,10 @@ configurationRegistry.registerConfiguration({
'description': nls.localize('watcherExclude', "Configure glob patterns of file paths to exclude from file watching. Changing this setting requires a restart. When you experience Code consuming lots of cpu time on startup, you can exclude large folders to reduce the initial load.")
},
'files.hotExit': {
'type': 'boolean',
'default': true,
'description': nls.localize('hotExit', "Controls whether unsaved files are restored after relaunching. If this is enabled there will be no prompt to save when exiting the editor.")
'type': 'string',
'enum': [HotExitConfiguration.OFF, HotExitConfiguration.APP_EXIT, HotExitConfiguration.APP_EXIT_AND_WINDOW_CLOSE],
'default': HotExitConfiguration.APP_EXIT,
'description': nls.localize('hotExit', "Whether hot exit is enabled which allows changes to unsaved files to be remembered between sessions, hiding the prompt t save when exiting the editor. Selecting \"{0}\" means that hot exit will only be triggered when the application is closed (workbench.action.quit command via command pallete, keybinding of menu) and ALL windows with backups will be restored upon next launch. Selecting \"{1}\" will trigger hot exit when any FOLDER window is closed, only NON-FOLDER windows will be restored when the application is restarted (not FOLDER workspaces).", HotExitConfiguration.APP_EXIT, HotExitConfiguration.APP_EXIT_AND_WINDOW_CLOSE)
}
}
});
......
......@@ -20,7 +20,7 @@ import { ConfirmResult } from 'vs/workbench/common/editor';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ILifecycleService, ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IFileService, IResolveContentOptions, IFilesConfiguration, IFileOperationResult, FileOperationResult, AutoSaveConfiguration } from 'vs/platform/files/common/files';
import { IFileService, IResolveContentOptions, IFilesConfiguration, IFileOperationResult, FileOperationResult, AutoSaveConfiguration, HotExitConfiguration } from 'vs/platform/files/common/files';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
......@@ -55,7 +55,7 @@ export abstract class TextFileService implements ITextFileService {
private configuredAutoSaveOnFocusChange: boolean;
private configuredAutoSaveOnWindowChange: boolean;
private configuredHotExit: boolean;
private configuredHotExit: string;
constructor(
@ILifecycleService private lifecycleService: ILifecycleService,
......@@ -186,7 +186,9 @@ export abstract class TextFileService implements ITextFileService {
let doBackup: boolean;
switch (reason) {
case ShutdownReason.CLOSE:
if (windowCount > 1 || platform.isMacintosh) {
if (this.contextService.hasWorkspace() && this.configuredHotExit === HotExitConfiguration.APP_EXIT_AND_WINDOW_CLOSE) {
doBackup = true; // backup if a folder is open and appExitAndWindowClose is configured
} else if (windowCount > 1 || platform.isMacintosh) {
doBackup = false; // do not backup if a window is closed that does not cause quitting of the application
} else {
doBackup = true; // backup if last window is closed on win/linux where the application quits right after
......@@ -353,7 +355,15 @@ export abstract class TextFileService implements ITextFileService {
}
// Hot exit
this.configuredHotExit = configuration && configuration.files && configuration.files.hotExit;
const hotExitMode = configuration && configuration.files ? configuration.files.hotExit : HotExitConfiguration.APP_EXIT;
// Handle the legacy case where hot exit was a boolean
if (<any>hotExitMode === false) {
this.configuredHotExit = HotExitConfiguration.OFF;
} else if (<any>hotExitMode === true) {
this.configuredHotExit = HotExitConfiguration.APP_EXIT;
} else {
this.configuredHotExit = hotExitMode;
}
}
public getDirty(resources?: URI[]): URI[] {
......@@ -690,7 +700,7 @@ export abstract class TextFileService implements ITextFileService {
}
public get isHotExitEnabled(): boolean {
return !this.environmentService.isExtensionDevelopment && this.configuredHotExit;
return !this.environmentService.isExtensionDevelopment && this.configuredHotExit !== HotExitConfiguration.OFF;
}
public dispose(): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册