From 441ea351f8b6ad496dd81d7e8a0f03d0932cfa03 Mon Sep 17 00:00:00 2001 From: Antonio Rodriguez Date: Tue, 4 Apr 2017 23:00:55 +0200 Subject: [PATCH] Check if file exist before opening (#82) * Check if file exist before opening When opening a file writing its path directly on the textfield, it wasn't checking if exists (also it wasn't adding it to recent list) * Update newfiledialog.cpp --- src/newfiledialog.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/newfiledialog.cpp b/src/newfiledialog.cpp index b4a386bc..abc30c87 100644 --- a/src/newfiledialog.cpp +++ b/src/newfiledialog.cpp @@ -90,11 +90,22 @@ void NewFileDialog::on_loadFileButton_clicked() { // Check that there is a file selected QString fname = ui->newFileEdit->text(); - if (fname.isEmpty()) { + QFileInfo checkfile(fname); + if (!checkfile.exists() || !checkfile.isFile()) { QMessageBox msgBox; msgBox.setText("Select a new program or a previous one\nbefore continue"); msgBox.exec(); } else { + // Add file to recent file list + QSettings settings; + QStringList files = settings.value("recentFileList").toStringList(); + files.removeAll(fname); + files.prepend(fname); + while (files.size() > MaxRecentFiles) + files.removeLast(); + + settings.setValue("recentFileList", files); + // Close dialog and open OptionsDialog close(); OptionsDialog* o = new OptionsDialog(fname); @@ -114,17 +125,7 @@ void NewFileDialog::on_newFileButton_clicked() if (!fileName.isEmpty()) { ui->newFileEdit->setText(fileName); - - // Add file to recent file list - QSettings settings; - QStringList files = settings.value("recentFileList").toStringList(); - files.removeAll(fileName); - files.prepend(fileName); - while (files.size() > MaxRecentFiles) - files.removeLast(); - - settings.setValue("recentFileList", files); - ui->loadFileButton->setFocus(); + ui->loadFileButton->setFocus(); } }