diff options
Diffstat (limited to 'src/gui/BreadCrumbs.cpp')
-rw-r--r-- | src/gui/BreadCrumbs.cpp | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/src/gui/BreadCrumbs.cpp b/src/gui/BreadCrumbs.cpp index 46a0757a..5bd4d30a 100644 --- a/src/gui/BreadCrumbs.cpp +++ b/src/gui/BreadCrumbs.cpp @@ -19,18 +19,21 @@ #include "App.hpp" #include "GraphView.hpp" -#include "ingen/client/SigClientInterface.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Message.hpp> +#include <ingen/URI.hpp> +#include <ingen/client/GraphModel.hpp> +#include <ingen/client/SigClientInterface.hpp> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> -#include <boost/variant/get.hpp> -#include <glibmm/signalproxy.h> #include <sigc++/adaptors/bind.h> #include <sigc++/functors/mem_fun.h> +#include <algorithm> #include <string> +#include <variant> -namespace ingen { -namespace gui { +namespace ingen::gui { using std::string; @@ -47,13 +50,13 @@ BreadCrumbs::BreadCrumbs(App& app) std::shared_ptr<GraphView> BreadCrumbs::view(const raul::Path& path) { - for (const auto& b : _breadcrumbs) { - if (b->path() == path) { - return b->view(); - } - } + const auto b = std::find_if(_breadcrumbs.begin(), + _breadcrumbs.end(), + [&path](const auto* crumb) { + return crumb->path() == path; + }); - return nullptr; + return b == _breadcrumbs.end() ? nullptr : (*b)->view(); } /** Sets up the crumbs to display `path`. @@ -65,12 +68,12 @@ void BreadCrumbs::build(const raul::Path& path, const std::shared_ptr<GraphView>& view) { - bool old_enable_signal = _enable_signal; + const bool old_enable_signal = _enable_signal; _enable_signal = false; if (!_breadcrumbs.empty() && (path.is_parent_of(_full_path) || path == _full_path)) { // Moving to a path we already contain, just switch the active button - for (const auto& b : _breadcrumbs) { + for (auto* b : _breadcrumbs) { if (b->path() == path) { b->set_active(true); if (!b->view()) { @@ -86,13 +89,12 @@ BreadCrumbs::build(const raul::Path& path, } _active_path = path; - _enable_signal = old_enable_signal; } else if (!_breadcrumbs.empty() && path.is_child_of(_full_path)) { // Moving to a child of the full path, append crumbs (preserve cache) string suffix = path.substr(_full_path.length()); - while (suffix.length() > 0) { + while (!suffix.empty()) { if (suffix[0] == '/') { suffix = suffix.substr(1); } @@ -109,7 +111,7 @@ BreadCrumbs::build(const raul::Path& path, suffix = suffix.substr(suffix.find('/') + 1); } - for (const auto& b : _breadcrumbs) { + for (auto* b : _breadcrumbs) { b->set_active(false); } _breadcrumbs.back()->set_active(true); @@ -122,7 +124,7 @@ BreadCrumbs::build(const raul::Path& path, _active_path = path; // Empty existing breadcrumbs - for (const auto& b : _breadcrumbs) { + for (auto* b : _breadcrumbs) { remove(*b); } _breadcrumbs.clear(); @@ -135,7 +137,7 @@ BreadCrumbs::build(const raul::Path& path, raul::Path working_path("/"); string suffix = path.substr(1); - while (suffix.length() > 0) { + while (!suffix.empty()) { if (suffix[0] == '/') { suffix = suffix.substr(1); } @@ -196,7 +198,7 @@ BreadCrumbs::breadcrumb_clicked(BreadCrumb* crumb) void BreadCrumbs::message(const Message& msg) { - if (const Del* const del = boost::get<Del>(&msg)) { + if (const Del* const del = std::get_if<Del>(&msg)) { object_destroyed(del->uri); } } @@ -204,15 +206,19 @@ BreadCrumbs::message(const Message& msg) void BreadCrumbs::object_destroyed(const URI& uri) { - for (auto i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) { - if ((*i)->path() == uri.c_str()) { - // Remove all crumbs after the removed one (inclusive) - for (auto j = i; j != _breadcrumbs.end(); ) { - BreadCrumb* bc = *j; - j = _breadcrumbs.erase(j); - remove(*bc); - } - break; + const auto i = std::find_if(_breadcrumbs.begin(), + _breadcrumbs.end(), + [&uri](const auto& b) { + return b->path() == uri.c_str(); + }); + + if (i != _breadcrumbs.end()) { + // Remove all crumbs after the removed one (inclusive) + for (auto j = i; j != _breadcrumbs.end();) { + BreadCrumb* const bc = *j; + + j = _breadcrumbs.erase(j); + remove(*bc); } } } @@ -220,12 +226,11 @@ BreadCrumbs::object_destroyed(const URI& uri) void BreadCrumbs::object_moved(const raul::Path& old_path, const raul::Path& new_path) { - for (const auto& b : _breadcrumbs) { + for (auto* b : _breadcrumbs) { if (b->path() == old_path) { b->set_path(new_path); } } } -} // namespace gui -} // namespace ingen +} // namespace ingen::gui |