Add load most recent script menu option (#3266)

This commit is contained in:
anthonydo8196 2024-08-19 20:58:47 -05:00 committed by GitHub
parent eaee4228ba
commit ecfdff2338
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 1 deletions

BIN
.gitignore vendored

Binary file not shown.

View File

@ -39,6 +39,7 @@ ScriptingView::ScriptingView(ScriptingController* controller, ConfigController*
connect(m_ui.buffers->selectionModel(), &QItemSelectionModel::currentChanged, this, &ScriptingView::selectBuffer);
connect(m_ui.load, &QAction::triggered, this, &ScriptingView::load);
connect(m_ui.loadMostRecent, &QAction::triggered, this, &ScriptingView::loadMostRecent);
connect(m_ui.reset, &QAction::triggered, controller, &ScriptingController::reset);
m_mruFiles = m_config->getMRU(ConfigController::MRU::Script);
@ -66,6 +67,10 @@ void ScriptingView::load() {
}
}
void ScriptingView::loadMostRecent() {
m_controller->loadFile(m_mruFiles.at(0));
}
void ScriptingView::controllerReset() {
selectBuffer(QModelIndex());
}
@ -105,7 +110,15 @@ void ScriptingView::updateMRU() {
m_ui.mru->clear();
for (const auto& fname : m_mruFiles) {
m_ui.mru->addAction(fname, [this, fname]() {
m_controller->loadFile(fname);
if (m_controller->loadFile(fname)) {
appendMRU(fname);
}
});
}
checkEmptyMRU();
}
void ScriptingView::checkEmptyMRU() {
m_ui.loadMostRecent->setEnabled(!m_mruFiles.isEmpty());
}

View File

@ -22,6 +22,7 @@ public:
private slots:
void submitRepl();
void load();
void loadMostRecent();
void controllerReset();
void selectBuffer(const QModelIndex& current, const QModelIndex& = QModelIndex());
@ -31,6 +32,7 @@ private:
void appendMRU(const QString&);
void updateMRU();
void checkEmptyMRU();
Ui::ScriptingView m_ui;

View File

@ -98,6 +98,7 @@
</widget>
<addaction name="load"/>
<addaction name="mru"/>
<addaction name="loadMostRecent"/>
<addaction name="separator"/>
<addaction name="reset"/>
</widget>
@ -108,6 +109,11 @@
<property name="text">
<string>Load script...</string>
</property>
</action>
<action name="loadMostRecent">
<property name="text">
<string>&amp;Load most recent</string>
</property>
</action>
<action name="reset">
<property name="text">