implement auto-save on run and quit
This commit is contained in:
@ -5,7 +5,8 @@ LAMMPS-GUI TODO list:
|
||||
- figure out how widgets can be resized to fraction of available screen size.
|
||||
- figure out stacking order of frames and whether it can be more flexible
|
||||
- figure out how to avoid corrupted cached thermo data while reading it.
|
||||
- bundle LAMMPS tutorial input files
|
||||
- implement a timed "Auto-Save" feature that saves after some idle time. set timeout in Editor preferences.
|
||||
- bundle or download? LAMMPS tutorial input files
|
||||
- add a "Colors" menu to the image viewer to adjust color settings for the
|
||||
current image (unlike the defaults in the perferences). Support color by
|
||||
property (e.g. scan computes or fixes with per-atom data), define colormaps etc.
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "lammpsgui.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QEvent>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QIcon>
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include <QClipboard>
|
||||
#include <QCoreApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QFont>
|
||||
@ -154,6 +155,8 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
lammps_args.push_back(mystrdup("-log"));
|
||||
lammps_args.push_back(mystrdup("none"));
|
||||
|
||||
installEventFilter(this);
|
||||
|
||||
setWindowIcon(QIcon(":/icons/lammps-icon-128x128.png"));
|
||||
|
||||
QFont all_font("Arial", -1);
|
||||
@ -715,6 +718,7 @@ void LammpsGui::quit()
|
||||
lammpsstatus->hide();
|
||||
lammps.finalize();
|
||||
|
||||
autoSave();
|
||||
if (ui->textEdit->document()->isModified()) {
|
||||
QMessageBox msg;
|
||||
msg.setWindowTitle("Unsaved Changes");
|
||||
@ -1004,6 +1008,7 @@ void LammpsGui::do_run(bool use_buffer)
|
||||
return;
|
||||
}
|
||||
|
||||
autoSave();
|
||||
if (!use_buffer && ui->textEdit->document()->isModified()) {
|
||||
QMessageBox msg;
|
||||
msg.setWindowTitle("Unsaved Changes");
|
||||
@ -1231,6 +1236,23 @@ void LammpsGui::setDocver()
|
||||
}
|
||||
}
|
||||
|
||||
void LammpsGui::autoSave()
|
||||
{
|
||||
// no need to auto-save, if the document has no name or is not modified.
|
||||
QString fileName = current_file;
|
||||
if (fileName.isEmpty()) return;
|
||||
if (!ui->textEdit->document()->isModified()) return;
|
||||
|
||||
// check preference
|
||||
bool autosave = false;
|
||||
QSettings settings;
|
||||
settings.beginGroup("reformat");
|
||||
autosave = settings.value("autosave", false).toBool();
|
||||
settings.endGroup();
|
||||
|
||||
if (autosave) write_file(fileName);
|
||||
}
|
||||
|
||||
void LammpsGui::about()
|
||||
{
|
||||
std::string version = "This is LAMMPS-GUI version " LAMMPS_GUI_VERSION;
|
||||
@ -1505,6 +1527,13 @@ void LammpsGui::start_lammps()
|
||||
}
|
||||
}
|
||||
|
||||
bool LammpsGui::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::Close) {
|
||||
autoSave();
|
||||
}
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
// Local Variables:
|
||||
// c-basic-offset: 4
|
||||
// End:
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QGridLayout>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
@ -70,6 +71,8 @@ protected:
|
||||
void start_lammps();
|
||||
void run_done();
|
||||
void setDocver();
|
||||
void autoSave();
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
public slots:
|
||||
void quit();
|
||||
|
||||
@ -196,6 +196,8 @@ void Preferences::accept()
|
||||
if (box) settings->setValue("return", box->isChecked());
|
||||
box = tabWidget->findChild<QCheckBox *>("autoval");
|
||||
if (box) settings->setValue("automatic", box->isChecked());
|
||||
box = tabWidget->findChild<QCheckBox *>("savval");
|
||||
if (box) settings->setValue("autosave", box->isChecked());
|
||||
settings->endGroup();
|
||||
|
||||
QDialog::accept();
|
||||
@ -536,29 +538,34 @@ EditorTab::EditorTab(QSettings *_settings, QWidget *parent) : QWidget(parent), s
|
||||
auto *namelbl = new QLabel("Name width:");
|
||||
auto *retlbl = new QLabel("Reformat with 'Enter':");
|
||||
auto *autolbl = new QLabel("Automatic completion:");
|
||||
auto *savlbl = new QLabel("Auto-save on 'Run' and 'Quit':");
|
||||
auto *cmdval = new QSpinBox;
|
||||
auto *typeval = new QSpinBox;
|
||||
auto *idval = new QSpinBox;
|
||||
auto *nameval = new QSpinBox;
|
||||
auto *retval = new QCheckBox;
|
||||
auto *autoval = new QCheckBox;
|
||||
auto *savval = new QCheckBox;
|
||||
cmdval->setObjectName("cmdval");
|
||||
cmdval->setRange(1, 32);
|
||||
cmdval->setValue(settings->value("command", "16").toInt());
|
||||
cmdval->setObjectName("cmdval");
|
||||
typeval->setObjectName("typeval");
|
||||
typeval->setRange(1, 32);
|
||||
typeval->setValue(settings->value("type", "4").toInt());
|
||||
typeval->setObjectName("typeval");
|
||||
idval->setObjectName("idval");
|
||||
idval->setRange(1, 32);
|
||||
idval->setValue(settings->value("id", "8").toInt());
|
||||
idval->setObjectName("idval");
|
||||
nameval->setObjectName("nameval");
|
||||
nameval->setRange(1, 32);
|
||||
nameval->setValue(settings->value("name", "8").toInt());
|
||||
nameval->setObjectName("nameval");
|
||||
retval->setCheckState(settings->value("return", false).toBool() ? Qt::Checked : Qt::Unchecked);
|
||||
retval->setObjectName("retval");
|
||||
retval->setCheckState(settings->value("return", false).toBool() ? Qt::Checked : Qt::Unchecked);
|
||||
autoval->setObjectName("autoval");
|
||||
autoval->setCheckState(settings->value("automatic", true).toBool() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
autoval->setObjectName("autoval");
|
||||
savval->setObjectName("savval");
|
||||
savval->setCheckState(settings->value("autosave", false).toBool() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
settings->endGroup();
|
||||
|
||||
int i = 0;
|
||||
@ -575,6 +582,8 @@ EditorTab::EditorTab(QSettings *_settings, QWidget *parent) : QWidget(parent), s
|
||||
grid->addWidget(retval, i++, 1, Qt::AlignVCenter);
|
||||
grid->addWidget(autolbl, i, 0, Qt::AlignTop);
|
||||
grid->addWidget(autoval, i++, 1, Qt::AlignVCenter);
|
||||
grid->addWidget(savlbl, i, 0, Qt::AlignTop);
|
||||
grid->addWidget(savval, i++, 1, Qt::AlignVCenter);
|
||||
|
||||
grid->addItem(new QSpacerItem(100, 100, QSizePolicy::Minimum, QSizePolicy::Expanding), i, 0);
|
||||
grid->addItem(new QSpacerItem(100, 100, QSizePolicy::Minimum, QSizePolicy::Expanding), i, 1);
|
||||
|
||||
Reference in New Issue
Block a user