From 46dd1d0cb2c879056eb1e9590a569b21d3bc9b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Wed, 13 Jan 2010 14:45:32 +0100 Subject: [PATCH] Fixed an issue with keeping a shipped color scheme selected When the path to the shipped color schemes changes, Qt Creator was unable to load the chosen color scheme. Now, when it can't find the color scheme, it will look for it in the default color scheme path. Reviewed-by: con (cherry picked from commit 87a7ed94a3e5d57c02cfc68a8be87a76109bdb0b) --- src/plugins/texteditor/colorscheme.cpp | 2 -- src/plugins/texteditor/fontsettings.cpp | 26 +++++++++++++++++++------ src/plugins/texteditor/fontsettings.h | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/plugins/texteditor/colorscheme.cpp b/src/plugins/texteditor/colorscheme.cpp index 87ab6efe0cb..545702efcc7 100644 --- a/src/plugins/texteditor/colorscheme.cpp +++ b/src/plugins/texteditor/colorscheme.cpp @@ -145,8 +145,6 @@ bool ColorScheme::save(const QString &fileName) const if (!m_name.isEmpty()) w.writeAttribute(QLatin1String("name"), m_name); - Format textFormat = formatFor(QLatin1String(Constants::C_TEXT)); - QMapIterator i(m_formats); while (i.hasNext()) { const Format &format = i.next().value(); diff --git a/src/plugins/texteditor/fontsettings.cpp b/src/plugins/texteditor/fontsettings.cpp index 8631645a485..f7718344713 100644 --- a/src/plugins/texteditor/fontsettings.cpp +++ b/src/plugins/texteditor/fontsettings.cpp @@ -33,6 +33,8 @@ #include #include +#include +#include #include #include #include @@ -114,8 +116,10 @@ bool FontSettings::fromSettings(const QString &category, if (s->contains(group + QLatin1String(schemeFileNameKey))) { // Load the selected color scheme - loadColorScheme(s->value(group + QLatin1String(schemeFileNameKey), defaultSchemeFileName()).toString(), - descriptions); + QString scheme = s->value(group + QLatin1String(schemeFileNameKey)).toString(); + if (scheme.isEmpty() || !QFile::exists(scheme)) + scheme = defaultSchemeFileName(QFileInfo(scheme).fileName()); + loadColorScheme(scheme, descriptions); } else { // Load color scheme from ini file foreach (const FormatDescription &desc, descriptions) { @@ -316,11 +320,21 @@ int FontSettings::defaultFontSize() return DEFAULT_FONT_SIZE; } -QString FontSettings::defaultSchemeFileName() +/** + * Returns the default scheme file name, or the path to a shipped scheme when + * one exists with the given \a fileName. + */ +QString FontSettings::defaultSchemeFileName(const QString &fileName) { - QString fileName = Core::ICore::instance()->resourcePath(); - fileName += QLatin1String("/styles/default.xml"); - return fileName; + QString defaultScheme = Core::ICore::instance()->resourcePath(); + defaultScheme += QLatin1String("/styles/"); + + if (!fileName.isEmpty() && QFile::exists(defaultScheme + fileName)) + defaultScheme += fileName; + else + defaultScheme += QLatin1String("default.xml"); + + return defaultScheme; } } // namespace TextEditor diff --git a/src/plugins/texteditor/fontsettings.h b/src/plugins/texteditor/fontsettings.h index 38ffa2d66e2..71035b87315 100644 --- a/src/plugins/texteditor/fontsettings.h +++ b/src/plugins/texteditor/fontsettings.h @@ -100,7 +100,7 @@ public: static int defaultFontSize(); private: - static QString defaultSchemeFileName(); + static QString defaultSchemeFileName(const QString &fileName = QString()); QString m_family; QString m_schemeFileName;