mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 15:36:09 -06:00
#4555 Fix errors in filter behavior.
Handle double separators Handle */ pathfilter correctly (no recursive search)
This commit is contained in:
parent
e1c061fd15
commit
cd5943a39c
@ -112,3 +112,19 @@ std::pair<QString, QString> RiaFilePathTools::toFolderAndFileName(const QString&
|
|||||||
return std::make_pair("", absFN);
|
return std::make_pair("", absFN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RiaFilePathTools::removeDuplicatePathSeparators(const QString& path)
|
||||||
|
{
|
||||||
|
QString correctedPath = path;
|
||||||
|
int len;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
len = correctedPath.size();
|
||||||
|
correctedPath.replace(QString("%1%1").arg(SEPARATOR), SEPARATOR);
|
||||||
|
} while (correctedPath.size() != len);
|
||||||
|
|
||||||
|
return correctedPath;
|
||||||
|
}
|
||||||
|
@ -40,4 +40,5 @@ public:
|
|||||||
static bool equalPaths(const QString& path1, const QString& path2);
|
static bool equalPaths(const QString& path1, const QString& path2);
|
||||||
static QString canonicalPath(const QString& path);
|
static QString canonicalPath(const QString& path);
|
||||||
static std::pair<QString, QString> toFolderAndFileName(const QString& absFileName);
|
static std::pair<QString, QString> toFolderAndFileName(const QString& absFileName);
|
||||||
|
static QString removeDuplicatePathSeparators(const QString& path);
|
||||||
};
|
};
|
||||||
|
@ -190,7 +190,7 @@ RicFileHierarchyDialogResult RicFileHierarchyDialog::runRecursiveSearchDialog(QW
|
|||||||
dialog.resize(DEFAULT_DIALOG_WIDTH, DEFAULT_DIALOG_INIT_HEIGHT);
|
dialog.resize(DEFAULT_DIALOG_WIDTH, DEFAULT_DIALOG_INIT_HEIGHT);
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
|
|
||||||
return RicFileHierarchyDialogResult(dialog.result() == QDialog::Accepted, dialog.files(), dialog.rootDir(), dialog.pathFilter(), dialog.fileNameFilter());
|
return RicFileHierarchyDialogResult(dialog.result() == QDialog::Accepted, dialog.files(), dialog.rootDirWithEndSeparator(), dialog.pathFilter(), dialog.fileNameFilter());
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -204,9 +204,10 @@ QStringList RicFileHierarchyDialog::files() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RicFileHierarchyDialog::rootDir() const
|
QString RicFileHierarchyDialog::rootDirWithEndSeparator() const
|
||||||
{
|
{
|
||||||
QString rootDir = RiaFilePathTools::toInternalSeparator(m_rootDir->text().trimmed());
|
QString rootDir = RiaFilePathTools::toInternalSeparator(m_rootDir->text().trimmed());
|
||||||
|
rootDir = RiaFilePathTools::removeDuplicatePathSeparators(rootDir);
|
||||||
return RiaFilePathTools::appendSeparatorIfNo(rootDir);
|
return RiaFilePathTools::appendSeparatorIfNo(rootDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +216,10 @@ QString RicFileHierarchyDialog::rootDir() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RicFileHierarchyDialog::pathFilter() const
|
QString RicFileHierarchyDialog::pathFilter() const
|
||||||
{
|
{
|
||||||
return RiaFilePathTools::toInternalSeparator(m_pathFilter->text().trimmed()).replace(QString("**"), QString("*"));
|
QString pathFilter = m_pathFilter->text().trimmed();
|
||||||
|
pathFilter = RiaFilePathTools::toInternalSeparator(pathFilter);
|
||||||
|
pathFilter.replace(QString("**"), QString("*"));
|
||||||
|
return RiaFilePathTools::removeDuplicatePathSeparators(pathFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -281,7 +285,7 @@ bool RicFileHierarchyDialog::cancelPressed() const
|
|||||||
void RicFileHierarchyDialog::appendToFileList(const QString& fileName)
|
void RicFileHierarchyDialog::appendToFileList(const QString& fileName)
|
||||||
{
|
{
|
||||||
QString itemText = fileName;
|
QString itemText = fileName;
|
||||||
itemText.remove(0, rootDir().size());
|
itemText.remove(0, rootDirWithEndSeparator().size());
|
||||||
QListWidgetItem* item = new QListWidgetItem(QDir::toNativeSeparators(itemText), m_fileList);
|
QListWidgetItem* item = new QListWidgetItem(QDir::toNativeSeparators(itemText), m_fileList);
|
||||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||||
item->setCheckState(Qt::Checked);
|
item->setCheckState(Qt::Checked);
|
||||||
@ -350,7 +354,12 @@ QStringList RicFileHierarchyDialog::findMatchingFiles()
|
|||||||
|
|
||||||
QStringList dirs;
|
QStringList dirs;
|
||||||
|
|
||||||
buildDirectoryListRecursiveSimple(this->rootDir(), this->pathFilter(), &dirs);
|
QString pathFilter = this->pathFilter();
|
||||||
|
if (pathFilter.startsWith(SEPARATOR)) pathFilter.remove(0, 1);
|
||||||
|
QString rootDir = this->rootDirWithEndSeparator();
|
||||||
|
if (rootDir.endsWith(SEPARATOR)) rootDir.chop(1);
|
||||||
|
|
||||||
|
buildDirectoryListRecursiveSimple(rootDir, pathFilter, &dirs);
|
||||||
|
|
||||||
const QStringList& files = findFilesInDirs(dirs);
|
const QStringList& files = findFilesInDirs(dirs);
|
||||||
|
|
||||||
@ -390,7 +399,7 @@ QStringList RicFileHierarchyDialog::buildDirectoryListRecursive(const QString& c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString currRelPath = RiaFilePathTools::relativePath(rootDir(), currentDir);
|
QString currRelPath = RiaFilePathTools::relativePath(rootDirWithEndSeparator(), currentDir);
|
||||||
if (pathFilterMatch(currPathFilter, currRelPath))
|
if (pathFilterMatch(currPathFilter, currRelPath))
|
||||||
{
|
{
|
||||||
allDirs.push_back(currentDir);
|
allDirs.push_back(currentDir);
|
||||||
@ -415,15 +424,12 @@ QStringList RicFileHierarchyDialog::buildDirectoryListRecursive(const QString& c
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicFileHierarchyDialog::buildDirectoryListRecursiveSimple(const QString& currentDir,
|
void RicFileHierarchyDialog::buildDirectoryListRecursiveSimple(const QString& currentDirFullPathNoEndSeparator,
|
||||||
const QString& currentPathFilter,
|
const QString& currentPathFilterNoEndSeparator,
|
||||||
QStringList* accumulatedDirs)
|
QStringList* accumulatedDirs)
|
||||||
{
|
{
|
||||||
QString currDir = currentDir;
|
QString currDir = currentDirFullPathNoEndSeparator;
|
||||||
QString pathFilter = currentPathFilter;
|
QString pathFilter = currentPathFilterNoEndSeparator;
|
||||||
if (pathFilter.startsWith(SEPARATOR)) pathFilter.remove(0, 1);
|
|
||||||
if (pathFilter.endsWith(SEPARATOR)) pathFilter.chop(1);
|
|
||||||
if (currDir.endsWith(SEPARATOR)) currDir.chop(1);
|
|
||||||
|
|
||||||
if (cancelPressed())
|
if (cancelPressed())
|
||||||
{
|
{
|
||||||
@ -436,15 +442,15 @@ void RicFileHierarchyDialog::buildDirectoryListRecursiveSimple(const QString& cu
|
|||||||
|
|
||||||
if (pathFilter.isEmpty())
|
if (pathFilter.isEmpty())
|
||||||
{
|
{
|
||||||
accumulatedDirs->push_back(currentDir);
|
accumulatedDirs->push_back(currentDirFullPathNoEndSeparator);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList pathFilters = pathFilter.split(SEPARATOR);
|
QStringList pathFilterPartList = pathFilter.split(SEPARATOR);
|
||||||
QDir qdir(currDir, pathFilters[0], QDir::NoSort, QDir::Dirs | QDir::NoDotAndDotDot);
|
QDir qdir(currDir, pathFilterPartList[0], QDir::NoSort, QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
QStringList subDirs = qdir.entryList();
|
QStringList subDirs = qdir.entryList();
|
||||||
|
|
||||||
if (pathFilters.size() == 1 && pathFilters[0] == "*")
|
if (pathFilterPartList.size() == 1 && pathFilterPartList[0] == "*")
|
||||||
{
|
{
|
||||||
accumulatedDirs->push_back(currDir);
|
accumulatedDirs->push_back(currDir);
|
||||||
}
|
}
|
||||||
@ -454,13 +460,13 @@ void RicFileHierarchyDialog::buildDirectoryListRecursiveSimple(const QString& cu
|
|||||||
QString fullPath = qdir.absoluteFilePath(subDir);
|
QString fullPath = qdir.absoluteFilePath(subDir);
|
||||||
QString nextPathFilter;
|
QString nextPathFilter;
|
||||||
|
|
||||||
if (pathFilters.size() == 1 && pathFilters[0] == "*")
|
if (pathFilterPartList.size() == 1 && pathFilterPartList[0] == "*")
|
||||||
{
|
{
|
||||||
nextPathFilter = "*";
|
nextPathFilter = "*";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto pf = pathFilters;
|
auto pf = pathFilterPartList;
|
||||||
pf.removeFirst();
|
pf.removeFirst();
|
||||||
nextPathFilter = pf.join(SEPARATOR);
|
nextPathFilter = pf.join(SEPARATOR);
|
||||||
}
|
}
|
||||||
@ -545,18 +551,12 @@ void RicFileHierarchyDialog::updateEffectiveFilter()
|
|||||||
pathFilterText = pathFilterText + "...";
|
pathFilterText = pathFilterText + "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString effFilterText = QString("%1/%2/%3")
|
QString effFilterText = QString("%1%2/%3")
|
||||||
.arg(rootDir())
|
.arg(rootDirWithEndSeparator())
|
||||||
.arg(pathFilterText)
|
.arg(pathFilterText)
|
||||||
.arg(createFileNameFilterList().join("|"));
|
.arg(createFileNameFilterList().join("|"));
|
||||||
|
|
||||||
// Remove duplicate separators
|
effFilterText = RiaFilePathTools::removeDuplicatePathSeparators(effFilterText);
|
||||||
int len;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
len = effFilterText.size();
|
|
||||||
effFilterText.replace(QString("%1%1").arg(SEPARATOR), SEPARATOR);
|
|
||||||
} while (effFilterText.size() != len);
|
|
||||||
|
|
||||||
// Present native separators to the user
|
// Present native separators to the user
|
||||||
m_effectiveFilter->setText(QDir::toNativeSeparators(effFilterText));
|
m_effectiveFilter->setText(QDir::toNativeSeparators(effFilterText));
|
||||||
@ -721,7 +721,7 @@ void RicFileHierarchyDialog::slotDialogOkClicked()
|
|||||||
const QListWidgetItem* item = m_fileList->item(i);
|
const QListWidgetItem* item = m_fileList->item(i);
|
||||||
if ((item->flags() & Qt::ItemIsUserCheckable) != 0 && item->checkState())
|
if ((item->flags() & Qt::ItemIsUserCheckable) != 0 && item->checkState())
|
||||||
{
|
{
|
||||||
m_files.push_back(rootDir() + RiaFilePathTools::toInternalSeparator(item->text()));
|
m_files.push_back(rootDirWithEndSeparator() + RiaFilePathTools::toInternalSeparator(item->text()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accept();
|
accept();
|
||||||
|
@ -55,7 +55,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList files() const;
|
QStringList files() const;
|
||||||
QString rootDir() const;
|
QString rootDirWithEndSeparator() const;
|
||||||
QString pathFilter() const;
|
QString pathFilter() const;
|
||||||
QString fileNameFilter() const;
|
QString fileNameFilter() const;
|
||||||
QStringList fileExtensions() const;
|
QStringList fileExtensions() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user