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

Added importing of customized color schemes from the ini file

So people's customized color schemes don't get lost, but get converted
to the new format instead.
parent 88facd84
......@@ -77,7 +77,6 @@ void FontSettings::clear()
}
void FontSettings::toSettings(const QString &category,
const FormatDescriptions &descriptions,
QSettings *s) const
{
s->beginGroup(category);
......@@ -111,8 +110,30 @@ bool FontSettings::fromSettings(const QString &category,
m_family = s->value(group + QLatin1String(fontFamilyKey), defaultFixedFontFamily()).toString();
m_fontSize = s->value(group + QLatin1String(fontSizeKey), m_fontSize).toInt();
m_antialias = s->value(group + QLatin1String(antialiasKey), DEFAULT_ANTIALIAS).toBool();
loadColorScheme(s->value(group + QLatin1String(schemeFileNameKey), defaultSchemeFileName()).toString(),
descriptions);
if (s->contains(group + QLatin1String(schemeFileNameKey))) {
// Load the selected color scheme
loadColorScheme(s->value(group + QLatin1String(schemeFileNameKey), defaultSchemeFileName()).toString(),
descriptions);
} else {
// Load color scheme from ini file
foreach (const FormatDescription &desc, descriptions) {
const QString name = desc.name();
const QString fmt = s->value(group + name, QString()).toString();
Format format;
if (fmt.isEmpty()) {
format.setForeground(desc.foreground());
format.setBackground(desc.background());
format.setBold(desc.format().bold());
format.setItalic(desc.format().italic());
} else {
format.fromString(fmt);
}
m_scheme.setFormatFor(name, format);
}
m_scheme.setName(QObject::tr("Customized"));
}
return true;
}
......@@ -256,10 +277,18 @@ bool FontSettings::loadColorScheme(const QString &fileName,
return loaded;
}
bool FontSettings::saveColorScheme(const QString &fileName)
{
const bool saved = m_scheme.save(fileName);
if (saved)
m_schemeFileName = fileName;
return saved;
}
/**
* Returns the currently active color scheme.
*/
ColorScheme FontSettings::colorScheme() const
const ColorScheme &FontSettings::colorScheme() const
{
return m_scheme;
}
......
......@@ -62,7 +62,6 @@ public:
inline bool isEmpty() const { return m_scheme.isEmpty(); }
void toSettings(const QString &category,
const FormatDescriptions &descriptions,
QSettings *s) const;
bool fromSettings(const QString &category,
......@@ -86,8 +85,9 @@ public:
QString colorSchemeFileName() const;
void setColorSchemeFileName(const QString &fileName);
bool loadColorScheme(const QString &fileName, const FormatDescriptions &descriptions);
bool saveColorScheme(const QString &fileName);
ColorScheme colorScheme() const;
const ColorScheme &colorScheme() const;
void setColorScheme(const ColorScheme &scheme);
bool equals(const FontSettings &f) const;
......
......@@ -90,6 +90,13 @@ Q_DECLARE_METATYPE(TextEditor::Internal::ColorSchemeEntry)
using namespace TextEditor;
using namespace TextEditor::Internal;
static QString customStylesPath()
{
QString path = QFileInfo(Core::ICore::instance()->settings()->fileName()).path();
path.append(QLatin1String("/qtcreator/styles/"));
return path;
}
// ------- FontSettingsPagePrivate
FontSettingsPagePrivate::FontSettingsPagePrivate(const TextEditor::FormatDescriptions &fd,
......@@ -103,22 +110,38 @@ FontSettingsPagePrivate::FontSettingsPagePrivate(const TextEditor::FormatDescrip
m_descriptions(fd)
{
bool settingsFound = false;
if (const QSettings *settings = Core::ICore::instance()->settings())
QSettings *settings = Core::ICore::instance()->settings();
if (settings)
settingsFound = m_value.fromSettings(m_settingsGroup, m_descriptions, settings);
if (!settingsFound) { // Apply defaults
foreach (const FormatDescription &f, m_descriptions) {
const QString name = f.name();
m_lastValue.formatFor(name).setForeground(f.foreground());
m_lastValue.formatFor(name).setBackground(f.background());
m_lastValue.formatFor(name).setBold(f.format().bold());
m_lastValue.formatFor(name).setItalic(f.format().italic());
m_value.formatFor(name).setForeground(f.foreground());
m_value.formatFor(name).setBackground(f.background());
m_value.formatFor(name).setBold(f.format().bold());
m_value.formatFor(name).setItalic(f.format().italic());
}
} else if (m_value.colorSchemeFileName().isEmpty()) {
// No color scheme was loaded, but one might be imported from the ini file
ColorScheme defaultScheme;
foreach (const FormatDescription &f, m_descriptions) {
const QString name = f.name();
defaultScheme.formatFor(name).setForeground(f.foreground());
defaultScheme.formatFor(name).setBackground(f.background());
defaultScheme.formatFor(name).setBold(f.format().bold());
defaultScheme.formatFor(name).setItalic(f.format().italic());
}
if (m_value.colorScheme() != defaultScheme) {
// Save it as a color scheme file
QString stylesPath = customStylesPath();
if (QFile::exists(stylesPath) || QDir().mkpath(stylesPath)) {
QString schemeFileName = stylesPath + QLatin1String("customized.xml");
if (m_value.saveColorScheme(schemeFileName) && settings)
m_value.toSettings(m_category, settings);
}
}
}
m_lastValue = m_value;
......@@ -436,13 +459,6 @@ void FontSettingsPage::refreshColorSchemeList()
d_ptr->ui.schemeListWidget->setCurrentIndex(s);
}
QString FontSettingsPage::customStylesPath()
{
QString path = QFileInfo(Core::ICore::instance()->settings()->fileName()).path();
path.append(QLatin1String("/qtcreator/styles/"));
return path;
}
void FontSettingsPage::delayedChange()
{
emit changed(d_ptr->m_value);
......@@ -471,7 +487,7 @@ void FontSettingsPage::saveSettings()
if (d_ptr->m_value != d_ptr->m_lastValue) {
d_ptr->m_lastValue = d_ptr->m_value;
if (QSettings *settings = Core::ICore::instance()->settings())
d_ptr->m_value.toSettings(d_ptr->m_settingsGroup, d_ptr->m_descriptions, settings);
d_ptr->m_value.toSettings(d_ptr->m_settingsGroup, settings);
QTimer::singleShot(0, this, SLOT(delayedChange()));
}
......
......@@ -119,7 +119,6 @@ private slots:
private:
void addColorSchemeEntry(const QString &fileName, bool readOnly);
void refreshColorSchemeList();
static QString customStylesPath();
Internal::FontSettingsPagePrivate *d_ptr;
};
......
......@@ -131,7 +131,7 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
#endif
connect(completionShortcut, SIGNAL(activated()), this, SLOT(invokeCompletion()));
// Add shortcut for invoking automatic completion
// Add shortcut for invoking quick fix options
QShortcut *quickFixShortcut = new QShortcut(core->mainWindow());
quickFixShortcut->setWhatsThis(tr("Triggers a quick fix in this scope"));
// Make sure the shortcut still works when the quick fix widget is active
......
Supports Markdown
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