From 570104ceed8613903f249f2e5768c5cceb6f0012 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 29 Jan 2015 13:24:20 +0900 Subject: Added 'max depth' search option to TDEFileReplace. This resolves bug 1238. Signed-off-by: Michele Calgaro --- tdefilereplace/tdefilereplacepart.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'tdefilereplace/tdefilereplacepart.cpp') diff --git a/tdefilereplace/tdefilereplacepart.cpp b/tdefilereplace/tdefilereplacepart.cpp index 008198e..dc96db4 100644 --- a/tdefilereplace/tdefilereplacepart.cpp +++ b/tdefilereplace/tdefilereplacepart.cpp @@ -130,7 +130,7 @@ void TDEFileReplacePart::slotSearchingOperation() uint filesNumber = 0; if(m_option->m_recursive) - recursiveFileSearch(currentDirectory, currentFilter, filesNumber); + recursiveFileSearch(currentDirectory, currentFilter, filesNumber, 0); else fileSearch(currentDirectory, currentFilter); @@ -687,6 +687,8 @@ void TDEFileReplacePart::loadOptions() m_option->m_encoding = m_config->readEntry(rcEncoding, EncodingOption); m_option->m_recursive = m_config->readBoolEntry(rcRecursive, RecursiveOption); + m_option->m_limitDepth = m_config->readBoolEntry(rcLimitDepth, LimitDepthOption); + m_option->m_maxDepth = m_config->readNumEntry(rcMaxDepth, MaxDepthOption); m_option->m_caseSensitive = m_config->readBoolEntry(rcCaseSensitive, CaseSensitiveOption); m_option->m_variables = m_config->readBoolEntry(rcVariables, VariablesOption); @@ -822,6 +824,8 @@ void TDEFileReplacePart::saveOptions() m_config->writeEntry(rcEncoding, m_option->m_encoding); m_config->writeEntry(rcRecursive, m_option->m_recursive); + m_config->writeEntry(rcLimitDepth, m_option->m_limitDepth); + m_config->writeEntry(rcMaxDepth, m_option->m_maxDepth); m_config->writeEntry(rcCaseSensitive, m_option->m_caseSensitive); m_config->writeEntry(rcVariables, m_option->m_variables); m_config->writeEntry(rcRegularExpressions, m_option->m_regularExpressions); @@ -1281,10 +1285,11 @@ void TDEFileReplacePart::fileSearch(const TQString& directoryName, const TQStrin } } -void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, const TQString& filters, uint& filesNumber) +void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, const TQString& filters, + uint& filesNumber, int depth) { - // if m_stop == true then interrupt recursion - if(m_stop) + // if m_stop == true or the max depth level is reached, then interrupt recursion + if (m_stop || (m_option->m_limitDepth && depth > m_option->m_maxDepth)) return; else { @@ -1313,9 +1318,14 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons m_view->displayScannedFiles(filesNumber); - // Searchs recursively if "filePath" is a directory - if(fileInfo.isDir()) - recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber); + // Searchs recursively if "filePath" is a directory and we have not reached the max depth level + if (fileInfo.isDir()) + { + if (!m_option->m_limitDepth || depth < m_option->m_maxDepth) + { + recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber, depth+1); + } + } else { kapp->processEvents(); -- cgit v1.2.1