mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-21 22:13:25 -06:00
#1294 - Adding function for getting save directory from dialog, checking if files already exsist in dir and if so ask in dialog if they should be overwritten.
This commit is contained in:
parent
eb3283041f
commit
04c9616abc
@ -44,6 +44,9 @@
|
|||||||
|
|
||||||
#include <QtOpenGL/QGLContext>
|
#include <QtOpenGL/QGLContext>
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
namespace caf {
|
namespace caf {
|
||||||
|
|
||||||
|
|
||||||
@ -161,5 +164,58 @@ QString Utils::indentString(int numSpacesToIndent, const QString& str)
|
|||||||
return retStr;
|
return retStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool Utils::getSaveDirectoryAndCheckOverwriteFiles(QString& saveDir, std::vector<QString> fileNames)
|
||||||
|
{
|
||||||
|
bool overWriteFiles = false;
|
||||||
|
saveDir = QFileDialog::getExistingDirectory(NULL, "Select save directory", saveDir);
|
||||||
|
|
||||||
|
std::vector<QString> filesToOverwrite;
|
||||||
|
for (QString fileName : fileNames)
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo(saveDir + "/" + fileName);
|
||||||
|
if (fileInfo.exists())
|
||||||
|
{
|
||||||
|
filesToOverwrite.push_back(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filesToOverwrite.size() > 0)
|
||||||
|
{
|
||||||
|
QMessageBox msgBox;
|
||||||
|
|
||||||
|
QString message = "The following files will be overwritten in the export:";
|
||||||
|
for (QString fileName : filesToOverwrite)
|
||||||
|
{
|
||||||
|
message += "\n" + saveDir + "/" + fileName;
|
||||||
|
}
|
||||||
|
msgBox.setText(message);
|
||||||
|
|
||||||
|
|
||||||
|
msgBox.setInformativeText("Do you want to continue?");
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||||
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
|
int ret = msgBox.exec();
|
||||||
|
|
||||||
|
switch (ret)
|
||||||
|
{
|
||||||
|
case QMessageBox::Ok:
|
||||||
|
overWriteFiles = true;
|
||||||
|
break;
|
||||||
|
case QMessageBox::Cancel:
|
||||||
|
overWriteFiles = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// should never be reached
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return overWriteFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace caf
|
} // namespace caf
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QString;
|
class QString;
|
||||||
class QStringList;
|
class QStringList;
|
||||||
@ -60,6 +62,8 @@ public:
|
|||||||
|
|
||||||
static QString indentString(int numSpacesToIndent, const QString& str);
|
static QString indentString(int numSpacesToIndent, const QString& str);
|
||||||
|
|
||||||
|
static bool getSaveDirectoryAndCheckOverwriteFiles(QString& defaultDir, std::vector<QString> fileNames);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user