From ecfdff23382c16d6772d6be89f69afafcb3491b2 Mon Sep 17 00:00:00 2001 From: anthonydo8196 Date: Mon, 19 Aug 2024 20:58:47 -0500 Subject: [PATCH] Add load most recent script menu option (#3266) --- .gitignore | Bin 323 -> 454 bytes src/platform/qt/scripting/ScriptingView.cpp | 15 ++++++++++++++- src/platform/qt/scripting/ScriptingView.h | 2 ++ src/platform/qt/scripting/ScriptingView.ui | 6 ++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fedbc461f4689076caf4b0cd451a299043c4fcdf..e9e3b3956726efab97169a7e106d812bb3e0b72f 100644 GIT binary patch literal 454 zcmZWl!EVDK4D~ru{sF1CN+tV-RoYIIs!cmr1l-0gfe4eVz3kg((qudAfS=#9{V;6Q zD+Wwt)rmZEU2XNqn6{F97s6jdf#GiJs;)Nbc_idur#z`vMEY8x|HzV2S%TbH%-}9qN3`3x9bmIoCcgX9{Q57mi`6f6DHMgp7HW zZR`gbItunCxK(bnE!K}+ZFG{^UM@UR;B36tGpno4aLC$WK|8aW-Huo@~+JTMIZY7SbdWk}K= Oq=O{a;>WXFnfw82-g}Jz literal 323 zcmYLF!EVDK488j+ka~+$vTsize)|l`v;%(jv;BCmGq0Gi zkT)la$k5rDv2@TqH0A50ak_heoq3)q1{0{Dmt06^`=L@B>^tb~!vB+hdQK(6JselectionModel(), &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()); +} \ No newline at end of file diff --git a/src/platform/qt/scripting/ScriptingView.h b/src/platform/qt/scripting/ScriptingView.h index 1f90a3f19..a62bd2314 100644 --- a/src/platform/qt/scripting/ScriptingView.h +++ b/src/platform/qt/scripting/ScriptingView.h @@ -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; diff --git a/src/platform/qt/scripting/ScriptingView.ui b/src/platform/qt/scripting/ScriptingView.ui index 8b97449b0..4d55a8707 100644 --- a/src/platform/qt/scripting/ScriptingView.ui +++ b/src/platform/qt/scripting/ScriptingView.ui @@ -98,6 +98,7 @@ + @@ -108,6 +109,11 @@ Load script... + + + + &Load most recent +