Skip to content

Commit

Permalink
Change default scope for PreferenceService.set
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Grant <colin.grant@ericsson.com>
  • Loading branch information
colin-grant-work committed Mar 11, 2021
1 parent 3bef155 commit 34603ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions packages/core/src/browser/preferences/preference-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,7 @@ export class PreferenceServiceImpl implements PreferenceService {
}

async set(preferenceName: string, value: any, scope: PreferenceScope | undefined, resourceUri?: string): Promise<void> {
const resolvedScope = scope !== undefined ? scope : (!resourceUri ? PreferenceScope.Workspace : PreferenceScope.Folder);
if (resolvedScope === PreferenceScope.User && this.configurations.isSectionName(preferenceName.split('.', 1)[0])) {
throw new Error(`Unable to write to User Settings because ${preferenceName} does not support for global scope.`);
}
const resolvedScope = scope ?? (!resourceUri ? PreferenceScope.Workspace : PreferenceScope.Folder);
if (resolvedScope === PreferenceScope.Folder && !resourceUri) {
throw new Error('Unable to write to Folder Settings because no resource is provided.');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/browser/editor-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { inject, injectable, postConstruct } from 'inversify';
import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common';
import URI from '@theia/core/lib/common/uri';
import { CommonCommands, PreferenceService, QuickPickItem, QuickPickService, LabelProvider, QuickPickValue, ApplicationShell } from '@theia/core/lib/browser';
import { CommonCommands, PreferenceService, QuickPickItem, QuickPickService, LabelProvider, QuickPickValue, ApplicationShell, PreferenceScope } from '@theia/core/lib/browser';
import { EditorManager } from './editor-manager';
import { EncodingMode } from './editor';
import { EditorPreferences } from './editor-preferences';
Expand Down Expand Up @@ -333,6 +333,6 @@ export class EditorCommandContribution implements CommandContribution {
return autoSave === 'on' || autoSave === undefined;
}
private async toggleAutoSave(): Promise<void> {
this.preferencesService.set(EditorCommandContribution.AUTOSAVE_PREFERENCE, this.isAutoSaveOn() ? 'off' : 'on');
this.preferencesService.set(EditorCommandContribution.AUTOSAVE_PREFERENCE, this.isAutoSaveOn() ? 'off' : 'on', PreferenceScope.User);
}
}

0 comments on commit 34603ac

Please sign in to comment.