aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/texteditoractionhandler.cpp
diff options
context:
space:
mode:
authorMarcus Tillmanns <marcus.tillmanns@qt.io>2023-08-31 08:50:11 +0200
committerMarcus Tillmanns <marcus.tillmanns@qt.io>2023-09-04 12:04:14 +0000
commit705232c7372eccc37d92b54706737829c8308945 (patch)
tree55468ee1a230ff17a49f454c9bf7169b9a8606a0 /src/plugins/texteditor/texteditoractionhandler.cpp
parent37022ff0dfa3031f559658bb2f3afb92e82b59d7 (diff)
TextEditor: Allow overwriting undo handling
In preparation for CompilerExplorer undo / redo handling. Change-Id: Iefad5cc497c8e439f626e375fe8862526b52a36e Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src/plugins/texteditor/texteditoractionhandler.cpp')
-rw-r--r--src/plugins/texteditor/texteditoractionhandler.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp
index d22f8c9657..d8405d3346 100644
--- a/src/plugins/texteditor/texteditoractionhandler.cpp
+++ b/src/plugins/texteditor/texteditoractionhandler.cpp
@@ -100,6 +100,9 @@ public:
void updateCurrentEditor(Core::IEditor *editor);
+ void setCanUndoCallback(const TextEditorActionHandler::Predicate &callback);
+ void setCanRedoCallback(const TextEditorActionHandler::Predicate &callback);
+
public:
TextEditorActionHandler::TextEditorWidgetResolver m_findTextWidget;
QAction *m_undoAction = nullptr;
@@ -124,8 +127,12 @@ public:
uint m_optionalActions = TextEditorActionHandler::None;
QPointer<TextEditorWidget> m_currentEditorWidget;
+ QPointer<Core::IEditor> m_currentEditor;
Utils::Id m_editorId;
Utils::Id m_contextId;
+
+ TextEditorActionHandler::Predicate m_canUndoCallback;
+ TextEditorActionHandler::Predicate m_canRedoCallback;
};
TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
@@ -463,9 +470,17 @@ void TextEditorActionHandlerPrivate::updateActions()
m_textWrappingAction->setChecked(m_currentEditorWidget->displaySettings().m_textWrapping);
}
- updateRedoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isRedoAvailable());
- updateUndoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isUndoAvailable());
- updateCopyAction(m_currentEditorWidget && m_currentEditorWidget->textCursor().hasSelection());
+ if (m_currentEditorWidget) {
+ updateRedoAction(m_canRedoCallback ? m_canRedoCallback(m_currentEditor)
+ : m_currentEditorWidget->document()->isRedoAvailable());
+ updateUndoAction(m_canUndoCallback ? m_canUndoCallback(m_currentEditor)
+ : m_currentEditorWidget->document()->isUndoAvailable());
+ updateCopyAction(m_currentEditorWidget->textCursor().hasSelection());
+ } else {
+ updateRedoAction(false);
+ updateUndoAction(false);
+ updateCopyAction(false);
+ }
updateOptionalActions();
}
@@ -523,6 +538,8 @@ void TextEditorActionHandlerPrivate::updateCurrentEditor(Core::IEditor *editor)
m_currentEditorWidget->disconnect(this);
m_currentEditorWidget = nullptr;
+ m_currentEditor = editor;
+
if (editor && editor->document()->id() == m_editorId) {
TextEditorWidget *editorWidget = m_findTextWidget(editor);
QTC_ASSERT(editorWidget, return); // editor has our id, so shouldn't happen
@@ -570,4 +587,19 @@ void TextEditorActionHandler::updateCurrentEditor()
d->updateCurrentEditor(Core::EditorManager::currentEditor());
}
+void TextEditorActionHandler::updateActions()
+{
+ d->updateActions();
+}
+
+void TextEditorActionHandler::setCanUndoCallback(const Predicate &callback)
+{
+ d->m_canUndoCallback = callback;
+}
+
+void TextEditorActionHandler::setCanRedoCallback(const Predicate &callback)
+{
+ d->m_canRedoCallback = callback;
+}
+
} // namespace TextEditor