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:
@ -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;
|
||||
}
|
||||
setWindowTitle(QString("LAMMPS-GUI - " + current_file));
|
||||
run_counter = 0;
|
||||
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;
|
||||
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.");
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user