Remove the registered actions before updating the delta time keybindings (closes #2764)

This commit is contained in:
Alexander Bock
2023-06-13 19:38:00 +02:00
parent 7575be32c0
commit 07ebac5cd3
+14 -2
View File
@@ -75,7 +75,9 @@ namespace {
};
constexpr std::string_view DeltaTimeStepsGuiPath = "/Time/Simulation Speed/Steps";
}
constexpr std::string_view DeltaTimeActionPrefix = "core.time.delta_time";
} // namespace
namespace openspace {
@@ -466,6 +468,7 @@ void TimeManager::setDeltaTimeSteps(std::vector<double> deltaTimes) {
_deltaTimeSteps = std::move(deltaTimes);
_deltaTimeStepsChanged = true;
clearDeltaTimesKeybindings();
addDeltaTimesKeybindings();
}
@@ -500,7 +503,7 @@ void TimeManager::addDeltaTimesKeybindings() {
auto addDeltaTimeKeybind = [this](Key key, KeyModifier mod, double step) {
const std::string s = fmt::format("{:.0f}", step);
std::string identifier = fmt::format("core.time.delta_time.{}", s);
std::string identifier = fmt::format("{}.{}", DeltaTimeActionPrefix, s);
interaction::Action action;
action.identifier = identifier;
action.command = fmt::format("openspace.time.interpolateDeltaTime({})", s);
@@ -551,6 +554,15 @@ void TimeManager::addDeltaTimesKeybindings() {
}
void TimeManager::clearDeltaTimesKeybindings() {
// Iterate over all of the registered actions with the common prefix that we created
// in the addDeltaTimesKeybindings function
std::vector<interaction::Action> actions = global::actionManager->actions();
for (const interaction::Action& action : actions) {
if (action.identifier.starts_with(DeltaTimeActionPrefix)) {
global::actionManager->removeAction(action.identifier);
}
}
for (const KeyWithModifier& kb : _deltaTimeStepKeybindings) {
// Check if there are multiple keys bound to the same key
auto bindings = global::keybindingManager->keyBinding(kb);