forked from qt-creator/qt-creator
Core: Handle an invalid theme id from the settings
Don't crash if the settings contain an outdated/invalid "CreatorTheme" entry. This change makes ThemeEntry::themeSetting() validate the entry. If no theme with that id exists, it returs the default/first theme instead. Task-number: QTCREATORBUG-17517 Change-Id: I87658fade33ba4d956d3a4c5591dd86db4051426 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -221,8 +221,16 @@ QList<ThemeEntry> ThemeEntry::availableThemes()
|
||||
|
||||
Id ThemeEntry::themeSetting()
|
||||
{
|
||||
return Id::fromSetting(ICore::settings()->value(QLatin1String(Constants::SETTINGS_THEME),
|
||||
QLatin1String(Constants::DEFAULT_THEME)));
|
||||
const Id setting =
|
||||
Id::fromSetting(ICore::settings()->value(QLatin1String(Constants::SETTINGS_THEME),
|
||||
QLatin1String(Constants::DEFAULT_THEME)));
|
||||
|
||||
const QList<ThemeEntry> themes = availableThemes();
|
||||
if (themes.empty())
|
||||
return Id();
|
||||
const bool settingValid = Utils::contains(themes, Utils::equal(&ThemeEntry::id, setting));
|
||||
|
||||
return settingValid ? setting : themes.first().id();
|
||||
}
|
||||
|
||||
Theme *ThemeEntry::createTheme(Id id)
|
||||
|
||||
Reference in New Issue
Block a user