From 071c79c5cb93405d0c88c0d0593c9fa92256d384 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Wed, 17 Jun 2009 22:35:24 +0300 Subject: [PATCH] GUI: Use native dialogs in Windows for check file/directory selection. --- gui/mainwindow.cpp | 35 +++++++++++++++++++++++++---------- gui/mainwindow.h | 4 +++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 1034f1b41..f956e53e4 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "aboutdialog.h" #include "fileviewdialog.h" #include "../src/filelister.h" @@ -216,13 +217,28 @@ void MainWindow::SaveSettings() void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) { - QFileDialog dialog(this); - dialog.setDirectory(QDir(mSettings.value(tr("Check path"), "").toString())); - dialog.setFileMode(mode); + QStringList selected; - 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; QString selection; @@ -236,24 +252,23 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) if (fileNames.isEmpty()) { - QMessageBox msg(QMessageBox::Warning, tr("Cppcheck"), tr("No suitable files found to check!"), QMessageBox::Ok, this); - msg.exec(); - return; } mResults.CheckingStarted(); 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); - mResults.SetCheckDirectory(dialog.directory().absolutePath()); + mResults.SetCheckDirectory(absDirectory); mThread.Check(GetCppcheckSettings(), false); } } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 3c7d78133..eed36b83b 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -180,7 +180,9 @@ protected: 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) */