From 146df0306c8988e0c83986baf56089e9dccb0156 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 28 Jan 2025 13:28:03 -0700 Subject: [PATCH] provide new API for Gtkmm2ext to allow ActionGroup cleanup --- libs/gtkmm2ext/actions.cc | 35 ++++++++++++++++++++++++++++++ libs/gtkmm2ext/gtkmm2ext/actions.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/libs/gtkmm2ext/actions.cc b/libs/gtkmm2ext/actions.cc index d0fc849189..dcf24b4cd1 100644 --- a/libs/gtkmm2ext/actions.cc +++ b/libs/gtkmm2ext/actions.cc @@ -438,6 +438,7 @@ ActionManager::register_radio_action (RefPtr group, { string fullpath; + DEBUG_TRACE (PBD::DEBUG::Actions, string_compose ("creating action %1 in %2\n", name, group->get_name())); RefPtr act = RadioAction::create (rgroup, name, label); DEBUG_TRACE (PBD::DEBUG::Actions, string_compose ("created action %1 in %2 success: %3\n", name, group->get_name(), (bool) act)); RefPtr ract = RefPtr::cast_dynamic(act); @@ -562,3 +563,37 @@ ActionManager::get_all_actions (std::vector& paths, #endif } } + +void +ActionManager::drop_action_group (Glib::RefPtr group) +{ + /* Although ActionGroups are refcnt'ed we hold a reference on the + actions they contain in our global actions map. So an action group, if + to be deleted fully, needs to be passed in here first so that we can + drop those references. + */ + + string group_name = group->get_name(); + string::size_type group_name_length = group_name.length(); + + for (auto iter = actions.begin(); iter != actions.end(); ) { + + string::size_type pos = iter->first.find (group_name); + + if (pos == 0 && iter->first.length() >= pos+group_name_length && iter->first[group_name_length] == '/') { + iter = actions.erase (iter); + } else { + iter++; + } + } + + for (auto iter = groups.begin(); iter != groups.end(); ++iter) { + /* could use ptr equivalence here too */ + if ((*iter)->get_name() == group_name) { + groups.erase (iter); + break; + } + } + + ActionManager::ui_manager->remove_action_group (group); +} diff --git a/libs/gtkmm2ext/gtkmm2ext/actions.h b/libs/gtkmm2ext/gtkmm2ext/actions.h index 7a5921a6d4..a401eeb4ce 100644 --- a/libs/gtkmm2ext/gtkmm2ext/actions.h +++ b/libs/gtkmm2ext/gtkmm2ext/actions.h @@ -106,6 +106,8 @@ namespace ActionManager { LIBGTKMM2EXT_API extern Glib::RefPtr get_radio_action (const std::string& name, bool or_die = true); LIBGTKMM2EXT_API extern Glib::RefPtr get_radio_action (char const * group_name, char const * action_name, bool or_die = true); + LIBGTKMM2EXT_API extern void drop_action_group (Glib::RefPtr); + LIBGTKMM2EXT_API extern void get_actions (void* owner, std::vector >&); LIBGTKMM2EXT_API extern void get_all_actions (std::vector& paths,