reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 9070d20b9a7cdfb99ed6fbeb6902341aa2184d7a
parent 9b1ca931e10efd9062b01e2901fe45eff0d441c0
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 18 Jan 2016 22:52:55 -0500

implement remote removal from the list

Diffstat:
Msrc/listview.cpp | 5+++++
Msrc/listview.hpp | 1+
Msrc/manager.cpp | 19+++++++++++++++++++
Msrc/manager.hpp | 2++
Msrc/reapack.cpp | 2--
Msrc/remote.cpp | 8++++++++
Msrc/remote.hpp | 7++++---
Mtest/remote.cpp | 15+++++++++++++++
8 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/src/listview.cpp b/src/listview.cpp @@ -72,6 +72,11 @@ void ListView::replaceRow(const int index, const Row &content) } } +void ListView::removeRow(const int index) +{ + ListView_DeleteItem(m_handle, index); +} + ListView::Row ListView::getRow(const int rowIndex) const { Row row(m_columnSize); diff --git a/src/listview.hpp b/src/listview.hpp @@ -45,6 +45,7 @@ public: int addRow(const Row &); Row getRow(const int index) const; void replaceRow(const int index, const Row &); + void removeRow(const int index); void clear(); bool hasSelection() const; diff --git a/src/manager.cpp b/src/manager.cpp @@ -62,6 +62,7 @@ void Manager::onCommand(WPARAM wParam, LPARAM) setRemoteEnabled(false); break; case ACTION_UNINSTALL: + uninstall(); break; case IDOK: apply(); @@ -152,6 +153,19 @@ bool Manager::isRemoteEnabled(const Remote &remote) const return it->second; } +void Manager::uninstall() +{ + const Remote &remote = currentRemote(); + m_uninstall.push_back(remote); + + const auto it = m_enableOverrides.find(remote.name()); + + if(it != m_enableOverrides.end()) + m_enableOverrides.erase(it); + + m_list->removeRow(m_list->currentIndex()); +} + void Manager::apply() { RemoteList *list = m_reapack->config()->remotes(); @@ -169,12 +183,17 @@ void Manager::apply() m_reapack->synchronize(remote); } + for(const Remote &remote : m_uninstall) { + list->remove(remote); + } + m_reapack->config()->write(); } void Manager::reset() { m_enableOverrides.clear(); + m_uninstall.clear(); } ListView::Row Manager::makeRow(const Remote &remote) const diff --git a/src/manager.hpp b/src/manager.hpp @@ -46,6 +46,7 @@ private: Remote currentRemote() const; void setRemoteEnabled(const bool); bool isRemoteEnabled(const Remote &remote) const; + void uninstall(); void apply(); void reset(); @@ -54,6 +55,7 @@ private: ListView *m_list; std::map<std::string, bool> m_enableOverrides; + std::vector<Remote> m_uninstall; }; #endif diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -224,8 +224,6 @@ Transaction *ReaPack::createTransaction() m_progress->enable(); m_progress->hide(); - - m_config->write(); }); m_transaction->onDestroy([=] { diff --git a/src/remote.cpp b/src/remote.cpp @@ -162,6 +162,14 @@ void RemoteList::add(const Remote &remote) m_remotes[remote.name()] = remote; } +void RemoteList::remove(const string &name) +{ + const auto it = m_remotes.find(name); + + if(it != m_remotes.end()) + m_remotes.erase(it); +} + Remote RemoteList::get(const string &name) const { const auto it = m_remotes.find(name); diff --git a/src/remote.hpp b/src/remote.hpp @@ -71,6 +71,10 @@ private: public: void add(const Remote &); + void remove(const Remote &remote) { remove(remote.name()); } + void remove(const std::string &name); + Remote get(const std::string &name) const; + std::vector<Remote> getEnabled() const; bool empty() const { return m_remotes.empty(); } size_t size() const { return m_remotes.size(); } @@ -82,9 +86,6 @@ public: auto end() const -> decltype(boost::adaptors::values(m_remotes).end()) { return boost::adaptors::values(m_remotes).end(); } - - Remote get(const std::string &name) const; - std::vector<Remote> getEnabled() const; }; #endif diff --git a/test/remote.cpp b/test/remote.cpp @@ -260,3 +260,18 @@ TEST_CASE("get enabled remotes", M) { REQUIRE(array.size() == 1); REQUIRE(array[0].name() == "hello"); } + +TEST_CASE("remove remote", M) { + const Remote remote{"hello", "url"}; + RemoteList list; + + list.add(remote); + REQUIRE(list.size() == 1); + REQUIRE_FALSE(list.empty()); + + list.remove(remote); + REQUIRE(list.size() == 0); + REQUIRE(list.empty()); + + list.remove("world"); // no crash +}