Commit 87a7ed94 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

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
parent 232db420
...@@ -145,8 +145,6 @@ bool ColorScheme::save(const QString &fileName) const ...@@ -145,8 +145,6 @@ bool ColorScheme::save(const QString &fileName) const
if (!m_name.isEmpty()) if (!m_name.isEmpty())
w.writeAttribute(QLatin1String("name"), m_name); w.writeAttribute(QLatin1String("name"), m_name);
Format textFormat = formatFor(QLatin1String(Constants::C_TEXT));
QMapIterator<QString, Format> i(m_formats); QMapIterator<QString, Format> i(m_formats);
while (i.hasNext()) { while (i.hasNext()) {
const Format &format = i.next().value(); const Format &format = i.next().value();
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtGui/QTextCharFormat> #include <QtGui/QTextCharFormat>
...@@ -114,8 +116,10 @@ bool FontSettings::fromSettings(const QString &category, ...@@ -114,8 +116,10 @@ bool FontSettings::fromSettings(const QString &category,
if (s->contains(group + QLatin1String(schemeFileNameKey))) { if (s->contains(group + QLatin1String(schemeFileNameKey))) {
// Load the selected color scheme // Load the selected color scheme
loadColorScheme(s->value(group + QLatin1String(schemeFileNameKey), defaultSchemeFileName()).toString(), QString scheme = s->value(group + QLatin1String(schemeFileNameKey)).toString();
descriptions); if (scheme.isEmpty() || !QFile::exists(scheme))
scheme = defaultSchemeFileName(QFileInfo(scheme).fileName());
loadColorScheme(scheme, descriptions);
} else { } else {
// Load color scheme from ini file // Load color scheme from ini file
foreach (const FormatDescription &desc, descriptions) { foreach (const FormatDescription &desc, descriptions) {
...@@ -316,11 +320,21 @@ int FontSettings::defaultFontSize() ...@@ -316,11 +320,21 @@ int FontSettings::defaultFontSize()
return DEFAULT_FONT_SIZE; 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(); QString defaultScheme = Core::ICore::instance()->resourcePath();
fileName += QLatin1String("/styles/default.xml"); defaultScheme += QLatin1String("/styles/");
return fileName;
if (!fileName.isEmpty() && QFile::exists(defaultScheme + fileName))
defaultScheme += fileName;
else
defaultScheme += QLatin1String("default.xml");
return defaultScheme;
} }
} // namespace TextEditor } // namespace TextEditor
...@@ -100,7 +100,7 @@ public: ...@@ -100,7 +100,7 @@ public:
static int defaultFontSize(); static int defaultFontSize();
private: private:
static QString defaultSchemeFileName(); static QString defaultSchemeFileName(const QString &fileName = QString());
QString m_family; QString m_family;
QString m_schemeFileName; QString m_schemeFileName;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment