From b6dd5f93fce6c69db485ef310bddafe5333ace01 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 11 Jul 2024 11:14:58 +0200 Subject: [PATCH] TextEditor: add actions to fold/unfold blocks recursively Change-Id: Ie0d15ec02be7fb90e9b94ea0226b49ce724e4266 Reviewed-by: Christian Stenger --- src/plugins/texteditor/texteditor.cpp | 8 ++++++++ src/plugins/texteditor/texteditorconstants.h | 2 ++ src/plugins/texteditor/texteditorplugin.cpp | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index ba15f0b68f8..292a3950cbb 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -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(); }) diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index d53c09cf42a..a7e54971224 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -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"; diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 047f0a3f973..5c47d0eaeac 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -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);