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 87a7ed94a3)
This commit is contained in:
Thorbjørn Lindeijer
2010-01-13 14:45:32 +01:00
committed by con
parent 1f3720a14d
commit 46dd1d0cb2
3 changed files with 21 additions and 9 deletions

View File

@@ -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();

View File

@@ -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

View File

@@ -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;