提交 07e81e6e 编写于 作者: S Sandeep Somavarapu

#53526 Migrate from TPromise in Keybindings Editor

上级 67329220
......@@ -5,7 +5,6 @@
import 'vs/css!./media/keybindingsEditor';
import { localize } from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { Delayer } from 'vs/base/common/async';
import * as DOM from 'vs/base/browser/dom';
import { OS } from 'vs/base/common/platform';
......@@ -154,7 +153,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
return focusedElement && focusedElement.templateId === KEYBINDING_ENTRY_TEMPLATE_ID ? <IKeybindingItemEntry>focusedElement : null;
}
defineKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any> {
defineKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable<any> {
this.selectEntry(keybindingEntry);
this.showOverlayContainer();
return this.defineKeybindingWidget.define().then(key => {
......@@ -182,7 +181,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
});
}
removeKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any> {
removeKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable<any> {
this.selectEntry(keybindingEntry);
if (keybindingEntry.keybindingItem.keybinding) { // This should be a pre-condition
this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_REMOVE, keybindingEntry.keybindingItem.command, keybindingEntry.keybindingItem.keybinding);
......@@ -193,10 +192,10 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
this.selectEntry(keybindingEntry);
});
}
return TPromise.as(null);
return Promise.resolve(null);
}
resetKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any> {
resetKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable<any> {
this.selectEntry(keybindingEntry);
this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_RESET, keybindingEntry.keybindingItem.command, keybindingEntry.keybindingItem.keybinding);
return this.keybindingEditingService.resetKeybinding(keybindingEntry.keybindingItem.keybindingItem)
......@@ -212,7 +211,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
});
}
copyKeybinding(keybinding: IKeybindingItemEntry): TPromise<any> {
copyKeybinding(keybinding: IKeybindingItemEntry): void {
this.selectEntry(keybinding);
this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_COPY, keybinding.keybindingItem.command, keybinding.keybindingItem.keybinding);
const userFriendlyKeybinding: IUserFriendlyKeybinding = {
......@@ -223,14 +222,12 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
userFriendlyKeybinding.when = keybinding.keybindingItem.when;
}
this.clipboardService.writeText(JSON.stringify(userFriendlyKeybinding, null, ' '));
return TPromise.as(null);
}
copyKeybindingCommand(keybinding: IKeybindingItemEntry): TPromise<any> {
copyKeybindingCommand(keybinding: IKeybindingItemEntry): void {
this.selectEntry(keybinding);
this.reportKeybindingAction(KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND, keybinding.keybindingItem.command, keybinding.keybindingItem.keybinding);
this.clipboardService.writeText(keybinding.keybindingItem.command);
return TPromise.as(null);
}
focusSearch(): void {
......@@ -246,12 +243,11 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
this.searchWidget.clear();
}
showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): TPromise<any> {
showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): void {
const value = `"${keybindingEntry.keybindingItem.keybinding.getAriaLabel()}"`;
if (value !== this.searchWidget.getValue()) {
this.searchWidget.setValue(value);
}
return TPromise.as(null);
}
private createAriaLabelElement(parent: HTMLElement): void {
......@@ -425,7 +421,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
}));
}
private render(preserveFocus: boolean, token: CancellationToken): TPromise<any> {
private render(preserveFocus: boolean, token: CancellationToken): Thenable<any> {
if (this.input) {
return this.input.resolve()
.then((keybindingsModel: KeybindingsEditorModel) => {
......@@ -450,7 +446,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
this.renderKeybindingsEntries(false, preserveFocus);
});
}
return TPromise.as(null);
return Promise.resolve();
}
private filterKeybindings(): void {
......
......@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TPromise } from 'vs/base/common/winjs.base';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { join } from 'vs/base/common/paths';
......@@ -54,12 +53,12 @@ export interface IKeybindingsEditor extends IEditor {
focusKeybindings(): void;
recordSearchKeys(): void;
toggleSortByPrecedence(): void;
defineKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
removeKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
resetKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
copyKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
copyKeybindingCommand(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): TPromise<any>;
defineKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable<any>;
removeKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable<any>;
resetKeybinding(keybindingEntry: IKeybindingItemEntry): Thenable<any>;
copyKeybinding(keybindingEntry: IKeybindingItemEntry): void;
copyKeybindingCommand(keybindingEntry: IKeybindingItemEntry): void;
showSimilarKeybindings(keybindingEntry: IKeybindingItemEntry): void;
}
export const CONTEXT_SETTINGS_EDITOR = new RawContextKey<boolean>('inSettingsEditor', false);
......
......@@ -35,7 +35,6 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { ICommandService } from 'vs/platform/commands/common/commands';
import { CommandService } from 'vs/workbench/services/commands/common/commandService';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { createHash } from 'crypto';
class SettingsTestEnvironmentService extends EnvironmentService {
......@@ -83,14 +82,14 @@ suite('ConfigurationEditingService', () => {
.then(() => setUpServices());
});
function setUpWorkspace(): TPromise<boolean> {
async function setUpWorkspace(): Promise<boolean> {
const id = uuid.generateUuid();
parentDir = path.join(os.tmpdir(), 'vsctests', id);
workspaceDir = path.join(parentDir, 'workspaceconfig', id);
globalSettingsFile = path.join(workspaceDir, 'config.json');
workspaceSettingsDir = path.join(workspaceDir, '.vscode');
return mkdirp(workspaceSettingsDir, 493);
return await mkdirp(workspaceSettingsDir, 493);
}
function setUpServices(noWorkspace: boolean = false): Promise<void> {
......
......@@ -11,7 +11,6 @@ import { Edit } from 'vs/base/common/jsonFormatter';
import { Disposable, IReference } from 'vs/base/common/lifecycle';
import { isArray } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
......@@ -33,11 +32,11 @@ export interface IKeybindingEditingService {
_serviceBrand: ServiceIdentifier<any>;
editKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): TPromise<void>;
editKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): Thenable<void>;
removeKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise<void>;
removeKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable<void>;
resetKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise<void>;
resetKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable<void>;
}
export class KeybindingsEditingService extends Disposable implements IKeybindingEditingService {
......@@ -58,19 +57,19 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
this.queue = new Queue<void>();
}
editKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): TPromise<void> {
editKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): Thenable<void> {
return this.queue.queue(() => this.doEditKeybinding(key, keybindingItem)); // queue up writes to prevent race conditions
}
resetKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise<void> {
resetKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable<void> {
return this.queue.queue(() => this.doResetKeybinding(keybindingItem)); // queue up writes to prevent race conditions
}
removeKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise<void> {
removeKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable<void> {
return this.queue.queue(() => this.doRemoveKeybinding(keybindingItem)); // queue up writes to prevent race conditions
}
private doEditKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): TPromise<void> {
private doEditKeybinding(key: string, keybindingItem: ResolvedKeybindingItem): Thenable<void> {
return this.resolveAndValidate()
.then(reference => {
const model = reference.object.textEditorModel;
......@@ -84,7 +83,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
});
}
private doRemoveKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise<void> {
private doRemoveKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable<void> {
return this.resolveAndValidate()
.then(reference => {
const model = reference.object.textEditorModel;
......@@ -97,7 +96,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
});
}
private doResetKeybinding(keybindingItem: ResolvedKeybindingItem): TPromise<void> {
private doResetKeybinding(keybindingItem: ResolvedKeybindingItem): Thenable<void> {
return this.resolveAndValidate()
.then(reference => {
const model = reference.object.textEditorModel;
......@@ -109,7 +108,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
});
}
private save(): TPromise<any> {
private save(): Thenable<any> {
return this.textFileService.save(this.resource);
}
......@@ -198,20 +197,20 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
}
private resolveModelReference(): TPromise<IReference<ITextEditorModel>> {
private resolveModelReference(): Thenable<IReference<ITextEditorModel>> {
return this.fileService.existsFile(this.resource)
.then(exists => {
const EOL = this.configurationService.getValue('files', { overrideIdentifier: 'json' })['eol'];
const result = exists ? TPromise.as(null) : this.fileService.updateContent(this.resource, this.getEmptyContent(EOL), { encoding: 'utf8' });
const result: Thenable<any> = exists ? Promise.resolve(null) : this.fileService.updateContent(this.resource, this.getEmptyContent(EOL), { encoding: 'utf8' });
return result.then(() => this.textModelResolverService.createModelReference(this.resource));
});
}
private resolveAndValidate(): TPromise<IReference<ITextEditorModel>> {
private resolveAndValidate(): Thenable<IReference<ITextEditorModel>> {
// Target cannot be dirty if not writing into buffer
if (this.textFileService.isDirty(this.resource)) {
return TPromise.wrapError<IReference<ITextEditorModel>>(new Error(localize('errorKeybindingsFileDirty', "Unable to write because the keybindings configuration file is dirty. Please save it first and then try again.")));
return Promise.reject(new Error(localize('errorKeybindingsFileDirty', "Unable to write because the keybindings configuration file is dirty. Please save it first and then try again.")));
}
return this.resolveModelReference()
......@@ -221,11 +220,11 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
if (model.getValue()) {
const parsed = this.parse(model);
if (parsed.parseErrors.length) {
return TPromise.wrapError<IReference<ITextEditorModel>>(new Error(localize('parseErrors', "Unable to write to the keybindings configuration file. Please open it to correct errors/warnings in the file and try again.")));
return Promise.reject(new Error(localize('parseErrors', "Unable to write to the keybindings configuration file. Please open it to correct errors/warnings in the file and try again.")));
}
if (parsed.result) {
if (!isArray(parsed.result)) {
return TPromise.wrapError<IReference<ITextEditorModel>>(new Error(localize('errorInvalidConfiguration', "Unable to write to the keybindings configuration file. It has an object which is not of type Array. Please open the file to clean up and try again.")));
return Promise.reject(new Error(localize('errorInvalidConfiguration', "Unable to write to the keybindings configuration file. It has an object which is not of type Array. Please open the file to clean up and try again.")));
}
} else {
const content = EOL + '[]';
......
......@@ -11,7 +11,6 @@ import * as json from 'vs/base/common/json';
import { ChordKeybinding, KeyCode, SimpleKeybinding } from 'vs/base/common/keyCodes';
import { OS } from 'vs/base/common/platform';
import * as uuid from 'vs/base/common/uuid';
import { TPromise } from 'vs/base/common/winjs.base';
import * as extfs from 'vs/base/node/extfs';
import { mkdirp } from 'vs/base/node/pfs';
import { IModeService } from 'vs/editor/common/services/modeService';
......@@ -104,9 +103,9 @@ suite('KeybindingsEditing', () => {
});
});
function setUpWorkspace(): TPromise<boolean> {
async function setUpWorkspace(): Promise<boolean> {
testDir = path.join(os.tmpdir(), 'vsctests', uuid.generateUuid());
return mkdirp(testDir, 493);
return await mkdirp(testDir, 493);
}
teardown(() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册