textFileService.ts 1.4 KB
Newer Older
B
Benjamin Pasero 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService';
7
import { ITextFileService, IResourceEncodings, IResourceEncoding } from 'vs/workbench/services/textfile/common/textfiles';
B
Benjamin Pasero 已提交
8
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
9
import { ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
B
Benjamin Pasero 已提交
10 11 12 13 14 15 16 17

export class BrowserTextFileService extends TextFileService {

	readonly encoding: IResourceEncodings = {
		getPreferredWriteEncoding(): IResourceEncoding {
			return { encoding: 'utf8', hasBOM: false };
		}
	};
18 19 20 21 22 23 24 25 26 27 28 29 30

	protected beforeShutdown(reason: ShutdownReason): boolean | Promise<boolean> {
		const veto = super.beforeShutdown(reason);

		// Web: there is no support for long running unload handlers. As such
		// we need to return a direct boolean veto when we detect that there
		// are dirty files around. 
		if (veto instanceof Promise) {
			return this.getDirty().length > 0;
		}

		return veto;
	}
B
Benjamin Pasero 已提交
31 32 33
}

registerSingleton(ITextFileService, BrowserTextFileService);