Implement more conventional behavior when opening non-existing file.

Instead of only printing a warning we now create a *named* and
empty buffer and change to the directory of the filename, so that
the file will be created in the desired location as soon as it is saved.
This commit is contained in:
Axel Kohlmeyer
2023-10-06 06:42:40 -04:00
parent fcc92b50db
commit d388ef762d
2 changed files with 8 additions and 12 deletions

View File

@ -588,22 +588,23 @@ void LammpsGui::open_file(const QString &fileName)
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, "Warning",
"Cannot open file " + path.absoluteFilePath() + ": " +
file.errorString());
return;
file.errorString() + ".\nWill create new file on saving editor buffer.");
ui->textEdit->document()->setPlainText(QString());
} else {
QTextStream in(&file);
QString text = in.readAll();
ui->textEdit->document()->setPlainText(text);
ui->textEdit->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
file.close();
}
setWindowTitle(QString("LAMMPS-GUI - " + current_file));
run_counter = 0;
QTextStream in(&file);
QString text = in.readAll();
ui->textEdit->document()->setPlainText(text);
ui->textEdit->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
ui->textEdit->document()->setModified(false);
ui->textEdit->setGroupList();
ui->textEdit->setVarNameList();
ui->textEdit->setComputeIDList();
ui->textEdit->setFixIDList();
ui->textEdit->setFileList();
file.close();
dirstatus->setText(QString(" Directory: ") + current_dir);
status->setText("Ready.");

View File

@ -32,11 +32,6 @@ int main(int argc, char *argv[])
printf("Usage: %s [-h|-help|<inputfile>]\n", argv[0]);
return 1;
}
if (!QFileInfo::exists(infile)) {
printf("Input file %s does not exist\n", infile);
printf("Usage: %s [-h|-help|<inputfile>]\n", argv[0]);
return 2;
}
}
LammpsGui w(nullptr, infile);