From bdc8411af5d73187955e7d612b4795bab8049647 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 15 Jun 2020 10:14:35 +0200 Subject: Editor: add update optional actions function to action handler Change-Id: I342fc53aaa845c6fa2933ea19a0a36a6dc8e6338 Reviewed-by: Christian Stenger --- src/plugins/texteditor/texteditoractionhandler.cpp | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'src/plugins/texteditor') diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 1077417859..b04e89af32 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -114,6 +114,7 @@ public: void createActions(); void updateActions(); + void updateOptionalActions(); void updateRedoAction(bool on); void updateUndoAction(bool on); void updateCopyAction(bool on); @@ -517,13 +518,7 @@ void TextEditorActionHandlerPrivate::createActions() m_modifyingActions << m_upperCaseSelectionAction; m_modifyingActions << m_sortSelectedLinesAction; - // set enabled state of optional actions - m_followSymbolAction->setEnabled(m_optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor); - m_followSymbolInNextSplitAction->setEnabled(m_optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor); - m_jumpToFileAction->setEnabled(m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor); - m_jumpToFileInNextSplitAction->setEnabled(m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor); - m_unfoldAllAction->setEnabled(m_optionalActions & TextEditorActionHandler::UnCollapseAll); - m_renameSymbolAction->setEnabled(m_optionalActions & TextEditorActionHandler::RenameSymbol); + updateOptionalActions(); } void TextEditorActionHandlerPrivate::updateActions() @@ -531,8 +526,6 @@ void TextEditorActionHandlerPrivate::updateActions() bool isWritable = m_currentEditorWidget && !m_currentEditorWidget->isReadOnly(); foreach (QAction *a, m_modifyingActions) a->setEnabled(isWritable); - m_autoIndentAction->setEnabled((m_optionalActions & TextEditorActionHandler::Format) && isWritable); - m_autoFormatAction->setEnabled((m_optionalActions & TextEditorActionHandler::Format) && isWritable); m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable); m_visualizeWhitespaceAction->setEnabled(m_currentEditorWidget); m_textWrappingAction->setEnabled(m_currentEditorWidget); @@ -545,6 +538,28 @@ void TextEditorActionHandlerPrivate::updateActions() updateRedoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isRedoAvailable()); updateUndoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isUndoAvailable()); updateCopyAction(m_currentEditorWidget && m_currentEditorWidget->textCursor().hasSelection()); + updateOptionalActions(); +} + +void TextEditorActionHandlerPrivate::updateOptionalActions() +{ + m_followSymbolAction->setEnabled( + m_optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor); + m_followSymbolInNextSplitAction->setEnabled( + m_optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor); + m_jumpToFileAction->setEnabled( + m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor); + m_jumpToFileInNextSplitAction->setEnabled( + m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor); + m_unfoldAllAction->setEnabled( + m_optionalActions & TextEditorActionHandler::UnCollapseAll); + m_renameSymbolAction->setEnabled( + m_optionalActions & TextEditorActionHandler::RenameSymbol); + + bool formatEnabled = (m_optionalActions & TextEditorActionHandler::Format) + && m_currentEditorWidget && !m_currentEditorWidget->isReadOnly(); + m_autoIndentAction->setEnabled(formatEnabled); + m_autoFormatAction->setEnabled(formatEnabled); } void TextEditorActionHandlerPrivate::updateRedoAction(bool on) -- cgit v1.2.3