Skip to content

Commit

Permalink
Live change of theme from Preferences dropdown (arduino#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
francescospissu authored Aug 9, 2022
1 parent 54db9bb commit aebec0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,7 @@ export class SettingsComponent extends React.Component<
<div className="flex-line">
<select
className="theia-select"
value={
ThemeService.get()
.getThemes()
.find(({ id }) => id === this.state.themeId)?.label ||
nls.localize('arduino/common/unknown', 'Unknown')
}
value={ThemeService.get().getCurrentTheme().label}
onChange={this.themeDidChange}
>
{ThemeService.get()
Expand Down Expand Up @@ -591,6 +586,9 @@ export class SettingsComponent extends React.Component<
const theme = ThemeService.get().getThemes()[selectedIndex];
if (theme) {
this.setState({ themeId: theme.id });
if (ThemeService.get().getCurrentTheme().id !== theme.id) {
ThemeService.get().setCurrentTheme(theme.id);
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SettingsComponent } from './settings-component';
import { AsyncLocalizationProvider } from '@theia/core/lib/common/i18n/localization';
import { AdditionalUrls } from '../../../common/protocol';
import { AbstractDialog } from '../../theia/dialogs/dialogs';
import { ThemeService } from '@theia/core/lib/browser/theming';

@injectable()
export class SettingsWidget extends ReactWidget {
Expand Down Expand Up @@ -118,6 +119,17 @@ export class SettingsDialog extends AbstractDialog<Promise<Settings>> {

this.widget.activate();
}

override async open(): Promise<Promise<Settings> | undefined> {
const themeIdBeforeOpen = ThemeService.get().getCurrentTheme().id;
const result = await super.open();
if (!result) {
if (ThemeService.get().getCurrentTheme().id !== themeIdBeforeOpen) {
ThemeService.get().setCurrentTheme(themeIdBeforeOpen);
}
}
return result;
}
}

export class AdditionalUrlsDialog extends AbstractDialog<string[]> {
Expand Down

0 comments on commit aebec0f

Please sign in to comment.