forked from qt-creator/qt-creator
Editor: enable optional actions per editor
Use an additional action mask to enable actions like find usage and rename symbol per editor instance. Change-Id: Iabee1820d0f3c156ad30ba760bfce9f6181045e6 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -628,6 +628,7 @@ public:
|
|||||||
QComboBox *m_fileLineEnding = nullptr;
|
QComboBox *m_fileLineEnding = nullptr;
|
||||||
QAction *m_fileLineEndingAction = nullptr;
|
QAction *m_fileLineEndingAction = nullptr;
|
||||||
|
|
||||||
|
uint m_optionalActionMask = TextEditorActionHandler::None;
|
||||||
bool m_contentsChanged = false;
|
bool m_contentsChanged = false;
|
||||||
bool m_lastCursorChangeWasInteresting = false;
|
bool m_lastCursorChangeWasInteresting = false;
|
||||||
|
|
||||||
@@ -7827,6 +7828,16 @@ void TextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint TextEditorWidget::optionalActionMask()
|
||||||
|
{
|
||||||
|
return d->m_optionalActionMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextEditorWidget::addOptionalActions(uint optionalActionMask)
|
||||||
|
{
|
||||||
|
d->m_optionalActionMask |= optionalActionMask;
|
||||||
|
emit optionalActionMaskChanged();
|
||||||
|
}
|
||||||
|
|
||||||
BaseTextEditor::BaseTextEditor()
|
BaseTextEditor::BaseTextEditor()
|
||||||
: d(new BaseTextEditorPrivate)
|
: d(new BaseTextEditorPrivate)
|
||||||
|
@@ -204,6 +204,9 @@ public:
|
|||||||
|
|
||||||
void appendStandardContextMenuActions(QMenu *menu);
|
void appendStandardContextMenuActions(QMenu *menu);
|
||||||
|
|
||||||
|
uint optionalActionMask();
|
||||||
|
void addOptionalActions(uint optionalActionMask);
|
||||||
|
|
||||||
void setAutoCompleter(AutoCompleter *autoCompleter);
|
void setAutoCompleter(AutoCompleter *autoCompleter);
|
||||||
AutoCompleter *autoCompleter() const;
|
AutoCompleter *autoCompleter() const;
|
||||||
|
|
||||||
@@ -492,6 +495,7 @@ signals:
|
|||||||
bool resolveTarget, bool inNextSplit);
|
bool resolveTarget, bool inNextSplit);
|
||||||
void requestUsages(const QTextCursor &cursor);
|
void requestUsages(const QTextCursor &cursor);
|
||||||
void requestRename(const QTextCursor &cursor);
|
void requestRename(const QTextCursor &cursor);
|
||||||
|
void optionalActionMaskChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTextBlock blockForVisibleRow(int row) const;
|
QTextBlock blockForVisibleRow(int row) const;
|
||||||
|
@@ -543,20 +543,23 @@ void TextEditorActionHandlerPrivate::updateActions()
|
|||||||
|
|
||||||
void TextEditorActionHandlerPrivate::updateOptionalActions()
|
void TextEditorActionHandlerPrivate::updateOptionalActions()
|
||||||
{
|
{
|
||||||
|
uint optionalActions = m_optionalActions;
|
||||||
|
if (m_currentEditorWidget)
|
||||||
|
optionalActions |= m_currentEditorWidget->optionalActionMask();
|
||||||
m_followSymbolAction->setEnabled(
|
m_followSymbolAction->setEnabled(
|
||||||
m_optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor);
|
optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor);
|
||||||
m_followSymbolInNextSplitAction->setEnabled(
|
m_followSymbolInNextSplitAction->setEnabled(
|
||||||
m_optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor);
|
optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor);
|
||||||
m_jumpToFileAction->setEnabled(
|
m_jumpToFileAction->setEnabled(
|
||||||
m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor);
|
optionalActions & TextEditorActionHandler::JumpToFileUnderCursor);
|
||||||
m_jumpToFileInNextSplitAction->setEnabled(
|
m_jumpToFileInNextSplitAction->setEnabled(
|
||||||
m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor);
|
optionalActions & TextEditorActionHandler::JumpToFileUnderCursor);
|
||||||
m_unfoldAllAction->setEnabled(
|
m_unfoldAllAction->setEnabled(
|
||||||
m_optionalActions & TextEditorActionHandler::UnCollapseAll);
|
optionalActions & TextEditorActionHandler::UnCollapseAll);
|
||||||
m_renameSymbolAction->setEnabled(
|
m_renameSymbolAction->setEnabled(
|
||||||
m_optionalActions & TextEditorActionHandler::RenameSymbol);
|
optionalActions & TextEditorActionHandler::RenameSymbol);
|
||||||
|
|
||||||
bool formatEnabled = (m_optionalActions & TextEditorActionHandler::Format)
|
bool formatEnabled = (optionalActions & TextEditorActionHandler::Format)
|
||||||
&& m_currentEditorWidget && !m_currentEditorWidget->isReadOnly();
|
&& m_currentEditorWidget && !m_currentEditorWidget->isReadOnly();
|
||||||
m_autoIndentAction->setEnabled(formatEnabled);
|
m_autoIndentAction->setEnabled(formatEnabled);
|
||||||
m_autoFormatAction->setEnabled(formatEnabled);
|
m_autoFormatAction->setEnabled(formatEnabled);
|
||||||
@@ -599,6 +602,8 @@ void TextEditorActionHandlerPrivate::updateCurrentEditor(Core::IEditor *editor)
|
|||||||
this, &TextEditorActionHandlerPrivate::updateCopyAction);
|
this, &TextEditorActionHandlerPrivate::updateCopyAction);
|
||||||
connect(editorWidget, &TextEditorWidget::readOnlyChanged,
|
connect(editorWidget, &TextEditorWidget::readOnlyChanged,
|
||||||
this, &TextEditorActionHandlerPrivate::updateActions);
|
this, &TextEditorActionHandlerPrivate::updateActions);
|
||||||
|
connect(editorWidget, &TextEditorWidget::optionalActionMaskChanged,
|
||||||
|
this, &TextEditorActionHandlerPrivate::updateOptionalActions);
|
||||||
}
|
}
|
||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user