Commit 3d1b70c5 authored by Eike Ziller's avatar Eike Ziller

Remove the need to register editors in the action handler

The action handler already knows which editors to handle through the
context. It only needs to receive signals for updating the actions from
the current editor. So there is no need to tell the action handler about
every individual editor. This also removes some noise from the text
editor implementations.

Change-Id: I76dc5b1559cc8cf54ff313e6cdba4e789a3108aa
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 3ee9fb4d
......@@ -51,7 +51,7 @@ AndroidManifestEditorFactory::AndroidManifestEditorFactory(QObject *parent)
Core::IEditor *AndroidManifestEditorFactory::createEditor(QWidget *parent)
{
AndroidManifestEditorWidget *editor = new AndroidManifestEditorWidget(parent, m_actionHandler);
AndroidManifestEditorWidget *editor = new AndroidManifestEditorWidget(parent);
TextEditor::TextEditorSettings::initializeEditor(editor);
return editor->editor();
}
......@@ -95,7 +95,7 @@ Project *androidProject(const QString &file)
} // anonymous namespace
AndroidManifestEditorWidget::AndroidManifestEditorWidget(QWidget *parent, TextEditor::TextEditorActionHandler *ah)
AndroidManifestEditorWidget::AndroidManifestEditorWidget(QWidget *parent)
: TextEditor::PlainTextEditorWidget(parent),
m_dirty(false),
m_stayClean(false),
......@@ -106,7 +106,6 @@ AndroidManifestEditorWidget::AndroidManifestEditorWidget(QWidget *parent, TextEd
doc->setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
setBaseTextDocument(doc);
ah->setupActions(this);
configure(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
initializePage();
......
......@@ -51,8 +51,6 @@ QT_END_NAMESPACE
namespace Core { class IEditor; }
namespace TextEditor { class TextEditorActionHandler; }
namespace Android {
namespace Internal {
class AndroidManifestEditor;
......@@ -86,7 +84,7 @@ public:
Source
};
explicit AndroidManifestEditorWidget(QWidget *parent, TextEditor::TextEditorActionHandler *ah);
explicit AndroidManifestEditorWidget(QWidget *parent);
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
......
......@@ -68,7 +68,7 @@ CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
Core::IEditor *CMakeEditor::duplicate(QWidget *parent)
{
CMakeEditorWidget *w = qobject_cast<CMakeEditorWidget*>(widget());
CMakeEditorWidget *ret = new CMakeEditorWidget(parent, w->factory(), w->actionHandler());
CMakeEditorWidget *ret = new CMakeEditorWidget(parent, w->factory());
ret->duplicateFrom(w);
TextEditor::TextEditorSettings::initializeEditor(ret);
return ret->editor();
......@@ -116,8 +116,8 @@ void CMakeEditor::build()
// CMakeEditor
//
CMakeEditorWidget::CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factory, TextEditor::TextEditorActionHandler *ah)
: BaseTextEditorWidget(parent), m_factory(factory), m_ah(ah)
CMakeEditorWidget::CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factory)
: BaseTextEditorWidget(parent), m_factory(factory)
{
QSharedPointer<CMakeDocument> doc(new CMakeDocument);
doc->setMimeType(QLatin1String(CMakeProjectManager::Constants::CMAKEMIMETYPE));
......@@ -127,8 +127,6 @@ CMakeEditorWidget::CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factor
m_commentDefinition.clearCommentStyles();
m_commentDefinition.singleLine = QLatin1Char('#');
ah->setupActions(this);
}
TextEditor::BaseTextEditor *CMakeEditorWidget::createEditor()
......
......@@ -71,12 +71,11 @@ class CMakeEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factory, TextEditor::TextEditorActionHandler *ah);
CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factory);
bool save(const QString &fileName = QString());
CMakeEditorFactory *factory() { return m_factory; }
TextEditor::TextEditorActionHandler *actionHandler() const { return m_ah; }
Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true, bool inNextSplit = false);
......@@ -89,7 +88,6 @@ public slots:
private:
CMakeEditorFactory *m_factory;
TextEditor::TextEditorActionHandler *m_ah;
Utils::CommentDefinition m_commentDefinition;
};
......
......@@ -72,7 +72,7 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager)
Core::IEditor *CMakeEditorFactory::createEditor(QWidget *parent)
{
CMakeEditorWidget *rc = new CMakeEditorWidget(parent, this, m_actionHandler);
CMakeEditorWidget *rc = new CMakeEditorWidget(parent, this);
TextEditor::TextEditorSettings::initializeEditor(rc);
return rc->editor();
}
......@@ -125,8 +125,6 @@ CppEditorPlugin *CppEditorPlugin::instance()
void CppEditorPlugin::initializeEditor(CPPEditorWidget *editor)
{
m_actionHandler->setupActions(editor);
editor->setLanguageSettingsId(CppTools::Constants::CPP_SETTINGS_ID);
TextEditor::TextEditorSettings::initializeEditor(editor);
......@@ -298,8 +296,6 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
| TextEditor::TextEditorActionHandler::UnCollapseAll
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
m_actionHandler->initializeActions();
contextMenu->addSeparator(context);
cmd = ActionManager::command(TextEditor::Constants::AUTO_INDENT_SELECTION);
......
......@@ -50,9 +50,8 @@ namespace Internal {
//
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesFactory::ProjectFilesFactory(Manager *manager, TextEditorActionHandler *handler)
: Core::IEditorFactory(manager),
m_actionHandler(handler)
ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
: Core::IEditorFactory(manager)
{
setId(Constants::FILES_EDITOR_ID);
setDisplayName(QCoreApplication::translate("OpenWith::Editors", ".files Editor"));
......@@ -63,7 +62,7 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager, TextEditorActionHandl
Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent)
{
ProjectFilesEditorWidget *ed = new ProjectFilesEditorWidget(parent, this, m_actionHandler);
ProjectFilesEditorWidget *ed = new ProjectFilesEditorWidget(parent, this);
TextEditorSettings::initializeEditor(ed);
return ed->editor();
}
......@@ -94,8 +93,7 @@ Core::IEditor *ProjectFilesEditor::duplicate(QWidget *parent)
{
ProjectFilesEditorWidget *parentEditor = qobject_cast<ProjectFilesEditorWidget *>(editorWidget());
ProjectFilesEditorWidget *editor = new ProjectFilesEditorWidget(parent,
parentEditor->factory(),
parentEditor->actionHandler());
parentEditor->factory());
TextEditorSettings::initializeEditor(editor);
return editor->editor();
}
......@@ -106,16 +104,12 @@ Core::IEditor *ProjectFilesEditor::duplicate(QWidget *parent)
//
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent, ProjectFilesFactory *factory,
TextEditorActionHandler *handler)
ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent, ProjectFilesFactory *factory)
: BaseTextEditorWidget(parent),
m_factory(factory),
m_actionHandler(handler)
m_factory(factory)
{
QSharedPointer<BaseTextDocument> doc(new BaseTextDocument());
setBaseTextDocument(doc);
handler->setupActions(this);
}
ProjectFilesFactory *ProjectFilesEditorWidget::factory() const
......@@ -123,11 +117,6 @@ ProjectFilesFactory *ProjectFilesEditorWidget::factory() const
return m_factory;
}
TextEditorActionHandler *ProjectFilesEditorWidget::actionHandler() const
{
return m_actionHandler;
}
BaseTextEditor *ProjectFilesEditorWidget::createEditor()
{
return new ProjectFilesEditor(this);
......
......@@ -35,10 +35,6 @@
#include <coreplugin/editormanager/ieditorfactory.h>
namespace TextEditor {
class TextEditorActionHandler;
}
namespace GenericProjectManager {
namespace Internal {
......@@ -52,12 +48,9 @@ class ProjectFilesFactory: public Core::IEditorFactory
Q_OBJECT
public:
ProjectFilesFactory(Manager *manager, TextEditor::TextEditorActionHandler *handler);
ProjectFilesFactory(Manager *manager);
Core::IEditor *createEditor(QWidget *parent);
private:
TextEditor::TextEditorActionHandler *m_actionHandler;
};
class ProjectFilesEditor : public TextEditor::BaseTextEditor
......@@ -77,16 +70,13 @@ class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
ProjectFilesEditorWidget(QWidget *parent, ProjectFilesFactory *factory,
TextEditor::TextEditorActionHandler *handler);
ProjectFilesEditorWidget(QWidget *parent, ProjectFilesFactory *factory);
ProjectFilesFactory *factory() const;
TextEditor::TextEditorActionHandler *actionHandler() const;
TextEditor::BaseTextEditor *createEditor();
private:
ProjectFilesFactory *m_factory;
TextEditor::TextEditorActionHandler *m_actionHandler;
};
} // namespace Internal
......
......@@ -75,10 +75,9 @@ bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage
Manager *manager = new Manager;
TextEditor::TextEditorActionHandler *actionHandler =
new TextEditor::TextEditorActionHandler(Constants::C_FILESEDITOR);
new TextEditor::TextEditorActionHandler(Constants::C_FILESEDITOR); // owned by ICore
m_projectFilesEditorFactory = new ProjectFilesFactory(manager, actionHandler);
m_projectFilesEditorFactory = new ProjectFilesFactory(manager);
addObject(m_projectFilesEditorFactory);
addAutoReleasedObject(manager);
......
......@@ -191,7 +191,7 @@ Core::IEditor *GLSLEditorEditable::duplicate(QWidget *parent)
{
GLSLTextEditorWidget *newEditor = new GLSLTextEditorWidget(parent);
newEditor->duplicateFrom(editorWidget());
GLSLEditorPlugin::initializeEditor(newEditor);
TextEditor::TextEditorSettings::initializeEditor(newEditor);
return newEditor->editor();
}
......
......@@ -37,6 +37,7 @@
#include <extensionsystem/pluginspec.h>
#include <coreplugin/icore.h>
#include <texteditor/texteditorsettings.h>
#include <QCoreApplication>
#include <QSettings>
......@@ -59,7 +60,7 @@ GLSLEditorFactory::GLSLEditorFactory(QObject *parent)
Core::IEditor *GLSLEditorFactory::createEditor(QWidget *parent)
{
GLSLTextEditorWidget *rc = new GLSLTextEditorWidget(parent);
GLSLEditorPlugin::initializeEditor(rc);
TextEditor::TextEditorSettings::initializeEditor(rc);
return rc->editor();
}
......
......@@ -48,7 +48,6 @@
#include <projectexplorer/taskhub.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/textfilewizard.h>
#include <texteditor/texteditoractionhandler.h>
#include <utils/qtcassert.h>
......@@ -149,7 +148,6 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll);
dd->m_actionHandler->initializeActions();
ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT);
ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL));
......@@ -245,13 +243,6 @@ ExtensionSystem::IPlugin::ShutdownFlag GLSLEditorPlugin::aboutToShutdown()
return IPlugin::aboutToShutdown();
}
void GLSLEditorPlugin::initializeEditor(GLSLTextEditorWidget *editor)
{
QTC_CHECK(m_instance);
dd->m_actionHandler->setupActions(editor);
TextEditorSettings::initializeEditor(editor);
}
static QByteArray glslFile(const QString &fileName)
{
QFile file(ICore::resourcePath() + QLatin1String("/glsl/") + fileName);
......
......@@ -52,8 +52,6 @@ public:
void extensionsInitialized();
ShutdownFlag aboutToShutdown();
static void initializeEditor(GLSLTextEditorWidget *editor);
struct InitFile
{
InitFile(GLSL::Engine *engine = 0, GLSL::TranslationUnitAST *ast = 0)
......
......@@ -62,7 +62,7 @@ Core::IEditor *PythonEditor::duplicate(QWidget *parent)
{
EditorWidget *widget = new EditorWidget(parent);
widget->duplicateFrom(editorWidget());
PythonEditorPlugin::initializeEditor(widget);
TextEditor::TextEditorSettings::initializeEditor(widget);
return widget->editor();
}
......
......@@ -52,7 +52,7 @@ EditorFactory::EditorFactory(QObject *parent)
Core::IEditor *EditorFactory::createEditor(QWidget *parent)
{
EditorWidget *widget = new EditorWidget(parent);
PythonEditorPlugin::initializeEditor(widget);
TextEditor::TextEditorSettings::initializeEditor(widget);
return widget->editor();
}
......
......@@ -43,7 +43,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <QtPlugin>
#include <QCoreApplication>
......@@ -223,12 +222,11 @@ bool PythonEditorPlugin::initialize(const QStringList &arguments, QString *error
addObject(m_factory);
// Initialize editor actions handler
m_actionHandler.reset(new TextEditor::TextEditorActionHandler(
m_actionHandler = new TextEditor::TextEditorActionHandler(
C_PYTHONEDITOR_ID,
TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll));
m_actionHandler->initializeActions();
| TextEditor::TextEditorActionHandler::UnCollapseAll);
// Add MIME overlay icons (these icons displayed at Project dock panel)
const QIcon icon = QIcon::fromTheme(QLatin1String(C_PY_MIME_ICON));
......@@ -247,12 +245,6 @@ void PythonEditorPlugin::extensionsInitialized()
{
}
void PythonEditorPlugin::initializeEditor(EditorWidget *widget)
{
instance()->m_actionHandler->setupActions(widget);
TextEditor::TextEditorSettings::initializeEditor(widget);
}
QSet<QString> PythonEditorPlugin::keywords()
{
return instance()->m_keywords;
......
......@@ -57,7 +57,6 @@ public:
virtual bool initialize(const QStringList &arguments, QString *errorMessage);
virtual void extensionsInitialized();
static PythonEditorPlugin *instance() { return m_instance; }
static void initializeEditor(EditorWidget *widget);
static QSet<QString> keywords();
static QSet<QString> magics();
......@@ -66,7 +65,7 @@ public:
private:
static PythonEditorPlugin *m_instance;
EditorFactory *m_factory;
QScopedPointer<TextEditor::TextEditorActionHandler> m_actionHandler;
TextEditor::TextEditorActionHandler *m_actionHandler;
QSet<QString> m_keywords;
QSet<QString> m_magics;
QSet<QString> m_builtins;
......
......@@ -61,8 +61,7 @@ ProFileEditor::ProFileEditor(ProFileEditorWidget *editor)
Core::IEditor *ProFileEditor::duplicate(QWidget *parent)
{
ProFileEditorWidget *ret = new ProFileEditorWidget(parent, qobject_cast<ProFileEditorWidget*>(editorWidget())->factory(),
qobject_cast<ProFileEditorWidget*>(editorWidget())->actionHandler());
ProFileEditorWidget *ret = new ProFileEditorWidget(parent, qobject_cast<ProFileEditorWidget*>(editorWidget())->factory());
ret->duplicateFrom(editorWidget());
TextEditor::TextEditorSettings::initializeEditor(ret);
return ret->editor();
......@@ -82,15 +81,13 @@ TextEditor::CompletionAssistProvider *ProFileEditor::completionAssistProvider()
// ProFileEditorWidget
//
ProFileEditorWidget::ProFileEditorWidget(QWidget *parent, ProFileEditorFactory *factory, TextEditor::TextEditorActionHandler *ah)
: BaseTextEditorWidget(parent), m_factory(factory), m_ah(ah)
ProFileEditorWidget::ProFileEditorWidget(QWidget *parent, ProFileEditorFactory *factory)
: BaseTextEditorWidget(parent), m_factory(factory)
{
QSharedPointer<ProFileDocument> doc(new ProFileDocument());
doc->setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE));
setBaseTextDocument(doc);
ah->setupActions(this);
baseTextDocument()->setSyntaxHighlighter(new ProFileHighlighter);
m_commentDefinition.clearCommentStyles();
m_commentDefinition.singleLine = QLatin1Char('#');
......
......@@ -34,11 +34,6 @@
#include <texteditor/basetexteditor.h>
#include <utils/uncommentselection.h>
namespace TextEditor {
class FontSettings;
class TextEditorActionHandler;
}
namespace QmakeProjectManager {
namespace Internal {
......@@ -63,11 +58,9 @@ class ProFileEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
ProFileEditorWidget(QWidget *parent, ProFileEditorFactory *factory,
TextEditor::TextEditorActionHandler *ah);
ProFileEditorWidget(QWidget *parent, ProFileEditorFactory *factory);
ProFileEditorFactory *factory() { return m_factory; }
TextEditor::TextEditorActionHandler *actionHandler() const { return m_ah; }
void unCommentSelection();
......@@ -79,7 +72,6 @@ protected:
private:
ProFileEditorFactory *m_factory;
TextEditor::TextEditorActionHandler *m_ah;
Utils::CommentDefinition m_commentDefinition;
};
......
......@@ -59,7 +59,7 @@ ProFileEditorFactory::ProFileEditorFactory(QmakeManager *manager, TextEditor::Te
Core::IEditor *ProFileEditorFactory::createEditor(QWidget *parent)
{
ProFileEditorWidget *editor = new ProFileEditorWidget(parent, this, m_actionHandler);
ProFileEditorWidget *editor = new ProFileEditorWidget(parent, this);
TextEditor::TextEditorSettings::initializeEditor(editor);
return editor->editor();
}
......@@ -170,7 +170,6 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
m_actionHandler->initializeActions();
Core::ActionContainer *contextMenu = Core::ActionManager::createMenu(Constants::M_CONTEXT);
Core::ActionContainer *qmlToolsMenu = Core::ActionManager::actionContainer(Core::Id(QmlJSTools::Constants::M_TOOLS_QMLJS));
......@@ -266,8 +265,6 @@ void QmlJSEditorPlugin::initializeEditor(QmlJSTextEditorWidget *editor)
{
QTC_CHECK(m_instance);
m_actionHandler->setupActions(editor);
editor->setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
TextEditor::TextEditorSettings::initializeEditor(editor);
}
......
......@@ -72,6 +72,6 @@ BarDescriptorEditorFactory::~BarDescriptorEditorFactory()
Core::IEditor *BarDescriptorEditorFactory::createEditor(QWidget *parent)
{
BarDescriptorEditorWidget *editorWidget = new BarDescriptorEditorWidget(parent, m_actionHandler);
BarDescriptorEditorWidget *editorWidget = new BarDescriptorEditorWidget(parent);
return editorWidget->editor();
}
......@@ -45,18 +45,15 @@
#include <projectexplorer/iprojectproperties.h>
#include <projectexplorer/projectwindow.h>
#include <texteditor/plaintexteditor.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/texteditorconstants.h>
using namespace Qnx;
using namespace Qnx::Internal;
BarDescriptorEditorWidget::BarDescriptorEditorWidget(
QWidget *parent, TextEditor::TextEditorActionHandler *handler)
BarDescriptorEditorWidget::BarDescriptorEditorWidget(QWidget *parent)
: QStackedWidget(parent)
, m_editor(0)
, m_handler(handler)
, m_dirty(false)
{
Core::IContext *myContext = new Core::IContext(this);
......@@ -161,7 +158,6 @@ void BarDescriptorEditorWidget::initSourcePage()
addWidget(m_xmlSourceWidget);
TextEditor::TextEditorSettings::initializeEditor(m_xmlSourceWidget);
m_handler->setupActions(m_xmlSourceWidget);
m_xmlSourceWidget->configure(QLatin1String(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE));
connect(m_xmlSourceWidget, SIGNAL(textChanged()), this, SLOT(setDirty()));
}
......
......@@ -46,7 +46,6 @@ class PanelsWidget;
namespace TextEditor {
class PlainTextEditorWidget;
class TextEditorActionHandler;
class BaseTextEditorWidget;
}
......@@ -67,7 +66,7 @@ class BarDescriptorEditorWidget : public QStackedWidget
Q_OBJECT
public:
explicit BarDescriptorEditorWidget(QWidget *parent, TextEditor::TextEditorActionHandler *handler);
explicit BarDescriptorEditorWidget(QWidget *parent);
Core::IEditor *editor() const;
......@@ -107,7 +106,6 @@ private:
mutable Core::IEditor *m_editor;
TextEditor::TextEditorActionHandler *m_handler;
bool m_dirty;
// New UI
......
......@@ -102,7 +102,6 @@ public:
BaseTextEditorWidgetPrivate();
~BaseTextEditorWidgetPrivate();
void setupBasicEditActions(TextEditorActionHandler *actionHandler);
void setupDocumentSignals(const QSharedPointer<BaseTextDocument> &document);
void updateLineSelectionColor();
......
......@@ -79,7 +79,7 @@ IEditor *PlainTextEditor::duplicate(QWidget *parent)
{
PlainTextEditorWidget *newWidget = new PlainTextEditorWidget(parent);
newWidget->duplicateFrom(editorWidget());
TextEditorPlugin::instance()->initializeEditor(newWidget);
TextEditorSettings::initializeEditor(newWidget);
return newWidget->editor();
}
......
......@@ -30,9 +30,10 @@
#include "plaintexteditorfactory.h"
#include "plaintexteditor.h"
#include "basetextdocument.h"
#include "texteditoractionhandler.h"
#include "texteditorconstants.h"
#include "texteditorplugin.h"
#include "texteditoractionhandler.h"
#include "texteditorsettings.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/infobar.h>
......@@ -65,7 +66,7 @@ PlainTextEditorFactory::~PlainTextEditorFactory()
Core::IEditor *PlainTextEditorFactory::createEditor(QWidget *parent)
{
PlainTextEditorWidget *rc = new PlainTextEditorWidget(parent);
TextEditorPlugin::instance()->initializeEditor(rc);
TextEditorSettings::initializeEditor(rc);
connect(rc, SIGNAL(configured(Core::IEditor*)),
this, SLOT(updateEditorInfoBar(Core::IEditor*)));
updateEditorInfoBar(rc->editor());
......
......@@ -102,10 +102,10 @@ TextEditorActionHandler::TextEditorActionHandler(Core::Id contextId, uint option
m_jumpToFileAction(0),
m_jumpToFileInNextSplitAction(0),
m_optionalActions(optionalActions),
m_currentEditor(0),
m_contextId(contextId),
m_initialized(false)
m_currentEditorWidget(0),
m_contextId(contextId)
{
createActions();
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentEditor(Core::IEditor*)));
}
......@@ -114,24 +114,6 @@ TextEditorActionHandler::~TextEditorActionHandler()
{
}
void TextEditorActionHandler::setupActions(BaseTextEditorWidget *editor)
{
initializeActions();
QObject::connect(editor, SIGNAL(undoAvailable(bool)), this, SLOT(updateUndoAction()));
QObject::connect(editor, SIGNAL(redoAvailable(bool)), this, SLOT(updateRedoAction()));
QObject::connect(editor, SIGNAL(copyAvailable(bool)), this, SLOT(updateCopyAction()));
QObject::connect(editor, SIGNAL(readOnlyChanged()), this, SLOT(updateActions()));
}
void TextEditorActionHandler::initializeActions()
{
if (!m_initialized) {
createActions();
m_initialized = true;
}
}
void TextEditorActionHandler::createActions()
{
using namespace Core::Constants;
......@@ -369,6 +351,13 @@ void TextEditorActionHandler::createActions()
m_modifyingActions << m_switchUtf8bomAction;
m_modifyingActions << m_indentAction;
m_modifyingActions << m_unindentAction;
// set enabled state of optional actions
m_followSymbolAction->setEnabled(m_optionalActions & FollowSymbolUnderCursor);
m_followSymbolInNextSplitAction->setEnabled(m_optionalActions & FollowSymbolUnderCursor);
m_jumpToFileAction->setEnabled(m_optionalActions & JumpToFileUnderCursor);
m_jumpToFileInNextSplitAction->setEnabled(m_optionalActions & JumpToFileUnderCursor);
m_unfoldAllAction->setEnabled(m_optionalActions & UnCollapseAll);
}
QAction *TextEditorActionHandler::registerAction(const Core::Id &id,
......@@ -391,34 +380,16 @@ QAction *TextEditorActionHandler::registerAction(const Core::Id &id,
return result;
}
TextEditorActionHandler::UpdateMode TextEditorActionHandler::updateMode() const
{
Q_ASSERT(m_currentEditor != 0);
return m_currentEditor->isReadOnly() ? ReadOnlyMode : WriteMode;
}
void TextEditorActionHandler::updateActions()
{
if (!m_currentEditor || !m_initialized)
return;
updateActions(updateMode());
}
void TextEditorActionHandler::updateActions(UpdateMode um)
{
QTC_ASSERT(m_currentEditorWidget, return);
bool isWritable = !m_currentEditorWidget->isReadOnly();
foreach (QAction *a, m_modifyingActions)
a->setEnabled(um != ReadOnlyMode);
m_formatAction->setEnabled((m_optionalActions & Format) && um != ReadOnlyMode);
m_unCommentSelectionAction->setEnabled((m_optionalActions & UnCommentSelection) && um != ReadOnlyMode);
m_followSymbolAction->setEnabled(m_optionalActions & FollowSymbolUnderCursor);
m_followSymbolInNextSplitAction->setEnabled(m_optionalActions & FollowSymbolUnderCursor);
m_jumpToFileAction->setEnabled(m_optionalActions & JumpToFileUnderCursor);
m_jumpToFileInNextSplitAction->setEnabled(m_optionalActions & JumpToFileUnderCursor);
m_unfoldAllAction->setEnabled((m_optionalActions & UnCollapseAll));
m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace);
if (m_textWrappingAction)
m_textWrappingAction->setChecked(m_currentEditor->displaySettings().m_textWrapping);
a->setEnabled(isWritable);
m_formatAction->setEnabled((m_optionalActions & Format) && isWritable);
m_unCommentSelectionAction->setEnabled((m_optionalActions & UnCommentSelection) && isWritable);
m_visualizeWhitespaceAction->setChecked(m_currentEditorWidget->displaySettings().m_visualizeWhitespace);
m_textWrappingAction->setChecked(m_currentEditorWidget->displaySettings().m_textWrapping);
updateRedoAction();
updateUndoAction();
......@@ -427,21 +398,22 @@ void TextEditorActionHandler::updateActions(UpdateMode um)
void TextEditorActionHandler::updateRedoAction()
{
if (m_redoAction)
m_redoAction->setEnabled(m_currentEditor && m_currentEditor->document()->isRedoAvailable());
QTC_ASSERT(m_currentEditorWidget, return);
m_redoAction->setEnabled(m_currentEditorWidget->document()->isRedoAvailable());
}
void TextEditorActionHandler::updateUndoAction()
{
if (m_undoAction)
m_undoAction->setEnabled(m_currentEditor && m_currentEditor->document()->isUndoAvailable());
QTC_ASSERT(m_currentEditorWidget, return);
m_undoAction->setEnabled(m_currentEditorWidget->document()->isUndoAvailable());
}
void TextEditorActionHandler::updateCopyAction()
{
const bool hasCopyableText = m_currentEditor && m_currentEditor->textCursor().hasSelection();