aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2013-12-10 15:54:20 +0100
committerEike Ziller <eike.ziller@digia.com>2013-12-12 09:59:27 +0100
commit3d1b70c58e0d2eea47572ec4a018a18674508f9b (patch)
tree2217255fb7d6bc8e3e30603bb985cb655ab7be7d /src/plugins/texteditor
parent3ee9fb4d1c74058c785f24d19bac5fe879c75109 (diff)
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: David Schulz <david.schulz@digia.com>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/basetexteditor_p.h1
-rw-r--r--src/plugins/texteditor/plaintexteditor.cpp2
-rw-r--r--src/plugins/texteditor/plaintexteditorfactory.cpp5
-rw-r--r--src/plugins/texteditor/texteditoractionhandler.cpp123
-rw-r--r--src/plugins/texteditor/texteditoractionhandler.h24
-rw-r--r--src/plugins/texteditor/texteditorplugin.cpp13
-rw-r--r--src/plugins/texteditor/texteditorplugin.h2
7 files changed, 59 insertions, 111 deletions
diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h
index c970d6bc19..0ea3d5fdf6 100644
--- a/src/plugins/texteditor/basetexteditor_p.h
+++ b/src/plugins/texteditor/basetexteditor_p.h
@@ -102,7 +102,6 @@ public:
BaseTextEditorWidgetPrivate();
~BaseTextEditorWidgetPrivate();
- void setupBasicEditActions(TextEditorActionHandler *actionHandler);
void setupDocumentSignals(const QSharedPointer<BaseTextDocument> &document);
void updateLineSelectionColor();
diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp
index c664cdbafa..297441922e 100644
--- a/src/plugins/texteditor/plaintexteditor.cpp
+++ b/src/plugins/texteditor/plaintexteditor.cpp
@@ -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();
}
diff --git a/src/plugins/texteditor/plaintexteditorfactory.cpp b/src/plugins/texteditor/plaintexteditorfactory.cpp
index c31d411e58..af85d21ac5 100644
--- a/src/plugins/texteditor/plaintexteditorfactory.cpp
+++ b/src/plugins/texteditor/plaintexteditorfactory.cpp
@@ -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());
diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp
index 7ba3466710..eeaf6affd9 100644
--- a/src/plugins/texteditor/texteditoractionhandler.cpp
+++ b/src/plugins/texteditor/texteditoractionhandler.cpp
@@ -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();
+ QTC_ASSERT(m_currentEditorWidget, return);
+ const bool hasCopyableText = m_currentEditorWidget->textCursor().hasSelection();
if (m_cutAction)
- m_cutAction->setEnabled(hasCopyableText && updateMode() == WriteMode);
+ m_cutAction->setEnabled(hasCopyableText && !m_currentEditorWidget->isReadOnly());
if (m_copyAction)
m_copyAction->setEnabled(hasCopyableText);
}
@@ -457,37 +429,37 @@ void TextEditorActionHandler::gotoAction()
void TextEditorActionHandler::printAction()
{
- if (m_currentEditor)
- m_currentEditor->print(Core::ICore::printer());
+ if (m_currentEditorWidget)
+ m_currentEditorWidget->print(Core::ICore::printer());
}
void TextEditorActionHandler::setVisualizeWhitespace(bool checked)
{
- if (m_currentEditor) {
- DisplaySettings ds = m_currentEditor->displaySettings();
+ if (m_currentEditorWidget) {
+ DisplaySettings ds = m_currentEditorWidget->displaySettings();
ds.m_visualizeWhitespace = checked;
- m_currentEditor->setDisplaySettings(ds);
+ m_currentEditorWidget->setDisplaySettings(ds);
}
}
void TextEditorActionHandler::setTextWrapping(bool checked)
{
- if (m_currentEditor) {
- DisplaySettings ds = m_currentEditor->displaySettings();
+ if (m_currentEditorWidget) {
+ DisplaySettings ds = m_currentEditorWidget->displaySettings();
ds.m_textWrapping = checked;
- m_currentEditor->setDisplaySettings(ds);
+ m_currentEditorWidget->setDisplaySettings(ds);
}
}
#define FUNCTION(funcname) void TextEditorActionHandler::funcname ()\
{\
- if (m_currentEditor)\
- m_currentEditor->funcname ();\
+ if (m_currentEditorWidget)\
+ m_currentEditorWidget->funcname ();\
}
#define FUNCTION2(funcname, funcname2) void TextEditorActionHandler::funcname ()\
{\
- if (m_currentEditor)\
- m_currentEditor->funcname2 ();\
+ if (m_currentEditorWidget)\
+ m_currentEditorWidget->funcname2 ();\
}
@@ -566,20 +538,21 @@ BaseTextEditorWidget *TextEditorActionHandler::resolveTextEditorWidget(Core::IEd
void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
{
- m_currentEditor = 0;
+ if (m_currentEditorWidget)
+ m_currentEditorWidget->disconnect(this);
+ m_currentEditorWidget = 0;
+ // don't need to do anything if the editor's context doesn't match
+ // (our actions will be disabled because our context will not be active)
if (!editor || !editor->context().contains(m_contextId))
return;
- BaseTextEditorWidget *baseEditor = resolveTextEditorWidget(editor);
-
- if (!baseEditor)
- return;
- m_currentEditor = baseEditor;
+ BaseTextEditorWidget *editorWidget = resolveTextEditorWidget(editor);
+ QTC_ASSERT(editorWidget, return); // editor has our context id, so shouldn't happen
+ m_currentEditorWidget = editorWidget;
+ connect(m_currentEditorWidget, SIGNAL(undoAvailable(bool)), this, SLOT(updateUndoAction()));
+ connect(m_currentEditorWidget, SIGNAL(redoAvailable(bool)), this, SLOT(updateRedoAction()));
+ connect(m_currentEditorWidget, SIGNAL(copyAvailable(bool)), this, SLOT(updateCopyAction()));
+ connect(m_currentEditorWidget, SIGNAL(readOnlyChanged()), this, SLOT(updateActions()));
updateActions();
}
-
-const QPointer<BaseTextEditorWidget> &TextEditorActionHandler::currentEditor() const
-{
- return m_currentEditor;
-}
diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h
index 48f79408e0..eaea4735cf 100644
--- a/src/plugins/texteditor/texteditoractionhandler.h
+++ b/src/plugins/texteditor/texteditoractionhandler.h
@@ -68,20 +68,10 @@ public:
explicit TextEditorActionHandler(Core::Id contextId, uint optionalActions = None);
~TextEditorActionHandler();
- void setupActions(BaseTextEditorWidget *editor);
-
- void initializeActions();
-
-public slots:
- void updateActions();
- void updateRedoAction();
- void updateUndoAction();
- void updateCopyAction();
-
protected:
virtual BaseTextEditorWidget *resolveTextEditorWidget(Core::IEditor *editor) const;
- const QPointer<BaseTextEditorWidget> &currentEditor() const;
+private:
QAction *registerAction(const Core::Id &id,
const char *slot,
bool scriptable = false,
@@ -90,13 +80,14 @@ protected:
const char *menueGroup = 0,
Core::ActionContainer *container = 0);
- enum UpdateMode { ReadOnlyMode, WriteMode };
- UpdateMode updateMode() const;
-
void createActions();
- void updateActions(UpdateMode um);
private slots:
+ void updateActions();
+ void updateRedoAction();
+ void updateUndoAction();
+ void updateCopyAction();
+
void undoAction();
void redoAction();
void copyAction();
@@ -225,9 +216,8 @@ private:
QList<QAction *> m_modifyingActions;
uint m_optionalActions;
- QPointer<BaseTextEditorWidget> m_currentEditor;
+ QPointer<BaseTextEditorWidget> m_currentEditorWidget;
Core::Id m_contextId;
- bool m_initialized;
};
} // namespace TextEditor
diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp
index a61e82f02a..2721eac7c3 100644
--- a/src/plugins/texteditor/texteditorplugin.cpp
+++ b/src/plugins/texteditor/texteditorplugin.cpp
@@ -203,11 +203,6 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
m_outlineFactory = new OutlineFactory;
addAutoReleasedObject(m_outlineFactory);
- // We have to initialize the actions because other plugins that
- // depend upon the texteditorplugin expect that actions will be
- // registered in the action manager at plugin initialization time.
- m_editorFactory->actionHandler()->initializeActions();
-
m_baseTextMarkRegistry = new BaseTextMarkRegistry(this);
return true;
@@ -246,14 +241,6 @@ void TextEditorPlugin::extensionsInitialized()
this, SLOT(updateCurrentSelection(QString)));
}
-void TextEditorPlugin::initializeEditor(PlainTextEditorWidget *editor)
-{
- // common actions
- m_editorFactory->actionHandler()->setupActions(editor);
-
- TextEditorSettings::initializeEditor(editor);
-}
-
void TextEditorPlugin::invokeCompletion()
{
Core::IEditor *iface = Core::EditorManager::currentEditor();
diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h
index 3d19745a64..892c176816 100644
--- a/src/plugins/texteditor/texteditorplugin.h
+++ b/src/plugins/texteditor/texteditorplugin.h
@@ -64,8 +64,6 @@ public:
bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized();
- void initializeEditor(PlainTextEditorWidget *editor);
-
PlainTextEditorFactory *editorFactory() { return m_editorFactory; }
LineNumberFilter *lineNumberFilter() { return m_lineNumberFilter; }
BaseTextMarkRegistry *baseTextMarkRegistry() { return m_baseTextMarkRegistry; }