提交 a5f82bdc 编写于 作者: S Sandeep Somavarapu

Fix #16580

上级 996623e0
......@@ -10,7 +10,6 @@ import { Registry } from 'vs/platform/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
......@@ -25,7 +24,6 @@ export class ToggleActivityBarVisibilityAction extends Action {
id: string,
label: string,
@IPartService private partService: IPartService,
@IMessageService private messageService: IMessageService,
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService
) {
super(id, label);
......@@ -37,9 +35,7 @@ export class ToggleActivityBarVisibilityAction extends Action {
const visibility = this.partService.isVisible(Parts.ACTIVITYBAR_PART);
const newVisibilityValue = !visibility;
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleActivityBarVisibilityAction.activityBarVisibleKey, value: newVisibilityValue }).then(null, error => {
this.messageService.show(Severity.Error, error);
});
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleActivityBarVisibilityAction.activityBarVisibleKey, value: newVisibilityValue });
return TPromise.as(null);
}
......
......@@ -9,7 +9,6 @@ import nls = require('vs/nls');
import { Registry } from 'vs/platform/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IPartService, Position } from 'vs/workbench/services/part/common/partService';
......@@ -25,7 +24,6 @@ export class ToggleSidebarPositionAction extends Action {
id: string,
label: string,
@IPartService private partService: IPartService,
@IMessageService private messageService: IMessageService,
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService
) {
super(id, label);
......@@ -37,9 +35,7 @@ export class ToggleSidebarPositionAction extends Action {
const position = this.partService.getSideBarPosition();
const newPositionValue = (position === Position.LEFT) ? 'right' : 'left';
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleSidebarPositionAction.sidebarPositionConfigurationKey, value: newPositionValue }).then(null, error => {
this.messageService.show(Severity.Error, error);
});
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleSidebarPositionAction.sidebarPositionConfigurationKey, value: newPositionValue });
return TPromise.as(null);
}
......
......@@ -10,7 +10,6 @@ import { Registry } from 'vs/platform/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
......@@ -25,7 +24,6 @@ export class ToggleStatusbarVisibilityAction extends Action {
id: string,
label: string,
@IPartService private partService: IPartService,
@IMessageService private messageService: IMessageService,
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService
) {
super(id, label);
......@@ -37,9 +35,7 @@ export class ToggleStatusbarVisibilityAction extends Action {
const visibility = this.partService.isVisible(Parts.STATUSBAR_PART);
const newVisibilityValue = !visibility;
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleStatusbarVisibilityAction.statusbarVisibleKey, value: newVisibilityValue }).then(null, error => {
this.messageService.show(Severity.Error, error);
});
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleStatusbarVisibilityAction.statusbarVisibleKey, value: newVisibilityValue });
return TPromise.as(null);
}
......
......@@ -21,7 +21,6 @@ import { IMode } from 'vs/editor/common/modes';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
import { IFileEditorInput, EncodingMode, IEncodingSupport, toResource, SideBySideEditorInput } from 'vs/workbench/common/editor';
import { IDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IEditorAction, ICommonCodeEditor, EndOfLineSequence, IModel } from 'vs/editor/common/editorCommon';
......@@ -706,7 +705,6 @@ export class ChangeModeAction extends Action {
@IModelService private modelService: IModelService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService,
@IMessageService private messageService: IMessageService,
@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IPreferencesService private preferencesService: IPreferencesService,
......@@ -886,7 +884,7 @@ export class ChangeModeAction extends Action {
currentAssociations[associationKey] = language.id;
// Write config
this.configurationEditingService.writeConfiguration(target, { key: ChangeModeAction.FILE_ASSOCIATION_KEY, value: currentAssociations }).done(null, (error) => this.messageService.show(Severity.Error, error.toString()));
this.configurationEditingService.writeConfiguration(target, { key: ChangeModeAction.FILE_ASSOCIATION_KEY, value: currentAssociations });
}
});
});
......
......@@ -197,9 +197,7 @@ export class ToggleMenuBarAction extends Action {
newVisibilityValue = 'default';
}
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleMenuBarAction.menuBarVisibilityKey, value: newVisibilityValue }).then(null, error => {
this.messageService.show(Severity.Error, error);
});
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleMenuBarAction.menuBarVisibilityKey, value: newVisibilityValue });
return TPromise.as(null);
}
......
......@@ -464,7 +464,7 @@ export class ElectronWindow extends Themable {
newAutoSaveValue = AutoSaveConfiguration.AFTER_DELAY;
}
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ElectronWindow.AUTO_SAVE_SETTING, value: newAutoSaveValue }).done(null, error => this.messageService.show(Severity.Error, error));
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ElectronWindow.AUTO_SAVE_SETTING, value: newAutoSaveValue });
}
private includesFolder(resources: URI[]): TPromise<boolean> {
......
......@@ -8,7 +8,6 @@ import * as nls from 'vs/nls';
import { ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { editorAction, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
@editorAction
export class ToggleRenderControlCharacterAction extends EditorAction {
......@@ -24,12 +23,9 @@ export class ToggleRenderControlCharacterAction extends EditorAction {
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
const configurationEditingService = accessor.get(IConfigurationEditingService);
const messageService = accessor.get(IMessageService);
let newRenderControlCharacters = !editor.getConfiguration().viewInfo.renderControlCharacters;
configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: 'editor.renderControlCharacters', value: newRenderControlCharacters }).then(null, error => {
messageService.show(Severity.Error, error);
});
configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: 'editor.renderControlCharacters', value: newRenderControlCharacters });
}
}
......@@ -8,7 +8,6 @@ import * as nls from 'vs/nls';
import { ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { editorAction, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
@editorAction
export class ToggleRenderWhitespaceAction extends EditorAction {
......@@ -24,7 +23,6 @@ export class ToggleRenderWhitespaceAction extends EditorAction {
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
const configurationEditingService = accessor.get(IConfigurationEditingService);
const messageService = accessor.get(IMessageService);
let renderWhitespace = editor.getConfiguration().viewInfo.renderWhitespace;
let newRenderWhitespace: string;
......@@ -34,8 +32,6 @@ export class ToggleRenderWhitespaceAction extends EditorAction {
newRenderWhitespace = 'none';
}
configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: 'editor.renderWhitespace', value: newRenderWhitespace }).then(null, error => {
messageService.show(Severity.Error, error);
});
configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: 'editor.renderWhitespace', value: newRenderWhitespace });
}
}
......@@ -279,9 +279,7 @@ export class ExtensionTipsService implements IExtensionTipsService {
private setIgnoreRecommendationsConfig(configVal: boolean) {
let target = ConfigurationTarget.USER;
const configKey = 'extensions.ignoreRecommendations';
this.configurationEditingService.writeConfiguration(target, { key: configKey, value: configVal }).then(null, error => {
this.messageService.show(Severity.Error, error);
});
this.configurationEditingService.writeConfiguration(target, { key: configKey, value: configVal });
if (configVal) {
const ignoreWorkspaceRecommendationsStorageKey = 'extensionsAssistant/workspaceRecommendationsIgnore';
this.storageService.store(ignoreWorkspaceRecommendationsStorageKey, true, StorageScope.WORKSPACE);
......
......@@ -101,7 +101,7 @@ export class UserSettingsRenderer extends Disposable implements IPreferencesRend
this.telemetryService.publicLog('defaultSettingsActions.copySetting', { userConfigurationKeys: [key] });
const overrideIdentifier = source.overrideOf ? overrideIdentifierFromKey(source.overrideOf.key) : null;
this.configurationEditingService.writeConfiguration(this.preferencesModel.configurationTarget, { key, value, overrideIdentifier }, !this.textFileService.isDirty(this.preferencesModel.uri))
.then(() => this.onSettingUpdated(source), error => this.messageService.show(Severity.Error, error));
.then(() => this.onSettingUpdated(source));
}
private onModelChanged(): void {
......
......@@ -168,8 +168,7 @@ class WelcomePage {
showOnStartup.setAttribute('checked', 'checked');
}
showOnStartup.addEventListener('click', e => {
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: enabledKey, value: showOnStartup.checked })
.then(null, error => this.messageService.show(Severity.Error, error));
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: enabledKey, value: showOnStartup.checked });
});
recentlyOpened.then(({ folders }) => {
......
......@@ -29,6 +29,8 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationEditingService, ConfigurationEditingErrorCode, IConfigurationEditingError, ConfigurationTarget, IConfigurationValue } from 'vs/workbench/services/configuration/common/configurationEditing';
import { ITextModelResolverService, ITextEditorModel } from 'vs/editor/common/services/resolverService';
import { OVERRIDE_PROPERTY_PATTERN } from 'vs/platform/configuration/common/configurationRegistry';
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
import { ICommandService } from 'vs/platform/commands/common/commands';
interface IConfigurationEditOperation extends IConfigurationValue {
resource: URI;
......@@ -52,13 +54,15 @@ export class ConfigurationEditingService implements IConfigurationEditingService
@IEnvironmentService private environmentService: IEnvironmentService,
@IFileService private fileService: IFileService,
@ITextModelResolverService private textModelResolverService: ITextModelResolverService,
@ITextFileService private textFileService: ITextFileService
@ITextFileService private textFileService: ITextFileService,
@IChoiceService private choiceService: IChoiceService,
@ICommandService private commandService: ICommandService
) {
this.queue = new Queue<void>();
}
writeConfiguration(target: ConfigurationTarget, value: IConfigurationValue, save: boolean = true): TPromise<void> {
return this.queue.queue(() => this.doWriteConfiguration(target, value, save)); // queue up writes to prevent race conditions
return this.queue.queue(() => this.doWriteConfiguration(target, value, save).then(() => null, error => this.onError(error, target))); // queue up writes to prevent race conditions
}
private doWriteConfiguration(target: ConfigurationTarget, value: IConfigurationValue, save: boolean): TPromise<void> {
......@@ -92,6 +96,17 @@ export class ConfigurationEditingService implements IConfigurationEditingService
return false;
}
private onError(error: IConfigurationEditingError, target: ConfigurationTarget): TPromise<IConfigurationEditingError> {
this.choiceService.choose(Severity.Error, error.message, [nls.localize('open', "Open Settings"), nls.localize('close', "Close")], 1)
.then(value => {
switch (value) {
case 0:
this.commandService.executeCommand(ConfigurationTarget.USER === target ? 'workbench.action.openGlobalSettings' : 'workbench.action.openWorkspaceSettings');
}
});
return TPromise.wrapError(error);
}
private wrapError(code: ConfigurationEditingErrorCode, target: ConfigurationTarget): TPromise<any> {
const message = this.toErrorMessage(code, target);
......@@ -110,20 +125,20 @@ export class ConfigurationEditingService implements IConfigurationEditingService
case ConfigurationEditingErrorCode.ERROR_INVALID_TARGET: return nls.localize('errorInvalidTarget', "Unable to write to the configuration file (Invalid Target)");
// User issues
case ConfigurationEditingErrorCode.ERROR_NO_WORKSPACE_OPENED: return nls.localize('errorNoWorkspaceOpened', "Unable to write settings because no folder is opened. Please open a folder first and try again.");
case ConfigurationEditingErrorCode.ERROR_NO_WORKSPACE_OPENED: return nls.localize('errorNoWorkspaceOpened', "Unable to write into settings because no folder is opened. Please open a folder first and try again.");
case ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION: {
if (target === ConfigurationTarget.USER) {
return nls.localize('errorInvalidConfiguration', "Unable to write settings. Please open **User Settings** to correct errors/warnings in the file and try again.");
return nls.localize('errorInvalidConfiguration', "Unable to write into settings. Please open **User Settings** to correct errors/warnings in the file and try again.");
}
return nls.localize('errorInvalidConfigurationWorkspace', "Unable to write settings. Please open **Workspace Settings** to correct errors/warnings in the file and try again.");
return nls.localize('errorInvalidConfigurationWorkspace', "Unable to write into settings. Please open **Workspace Settings** to correct errors/warnings in the file and try again.");
};
case ConfigurationEditingErrorCode.ERROR_CONFIGURATION_FILE_DIRTY: {
if (target === ConfigurationTarget.USER) {
return nls.localize('errorConfigurationFileDirty', "Unable to write settings because the file is dirty. Please save the **User Settings** file and try again.");
return nls.localize('errorConfigurationFileDirty', "Unable to write into settings because the file is dirty. Please save the **User Settings** file and try again.");
}
return nls.localize('errorConfigurationFileDirtyWorkspace', "Unable to write settings because the file is dirty. Please save the **Workspace Settings** file and try again.");
return nls.localize('errorConfigurationFileDirtyWorkspace', "Unable to write into settings because the file is dirty. Please save the **Workspace Settings** file and try again.");
};
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册