GUI: Use native dialogs in Windows for check file/directory selection.
This commit is contained in:
parent
f8b3a57682
commit
071c79c5cb
|
@ -25,6 +25,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
#include <QFileInfo>
|
||||||
#include "aboutdialog.h"
|
#include "aboutdialog.h"
|
||||||
#include "fileviewdialog.h"
|
#include "fileviewdialog.h"
|
||||||
#include "../src/filelister.h"
|
#include "../src/filelister.h"
|
||||||
|
@ -216,13 +217,28 @@ void MainWindow::SaveSettings()
|
||||||
|
|
||||||
void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
|
void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
|
||||||
{
|
{
|
||||||
QFileDialog dialog(this);
|
QStringList selected;
|
||||||
dialog.setDirectory(QDir(mSettings.value(tr("Check path"), "").toString()));
|
|
||||||
dialog.setFileMode(mode);
|
|
||||||
|
|
||||||
if (dialog.exec())
|
// NOTE: we use QFileDialog::getOpenFileNames() and
|
||||||
|
// QFileDialog::getExistingDirectory() because they show native Windows
|
||||||
|
// selection dialog which is a lot more usable than QT:s own dialog.
|
||||||
|
if (mode == QFileDialog::ExistingFiles)
|
||||||
|
{
|
||||||
|
selected = QFileDialog::getOpenFileNames(this,
|
||||||
|
tr("Select files to check"),
|
||||||
|
mSettings.value(tr("Check path"), "").toString());
|
||||||
|
}
|
||||||
|
else if (mode == QFileDialog::DirectoryOnly)
|
||||||
|
{
|
||||||
|
QString dir = QFileDialog::getExistingDirectory(this,
|
||||||
|
tr("Select directory to check"),
|
||||||
|
mSettings.value(tr("Check path"), "").toString());
|
||||||
|
if (!dir.isEmpty())
|
||||||
|
selected.append(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected.count() > 0)
|
||||||
{
|
{
|
||||||
QStringList selected = dialog.selectedFiles();
|
|
||||||
QStringList fileNames;
|
QStringList fileNames;
|
||||||
QString selection;
|
QString selection;
|
||||||
|
|
||||||
|
@ -236,24 +252,23 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
|
||||||
|
|
||||||
if (fileNames.isEmpty())
|
if (fileNames.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
||||||
QMessageBox msg(QMessageBox::Warning,
|
QMessageBox msg(QMessageBox::Warning,
|
||||||
tr("Cppcheck"),
|
tr("Cppcheck"),
|
||||||
tr("No suitable files found to check!"),
|
tr("No suitable files found to check!"),
|
||||||
QMessageBox::Ok,
|
QMessageBox::Ok,
|
||||||
this);
|
this);
|
||||||
|
|
||||||
msg.exec();
|
msg.exec();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mResults.CheckingStarted();
|
mResults.CheckingStarted();
|
||||||
|
|
||||||
mThread.SetFiles(RemoveUnacceptedFiles(fileNames));
|
mThread.SetFiles(RemoveUnacceptedFiles(fileNames));
|
||||||
mSettings.setValue(tr("Check path"), dialog.directory().absolutePath());
|
QFileInfo inf(fileNames[0]);
|
||||||
|
QString absDirectory = inf.absoluteDir().path();
|
||||||
|
mSettings.setValue(tr("Check path"), absDirectory);
|
||||||
EnableCheckButtons(false);
|
EnableCheckButtons(false);
|
||||||
mResults.SetCheckDirectory(dialog.directory().absolutePath());
|
mResults.SetCheckDirectory(absDirectory);
|
||||||
mThread.Check(GetCppcheckSettings(), false);
|
mThread.Check(GetCppcheckSettings(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,9 @@ protected:
|
||||||
void EnableCheckButtons(bool enable);
|
void EnableCheckButtons(bool enable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper function to open a dialog to ask user to select files to check
|
* @brief Select files/or directory to check.
|
||||||
|
* Helper function to open a dialog to ask user to select files or
|
||||||
|
* directory to check. Use native dialogs instead of QT:s own dialogs.
|
||||||
*
|
*
|
||||||
* @param mode Dialog open mode (files or directories)
|
* @param mode Dialog open mode (files or directories)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue