Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preferences: update 'modified scope' #8025

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/preferences/src/browser/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,7 @@
.theia-settings-container .settings-section>li:last-child {
margin-bottom: 20px;
}

.theia-settings-container .settings-scope-underlined {
text-decoration: underline;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import * as React from 'react';
import { Menu, PreferenceDataProperty, PreferenceScope, PreferenceItem, PreferenceService, ContextMenuRenderer } from '@theia/core/lib/browser';
import { Menu, PreferenceScope, PreferenceItem, PreferenceService, ContextMenuRenderer } from '@theia/core/lib/browser';
import { PreferenceSelectInput, PreferenceBooleanInput, PreferenceStringInput, PreferenceNumberInput, PreferenceJSONInput, PreferenceArrayInput } from '.';
import { Preference, PreferenceMenus } from '../../util/preference-types';

Expand Down Expand Up @@ -91,7 +91,7 @@ export class SinglePreferenceWrapper extends React.Component<SinglePreferenceWra
>
<div className="pref-name">
{preferenceDisplayNode.name}
{this.renderOtherModifiedScopes(values, data, this.props.currentScope)}
{this.renderOtherModifiedScopes(singlePreferenceValueDisplayNode.id, values, this.props.currentScope, this.props.preferencesService)}
</div>
<div className={`pref-context-gutter ${!currentValueIsDefaultValue ? 'theia-mod-item-modified' : ''}`}
onMouseOver={this.showCog}
Expand Down Expand Up @@ -133,24 +133,54 @@ export class SinglePreferenceWrapper extends React.Component<SinglePreferenceWra
}

protected renderOtherModifiedScopes(
id: string,
preferenceValuesInAllScopes: Preference.ValuesInAllScopes | undefined,
data: PreferenceDataProperty,
currentScope: number): React.ReactNode[] | undefined {
currentScope: number,
service: PreferenceService): React.ReactNode[] | undefined {
if (preferenceValuesInAllScopes) {
return ['User', 'Workspace'].map((scope: 'User' | 'Workspace') => {
const matchingScope = PreferenceScope[scope];
const valueInCurrentScope = preferenceValuesInAllScopes[Preference.LookupKeys[currentScope] as keyof Preference.ValuesInAllScopes];
if (currentScope !== matchingScope) {
const valueInOtherScope = preferenceValuesInAllScopes[Preference.LookupKeys[matchingScope] as keyof Preference.ValuesInAllScopes];
if (valueInOtherScope && valueInOtherScope !== data.defaultValue) {
const message = valueInCurrentScope && valueInCurrentScope !== data.defaultValue ? `Also modified in: ${scope}.` : `Modified in: ${scope}.`;
return <i key={`modified-in-${scope}-alert`}><span> {message}</span></i>;
const info = service.inspect<PreferenceItem>(id);
if (!info) {
return;
}

const defaultValue = info.defaultValue;
const currentValue = this.getValueByScope(info, currentScope);
const matchingValue = this.getValueByScope(info, matchingScope);

if (matchingValue !== undefined) {

const bothOverridden = (
(currentValue !== defaultValue && currentValue !== undefined) &&
(matchingValue !== defaultValue && matchingValue !== undefined)
);

const message = bothOverridden ? 'Also modified in:' : 'Modified in:';
return <i key={`modified-in-${scope}-alert`}><span> ({message} <span className='settings-scope-underlined'>{scope}</span>)</span></i>;
}

}
});
}
}

protected getValueByScope(info: {
preferenceName: string;
defaultValue: PreferenceItem | undefined;
globalValue: PreferenceItem | undefined;
workspaceValue: PreferenceItem | undefined;
workspaceFolderValue: PreferenceItem | undefined;
}, scope: number): PreferenceItem | undefined {
if (scope === PreferenceScope.User) {
return info.globalValue;
} else if (scope === PreferenceScope.Workspace) {
return info.workspaceValue;
}
return undefined;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected setPreference = (preferenceName: string, preferenceValue: any): void => {
this.props.preferencesService.set(preferenceName, preferenceValue, this.props.currentScope, this.props.currentScopeURI);
Expand Down