[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kate] addons/filetree: CHANGELOG: Implemented Feature Request: Expand/Collapse all actions for item
From:       Christoph Cullmann <cullmann () kde ! org>
Date:       2016-10-19 12:54:29
Message-ID: E1bwqO5-000895-Fm () code ! kde ! org
[Download RAW message or body]

Git commit 0b2997addf31e4c68580445271c460c61c658342 by Christoph Cullmann, on behalf \
of Markus Pister. Committed on 19/10/2016 at 12:53.
Pushed by cullmann into branch 'master'.

CHANGELOG: Implemented Feature Request: Expand/Collapse all actions for items in the \
documents list

BUG: 360195

Patch by Markus Pister

M  +54   -0    addons/filetree/katefiletree.cpp
M  +4    -0    addons/filetree/katefiletree.h

http://commits.kde.org/kate/0b2997addf31e4c68580445271c460c61c658342

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;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic