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

Unduplicated the code that initializes editor settings

This stuff was all over the place, a relic from before the editor
settings were unified. Now the initialization is only done in
TextEditorSettings.

Fixes the .pro file editor and the generic project files editor, which
before only used the font settings.
parent a952a9bf
......@@ -47,6 +47,7 @@
#include <texteditor/fontsettings.h>
#include <texteditor/storagesettings.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorplugin.h>
#include <texteditor/texteditorsettings.h>
#include <cpptools/cpptoolsconstants.h>
......@@ -128,25 +129,9 @@ CppPlugin *CppPlugin::instance()
void CppPlugin::initializeEditor(CPPEditor *editor)
{
// common actions
m_actionHandler->setupActions(editor);
// settings
TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance();
connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
editor, SLOT(setFontSettings(TextEditor::FontSettings)));
connect(settings, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
editor, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(settings, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
editor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
connect(settings, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings)));
// tab settings rely on font settings
editor->setFontSettings(settings->fontSettings());
editor->setTabSettings(settings->tabSettings());
editor->setStorageSettings(settings->storageSettings());
editor->setDisplaySettings(settings->displaySettings());
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
// auto completion
connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)),
......
......@@ -39,7 +39,7 @@ Manager *ProjectFilesFactory::manager() const
Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent)
{
ProjectFilesEditor *ed = new ProjectFilesEditor(parent, this, _actionHandler);
ed->initialize();
TextEditor::TextEditorSettings::instance()->initializeEditor(ed);
return ed->editableInterface();
}
......@@ -98,7 +98,7 @@ Core::IEditor *ProjectFilesEditable::duplicate(QWidget *parent)
ProjectFilesEditor *editor = new ProjectFilesEditor(parent,
parentEditor->factory(),
parentEditor->actionHandler());
editor->initialize();
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
return editor->editableInterface();
}
......@@ -122,16 +122,6 @@ ProjectFilesEditor::ProjectFilesEditor(QWidget *parent, ProjectFilesFactory *fac
ProjectFilesEditor::~ProjectFilesEditor()
{ }
void ProjectFilesEditor::initialize()
{
TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance();
connect(settings, SIGNAL(fontSettingsChanged(const TextEditor::FontSettings&)),
this, SLOT(setFontSettings(const TextEditor::FontSettings&)));
setFontSettings(settings->fontSettings());
}
ProjectFilesFactory *ProjectFilesEditor::factory() const
{
return _factory;
......
......@@ -64,8 +64,6 @@ public:
TextEditor::TextEditorActionHandler *handler);
virtual ~ProjectFilesEditor();
void initialize();
ProjectFilesFactory *factory() const;
TextEditor::TextEditorActionHandler *actionHandler() const;
......
......@@ -68,7 +68,7 @@ Core::IEditor *ProFileEditorEditable::duplicate(QWidget *parent)
ProFileEditor *ret = new ProFileEditor(parent, qobject_cast<ProFileEditor*>(editor())->factory(),
qobject_cast<ProFileEditor*>(editor())->actionHandler());
ret->duplicateFrom(editor());
ret->initialize();
TextEditor::TextEditorSettings::instance()->initializeEditor(ret);
return ret->editableInterface();
}
......@@ -103,16 +103,6 @@ TextEditor::BaseTextEditorEditable *ProFileEditor::createEditableInterface()
return new ProFileEditorEditable(this);
}
void ProFileEditor::initialize()
{
TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance();
connect(settings, SIGNAL(fontSettingsChanged(const TextEditor::FontSettings&)),
this, SLOT(setFontSettings(const TextEditor::FontSettings&)));
setFontSettings(settings->fontSettings());
}
void ProFileEditor::setFontSettings(const TextEditor::FontSettings &fs)
{
TextEditor::BaseTextEditor::setFontSettings(fs);
......
......@@ -74,7 +74,6 @@ public:
ProFileEditor(QWidget *parent, ProFileEditorFactory *factory,
TextEditor::TextEditorActionHandler *ah);
~ProFileEditor();
void initialize();
bool save(const QString &fileName = QString());
......
......@@ -36,6 +36,7 @@
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorsettings.h>
#include <QtCore/QFileInfo>
#include <QtGui/QAction>
......@@ -76,7 +77,7 @@ Core::IFile *ProFileEditorFactory::open(const QString &fileName)
Core::IEditor *ProFileEditorFactory::createEditor(QWidget *parent)
{
ProFileEditor *rc = new ProFileEditor(parent, this, m_actionHandler);
rc->initialize();
TextEditor::TextEditorSettings::instance()->initializeEditor(rc);
return rc->editableInterface();
}
......
......@@ -109,21 +109,7 @@ void QtScriptEditorPlugin::initializeEditor(QtScriptEditor::Internal::ScriptEdit
{
QTC_ASSERT(m_instance, /**/);
TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance();
connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
editor, SLOT(setFontSettings(TextEditor::FontSettings)));
connect(settings, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
editor, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(settings, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
editor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
connect(settings, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings)));
// tab settings rely on font settings
editor->setFontSettings(settings->fontSettings());
editor->setTabSettings(settings->tabSettings());
editor->setStorageSettings(settings->storageSettings());
editor->setDisplaySettings(settings->displaySettings());
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
}
void QtScriptEditorPlugin::registerActions()
......
......@@ -88,7 +88,7 @@ TextEditorActionHandler::TextEditorActionHandler(const QString &context,
m_contextId << Core::UniqueIDManager::instance()->uniqueIdentifier(context);
connect(Core::ICore::instance()->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentEditor(Core::IEditor *)));
this, SLOT(updateCurrentEditor(Core::IEditor*)));
}
void TextEditorActionHandler::setupActions(BaseTextEditor *editor)
......
......@@ -140,26 +140,12 @@ void TextEditorPlugin::extensionsInitialized()
m_editorFactory->actionHandler()->initializeActions();
}
void TextEditorPlugin::initializeEditor(TextEditor::PlainTextEditor *editor)
void TextEditorPlugin::initializeEditor(PlainTextEditor *editor)
{
// common actions
m_editorFactory->actionHandler()->setupActions(editor);
// settings
connect(m_settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
editor, SLOT(setFontSettings(TextEditor::FontSettings)));
connect(m_settings, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
editor, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(m_settings, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
editor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
connect(m_settings, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings)));
// tab settings rely on font settings
editor->setFontSettings(m_settings->fontSettings());
editor->setTabSettings(m_settings->tabSettings());
editor->setStorageSettings(m_settings->storageSettings());
editor->setDisplaySettings(m_settings->displaySettings());
TextEditorSettings::instance()->initializeEditor(editor);
}
void TextEditorPlugin::invokeCompletion()
......
......@@ -29,6 +29,7 @@
#include "texteditorsettings.h"
#include "basetexteditor.h"
#include "behaviorsettingspage.h"
#include "displaysettings.h"
#include "displaysettingspage.h"
......@@ -138,6 +139,29 @@ TextEditorSettings *TextEditorSettings::instance()
return m_instance;
}
/**
* Initializes editor settings. Also connects signals to keep them up to date
* when they are changed.
*/
void TextEditorSettings::initializeEditor(BaseTextEditor *editor)
{
// Connect to settings change signals
connect(this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
editor, SLOT(setFontSettings(TextEditor::FontSettings)));
connect(this, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
editor, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
editor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
connect(this, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings)));
// Apply current settings (tab settings depend on font settings)
editor->setFontSettings(fontSettings());
editor->setTabSettings(tabSettings());
editor->setStorageSettings(storageSettings());
editor->setDisplaySettings(displaySettings());
}
FontSettings TextEditorSettings::fontSettings() const
{
return m_fontSettingsPage->fontSettings();
......
......@@ -36,6 +36,7 @@
namespace TextEditor {
class BaseTextEditor;
class BehaviorSettingsPage;
class DisplaySettingsPage;
class FontSettingsPage;
......@@ -59,6 +60,8 @@ public:
static TextEditorSettings *instance();
void initializeEditor(BaseTextEditor *editor);
FontSettings fontSettings() const;
TabSettings tabSettings() const;
StorageSettings storageSettings() 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