fix(menu): Close tree when item commands are invoked

This commit is contained in:
Michael Carlberg 2017-01-11 02:44:44 +01:00
parent 30f516dd7d
commit c1aa3319a1

View File

@ -86,25 +86,18 @@ namespace modules {
bool menu_module::input(string&& cmd) {
if (cmd.compare(0, 4, "menu") != 0) {
if (m_level > -1) {
for (auto&& item : m_levels[m_level]->items) {
if (item->exec == cmd) {
m_level = -1;
broadcast();
break;
}
}
}
return false;
}
// broadcast update when leaving leaving the function
auto exit_handler = scope_util::make_exit_handler<>([this]() {
if (!m_threads.empty()) {
m_log.trace("%s: Cleaning up previous broadcast threads", name());
for (auto&& thread : m_threads) {
if (thread.joinable()) {
thread.join();
}
}
m_threads.clear();
}
m_log.trace("%s: Dispatching broadcast thread", name());
m_threads.emplace_back(thread(&menu_module::broadcast, this));
});
if (cmd.compare(0, strlen(EVENT_MENU_OPEN), EVENT_MENU_OPEN) == 0) {
auto level = cmd.substr(strlen(EVENT_MENU_OPEN));
@ -121,8 +114,11 @@ namespace modules {
} else if (cmd == EVENT_MENU_CLOSE) {
m_log.info("%s: Closing menu tree", name());
m_level = -1;
} else {
return false;
}
broadcast();
return true;
}
}