Merge from vscode 1eb87b0e9ce9886afeaecec22b31abd0d9b7939f (#7282)

* Merge from vscode 1eb87b0e9ce9886afeaecec22b31abd0d9b7939f

* fix various icon issues

* fix preview features
This commit is contained in:
Anthony Dresser
2019-09-19 21:50:52 -07:00
committed by GitHub
parent 9d3d64eef3
commit db498db0a8
459 changed files with 10195 additions and 7528 deletions

View File

@@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AbstractTextFileService } from 'vs/workbench/services/textfile/browser/textFileService';
import { ITextFileService, IResourceEncodings, IResourceEncoding, ModelState } from 'vs/workbench/services/textfile/common/textfiles';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
export class BrowserTextFileService extends AbstractTextFileService {
readonly encoding: IResourceEncodings = {
getPreferredWriteEncoding(): IResourceEncoding {
return { encoding: 'utf8', hasBOM: false };
}
};
protected onBeforeShutdown(reason: ShutdownReason): boolean {
// Web: we cannot perform long running in the shutdown phase
// As such we need to check sync if there are any dirty files
// that have not been backed up yet and then prevent the shutdown
// if that is the case.
return this.doBeforeShutdownSync();
}
private doBeforeShutdownSync(): boolean {
if (this.models.getAll().some(model => model.hasState(ModelState.PENDING_SAVE) || model.hasState(ModelState.PENDING_AUTO_SAVE))) {
return true; // files are pending to be saved: veto
}
const dirtyResources = this.getDirty();
if (!dirtyResources.length) {
return false; // no dirty: no veto
}
if (!this.isHotExitEnabled) {
return true; // dirty without backup: veto
}
for (const dirtyResource of dirtyResources) {
let hasBackup = false;
if (this.fileService.canHandleResource(dirtyResource)) {
const model = this.models.get(dirtyResource);
hasBackup = !!(model && model.hasBackup());
} else if (dirtyResource.scheme === Schemas.untitled) {
hasBackup = this.untitledEditorService.hasBackup(dirtyResource);
}
if (!hasBackup) {
console.warn('Unload prevented: pending backups');
return true; // dirty without backup: veto
}
}
return false; // dirty with backups: no veto
}
}
registerSingleton(ITextFileService, BrowserTextFileService);