Skip to content

Commit 8d4fff5

Browse files
live change of theme from preferences
1 parent 36ac47b commit 8d4fff5

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/settings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class Settings extends SketchContribution {
3232
await this.settingsService.update(settings);
3333
await this.settingsService.save();
3434
} else {
35-
await this.settingsService.reset();
35+
await this.settingsService.reset(true);
3636
}
3737
},
3838
isEnabled: () => !this.settingsOpened,

Diff for: arduino-ide-extension/src/browser/dialogs/settings/settings-component.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,11 @@ export class SettingsComponent extends React.Component<
589589
): void => {
590590
const { selectedIndex } = event.target.options;
591591
const theme = ThemeService.get().getThemes()[selectedIndex];
592-
if (theme) {
593-
this.setState({ themeId: theme.id });
592+
const prevTheme = ThemeService.get().getCurrentTheme();
593+
if (theme && prevTheme) {
594+
this.setState({ themeId: theme.id, prevThemeId: prevTheme.id });
594595
}
596+
ThemeService.get().setCurrentTheme(theme.id);
595597
};
596598

597599
protected languageDidChange = (

Diff for: arduino-ide-extension/src/browser/dialogs/settings/settings-dialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class SettingsDialog extends AbstractDialog<Promise<Settings>> {
114114

115115
// calling settingsService.reset() in order to reload the settings from the preferenceService
116116
// and update the UI including changes triggered from the command palette
117-
this.settingsService.reset();
117+
this.settingsService.reset(false);
118118

119119
this.widget.activate();
120120
}

Diff for: arduino-ide-extension/src/browser/dialogs/settings/settings.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const SHOW_ALL_FILES_SETTING = `${SKETCHBOOK_SETTING}.showAllFiles`;
4646
export interface Settings {
4747
editorFontSize: number; // `editor.fontSize`
4848
themeId: string; // `workbench.colorTheme`
49+
prevThemeId: string; // `workbench.prevColorTheme`
4950
autoSave: Settings.AutoSave; // `files.autoSave`
5051
quickSuggestions: Record<'other' | 'comments' | 'strings', boolean>; // `editor.quickSuggestions`
5152

@@ -123,6 +124,7 @@ export class SettingsService {
123124
currentLanguage,
124125
editorFontSize,
125126
themeId,
127+
prevThemeId,
126128
autoSave,
127129
quickSuggestions,
128130
autoScaleInterface,
@@ -144,6 +146,7 @@ export class SettingsService {
144146
? 'arduino-theme-dark'
145147
: 'arduino-theme'
146148
),
149+
this.preferenceService.get<string>('workbench.prevColorTheme', ''),
147150
this.preferenceService.get<Settings.AutoSave>(
148151
AUTO_SAVE_SETTING,
149152
Settings.AutoSave.DEFAULT_ON
@@ -169,6 +172,7 @@ export class SettingsService {
169172
return {
170173
editorFontSize,
171174
themeId,
175+
prevThemeId,
172176
languages,
173177
currentLanguage,
174178
autoSave,
@@ -204,10 +208,14 @@ export class SettingsService {
204208
}
205209
}
206210

207-
async reset(): Promise<void> {
211+
async reset(resetFromDialog: boolean): Promise<void> {
212+
const prevThemeId = this._settings.prevThemeId;
208213
const settings = await this.loadSettings();
209214
await this.update(settings, false);
210215
this.onDidResetEmitter.fire(this._settings);
216+
if (resetFromDialog && prevThemeId) {
217+
ThemeService.get().setCurrentTheme(prevThemeId);
218+
}
211219
}
212220

213221
async validate(
@@ -259,6 +267,7 @@ export class SettingsService {
259267
currentLanguage,
260268
editorFontSize,
261269
themeId,
270+
prevThemeId,
262271
autoSave,
263272
quickSuggestions,
264273
autoScaleInterface,
@@ -283,6 +292,7 @@ export class SettingsService {
283292

284293
await this.savePreference('editor.fontSize', editorFontSize);
285294
await this.savePreference('workbench.colorTheme', themeId);
295+
await this.savePreference('workbench.prevColorTheme', prevThemeId);
286296
await this.savePreference(AUTO_SAVE_SETTING, autoSave);
287297
await this.savePreference('editor.quickSuggestions', quickSuggestions);
288298
await this.savePreference(AUTO_SCALE_SETTING, autoScaleInterface);

0 commit comments

Comments
 (0)