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

List:       kde-commits
Subject:    [kate] addons/search: Search&Replace: Expand/collapse results if the expand-button is clicked
From:       Alex Neundorf <null () kde ! org>
Date:       2017-09-30 21:16:19
Message-ID: E1dyP7T-0000xc-4s () code ! kde ! org
[Download RAW message or body]

Git commit 8b5711119721c6e1f61cb659ec3572d1949d333c by Alex Neundorf.
Committed on 30/09/2017 at 21:13.
Pushed by neundorf into branch 'master'.

Search&Replace: Expand/collapse results if the expand-button is clicked

Before this patch, the state of the button was only used to
decide whether initially the results should be expanded or collapsed.
Now the user can just click the button and expand/collapse the
results tree.

Alex

M  +24   -6    addons/search/plugin_search.cpp
M  +2    -0    addons/search/plugin_search.h

https://commits.kde.org/kate/8b5711119721c6e1f61cb659ec3572d1949d333c

diff --git a/addons/search/plugin_search.cpp b/addons/search/plugin_search.cpp
index 2fba6d673..961713610 100644
--- a/addons/search/plugin_search.cpp
+++ b/addons/search/plugin_search.cpp
@@ -296,6 +296,7 @@ m_mainWindow (mainWin)
 
     connect(m_ui.folderUpButton,   SIGNAL(clicked()), this, SLOT(navigateFolderUp()));
     connect(m_ui.currentFolderButton, SIGNAL(clicked()), this, SLOT(setCurrentFolder()));
+    connect(m_ui.expandResults, SIGNAL(clicked()), this, SLOT(expandResults()));
 
     connect(m_ui.searchCombo,      SIGNAL(editTextChanged(QString)), &m_changeTimer, SLOT(start()));
     connect(m_ui.matchCase,        SIGNAL(toggled(bool)), &m_changeTimer, SLOT(start()));
@@ -1174,12 +1175,7 @@ void KatePluginSearchView::searchDone()
 
     // expand the "header item " to display all files and all results if configured
     QTreeWidgetItem *root = m_curResults->tree->topLevelItem(0);
-    m_curResults->tree->expandItem(root);
-    if (root && (root->childCount() > 1) && (!m_ui.expandResults->isChecked())) {
-        for (int i=0; i<root->childCount(); i++) {
-            m_curResults->tree->collapseItem(root->child(i));
-        }
-    }
+    expandResults();
 
     if (root) {
         switch (m_ui.searchPlaceCombo->currentIndex())
@@ -1547,6 +1543,28 @@ void KatePluginSearchView::docViewChanged()
     }
 }
 
+void KatePluginSearchView::expandResults()
+{
+    m_curResults =qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
+    if (!m_curResults) {
+        qWarning() << "Results not found";
+        return;
+    }
+
+    if (m_ui.expandResults->isChecked()) {
+        m_curResults->tree->expandAll();
+    }
+    else {
+        QTreeWidgetItem *root = m_curResults->tree->topLevelItem(0);
+        m_curResults->tree->expandItem(root);
+        if (root && (root->childCount() > 1)) {
+            for (int i=0; i<root->childCount(); i++) {
+                m_curResults->tree->collapseItem(root->child(i));
+            }
+        }
+    }
+}
+
 void KatePluginSearchView::itemSelected(QTreeWidgetItem *item)
 {
     if (!item) return;
diff --git a/addons/search/plugin_search.h b/addons/search/plugin_search.h
index d3e13839e..829587d09 100644
--- a/addons/search/plugin_search.h
+++ b/addons/search/plugin_search.h
@@ -164,6 +164,8 @@ private Q_SLOTS:
 
     void resultTabChanged(int index);
 
+    void expandResults();
+
     /**
      * keep track if the project plugin is alive and if the project file did change
      */
[prev in list] [next in list] [prev in thread] [next in thread] 

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