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.
This commit is contained in:
Thorbjørn Lindeijer
2009-07-15 12:27:02 +02:00
parent 88facd8497
commit c1198e5ab9
5 changed files with 66 additions and 22 deletions

View File

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