Skip to content

Commit

Permalink
Fix #17376 (1.8)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Dec 19, 2016
1 parent 31ae0d5 commit 5dcb9c5
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/vs/workbench/parts/preferences/browser/preferencesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as labels from 'vs/base/common/labels';
import { Disposable } from 'vs/base/common/lifecycle';
import { parseTree, findNodeAtLocation } from 'vs/base/common/json';
import { asFileEditorInput, SideBySideEditorInput, EditorInput } from 'vs/workbench/common/editor';
import { StringEditorInput } from 'vs/workbench/common/editor/stringEditorInput';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceConfigurationService, WORKSPACE_CONFIG_DEFAULT_PATH } from 'vs/workbench/services/configuration/common/configuration';
Expand Down Expand Up @@ -136,11 +135,8 @@ export class PreferencesService extends Disposable implements IPreferencesServic

openGlobalKeybindingSettings(): TPromise<void> {
const emptyContents = '// ' + nls.localize('emptyKeybindingsHeader', "Place your key bindings in this file to overwrite the defaults") + '\n[\n]';
return this.createDefaultPreferencesEditorModel(PreferencesService.DEFAULT_KEY_BINDINGS_URI)
.then(editorModel => {
const defaultKeybindingsInput = this.instantiationService.createInstance(StringEditorInput, nls.localize('keybindingsEditorName', "Default Keyboard Shortcuts"), '', editorModel.content, 'json', true);
this.openTwoEditors(defaultKeybindingsInput, URI.file(this.environmentService.appKeybindingsPath), emptyContents);
});
return this.editorService.createInput({ resource: PreferencesService.DEFAULT_KEY_BINDINGS_URI })
.then(leftHandInput => this.openTwoEditors(<EditorInput>leftHandInput, URI.file(this.environmentService.appKeybindingsPath), emptyContents)).then(() => null);
}

private openEditableSettings(configurationTarget: ConfigurationTarget): TPromise<IEditor> {
Expand Down Expand Up @@ -223,7 +219,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
if (openDefaultSettings) {
const emptySettingsContents = this.getEmptyEditableSettingsContent(configurationTarget);
const settingsResource = this.getEditableSettingsURI(configurationTarget);
return this.openTwoEditors(this.getDefaultSettingsEditorInput(configurationTarget), settingsResource, emptySettingsContents).then(() => null);
return this.openSideBySideEditor(this.getDefaultSettingsEditorInput(configurationTarget), settingsResource, emptySettingsContents).then(() => null);
}
return this.openEditableSettings(configurationTarget).then(() => null);
}
Expand All @@ -243,7 +239,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
}
}

private openTwoEditors(leftHandDefaultInput: EditorInput, editableResource: URI, defaultEditableContents: string): TPromise<IEditor> {
private openSideBySideEditor(leftHandDefaultInput: EditorInput, editableResource: URI, defaultEditableContents: string): TPromise<IEditor> {
// Create as needed and open in editor
return this.createIfNotExists(editableResource, defaultEditableContents).then(() => {
return this.editorService.createInput({ resource: editableResource }).then(typedRightHandEditableInput => {
Expand All @@ -253,6 +249,21 @@ export class PreferencesService extends Disposable implements IPreferencesServic
});
}

private openTwoEditors(leftHandDefaultInput: EditorInput, editableResource: URI, defaultEditableContents: string): TPromise<void> {
// Create as needed and open in editor
return this.createIfNotExists(editableResource, defaultEditableContents).then(() => {
return this.editorService.createInput({ resource: editableResource }).then(typedRightHandEditableInput => {
const editors = [
{ input: leftHandDefaultInput, position: Position.ONE, options: { pinned: true } },
{ input: typedRightHandEditableInput, position: Position.TWO, options: { pinned: true } }
];
return this.editorService.openEditors(editors).then(result => {
this.editorGroupService.focusGroup(Position.TWO);
});
});
});
}

private createIfNotExists(resource: URI, contents: string): TPromise<boolean> {
return this.fileService.resolveContent(resource, { acceptTextOnly: true }).then(null, error => {
if ((<IFileOperationResult>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) {
Expand Down

0 comments on commit 5dcb9c5

Please sign in to comment.