]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
Move "Show in Groups" toggle action into Sort menu
[dolphin.git] / src / kitemviews / private / kitemlistkeyboardsearchmanager.cpp
index b7318b34406eeb0f1f42101fa273a8c1f1465b56..afc3bb0713e7f0e6a3f1ac73ee09b6fbae00d2f1 100644 (file)
@@ -10,7 +10,6 @@
 
 KItemListKeyboardSearchManager::KItemListKeyboardSearchManager(QObject *parent)
     : QObject(parent)
-    , m_isSearchRestarted(false)
     , m_timeout(1000)
 {
     m_keyboardInputTime.invalidate();
@@ -27,6 +26,11 @@ bool KItemListKeyboardSearchManager::shouldClearSearchIfInputTimeReached()
     return (keyboardInputTimeElapsed > m_timeout) || !keyboardTimeWasValid;
 }
 
+bool KItemListKeyboardSearchManager::isSearchAsYouTypeActive() const
+{
+    return !m_searchedString.isEmpty() && !m_keyboardInputTime.hasExpired(m_timeout);
+}
+
 void KItemListKeyboardSearchManager::addKeys(const QString &keys)
 {
     if (shouldClearSearchIfInputTimeReached()) {
@@ -50,24 +54,15 @@ void KItemListKeyboardSearchManager::addKeys(const QString &keys)
         const bool sameKey = m_searchedString.length() > 1 && m_searchedString.count(firstKey) == m_searchedString.length();
 
         // Searching for a matching item should start from the next item if either
-        // 1. a new search is started and a search has not been restarted or
+        // 1. a new search is started, or
         // 2. a 'repeated key' search is done.
-        const bool searchFromNextItem = (!m_isSearchRestarted && newSearch) || sameKey;
-
-        // to remember not to searchFromNextItem if selection was deselected
-        // losing keyboard search context basically
-        m_isSearchRestarted = false;
+        const bool searchFromNextItem = newSearch || sameKey;
 
         Q_EMIT changeCurrentItem(sameKey ? firstKey : m_searchedString, searchFromNextItem);
     }
     m_keyboardInputTime.start();
 }
 
-bool KItemListKeyboardSearchManager::addKeyBeginsNewSearch() const
-{
-    return m_keyboardInputTime.hasExpired(m_timeout) || m_searchedString.isEmpty();
-}
-
 void KItemListKeyboardSearchManager::setTimeout(qint64 milliseconds)
 {
     m_timeout = milliseconds;
@@ -80,7 +75,6 @@ qint64 KItemListKeyboardSearchManager::timeout() const
 
 void KItemListKeyboardSearchManager::cancelSearch()
 {
-    m_isSearchRestarted = true;
     m_searchedString.clear();
 }
 
@@ -101,3 +95,5 @@ void KItemListKeyboardSearchManager::slotSelectionChanged(const KItemSet &curren
         cancelSearch();
     }
 }
+
+#include "moc_kitemlistkeyboardsearchmanager.cpp"