GUI while opening FileDialog now remembers last path used

This commit is contained in:
Mateusz Pusz 2013-02-07 18:02:22 +01:00
parent 463121be71
commit 013de4857c
4 changed files with 24 additions and 17 deletions

View File

@ -59,7 +59,7 @@
#define SETTINGS_STD_POSIX "Platform Posix"
// Other settings
#define SETTINGS_CHECK_PATH "Check path"
#define SETTINGS_LAST_USED_PATH "Last used path"
#define SETTINGS_CHECK_FORCE "Check force"
#define SETTINGS_CHECK_THREADS "Check threads"
#define SETTINGS_SHOW_FULL_PATH "Show full path"
@ -82,7 +82,6 @@
#define PROGRESS_MAX 1024.0
#define SETTINGS_CHECKED_PLATFORM "Checked platform"
#define SETTINGS_LAST_PROJECT_PATH "Last project path"
/// @}
#endif

View File

@ -314,12 +314,11 @@ void MainWindow::DoCheckFiles(const QStringList &files)
mUI.mResults->CheckingStarted(fileNames.count());
mThread->SetFiles(fileNames);
QDir inf(mCurrentDirectory);
const QString checkPath = inf.canonicalPath();
mSettings->setValue(SETTINGS_CHECK_PATH, checkPath);
CheckLockDownUI(); // lock UI while checking
QDir inf(mCurrentDirectory);
const QString checkPath = inf.canonicalPath();
mUI.mResults->SetCheckDirectory(checkPath);
Settings checkSettings = GetCppcheckSettings();
@ -375,7 +374,7 @@ QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
if (mode == QFileDialog::ExistingFiles) {
selected = QFileDialog::getOpenFileNames(this,
tr("Select files to check"),
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
mSettings->value(SETTINGS_LAST_USED_PATH, "").toString());
if (selected.isEmpty())
mCurrentDirectory.clear();
else {
@ -386,7 +385,7 @@ QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
} else if (mode == QFileDialog::DirectoryOnly) {
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select directory to check"),
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
mSettings->value(SETTINGS_LAST_USED_PATH, "").toString());
if (!dir.isEmpty()) {
qDebug() << "Setting current directory to: " << dir;
mCurrentDirectory = dir;
@ -396,6 +395,8 @@ QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
}
}
mSettings->setValue(SETTINGS_LAST_USED_PATH, selected);
return selected;
}
@ -653,13 +654,14 @@ void MainWindow::OpenXML()
const QString filter(tr("XML files (*.xml)"));
QString selectedFile = QFileDialog::getOpenFileName(this,
tr("Open the report file"),
QString(),
mSettings->value(SETTINGS_LAST_USED_PATH, "").toString(),
filter,
&selectedFilter);
if (!selectedFile.isEmpty()) {
mUI.mResults->Clear(true);
mUI.mResults->ReadErrorsXml(selectedFile);
mSettings->setValue(SETTINGS_LAST_USED_PATH, selectedFile);
}
}
@ -785,7 +787,7 @@ void MainWindow::Save()
const QString filter(tr("XML files version 2 (*.xml);;XML files version 1 (*.xml);;Text files (*.txt);;CSV files (*.csv)"));
QString selectedFile = QFileDialog::getSaveFileName(this,
tr("Save the report file"),
QString(),
mSettings->value(SETTINGS_LAST_USED_PATH, "").toString(),
filter,
&selectedFilter);
@ -817,6 +819,7 @@ void MainWindow::Save()
}
mUI.mResults->Save(selectedFile, type);
mSettings->setValue(SETTINGS_LAST_USED_PATH, selectedFile);
}
}
@ -901,17 +904,16 @@ void MainWindow::OpenOnlineHelp()
void MainWindow::OpenProjectFile()
{
const QString lastPath = mSettings->value(SETTINGS_LAST_PROJECT_PATH, QString()).toString();
const QString filter = tr("Project files (*.cppcheck);;All files(*.*)");
const QString filepath = QFileDialog::getOpenFileName(this,
tr("Select Project File"),
lastPath,
mSettings->value(SETTINGS_LAST_USED_PATH, "").toString(),
filter);
if (!filepath.isEmpty()) {
const QFileInfo fi(filepath);
if (fi.exists() && fi.isFile() && fi.isReadable()) {
mSettings->setValue(SETTINGS_LAST_PROJECT_PATH, fi.path());
mSettings->setValue(SETTINGS_LAST_USED_PATH, fi.path());
LoadProjectFile(filepath);
}
}
@ -988,12 +990,14 @@ void MainWindow::NewProjectFile()
const QString filter = tr("Project files (*.cppcheck);;All files(*.*)");
QString filepath = QFileDialog::getSaveFileName(this,
tr("Select Project Filename"),
QString(),
mSettings->value(SETTINGS_LAST_USED_PATH, "").toString(),
filter);
if (filepath.isEmpty())
return;
mSettings->setValue(SETTINGS_LAST_USED_PATH, filepath);
EnableProjectActions(true);
QFileInfo inf(filepath);
const QString filename = inf.fileName();

View File

@ -690,10 +690,12 @@ QString ResultsTree::AskFileDir(const QString &file)
msgbox.setIcon(QMessageBox::Warning);
msgbox.exec();
QSettings settings;
QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"),
"",
settings.value(SETTINGS_LAST_USED_PATH, "").toString(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
mCheckPath = dir;
settings.setValue(SETTINGS_LAST_USED_PATH, dir);
return dir;
}

View File

@ -308,12 +308,14 @@ bool SettingsDialog::ShowErrorId() const
void SettingsDialog::AddIncludePath()
{
QSettings settings;
QString selectedDir = QFileDialog::getExistingDirectory(this,
tr("Select include directory"),
QString());
settings.value(SETTINGS_LAST_USED_PATH, "").toString());
if (!selectedDir.isEmpty()) {
AddIncludePath(selectedDir);
settings.setValue(SETTINGS_LAST_USED_PATH, selectedDir);
}
}