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
This commit is contained in:
Antonio Rodriguez 2017-04-04 23:00:55 +02:00 committed by Hugo Teso
parent af5276841a
commit 441ea351f8

View File

@ -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();
}
}