diff options
author | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2010-01-13 14:45:32 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2010-01-13 17:17:12 +0100 |
commit | 87a7ed94a3e5d57c02cfc68a8be87a76109bdb0b (patch) | |
tree | fc1fd58c78271ef29a619da1aba3485a2658a047 | |
parent | 232db42069cc6da3c8e89d0a37c155ee43888a27 (diff) |
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
-rw-r--r-- | src/plugins/texteditor/colorscheme.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettings.cpp | 26 | ||||
-rw-r--r-- | 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 87ab6efe0c..545702efcc 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<QString, Format> 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 8631645a48..f771834471 100644 --- a/src/plugins/texteditor/fontsettings.cpp +++ b/src/plugins/texteditor/fontsettings.cpp @@ -33,6 +33,8 @@ #include <utils/qtcassert.h> #include <coreplugin/icore.h> +#include <QtCore/QFile> +#include <QtCore/QFileInfo> #include <QtCore/QSettings> #include <QtCore/QCoreApplication> #include <QtGui/QTextCharFormat> @@ -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 38ffa2d66e..71035b8731 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; |