add support to store the 5 most recent files and add them to the file menu
This commit is contained in:
@ -8,11 +8,8 @@ LAMMPS-GUI TODO list:
|
|||||||
handle "&" continuation and multiline strings with """ like C style comments in Qt docs example
|
handle "&" continuation and multiline strings with """ like C style comments in Qt docs example
|
||||||
- add CTRL-q hotkey to log windows so you can exit the entire application (add do you really want to? dialog to this)
|
- add CTRL-q hotkey to log windows so you can exit the entire application (add do you really want to? dialog to this)
|
||||||
- add "syntax check" with enabled "-skiprun" flag
|
- add "syntax check" with enabled "-skiprun" flag
|
||||||
- add multi-tab settings dialog where certain properties can be set through customizing the LAMMPS command line
|
- need to handle "label" and "jump" commands from within ?
|
||||||
+ select Font
|
- switch processing of input to line based commands or?
|
||||||
- add list of 5(?) most recently opened/saved files to file dialog (and also write to settings state on exit) (note: must store full path!)
|
|
||||||
- need to handle "label" and "jump" commands from within
|
|
||||||
- switch processing of input to line based commands
|
|
||||||
- switch input file editor to read-only while loop is running
|
- switch input file editor to read-only while loop is running
|
||||||
|
|
||||||
# Long term ideas
|
# Long term ideas
|
||||||
|
|||||||
@ -55,6 +55,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const QString blank(" ");
|
static const QString blank(" ");
|
||||||
|
static constexpr int MAXRECENT = 5;
|
||||||
|
|
||||||
// duplicate string
|
// duplicate string
|
||||||
static char *mystrdup(const std::string &text)
|
static char *mystrdup(const std::string &text)
|
||||||
@ -72,19 +73,21 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
// enforce using the plain ASCII C locale within the GUI.
|
// enforce using the plain ASCII C locale within the GUI.
|
||||||
QLocale::setDefault(QLocale("C"));
|
QLocale::setDefault(QLocale("C"));
|
||||||
|
|
||||||
|
// register QList<QString>
|
||||||
|
qRegisterMetaTypeStreamOperators<QList<QString>>("QList<QString>");
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setCentralWidget(ui->textEdit);
|
this->setCentralWidget(ui->textEdit);
|
||||||
highlighter = new Highlighter(ui->textEdit->document());
|
highlighter = new Highlighter(ui->textEdit->document());
|
||||||
capturer = new StdCapture;
|
capturer = new StdCapture;
|
||||||
current_file.clear();
|
current_file.clear();
|
||||||
current_dir = QDir(".").absolutePath();
|
current_dir = QDir(".").absolutePath();
|
||||||
recent_files.clear();
|
|
||||||
|
|
||||||
QCoreApplication::setOrganizationName("The LAMMPS Developers");
|
QCoreApplication::setOrganizationName("The LAMMPS Developers");
|
||||||
QCoreApplication::setOrganizationDomain("lammps.org");
|
QCoreApplication::setOrganizationDomain("lammps.org");
|
||||||
QCoreApplication::setApplicationName("LAMMPS GUI");
|
QCoreApplication::setApplicationName("LAMMPS GUI");
|
||||||
|
|
||||||
// restorge and initialize settings
|
// restore and initialize settings
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
// switch configured accelerator back to "none" if needed.
|
// switch configured accelerator back to "none" if needed.
|
||||||
@ -160,6 +163,8 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
ui->textEdit->document()->setDefaultFont(text_font);
|
ui->textEdit->document()->setDefaultFont(text_font);
|
||||||
ui->textEdit->setMinimumSize(600, 400);
|
ui->textEdit->setMinimumSize(600, 400);
|
||||||
|
|
||||||
|
update_recents();
|
||||||
|
|
||||||
connect(ui->actionNew, &QAction::triggered, this, &LammpsGui::new_document);
|
connect(ui->actionNew, &QAction::triggered, this, &LammpsGui::new_document);
|
||||||
connect(ui->actionOpen, &QAction::triggered, this, &LammpsGui::open);
|
connect(ui->actionOpen, &QAction::triggered, this, &LammpsGui::open);
|
||||||
connect(ui->actionSave, &QAction::triggered, this, &LammpsGui::save);
|
connect(ui->actionSave, &QAction::triggered, this, &LammpsGui::save);
|
||||||
@ -180,6 +185,11 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
connect(ui->actionDefaults, &QAction::triggered, this, &LammpsGui::defaults);
|
connect(ui->actionDefaults, &QAction::triggered, this, &LammpsGui::defaults);
|
||||||
connect(ui->actionView_Log_Window, &QAction::triggered, this, &LammpsGui::view_log);
|
connect(ui->actionView_Log_Window, &QAction::triggered, this, &LammpsGui::view_log);
|
||||||
connect(ui->actionView_Graph_Window, &QAction::triggered, this, &LammpsGui::view_chart);
|
connect(ui->actionView_Graph_Window, &QAction::triggered, this, &LammpsGui::view_chart);
|
||||||
|
connect(ui->action_1, &QAction::triggered, this, &LammpsGui::open_recent);
|
||||||
|
connect(ui->action_2, &QAction::triggered, this, &LammpsGui::open_recent);
|
||||||
|
connect(ui->action_3, &QAction::triggered, this, &LammpsGui::open_recent);
|
||||||
|
connect(ui->action_4, &QAction::triggered, this, &LammpsGui::open_recent);
|
||||||
|
connect(ui->action_5, &QAction::triggered, this, &LammpsGui::open_recent);
|
||||||
|
|
||||||
connect(ui->textEdit->document(), &QTextDocument::modificationChanged, this,
|
connect(ui->textEdit->document(), &QTextDocument::modificationChanged, this,
|
||||||
&LammpsGui::modified);
|
&LammpsGui::modified);
|
||||||
@ -260,6 +270,66 @@ void LammpsGui::open()
|
|||||||
open_file(fileName);
|
open_file(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LammpsGui::open_recent()
|
||||||
|
{
|
||||||
|
QAction *act = qobject_cast<QAction *>(sender());
|
||||||
|
if (act) open_file(act->data().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LammpsGui::update_recents(const QString &filename)
|
||||||
|
{
|
||||||
|
QSettings settings;
|
||||||
|
recent = settings.value("recent").value<QList<QString>>();
|
||||||
|
|
||||||
|
for (int i = 0; i < recent.size(); ++i) {
|
||||||
|
QFileInfo fi(recent[i]);
|
||||||
|
if (!fi.isReadable()) {
|
||||||
|
recent.removeAt(i);
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filename.isEmpty() && !recent.contains(filename)) recent.prepend(filename);
|
||||||
|
if (recent.size() > 5) recent.removeLast();
|
||||||
|
settings.setValue("recent", QVariant::fromValue(recent));
|
||||||
|
|
||||||
|
ui->action_1->setVisible(false);
|
||||||
|
if ((recent.size() > 0) && !recent[0].isEmpty()) {
|
||||||
|
QFileInfo fi(recent[0]);
|
||||||
|
ui->action_1->setText(QString("1. ") + fi.fileName());
|
||||||
|
ui->action_1->setData(recent[0]);
|
||||||
|
ui->action_1->setVisible(true);
|
||||||
|
}
|
||||||
|
ui->action_2->setVisible(false);
|
||||||
|
if ((recent.size() > 1) && !recent[1].isEmpty()) {
|
||||||
|
QFileInfo fi(recent[1]);
|
||||||
|
ui->action_2->setText(QString("2. ") + fi.fileName());
|
||||||
|
ui->action_2->setData(recent[1]);
|
||||||
|
ui->action_2->setVisible(true);
|
||||||
|
}
|
||||||
|
ui->action_3->setVisible(false);
|
||||||
|
if ((recent.size() > 2) && !recent[2].isEmpty()) {
|
||||||
|
QFileInfo fi(recent[2]);
|
||||||
|
ui->action_3->setText(QString("3. ") + fi.fileName());
|
||||||
|
ui->action_3->setData(recent[2]);
|
||||||
|
ui->action_3->setVisible(true);
|
||||||
|
}
|
||||||
|
ui->action_4->setVisible(false);
|
||||||
|
if ((recent.size() > 3) && !recent[3].isEmpty()) {
|
||||||
|
QFileInfo fi(recent[3]);
|
||||||
|
ui->action_4->setText(QString("4. ") + fi.fileName());
|
||||||
|
ui->action_4->setData(recent[0]);
|
||||||
|
ui->action_4->setVisible(true);
|
||||||
|
}
|
||||||
|
ui->action_5->setVisible(false);
|
||||||
|
if ((recent.size() > 4) && !recent[4].isEmpty()) {
|
||||||
|
QFileInfo fi(recent[4]);
|
||||||
|
ui->action_5->setText(QString("5. ") + fi.fileName());
|
||||||
|
ui->action_5->setData(recent[0]);
|
||||||
|
ui->action_5->setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// open file and switch CWD to path of file
|
// open file and switch CWD to path of file
|
||||||
void LammpsGui::open_file(const QString &fileName)
|
void LammpsGui::open_file(const QString &fileName)
|
||||||
{
|
{
|
||||||
@ -291,6 +361,8 @@ void LammpsGui::open_file(const QString &fileName)
|
|||||||
current_dir = path.absolutePath();
|
current_dir = path.absolutePath();
|
||||||
QFile file(path.absoluteFilePath());
|
QFile file(path.absoluteFilePath());
|
||||||
|
|
||||||
|
update_recents(path.absoluteFilePath());
|
||||||
|
|
||||||
QDir::setCurrent(current_dir);
|
QDir::setCurrent(current_dir);
|
||||||
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
|
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
|
||||||
QMessageBox::warning(this, "Warning",
|
QMessageBox::warning(this, "Warning",
|
||||||
@ -310,16 +382,19 @@ void LammpsGui::open_file(const QString &fileName)
|
|||||||
|
|
||||||
void LammpsGui::write_file(const QString &fileName)
|
void LammpsGui::write_file(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFileInfo path(fileName);
|
||||||
QFileInfo path(file);
|
|
||||||
current_file = path.fileName();
|
current_file = path.fileName();
|
||||||
current_dir = path.absolutePath();
|
current_dir = path.absolutePath();
|
||||||
|
QFile file(path.absoluteFilePath());
|
||||||
|
|
||||||
if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
|
if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
|
||||||
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
|
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setWindowTitle(QString("LAMMPS-GUI - " + current_file));
|
setWindowTitle(QString("LAMMPS-GUI - " + current_file));
|
||||||
|
|
||||||
|
update_recents(path.absoluteFilePath());
|
||||||
|
|
||||||
QTextStream out(&file);
|
QTextStream out(&file);
|
||||||
QString text = ui->textEdit->toPlainText();
|
QString text = ui->textEdit->toPlainText();
|
||||||
out << text;
|
out << text;
|
||||||
|
|||||||
@ -56,12 +56,14 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void open_file(const QString &filename);
|
void open_file(const QString &filename);
|
||||||
void write_file(const QString &filename);
|
void write_file(const QString &filename);
|
||||||
|
void update_recents(const QString &filename = "");
|
||||||
void start_lammps();
|
void start_lammps();
|
||||||
void run_done();
|
void run_done();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void new_document();
|
void new_document();
|
||||||
void open();
|
void open();
|
||||||
|
void open_recent();
|
||||||
void save();
|
void save();
|
||||||
void save_as();
|
void save_as();
|
||||||
void quit();
|
void quit();
|
||||||
@ -101,10 +103,11 @@ private:
|
|||||||
|
|
||||||
QString current_file;
|
QString current_file;
|
||||||
QString current_dir;
|
QString current_dir;
|
||||||
|
QList<QString> recent;
|
||||||
|
|
||||||
LammpsWrapper lammps;
|
LammpsWrapper lammps;
|
||||||
std::string plugin_path;
|
std::string plugin_path;
|
||||||
bool is_running;
|
bool is_running;
|
||||||
QList<QString> recent_files;
|
|
||||||
std::vector<char *> lammps_args;
|
std::vector<char *> lammps_args;
|
||||||
};
|
};
|
||||||
#endif // LAMMPSGUI_H
|
#endif // LAMMPSGUI_H
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>600</width>
|
<width>600</width>
|
||||||
<height>23</height>
|
<height>24</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
@ -35,8 +35,15 @@
|
|||||||
<string>&File</string>
|
<string>&File</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionNew"/>
|
<addaction name="actionNew"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionOpen"/>
|
<addaction name="actionOpen"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="action_1"/>
|
||||||
|
<addaction name="action_2"/>
|
||||||
|
<addaction name="action_3"/>
|
||||||
|
<addaction name="action_4"/>
|
||||||
|
<addaction name="action_5"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionSave"/>
|
<addaction name="actionSave"/>
|
||||||
<addaction name="actionSave_As"/>
|
<addaction name="actionSave_As"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
@ -356,7 +363,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionView_Log_Window">
|
<action name="actionView_Log_Window">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="utilities-terminal"/>
|
<iconset theme="utilities-terminal">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Log Window</string>
|
<string>&Log Window</string>
|
||||||
@ -364,12 +372,38 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionView_Graph_Window">
|
<action name="actionView_Graph_Window">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="x-office-drawing"/>
|
<iconset theme="x-office-drawing">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Chart Window</string>
|
<string>&Chart Window</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="action_1">
|
||||||
|
<property name="text">
|
||||||
|
<string>&1.</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>&2.</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>&3.</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>&4.</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>&5.</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public:
|
|||||||
emit resultReady();
|
emit resultReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
// transfer info to worker thread
|
// transfer info to worker thread and reset LAMMPS instance
|
||||||
void setup_run(LammpsWrapper *_lammps, const char *_input)
|
void setup_run(LammpsWrapper *_lammps, const char *_input)
|
||||||
{
|
{
|
||||||
lammps = _lammps;
|
lammps = _lammps;
|
||||||
|
|||||||
Reference in New Issue
Block a user