aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Pister <info@markus-pister.de>2016-10-19 12:53:42 (GMT)
committerChristoph Cullmann <cullmann@kde.org>2016-10-19 12:53:42 (GMT)
commit0b2997addf31e4c68580445271c460c61c658342 (patch)
tree5c850cea12d10c18b27af85408a77c038e3047aa
parent58d306871b2024fa15a08f2697f9ff3b43d14846 (diff)
CHANGELOG: Implemented Feature Request: Expand/Collapse all actions for items in the documents list
BUG: 360195 Patch by Markus Pister
-rw-r--r--addons/filetree/katefiletree.cpp54
-rw-r--r--addons/filetree/katefiletree.h4
2 files changed, 58 insertions, 0 deletions
diff --git a/addons/filetree/katefiletree.cpp b/addons/filetree/katefiletree.cpp
index b4437c7..9729e9a 100644
--- a/addons/filetree/katefiletree.cpp
+++ b/addons/filetree/katefiletree.cpp
@@ -69,6 +69,14 @@ KateFileTree::KateFileTree(QWidget *parent): QTreeView(parent)
connect(m_filelistCloseDocument, SIGNAL(triggered()), this, SLOT(slotDocumentClose()));
m_filelistCloseDocument->setWhatsThis(i18n("Close the current document."));
+ m_filelistExpandRecursive = new QAction(QIcon::fromTheme(QLatin1String("view-list-tree")), i18nc("@action:inmenu", "Expand recursively"), this);
+ connect(m_filelistExpandRecursive, SIGNAL(triggered()), this, SLOT(slotExpandRecursive()));
+ m_filelistExpandRecursive->setWhatsThis(i18n("Expand the file list sub tree recursively."));
+
+ m_filelistCollapseRecursive = new QAction(QIcon::fromTheme(QLatin1String("view-list-tree")), i18nc("@action:inmenu", "Collapse recursively"), this);
+ connect(m_filelistCollapseRecursive, SIGNAL(triggered()), this, SLOT(slotCollapseRecursive()));
+ m_filelistCollapseRecursive->setWhatsThis(i18n("Collapse the file list sub tree recursively."));
+
m_filelistCloseOtherDocument = new QAction(QIcon::fromTheme(QLatin1String("document-close")), i18nc("@action:inmenu", "Close Other"), this);
connect(m_filelistCloseOtherDocument, SIGNAL(triggered()), this, SLOT(slotDocumentCloseOther()));
m_filelistCloseOtherDocument->setWhatsThis(i18n("Close other documents in this folder."));
@@ -225,6 +233,8 @@ void KateFileTree::contextMenuEvent(QContextMenuEvent *event)
QMenu menu;
menu.addAction(m_filelistReloadDocument);
menu.addAction(m_filelistCloseDocument);
+ menu.addAction(m_filelistExpandRecursive);
+ menu.addAction(m_filelistCollapseRecursive);
if (isFile) {
menu.addAction(m_filelistCloseOtherDocument);
@@ -337,6 +347,50 @@ void KateFileTree::slotDocumentClose()
KTextEditor::Editor::instance()->application()->closeDocuments(closingDocuments);
}
+void KateFileTree::slotExpandRecursive()
+{
+ if (! m_indexContextMenu.isValid()) {
+ return;
+ }
+
+ // Work list for DFS walk over sub tree
+ QList<QPersistentModelIndex> worklist = { m_indexContextMenu };
+
+ while (! worklist.isEmpty()) {
+ QPersistentModelIndex index = worklist.takeLast();
+
+ // Expand current item
+ expand(index);
+
+ // Append all children of current item
+ for (int i=0 ; i < model()->rowCount(index) ; ++i) {
+ worklist.append(index.child(i,0));
+ }
+ }
+}
+
+void KateFileTree::slotCollapseRecursive()
+{
+ if (! m_indexContextMenu.isValid()) {
+ return;
+ }
+
+ // Work list for DFS walk over sub tree
+ QList<QPersistentModelIndex> worklist = { m_indexContextMenu };
+
+ while (! worklist.isEmpty()) {
+ QPersistentModelIndex index = worklist.takeLast();
+
+ // Expand current item
+ collapse(index);
+
+ // Prepend all children of current item
+ for (int i=0 ; i < model()->rowCount(index) ; ++i) {
+ worklist.append(index.child(i,0));
+ }
+ }
+}
+
void KateFileTree::slotDocumentCloseOther()
{
QVariant v = model()->data(m_indexContextMenu.parent(), KateFileTreeModel::DocumentTreeRole);
diff --git a/addons/filetree/katefiletree.h b/addons/filetree/katefiletree.h
index 497f998..7593a0e 100644
--- a/addons/filetree/katefiletree.h
+++ b/addons/filetree/katefiletree.h
@@ -44,6 +44,8 @@ public:
public Q_SLOTS:
void slotDocumentClose();
+ void slotExpandRecursive();
+ void slotCollapseRecursive();
void slotDocumentCloseOther();
void slotDocumentReload();
void slotCopyFilename();
@@ -88,6 +90,8 @@ private:
private:
QAction *m_filelistCloseDocument;
+ QAction *m_filelistExpandRecursive;
+ QAction *m_filelistCollapseRecursive;
QAction *m_filelistCloseOtherDocument;
QAction *m_filelistReloadDocument;
QAction *m_filelistCopyFilename;