TextEditor: add actions to fold/unfold blocks recursively

Change-Id: Ie0d15ec02be7fb90e9b94ea0226b49ce724e4266
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2024-07-11 11:14:58 +02:00
parent 6cd306a992
commit b6dd5f93fc
3 changed files with 16 additions and 0 deletions

View File

@@ -4234,6 +4234,14 @@ void TextEditorWidgetPrivate::registerActions()
.setContext(m_editorContext)
.addOnTriggered([this] { q->unfoldCurrentBlock(); })
.setScriptable(true);
ActionBuilder(this, FOLD_RECURSIVELY)
.setContext(m_editorContext)
.addOnTriggered([this] { q->fold(q->textCursor().block(), true); })
.setScriptable(true);
ActionBuilder(this, UNFOLD_RECURSIVELY)
.setContext(m_editorContext)
.addOnTriggered([this] { q->unfold(q->textCursor().block(), true); })
.setScriptable(true);
m_unfoldAllAction = ActionBuilder(this, UNFOLD_ALL)
.setContext(m_editorContext)
.addOnTriggered([this] { q->toggleFoldAll(); })

View File

@@ -131,6 +131,8 @@ const char TEXT_WRAPPING[] = "TextEditor.TextWrapping";
const char UN_COMMENT_SELECTION[] = "TextEditor.UnCommentSelection";
const char FOLD[] = "TextEditor.Fold";
const char UNFOLD[] = "TextEditor.Unfold";
const char FOLD_RECURSIVELY[] = "TextEditor.FoldRecursively";
const char UNFOLD_RECURSIVELY[] = "TextEditor.UnfoldRecursively";
const char UNFOLD_ALL[] = "TextEditor.UnFoldAll";
const char AUTO_INDENT_SELECTION[] = "TextEditor.AutoIndentSelection";
const char AUTO_FORMAT_SELECTION[] = "TextEditor.AutoFormatSelection";

View File

@@ -512,6 +512,12 @@ void TextEditorPlugin::createEditorCommands()
.setText(Tr::tr("Unfold"))
.setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+>")))
.addToContainer(M_EDIT_ADVANCED, G_EDIT_COLLAPSING);
TextActionBuilder(this, FOLD_RECURSIVELY)
.setText(Tr::tr("Fold Recursively"))
.addToContainer(M_EDIT_ADVANCED, G_EDIT_COLLAPSING);
TextActionBuilder(this, UNFOLD_RECURSIVELY)
.setText(Tr::tr("Unfold Recursively"))
.addToContainer(M_EDIT_ADVANCED, G_EDIT_COLLAPSING);
TextActionBuilder(this, UNFOLD_ALL)
.setText(Tr::tr("Toggle &Fold All"))
.addToContainer(M_EDIT_ADVANCED, G_EDIT_COLLAPSING);