diff --git a/tools/lammps-gui/TODO.md b/tools/lammps-gui/TODO.md index f9fd7b4dde..170211516e 100644 --- a/tools/lammps-gui/TODO.md +++ b/tools/lammps-gui/TODO.md @@ -3,7 +3,6 @@ LAMMPS-GUI TODO list: # Short term goals - add "Help" entry to menu bar. Should open a popup window with a one page description of how to use it. Use HTML or Markdown text. -- add dialog when exiting asking if file should be saved when it is modified, similar dialog when opening a new file - add CTRL-q hotkey to log windows so you can exit the entire application (add do you really want to? dialog to this) - add "render" dialog where a "write_dump image" can be triggered. dialog should offer options for size, zoom, rotation, colors(?) - add "syntax check" with enabled "-skiprun" flag diff --git a/tools/lammps-gui/lammpsgui.cpp b/tools/lammps-gui/lammpsgui.cpp index f88c892f7e..c997b6d950 100644 --- a/tools/lammps-gui/lammpsgui.cpp +++ b/tools/lammps-gui/lammpsgui.cpp @@ -143,6 +143,29 @@ void LammpsGui::open() // open file and switch CWD to path of file void LammpsGui::open_file(const QString &fileName) { + if (ui->textEdit->document()->isModified()) { + QMessageBox msg; + msg.setWindowTitle("Unsaved Changes"); + msg.setWindowIcon(windowIcon()); + msg.setText(QString("The buffer ") + current_file + " has changes"); + msg.setInformativeText("Do you want to save the file before opening a new file?"); + msg.setIcon(QMessageBox::Question); + msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + int rv = msg.exec(); + switch (rv) { + case QMessageBox::Yes: + save(); + break; + case QMessageBox::Cancel: + return; + break; + case QMessageBox::No: // fallthrough + default: + // do nothing + break; + } + } + QFileInfo path(fileName); current_file = path.fileName(); current_dir = path.absolutePath(); @@ -214,6 +237,28 @@ void LammpsGui::quit() lammps_python_finalize(); } #endif + if (ui->textEdit->document()->isModified()) { + QMessageBox msg; + msg.setWindowTitle("Unsaved Changes"); + msg.setWindowIcon(windowIcon()); + msg.setText(QString("The buffer ") + current_file + " has changes"); + msg.setInformativeText("Do you want to save the file before exiting?"); + msg.setIcon(QMessageBox::Question); + msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + int rv = msg.exec(); + switch (rv) { + case QMessageBox::Yes: + save(); + break; + case QMessageBox::Cancel: + return; + break; + case QMessageBox::No: // fallthrough + default: + // do nothing + break; + } + } QCoreApplication::quit(); }