TextEditor: Remove "actionHack" and utilize contexts instead.

The actionHack was used to only forward actions to editors that "belong"
to that action handler instance. That is already clearly defined by the
context that the action handler is created for, so we can just use that
instead.

Change-Id: Ia4c6795c80bb281c1ed258324925f56ca7fd8150
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Eike Ziller
2013-12-10 12:36:15 +01:00
parent e922cd234b
commit b55df87a7b
5 changed files with 10 additions and 28 deletions

View File

@@ -2446,7 +2446,6 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate()
m_linkPressed(false), m_linkPressed(false),
m_delayedUpdateTimer(0), m_delayedUpdateTimer(0),
m_editor(0), m_editor(0),
m_actionHack(0),
m_inBlockSelectionMode(false), m_inBlockSelectionMode(false),
m_moveLineUndoHack(false), m_moveLineUndoHack(false),
m_findScopeVerticalBlockSelectionFirstColumn(-1), m_findScopeVerticalBlockSelectionFirstColumn(-1),
@@ -5177,16 +5176,6 @@ void BaseTextEditorWidget::_q_highlightBlocks()
} }
} }
void BaseTextEditorWidget::setActionHack(QObject *hack)
{
d->m_actionHack = hack;
}
QObject *BaseTextEditorWidget::actionHack() const
{
return d->m_actionHack;
}
void BaseTextEditorWidget::changeEvent(QEvent *e) void BaseTextEditorWidget::changeEvent(QEvent *e)
{ {
QPlainTextEdit::changeEvent(e); QPlainTextEdit::changeEvent(e);

View File

@@ -208,9 +208,6 @@ public:
int columnCount() const; int columnCount() const;
int rowCount() const; int rowCount() const;
void setActionHack(QObject *hack);
QObject *actionHack() const;
void setReadOnly(bool b); void setReadOnly(bool b);
void setTextCursor(const QTextCursor &cursor); void setTextCursor(const QTextCursor &cursor);

View File

@@ -195,8 +195,6 @@ public:
BaseTextEditor *m_editor; BaseTextEditor *m_editor;
QObject *m_actionHack;
QList<QTextEdit::ExtraSelection> m_extraSelections[BaseTextEditorWidget::NExtraSelectionKinds]; QList<QTextEdit::ExtraSelection> m_extraSelections[BaseTextEditorWidget::NExtraSelectionKinds];
// block selection mode // block selection mode

View File

@@ -49,8 +49,7 @@
using namespace TextEditor; using namespace TextEditor;
using namespace TextEditor::Internal; using namespace TextEditor::Internal;
TextEditorActionHandler::TextEditorActionHandler(const char *context, TextEditorActionHandler::TextEditorActionHandler(Core::Id contextId, uint optionalActions)
uint optionalActions)
: QObject(Core::ICore::instance()), : QObject(Core::ICore::instance()),
m_undoAction(0), m_undoAction(0),
m_redoAction(0), m_redoAction(0),
@@ -104,7 +103,7 @@ TextEditorActionHandler::TextEditorActionHandler(const char *context,
m_jumpToFileInNextSplitAction(0), m_jumpToFileInNextSplitAction(0),
m_optionalActions(optionalActions), m_optionalActions(optionalActions),
m_currentEditor(0), m_currentEditor(0),
m_contextId(context), m_contextId(contextId),
m_initialized(false) m_initialized(false)
{ {
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
@@ -118,7 +117,6 @@ TextEditorActionHandler::~TextEditorActionHandler()
void TextEditorActionHandler::setupActions(BaseTextEditorWidget *editor) void TextEditorActionHandler::setupActions(BaseTextEditorWidget *editor)
{ {
initializeActions(); initializeActions();
editor->setActionHack(this);
QObject::connect(editor, SIGNAL(undoAvailable(bool)), this, SLOT(updateUndoAction())); QObject::connect(editor, SIGNAL(undoAvailable(bool)), this, SLOT(updateUndoAction()));
QObject::connect(editor, SIGNAL(redoAvailable(bool)), this, SLOT(updateRedoAction())); QObject::connect(editor, SIGNAL(redoAvailable(bool)), this, SLOT(updateRedoAction()));
QObject::connect(editor, SIGNAL(copyAvailable(bool)), this, SLOT(updateCopyAction())); QObject::connect(editor, SIGNAL(copyAvailable(bool)), this, SLOT(updateCopyAction()));
@@ -382,7 +380,7 @@ QAction *TextEditorActionHandler::registerAction(const Core::Id &id,
Core::ActionContainer *container) Core::ActionContainer *container)
{ {
QAction *result = new QAction(title, this); QAction *result = new QAction(title, this);
Core::Command *command = Core::ActionManager::registerAction(result, id, m_contextId, scriptable); Core::Command *command = Core::ActionManager::registerAction(result, id, Core::Context(m_contextId), scriptable);
if (!keySequence.isEmpty()) if (!keySequence.isEmpty())
command->setDefaultKeySequence(keySequence); command->setDefaultKeySequence(keySequence);
@@ -570,15 +568,15 @@ void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
{ {
m_currentEditor = 0; m_currentEditor = 0;
if (!editor) if (!editor || !editor->context().contains(m_contextId))
return; return;
BaseTextEditorWidget *baseEditor = resolveTextEditorWidget(editor); BaseTextEditorWidget *baseEditor = resolveTextEditorWidget(editor);
if (baseEditor && baseEditor->actionHack() == this) { if (!baseEditor)
m_currentEditor = baseEditor; return;
updateActions(); m_currentEditor = baseEditor;
} updateActions();
} }
const QPointer<BaseTextEditorWidget> &TextEditorActionHandler::currentEditor() const const QPointer<BaseTextEditorWidget> &TextEditorActionHandler::currentEditor() const

View File

@@ -65,7 +65,7 @@ public:
JumpToFileUnderCursor = 16 JumpToFileUnderCursor = 16
}; };
explicit TextEditorActionHandler(const char *context, uint optionalActions = None); explicit TextEditorActionHandler(Core::Id contextId, uint optionalActions = None);
~TextEditorActionHandler(); ~TextEditorActionHandler();
void setupActions(BaseTextEditorWidget *editor); void setupActions(BaseTextEditorWidget *editor);
@@ -226,7 +226,7 @@ private:
uint m_optionalActions; uint m_optionalActions;
QPointer<BaseTextEditorWidget> m_currentEditor; QPointer<BaseTextEditorWidget> m_currentEditor;
Core::Context m_contextId; Core::Id m_contextId;
bool m_initialized; bool m_initialized;
}; };