From 23b906b576c51c02770bc9645c4b7291f5f3d6a7 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 30 Jan 2015 16:44:45 +0900 Subject: Fixed maxDepth option in search-n-replace in TDEFileRelace. This relates to bug 1238. Signed-off-by: Michele Calgaro --- tdefilereplace/tdefilereplacepart.cpp | 21 +++++++++++++-------- tdefilereplace/tdefilereplacepart.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'tdefilereplace') diff --git a/tdefilereplace/tdefilereplacepart.cpp b/tdefilereplace/tdefilereplacepart.cpp index dc96db4..d4433b6 100644 --- a/tdefilereplace/tdefilereplacepart.cpp +++ b/tdefilereplace/tdefilereplacepart.cpp @@ -196,7 +196,7 @@ void TDEFileReplacePart::slotReplacingOperation() if(m_option->m_recursive) { int filesNumber = 0; - recursiveFileReplace(currentDirectory, filesNumber); + recursiveFileReplace(currentDirectory, filesNumber, 0); } else { @@ -967,10 +967,10 @@ void TDEFileReplacePart::fileReplace() } } -void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int& filesNumber) +void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int& filesNumber, int depth) { - //if m_stop == true then interrupts 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 { @@ -1001,12 +1001,17 @@ void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int m_view->displayScannedFiles(filesNumber); - //if filePath is a directory then recursion - if(qi.isDir()) - recursiveFileReplace(filePath, filesNumber); + // Replace recursively if "filePath" is a directory and we have not reached the max depth level + if (qi.isDir()) + { + if (!m_option->m_limitDepth || depth < m_option->m_maxDepth) + { + recursiveFileReplace(filePath, filesNumber, depth+1); + } + } else { - kapp->processEvents(); + kapp->processEvents(); if(m_option->m_backup) replaceAndBackup(d.canonicalPath(), fileName); else diff --git a/tdefilereplace/tdefilereplacepart.h b/tdefilereplace/tdefilereplacepart.h index ee5352d..579f7ab 100644 --- a/tdefilereplace/tdefilereplacepart.h +++ b/tdefilereplace/tdefilereplacepart.h @@ -133,7 +133,7 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart * Replacing methods */ void fileReplace(); - void recursiveFileReplace(const TQString& dirName, int& filesNumber); + void recursiveFileReplace(const TQString& dirName, int& filesNumber, int depth); void replaceAndBackup(const TQString& currentDir, const TQString& oldFileName); void replaceAndOverwrite(const TQString& currentDir, const TQString& oldFileName); void replacingLoop(TQString& line, TDEListViewItem** item, bool& atLeastOneStringFound, int& occur, bool regularExpression, bool& askConfirmReplace); -- cgit v1.2.3