Commit 5740bd64 authored by Friedemann Kleint's avatar Friedemann Kleint

Made cpp file suffixes take effect after restart.

In CppTools, keep cpp file settings in plugin and settings page
via shared pointer and apply to mime DB in
extensionsInitialized() (after CppEditor has loaded
and registered the mime types).

Task-number: 252299
parent 794dbc74
......@@ -69,11 +69,11 @@ void CppFileSettings::fromSettings(QSettings *s)
s->endGroup();
}
void CppFileSettings::applySuffixesToMimeDB()
bool CppFileSettings::applySuffixesToMimeDB()
{
Core::MimeDatabase *mdb = Core::ICore::instance()->mimeDatabase();
mdb->setPreferredSuffix(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE), sourceSuffix);
mdb->setPreferredSuffix(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE), headerSuffix);
return mdb->setPreferredSuffix(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE), sourceSuffix)
&& mdb->setPreferredSuffix(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE), headerSuffix);
}
bool CppFileSettings::equals(const CppFileSettings &rhs) const
......@@ -129,11 +129,11 @@ void CppFileSettingsWidget::setSettings(const CppFileSettings &s)
}
// --------------- CppFileSettingsPage
CppFileSettingsPage::CppFileSettingsPage(QObject *parent) :
Core::IOptionsPage(parent)
CppFileSettingsPage::CppFileSettingsPage(QSharedPointer<CppFileSettings> &settings,
QObject *parent) :
Core::IOptionsPage(parent),
m_settings(settings)
{
m_settings.fromSettings(Core::ICore::instance()->settings());
m_settings.applySuffixesToMimeDB();
}
CppFileSettingsPage::~CppFileSettingsPage()
......@@ -164,7 +164,7 @@ QWidget *CppFileSettingsPage::createPage(QWidget *parent)
{
m_widget = new CppFileSettingsWidget(parent);
m_widget->setSettings(m_settings);
m_widget->setSettings(*m_settings);
return m_widget;
}
......@@ -172,10 +172,10 @@ void CppFileSettingsPage::apply()
{
if (m_widget) {
const CppFileSettings newSettings = m_widget->settings();
if (newSettings != m_settings) {
m_settings = newSettings;
m_settings.toSettings(Core::ICore::instance()->settings());
m_settings.applySuffixesToMimeDB();
if (newSettings != *m_settings) {
*m_settings = newSettings;
m_settings->toSettings(Core::ICore::instance()->settings());
m_settings->applySuffixesToMimeDB();
}
}
}
......
......@@ -32,6 +32,7 @@
#include <coreplugin/dialogs/ioptionspage.h>
#include <QtCore/QPointer>
#include <QtCore/QSharedPointer>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
......@@ -53,7 +54,7 @@ struct CppFileSettings {
void toSettings(QSettings *) const;
void fromSettings(QSettings *);
void applySuffixesToMimeDB();
bool applySuffixesToMimeDB();
bool equals(const CppFileSettings &rhs) const;
};
......@@ -76,8 +77,10 @@ private:
class CppFileSettingsPage : public Core::IOptionsPage
{
Q_DISABLE_COPY(CppFileSettingsPage)
public:
explicit CppFileSettingsPage(QObject *parent = 0);
explicit CppFileSettingsPage(QSharedPointer<CppFileSettings> &settings,
QObject *parent = 0);
virtual ~CppFileSettingsPage();
virtual QString id() const;
......@@ -90,8 +93,8 @@ public:
virtual void finish() { }
private:
const QSharedPointer<CppFileSettings> m_settings;
QPointer<CppFileSettingsWidget> m_widget;
CppFileSettings m_settings;
};
} // namespace Internal
......
......@@ -61,8 +61,10 @@ enum { debug = 0 };
CppToolsPlugin *CppToolsPlugin::m_instance = 0;
CppToolsPlugin::CppToolsPlugin()
: m_context(-1), m_modelManager(0)
CppToolsPlugin::CppToolsPlugin() :
m_context(-1),
m_modelManager(0),
m_fileSettings(new CppFileSettings)
{
m_instance = this;
}
......@@ -91,7 +93,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
addAutoReleasedObject(new CppClassesFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CompletionSettingsPage(m_completion));
addAutoReleasedObject(new CppFileSettingsPage);
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
// Menus
Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
......@@ -127,6 +129,11 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
void CppToolsPlugin::extensionsInitialized()
{
// The Cpp editor plugin, which is loaded later on, registers the Cpp mime types,
// so, apply settings here
m_fileSettings->fromSettings(Core::ICore::instance()->settings());
if (!m_fileSettings->applySuffixesToMimeDB())
qWarning("Unable to apply cpp suffixes to mime database (cpp mime types not found).\n");
}
void CppToolsPlugin::shutdown()
......
......@@ -32,6 +32,7 @@
#include <extensionsystem/iplugin.h>
#include <projectexplorer/projectexplorer.h>
#include <QtCore/QSharedPointer>
QT_BEGIN_NAMESPACE
class QFileInfo;
......@@ -43,11 +44,12 @@ namespace Internal {
class CppCodeCompletion;
class CppModelManager;
struct CppFileSettings;
class CppToolsPlugin : public ExtensionSystem::IPlugin
{
Q_DISABLE_COPY(CppToolsPlugin)
Q_OBJECT
public:
static CppToolsPlugin *instance() { return m_instance; }
......@@ -70,6 +72,7 @@ private:
int m_context;
CppModelManager *m_modelManager;
CppCodeCompletion *m_completion;
QSharedPointer<CppFileSettings> m_fileSettings;
static CppToolsPlugin *m_instance;
};
......
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