mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4589 Recursive Import Dialog: Merged Root and path filter into one field
Add "Root" label to show the root of the found files
This commit is contained in:
parent
7939e457f8
commit
8c144dce7f
@ -17,17 +17,10 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "RicRecursiveFileSearchDialog.h"
|
#include "RicRecursiveFileSearchDialog.h"
|
||||||
#include "ExportCommands/RicSnapshotViewToClipboardFeature.h"
|
|
||||||
#include "ExportCommands/RicSnapshotViewToFileFeature.h"
|
|
||||||
#include "ExportCommands/RicSnapshotFilenameGenerator.h"
|
|
||||||
|
|
||||||
#include "RiaGuiApplication.h"
|
#include "RiaGuiApplication.h"
|
||||||
#include "RiaFilePathTools.h"
|
#include "RiaFilePathTools.h"
|
||||||
|
|
||||||
#include "RimEclipseView.h"
|
|
||||||
#include "Rim3dOverlayInfoConfig.h"
|
|
||||||
|
|
||||||
#include "RiuPlotMainWindow.h"
|
|
||||||
#include "RiuTools.h"
|
#include "RiuTools.h"
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@ -48,17 +41,9 @@
|
|||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ctime>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#define DEFAULT_DIALOG_WIDTH 750
|
|
||||||
#define DEFAULT_DIALOG_INIT_HEIGHT 150
|
|
||||||
#define DEFAULT_DIALOG_FIND_HEIGHT 350
|
#define DEFAULT_DIALOG_FIND_HEIGHT 350
|
||||||
#define FIND_BUTTON_FIND_TEXT "Find"
|
#define FIND_BUTTON_FIND_TEXT "Find"
|
||||||
#define FIND_BUTTON_CANCEL_TEXT "Cancel"
|
|
||||||
#define NO_FILES_FOUND_TEXT "No files found"
|
|
||||||
#define SCANNING_DIRS_TEXT "Scanning Directories"
|
|
||||||
#define FINDING_FILES_TEXT "Finding Files"
|
|
||||||
#define FILES_FOUND_TEXT "Files found"
|
#define FILES_FOUND_TEXT "Files found"
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -80,16 +65,15 @@ RicRecursiveFileSearchDialog::RicRecursiveFileSearchDialog(QWidget* parent)
|
|||||||
: QDialog(parent, RiuTools::defaultDialogFlags())
|
: QDialog(parent, RiuTools::defaultDialogFlags())
|
||||||
{
|
{
|
||||||
// Create widgets
|
// Create widgets
|
||||||
m_rootDirLabel = new QLabel();
|
|
||||||
m_rootDirField = new QLineEdit();
|
|
||||||
m_browseButton = new QPushButton();
|
m_browseButton = new QPushButton();
|
||||||
m_pathFilterLabel = new QLabel();
|
m_pathFilterLabel = new QLabel();
|
||||||
m_pathFilterField = new QLineEdit();
|
m_pathFilterField = new QLineEdit();
|
||||||
m_fileFilterLabel = new QLabel();
|
m_fileFilterLabel = new QLabel();
|
||||||
m_fileFilterField = new QLineEdit();
|
m_fileFilterField = new QLineEdit();
|
||||||
//m_fileExtensionLabel = new QLabel();
|
|
||||||
m_effectiveFilterLabel = new QLabel();
|
m_effectiveFilterLabel = new QLabel();
|
||||||
m_effectiveFilterContentLabel = new QLabel();
|
m_effectiveFilterContentLabel = new QLabel();
|
||||||
|
m_searchRootLabel = new QLabel();
|
||||||
|
m_searchRootContentLabel = new QLabel();
|
||||||
m_findOrCancelButton = new QPushButton();
|
m_findOrCancelButton = new QPushButton();
|
||||||
m_fileListLabel = new QLabel();
|
m_fileListLabel = new QLabel();
|
||||||
m_fileListWidget = new QListWidget();
|
m_fileListWidget = new QListWidget();
|
||||||
@ -97,26 +81,32 @@ RicRecursiveFileSearchDialog::RicRecursiveFileSearchDialog(QWidget* parent)
|
|||||||
m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
// Connect to signals
|
// Connect to signals
|
||||||
connect(m_rootDirField, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterChanged(const QString&)));
|
|
||||||
connect(m_pathFilterField, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterChanged(const QString&)));
|
connect(m_pathFilterField, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterChanged(const QString&)));
|
||||||
connect(m_fileFilterField, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterChanged(const QString&)));
|
connect(m_fileFilterField, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterChanged(const QString&)));
|
||||||
|
|
||||||
connect(m_fileListWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(slotFileListCustomMenuRequested(const QPoint&)));
|
connect(m_fileListWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(slotFileListCustomMenuRequested(const QPoint&)));
|
||||||
|
|
||||||
connect(m_findOrCancelButton, SIGNAL(clicked()), this, SLOT(slotFindOrCancelButtonClicked()));
|
|
||||||
connect(m_buttons, SIGNAL(accepted()), this, SLOT(slotDialogOkClicked()));
|
|
||||||
connect(m_buttons, SIGNAL(rejected()), this, SLOT(slotDialogCancelClicked()));
|
|
||||||
connect(m_browseButton, SIGNAL(clicked()), this, SLOT(slotBrowseButtonClicked()));
|
connect(m_browseButton, SIGNAL(clicked()), this, SLOT(slotBrowseButtonClicked()));
|
||||||
|
|
||||||
// Set widget properties
|
connect(m_findOrCancelButton, SIGNAL(clicked()), this, SLOT(slotFindOrCancelButtonClicked()));
|
||||||
m_rootDirLabel->setText("Root folder");
|
|
||||||
m_pathFilterLabel->setText("Path pattern");
|
|
||||||
|
|
||||||
|
connect(m_buttons, SIGNAL(accepted()), this, SLOT(slotDialogOkClicked()));
|
||||||
|
connect(m_buttons, SIGNAL(rejected()), this, SLOT(slotDialogCancelClicked()));
|
||||||
|
|
||||||
|
// Set widget properties
|
||||||
|
m_pathFilterLabel->setText("Path pattern");
|
||||||
m_fileFilterLabel->setText("File pattern");
|
m_fileFilterLabel->setText("File pattern");
|
||||||
m_effectiveFilterLabel->setText("Effective filter");
|
m_effectiveFilterLabel->setText("Effective filter");
|
||||||
m_effectiveFilterContentLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
m_searchRootLabel->setText("Root");
|
||||||
|
m_searchRootLabel->setVisible(false);
|
||||||
|
|
||||||
m_fileListLabel->setText("Files found");
|
m_fileListLabel->setText("Files found");
|
||||||
m_fileListLabel->setVisible(false);
|
m_fileListLabel->setVisible(false);
|
||||||
|
|
||||||
|
m_effectiveFilterContentLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
|
m_searchRootContentLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
|
m_searchRootContentLabel->setVisible(false);
|
||||||
|
|
||||||
m_fileListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
m_fileListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
m_fileListWidget->setVisible(false);
|
m_fileListWidget->setVisible(false);
|
||||||
m_fileListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
m_fileListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
@ -124,6 +114,7 @@ RicRecursiveFileSearchDialog::RicRecursiveFileSearchDialog(QWidget* parent)
|
|||||||
|
|
||||||
m_browseButton->setText("...");
|
m_browseButton->setText("...");
|
||||||
m_browseButton->setFixedWidth(25);
|
m_browseButton->setFixedWidth(25);
|
||||||
|
|
||||||
m_findOrCancelButton->setText(FIND_BUTTON_FIND_TEXT);
|
m_findOrCancelButton->setText(FIND_BUTTON_FIND_TEXT);
|
||||||
m_findOrCancelButton->setFixedWidth(75);
|
m_findOrCancelButton->setFixedWidth(75);
|
||||||
m_findOrCancelButton->setDefault(true);
|
m_findOrCancelButton->setDefault(true);
|
||||||
@ -133,23 +124,24 @@ RicRecursiveFileSearchDialog::RicRecursiveFileSearchDialog(QWidget* parent)
|
|||||||
|
|
||||||
QGroupBox* inputGroup = new QGroupBox("Filter");
|
QGroupBox* inputGroup = new QGroupBox("Filter");
|
||||||
QGridLayout* inputGridLayout = new QGridLayout();
|
QGridLayout* inputGridLayout = new QGridLayout();
|
||||||
inputGridLayout->addWidget(m_rootDirLabel, 0, 0);
|
inputGridLayout->addWidget(m_pathFilterLabel, 0, 0);
|
||||||
inputGridLayout->addWidget(m_rootDirField, 0, 1);
|
inputGridLayout->addWidget(m_pathFilterField, 0, 1);
|
||||||
inputGridLayout->addWidget(m_browseButton, 0, 2);
|
inputGridLayout->addWidget(m_browseButton, 0, 2);
|
||||||
inputGridLayout->addWidget(m_pathFilterLabel, 1, 0);
|
inputGridLayout->addWidget(m_fileFilterLabel, 1, 0);
|
||||||
inputGridLayout->addWidget(m_pathFilterField, 1, 1);
|
inputGridLayout->addWidget(m_fileFilterField, 1, 1);
|
||||||
inputGridLayout->addWidget(m_fileFilterLabel, 2, 0);
|
|
||||||
inputGridLayout->addWidget(m_fileFilterField, 2, 1);
|
|
||||||
//inputGridLayout->addWidget(m_fileExtensionLabel, 2, 2);
|
|
||||||
inputGroup->setLayout(inputGridLayout);
|
inputGroup->setLayout(inputGridLayout);
|
||||||
|
|
||||||
QGroupBox* outputGroup = new QGroupBox("Files");
|
QGroupBox* outputGroup = new QGroupBox("Files");
|
||||||
QGridLayout* outputGridLayout = new QGridLayout();
|
QGridLayout* outputGridLayout = new QGridLayout();
|
||||||
outputGridLayout->addWidget(m_effectiveFilterLabel, 0, 0);
|
outputGridLayout->addWidget(m_effectiveFilterLabel, 0, 0);
|
||||||
outputGridLayout->addWidget(m_effectiveFilterContentLabel, 0, 1);
|
outputGridLayout->addWidget(m_effectiveFilterContentLabel, 0, 1);
|
||||||
|
outputGridLayout->addWidget(m_searchRootLabel, 1, 0);
|
||||||
|
outputGridLayout->addWidget(m_searchRootContentLabel, 1, 1);
|
||||||
|
|
||||||
outputGridLayout->addWidget(m_findOrCancelButton, 0, 2);
|
outputGridLayout->addWidget(m_findOrCancelButton, 0, 2);
|
||||||
outputGridLayout->addWidget(m_fileListLabel, 1, 0);
|
outputGridLayout->addWidget(m_fileListLabel, 2, 0);
|
||||||
outputGridLayout->addWidget(m_fileListWidget, 1, 1, 1, 2);
|
outputGridLayout->addWidget(m_fileListWidget, 2, 1, 1, 2);
|
||||||
outputGroup->setLayout(outputGridLayout);
|
outputGroup->setLayout(outputGridLayout);
|
||||||
|
|
||||||
dialogLayout->addWidget(inputGroup);
|
dialogLayout->addWidget(inputGroup);
|
||||||
@ -160,13 +152,17 @@ RicRecursiveFileSearchDialog::RicRecursiveFileSearchDialog(QWidget* parent)
|
|||||||
|
|
||||||
QString pathFilterHelpText =
|
QString pathFilterHelpText =
|
||||||
"The path filter uses normal wildcard file globbing, like in any unix shell. \n"
|
"The path filter uses normal wildcard file globbing, like in any unix shell. \n"
|
||||||
|
"When the filter ends with a single \"*\", however, ResInsight will \n"
|
||||||
|
"search recursively in all subdirectories from that point.\n"
|
||||||
|
"This is indicated by \"...\" in the Effective Filter label below."
|
||||||
"\n"
|
"\n"
|
||||||
"An asterix \"*\" matches any number of any characters, except the path separator.\n"
|
"An asterix \"*\" matches any number of any characters, except the path separator.\n"
|
||||||
"A question mark \"?\" matches any single character, except the path separator.\n"
|
"A question mark \"?\" matches any single character, except the path separator.\n"
|
||||||
"\n"
|
"Square brackets \"[]\" encloses a list of characters and matches one of the enclosed characters.\n"
|
||||||
"When the filter ends with a single \"*\", however, ResInsight will \n"
|
"they are also used to escape the characters *,? and []";
|
||||||
"search recursively in all subdirectories from that point.\n"
|
|
||||||
"This is indicated by \"...\" in the Effective Filter label below.";
|
|
||||||
|
// https://doc.qt.io/qt-5/qregularexpression.html#wildcardToRegularExpression
|
||||||
|
|
||||||
m_pathFilterLabel->setToolTip(pathFilterHelpText);
|
m_pathFilterLabel->setToolTip(pathFilterHelpText);
|
||||||
m_pathFilterField->setToolTip(pathFilterHelpText);
|
m_pathFilterField->setToolTip(pathFilterHelpText);
|
||||||
@ -196,20 +192,21 @@ RicRecursiveFileSearchDialog::~RicRecursiveFileSearchDialog()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RicRecursiveFileSearchDialogResult RicRecursiveFileSearchDialog::runRecursiveSearchDialog(QWidget *parent /*= 0*/,
|
RicRecursiveFileSearchDialogResult RicRecursiveFileSearchDialog::runRecursiveSearchDialog(QWidget *parent,
|
||||||
const QString &caption /*= QString()*/,
|
const QString &caption,
|
||||||
const QString &dir /*= QString()*/,
|
const QString &dir,
|
||||||
const QString &pathFilter /*= QString()*/,
|
const QString &pathFilter ,
|
||||||
const QString &fileNameFilter /*= QString()*/,
|
const QString &fileNameFilter,
|
||||||
const QStringList &fileExtensions /*= QStringList()*/)
|
const QStringList &fileExtensions)
|
||||||
{
|
{
|
||||||
QStringList files;
|
|
||||||
RicRecursiveFileSearchDialog dialog(parent);
|
RicRecursiveFileSearchDialog dialog(parent);
|
||||||
|
|
||||||
dialog.setWindowTitle(caption);
|
dialog.setWindowTitle(caption);
|
||||||
|
|
||||||
dialog.m_rootDirField->setText(QDir::toNativeSeparators(dir));
|
QString pathFilterText = dir;
|
||||||
dialog.m_pathFilterField->setText(QDir::toNativeSeparators(pathFilter));
|
RiaFilePathTools::appendSeparatorIfNo(pathFilterText);
|
||||||
|
pathFilterText += pathFilter;
|
||||||
|
dialog.m_pathFilterField->setText(QDir::toNativeSeparators(pathFilterText));
|
||||||
dialog.m_fileFilterField->setText(fileNameFilter);
|
dialog.m_fileFilterField->setText(fileNameFilter);
|
||||||
dialog.m_fileExtensions = trimLeftStrings(fileExtensions, ".");
|
dialog.m_fileExtensions = trimLeftStrings(fileExtensions, ".");
|
||||||
|
|
||||||
@ -217,22 +214,23 @@ RicRecursiveFileSearchDialogResult RicRecursiveFileSearchDialog::runRecursiveSea
|
|||||||
dialog.clearFileList();
|
dialog.clearFileList();
|
||||||
dialog.setOkButtonEnabled(false);
|
dialog.setOkButtonEnabled(false);
|
||||||
|
|
||||||
dialog.resize(DEFAULT_DIALOG_WIDTH, DEFAULT_DIALOG_INIT_HEIGHT);
|
dialog.resize(750, 150);
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
|
|
||||||
return RicRecursiveFileSearchDialogResult(dialog.result() == QDialog::Accepted,
|
return RicRecursiveFileSearchDialogResult(dialog.result() == QDialog::Accepted,
|
||||||
dialog.files(),
|
dialog.m_foundFiles,
|
||||||
dialog.rootDirWithEndSeparator(),
|
dialog.rootDirWithEndSeparator(),
|
||||||
dialog.pathFilter(),
|
dialog.pathFilterWithoutStartSeparator(),
|
||||||
dialog.fileNameFilter());
|
dialog.fileNameFilter());
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
QString RicRecursiveFileSearchDialog::cleanTextFromPathFilterField() const
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
QStringList RicRecursiveFileSearchDialog::files() const
|
|
||||||
{
|
{
|
||||||
return m_foundFiles;
|
QString pathFilterText = m_pathFilterField->text().trimmed();
|
||||||
|
pathFilterText = RiaFilePathTools::toInternalSeparator(pathFilterText);
|
||||||
|
pathFilterText = RiaFilePathTools::removeDuplicatePathSeparators(pathFilterText);
|
||||||
|
pathFilterText.replace(QString("**"), QString("*"));
|
||||||
|
return pathFilterText;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -240,20 +238,22 @@ QStringList RicRecursiveFileSearchDialog::files() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RicRecursiveFileSearchDialog::rootDirWithEndSeparator() const
|
QString RicRecursiveFileSearchDialog::rootDirWithEndSeparator() const
|
||||||
{
|
{
|
||||||
QString rootDir = RiaFilePathTools::toInternalSeparator(m_rootDirField->text().trimmed());
|
QString rootDir = this->cleanTextFromPathFilterField();
|
||||||
rootDir = RiaFilePathTools::removeDuplicatePathSeparators(rootDir);
|
rootDir = RiaFilePathTools::rootSearchPathFromSearchFilter(rootDir);
|
||||||
return RiaFilePathTools::appendSeparatorIfNo(rootDir);
|
return RiaFilePathTools::appendSeparatorIfNo(rootDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RicRecursiveFileSearchDialog::pathFilter() const
|
QString RicRecursiveFileSearchDialog::pathFilterWithoutStartSeparator() const
|
||||||
{
|
{
|
||||||
QString pathFilter = m_pathFilterField->text().trimmed();
|
QString pathFilter = this->cleanTextFromPathFilterField();
|
||||||
pathFilter = RiaFilePathTools::toInternalSeparator(pathFilter);
|
QString rootDir = RiaFilePathTools::rootSearchPathFromSearchFilter(pathFilter);
|
||||||
pathFilter.replace(QString("**"), QString("*"));
|
|
||||||
return RiaFilePathTools::removeDuplicatePathSeparators(pathFilter);
|
pathFilter.remove(0, rootDir.size());
|
||||||
|
if (pathFilter.startsWith(SEPARATOR)) pathFilter.remove(0, 1);
|
||||||
|
return pathFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -308,21 +308,22 @@ QString RicRecursiveFileSearchDialog::extensionFromFileNameFilter() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RicRecursiveFileSearchDialog::cancelPressed() const
|
void RicRecursiveFileSearchDialog::updateFileListWidget()
|
||||||
{
|
{
|
||||||
return m_cancelPressed;
|
m_fileListWidget->clear();
|
||||||
}
|
m_fileListLabel->setText(FILES_FOUND_TEXT);
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
int rootSearchPathLenght = rootDirWithEndSeparator().size();
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RicRecursiveFileSearchDialog::appendToFileList(const QString& fileName)
|
for (const auto& fileName : m_foundFiles)
|
||||||
{
|
{
|
||||||
QString itemText = fileName;
|
QString itemText = fileName;
|
||||||
itemText.remove(0, rootDirWithEndSeparator().size());
|
itemText.remove(0, rootSearchPathLenght);
|
||||||
QListWidgetItem* item = new QListWidgetItem(QDir::toNativeSeparators(itemText), m_fileListWidget);
|
QListWidgetItem* item = new QListWidgetItem(QDir::toNativeSeparators(itemText), m_fileListWidget);
|
||||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||||
item->setCheckState(Qt::Checked);
|
item->setCheckState(Qt::Checked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -353,8 +354,8 @@ void RicRecursiveFileSearchDialog::updateStatus(Status status, const QString& ex
|
|||||||
{
|
{
|
||||||
switch ( status )
|
switch ( status )
|
||||||
{
|
{
|
||||||
case SEARCHING_FOR_DIRS: newStatus = SCANNING_DIRS_TEXT; break;
|
case SEARCHING_FOR_DIRS: newStatus = "Scanning Directories"; break;
|
||||||
case SEARCHING_FOR_FILES: newStatus = FINDING_FILES_TEXT; break;
|
case SEARCHING_FOR_FILES: newStatus = "Finding Files"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int progress = 0; progress < progressLoopStep; ++progress)
|
for (int progress = 0; progress < progressLoopStep; ++progress)
|
||||||
@ -368,7 +369,7 @@ void RicRecursiveFileSearchDialog::updateStatus(Status status, const QString& ex
|
|||||||
}
|
}
|
||||||
else if (status == NO_FILES_FOUND)
|
else if (status == NO_FILES_FOUND)
|
||||||
{
|
{
|
||||||
newStatus = NO_FILES_FOUND_TEXT;
|
newStatus = "No files found";
|
||||||
}
|
}
|
||||||
|
|
||||||
lastStatusUpdate = now;
|
lastStatusUpdate = now;
|
||||||
@ -382,28 +383,18 @@ void RicRecursiveFileSearchDialog::updateStatus(Status status, const QString& ex
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QStringList RicRecursiveFileSearchDialog::findMatchingFiles()
|
QStringList RicRecursiveFileSearchDialog::findMatchingFiles()
|
||||||
{
|
{
|
||||||
if (m_rootDirField->text().isEmpty()) return QStringList();
|
if (cleanTextFromPathFilterField().isEmpty()) return QStringList();
|
||||||
|
|
||||||
//const QStringList& dirs = buildDirectoryListRecursive(rootDir());
|
|
||||||
|
|
||||||
QStringList dirs;
|
QStringList dirs;
|
||||||
|
|
||||||
QString pathFilter = this->pathFilter();
|
QString pathFilter = this->pathFilterWithoutStartSeparator();
|
||||||
if (pathFilter.startsWith(SEPARATOR)) pathFilter.remove(0, 1);
|
|
||||||
QString rootDir = this->rootDirWithEndSeparator();
|
QString rootDir = this->rootDirWithEndSeparator();
|
||||||
if (rootDir.endsWith(SEPARATOR)) rootDir.chop(1);
|
if (rootDir.endsWith(SEPARATOR)) rootDir.chop(1);
|
||||||
|
|
||||||
buildDirectoryListRecursiveSimple(rootDir, pathFilter, &dirs);
|
buildDirectoryListRecursiveSimple(rootDir, pathFilter, &dirs);
|
||||||
|
|
||||||
const QStringList& files = findFilesInDirs(dirs);
|
|
||||||
|
|
||||||
this->clearFileList();
|
return findFilesInDirs(dirs);
|
||||||
|
|
||||||
for (const auto& file : files)
|
|
||||||
{
|
|
||||||
appendToFileList(file);
|
|
||||||
}
|
|
||||||
return files;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -413,15 +404,15 @@ QStringList RicRecursiveFileSearchDialog::buildDirectoryListRecursive(const QStr
|
|||||||
{
|
{
|
||||||
QStringList allDirs;
|
QStringList allDirs;
|
||||||
|
|
||||||
if (cancelPressed()) return allDirs;
|
if (m_isCancelPressed) return allDirs;
|
||||||
|
|
||||||
QString currPathFilter = pathFilter();
|
QString currPathFilter = pathFilterWithoutStartSeparator();
|
||||||
bool subStringFilter = false;
|
bool subStringFilter = false;
|
||||||
|
|
||||||
// Optimizing for speed by a refined match at first directory level
|
// Optimizing for speed by a refined match at first directory level
|
||||||
if (level == 1)
|
if (level == 1)
|
||||||
{
|
{
|
||||||
QString pathFilter = this->pathFilter();
|
QString pathFilter = this->pathFilterWithoutStartSeparator();
|
||||||
if (!pathFilter.startsWith("*"))
|
if (!pathFilter.startsWith("*"))
|
||||||
{
|
{
|
||||||
int wildcardIndex = pathFilter.indexOf(QRegExp(QString("[*%1]").arg(SEPARATOR)));
|
int wildcardIndex = pathFilter.indexOf(QRegExp(QString("[*%1]").arg(SEPARATOR)));
|
||||||
@ -452,7 +443,7 @@ QStringList RicRecursiveFileSearchDialog::buildDirectoryListRecursive(const QStr
|
|||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
allDirs += buildDirectoryListRecursive(subDirFullPath, level + 1);
|
allDirs += buildDirectoryListRecursive(subDirFullPath, level + 1);
|
||||||
}
|
}
|
||||||
return cancelPressed() ? QStringList() : allDirs;
|
return m_isCancelPressed ? QStringList() : allDirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -465,7 +456,7 @@ void RicRecursiveFileSearchDialog::buildDirectoryListRecursiveSimple(const QStri
|
|||||||
QString currDir = currentDirFullPathNoEndSeparator;
|
QString currDir = currentDirFullPathNoEndSeparator;
|
||||||
QString pathFilter = currentPathFilterNoEndSeparator;
|
QString pathFilter = currentPathFilterNoEndSeparator;
|
||||||
|
|
||||||
if (cancelPressed())
|
if (m_isCancelPressed)
|
||||||
{
|
{
|
||||||
accumulatedDirs->clear();
|
accumulatedDirs->clear();
|
||||||
return;
|
return;
|
||||||
@ -523,7 +514,7 @@ QStringList RicRecursiveFileSearchDialog::findFilesInDirs(const QStringList& dir
|
|||||||
QDir qdir(dir);
|
QDir qdir(dir);
|
||||||
QStringList files = qdir.entryList(filters, QDir::Files);
|
QStringList files = qdir.entryList(filters, QDir::Files);
|
||||||
|
|
||||||
if (cancelPressed()) return QStringList();
|
if (m_isCancelPressed) return QStringList();
|
||||||
|
|
||||||
updateStatus(SEARCHING_FOR_FILES, qdir.absolutePath());
|
updateStatus(SEARCHING_FOR_FILES, qdir.absolutePath());
|
||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
@ -578,7 +569,7 @@ bool RicRecursiveFileSearchDialog::pathFilterMatch(const QString& pathFilter, co
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicRecursiveFileSearchDialog::updateEffectiveFilter()
|
void RicRecursiveFileSearchDialog::updateEffectiveFilter()
|
||||||
{
|
{
|
||||||
QString pathFilterText = pathFilter();
|
QString pathFilterText = pathFilterWithoutStartSeparator();
|
||||||
if (pathFilterText == "*" || pathFilterText.endsWith(QString(SEPARATOR) + "*"))
|
if (pathFilterText == "*" || pathFilterText.endsWith(QString(SEPARATOR) + "*"))
|
||||||
{
|
{
|
||||||
pathFilterText.chop(1);
|
pathFilterText.chop(1);
|
||||||
@ -594,6 +585,7 @@ void RicRecursiveFileSearchDialog::updateEffectiveFilter()
|
|||||||
|
|
||||||
// Present native separators to the user
|
// Present native separators to the user
|
||||||
m_effectiveFilterContentLabel->setText(QDir::toNativeSeparators(effFilterText));
|
m_effectiveFilterContentLabel->setText(QDir::toNativeSeparators(effFilterText));
|
||||||
|
m_searchRootContentLabel->setText(QDir::toNativeSeparators(rootDirWithEndSeparator()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -609,10 +601,11 @@ void RicRecursiveFileSearchDialog::setOkButtonEnabled(bool enabled)
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicRecursiveFileSearchDialog::warningIfInvalidCharacters()
|
void RicRecursiveFileSearchDialog::warningIfInvalidCharacters()
|
||||||
{
|
{
|
||||||
if (m_fileFilterField->text().contains(QRegExp("[\\\\/:]")))
|
if (fileNameFilter().contains(QRegExp("[\\\\/:]")))
|
||||||
{
|
{
|
||||||
QToolTip::showText(m_fileFilterField->mapToGlobal(QPoint(0, 0)), "File pattern contains invalid characters");
|
QToolTip::showText(m_fileFilterField->mapToGlobal(QPoint(0, 0)), "File pattern contains invalid characters");
|
||||||
m_effectiveFilterContentLabel->setText("(Invalid filter)");
|
m_effectiveFilterContentLabel->setText("(Invalid filter)");
|
||||||
|
m_searchRootContentLabel->setText("");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -727,18 +720,21 @@ void RicRecursiveFileSearchDialog::slotFindOrCancelButtonClicked()
|
|||||||
{
|
{
|
||||||
m_fileListLabel->setVisible(true);
|
m_fileListLabel->setVisible(true);
|
||||||
m_fileListWidget->setVisible(true);
|
m_fileListWidget->setVisible(true);
|
||||||
|
m_searchRootLabel->setVisible(true);
|
||||||
|
m_searchRootContentLabel->setVisible(true);
|
||||||
|
|
||||||
if(height() < DEFAULT_DIALOG_FIND_HEIGHT) resize(width(), DEFAULT_DIALOG_FIND_HEIGHT);
|
if(height() < DEFAULT_DIALOG_FIND_HEIGHT) resize(width(), DEFAULT_DIALOG_FIND_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_findOrCancelButton->setText(FIND_BUTTON_CANCEL_TEXT);
|
m_findOrCancelButton->setText("Cancel");
|
||||||
|
|
||||||
m_cancelPressed = false;
|
m_isCancelPressed = false;
|
||||||
m_foundFiles = findMatchingFiles();
|
m_foundFiles = findMatchingFiles();
|
||||||
|
this->updateFileListWidget();
|
||||||
|
|
||||||
m_findOrCancelButton->setText(FIND_BUTTON_FIND_TEXT);
|
m_findOrCancelButton->setText(FIND_BUTTON_FIND_TEXT);
|
||||||
|
|
||||||
if (m_cancelPressed)
|
if (m_isCancelPressed)
|
||||||
{
|
{
|
||||||
clearFileList();
|
clearFileList();
|
||||||
}
|
}
|
||||||
@ -756,7 +752,7 @@ void RicRecursiveFileSearchDialog::slotFindOrCancelButtonClicked()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_cancelPressed = true;
|
m_isCancelPressed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,7 +781,7 @@ void RicRecursiveFileSearchDialog::slotDialogOkClicked()
|
|||||||
void RicRecursiveFileSearchDialog::slotDialogCancelClicked()
|
void RicRecursiveFileSearchDialog::slotDialogCancelClicked()
|
||||||
{
|
{
|
||||||
m_foundFiles = QStringList();
|
m_foundFiles = QStringList();
|
||||||
m_cancelPressed = true;
|
m_isCancelPressed = true;
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -794,8 +790,10 @@ void RicRecursiveFileSearchDialog::slotDialogCancelClicked()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicRecursiveFileSearchDialog::slotBrowseButtonClicked()
|
void RicRecursiveFileSearchDialog::slotBrowseButtonClicked()
|
||||||
{
|
{
|
||||||
QString folder = QFileDialog::getExistingDirectory(this, "Select root folder", m_rootDirField->text());
|
QString folder = QFileDialog::getExistingDirectory(this, "Select folder", rootDirWithEndSeparator());
|
||||||
if(!folder.isEmpty()) m_rootDirField->setText(QDir::toNativeSeparators(folder));
|
RiaFilePathTools::appendSeparatorIfNo(folder);
|
||||||
|
folder += "*";
|
||||||
|
if(!folder.isEmpty()) m_pathFilterField->setText(QDir::toNativeSeparators(folder));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,16 +54,15 @@ public:
|
|||||||
const QStringList& fileExtensions = QStringList());
|
const QStringList& fileExtensions = QStringList());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList files() const;
|
QString cleanTextFromPathFilterField() const;
|
||||||
QString rootDirWithEndSeparator() const;
|
QString rootDirWithEndSeparator() const;
|
||||||
QString pathFilter() const;
|
QString pathFilterWithoutStartSeparator() const;
|
||||||
QString fileNameFilter() const;
|
QString fileNameFilter() const;
|
||||||
QStringList fileExtensions() const;
|
QStringList fileExtensions() const;
|
||||||
QString fileExtensionsText() const;
|
QString fileExtensionsText() const;
|
||||||
QString extensionFromFileNameFilter() const;
|
QString extensionFromFileNameFilter() const;
|
||||||
|
|
||||||
bool cancelPressed() const;
|
void updateFileListWidget();
|
||||||
void appendToFileList(const QString& fileName);
|
|
||||||
void clearFileList();
|
void clearFileList();
|
||||||
void updateStatus(Status status, const QString& extraText = "");
|
void updateStatus(Status status, const QString& extraText = "");
|
||||||
|
|
||||||
@ -102,20 +101,20 @@ private slots:
|
|||||||
void slotBrowseButtonClicked();
|
void slotBrowseButtonClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel* m_rootDirLabel;
|
|
||||||
QLineEdit* m_rootDirField;
|
|
||||||
QPushButton* m_browseButton;
|
|
||||||
|
|
||||||
QLabel* m_pathFilterLabel;
|
QLabel* m_pathFilterLabel;
|
||||||
QLineEdit* m_pathFilterField;
|
QLineEdit* m_pathFilterField;
|
||||||
|
QPushButton* m_browseButton;
|
||||||
|
|
||||||
QLabel* m_fileFilterLabel;
|
QLabel* m_fileFilterLabel;
|
||||||
QLineEdit* m_fileFilterField;
|
QLineEdit* m_fileFilterField;
|
||||||
//QLabel* m_fileExtensionLabel;
|
|
||||||
|
|
||||||
QLabel* m_effectiveFilterLabel;
|
QLabel* m_effectiveFilterLabel;
|
||||||
QLabel* m_effectiveFilterContentLabel;
|
QLabel* m_effectiveFilterContentLabel;
|
||||||
|
|
||||||
|
QLabel* m_searchRootLabel;
|
||||||
|
QLabel* m_searchRootContentLabel;
|
||||||
|
|
||||||
QLabel* m_fileListLabel;
|
QLabel* m_fileListLabel;
|
||||||
QListWidget* m_fileListWidget;
|
QListWidget* m_fileListWidget;
|
||||||
|
|
||||||
@ -125,7 +124,7 @@ private:
|
|||||||
QStringList m_foundFiles;
|
QStringList m_foundFiles;
|
||||||
QStringList m_fileExtensions;
|
QStringList m_fileExtensions;
|
||||||
|
|
||||||
bool m_cancelPressed;
|
bool m_isCancelPressed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user