Commit c410d268 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Move EditorSettings over to new save/restore scheme

Reviewed-by: dt
parent 533a85a6
......@@ -33,6 +33,10 @@
using namespace ProjectExplorer;
namespace {
const char * const CODEC("EditorConfiguration.Codec");
}
EditorConfiguration::EditorConfiguration()
: m_defaultTextCodec(QTextCodec::codecForLocale())
{
......@@ -45,6 +49,23 @@ QTextCodec *EditorConfiguration::defaultTextCodec() const
void EditorConfiguration::setDefaultTextCodec(QTextCodec *codec)
{
if (!codec)
return;
m_defaultTextCodec = codec;
}
QVariantMap EditorConfiguration::toMap() const
{
QVariantMap map;
map.insert(QLatin1String(CODEC), m_defaultTextCodec->name());
return map;
}
bool EditorConfiguration::fromMap(const QVariantMap &map)
{
QTextCodec *codec = QTextCodec::codecForName(map.value(QLatin1String(CODEC)).toString().toLocal8Bit());
if (!codec)
return false;
m_defaultTextCodec = codec;
return true;
}
......@@ -32,7 +32,7 @@
#include "projectexplorer_export.h"
#include <QtCore/qglobal.h>
#include <QtCore/QVariantMap>
QT_BEGIN_NAMESPACE
class QTextCodec;
......@@ -44,9 +44,13 @@ class PROJECTEXPLORER_EXPORT EditorConfiguration
{
public:
EditorConfiguration();
QTextCodec *defaultTextCodec() const;
void setDefaultTextCodec(QTextCodec *codec);
QVariantMap toMap() const;
bool fromMap(const QVariantMap &map);
private:
QTextCodec *m_defaultTextCodec;
};
......
......@@ -50,6 +50,7 @@ using namespace ProjectExplorer::Internal;
namespace {
const char * const PROJECT_FILE_POSTFIX(".user");
const char * const EDITOR_SETTINGS_KEY("ProjectExplorer.Project.EditorSettings");
} // namespace
// -------------------------------------------------------------------------
......@@ -211,7 +212,7 @@ void Project::saveSettingsImpl(PersistentSettingsWriter &writer)
writer.setPrefix(QString::null);
writer.saveValue("activeRunConfiguration", activeId);
writer.saveValue("defaultFileEncoding", m_editorConfiguration->defaultTextCodec()->name());
writer.saveValue(QLatin1String(EDITOR_SETTINGS_KEY), m_editorConfiguration->toMap());
}
bool Project::restoreSettingsImpl(PersistentSettingsReader &reader)
......@@ -386,13 +387,11 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader)
}
reader.setPrefix(QString::null);
QTextCodec *codec = QTextCodec::codecForName(reader.restoreValue("defaultFileEncoding").toByteArray());
if (codec)
m_editorConfiguration->setDefaultTextCodec(codec);
if (!m_activeRunConfiguration && !m_runConfigurations.isEmpty())
setActiveRunConfiguration(m_runConfigurations.at(0));
return true;
QVariantMap tmp = reader.restoreValue(QLatin1String(EDITOR_SETTINGS_KEY)).toMap();
return m_editorConfiguration->fromMap(tmp);
}
BuildConfiguration *Project::activeBuildConfiguration() const
......
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