actions: Switch all modules over to new system

All modules now expose their actions as public static constants

Issues: The menu module no longer closes when an item is clicked (before
it would intercept any executed command and look if it matches one of
its exec commands)
This commit is contained in:
patrick96
2020-05-24 18:35:12 +02:00
committed by Patrick Ziegler
parent 816b73a95f
commit ae2350167b
31 changed files with 197 additions and 232 deletions

View File

@ -3,6 +3,7 @@
#include "drawtypes/label.hpp"
#include "utils/factory.hpp"
#include "utils/scope.hpp"
#include "utils/actions.hpp"
#include "modules/meta/base.inl"
@ -57,7 +58,7 @@ namespace modules {
m_log.trace("%s: Creating menu level item %i", name(), m_levels.back()->items.size());
auto item = factory_util::unique<menu_tree_item>();
item->label = load_label(m_conf, name(), item_param);
item->exec = m_conf.get(name(), item_param + "-exec", string{EVENT_MENU_CLOSE});
item->exec = m_conf.get(name(), item_param + "-exec", actions_util::get_action_string(*this, EVENT_CLOSE));
m_levels.back()->items.emplace_back(move(item));
}
}
@ -65,13 +66,9 @@ namespace modules {
bool menu_module::build(builder* builder, const string& tag) const {
if (tag == TAG_LABEL_TOGGLE && m_level == -1) {
builder->cmd(mousebtn::LEFT, string(EVENT_MENU_OPEN) + "0");
builder->node(m_labelopen);
builder->cmd_close();
builder->action(mousebtn::LEFT, *this, string(EVENT_OPEN) + "0", m_labelopen);
} else if (tag == TAG_LABEL_TOGGLE && m_level > -1) {
builder->cmd(mousebtn::LEFT, EVENT_MENU_CLOSE);
builder->node(m_labelclose);
builder->cmd_close();
builder->action(mousebtn::LEFT, *this, EVENT_CLOSE, m_labelclose);
} else if (tag == TAG_MENU && m_level > -1) {
auto spacing = m_formatter->get(get_format())->spacing;
//Insert separator after menu-toggle and before menu-items for expand-right=true
@ -80,9 +77,7 @@ namespace modules {
builder->space(spacing);
}
for (auto&& item : m_levels[m_level]->items) {
builder->cmd(mousebtn::LEFT, item->exec);
builder->node(item->label);
builder->cmd_close();
builder->action(mousebtn::LEFT, item->exec, item->label);
if (item != m_levels[m_level]->items.back()) {
builder->space(spacing);
if (*m_labelseparator) {
@ -101,10 +96,11 @@ namespace modules {
return true;
}
bool menu_module::input(string&& cmd) {
if (cmd.compare(0, 4, "menu") != 0 && m_level > -1) {
bool menu_module::input(string&& action) {
// TODO Figure out how to close menu when command is executed (maybe exec-N action)
if (action.compare(0, 4, "menu") != 0 && m_level > -1) {
for (auto&& item : m_levels[m_level]->items) {
if (item->exec == cmd) {
if (item->exec == action) {
m_level = -1;
break;
}
@ -113,8 +109,8 @@ namespace modules {
return false;
}
if (cmd.compare(0, strlen(EVENT_MENU_OPEN), EVENT_MENU_OPEN) == 0) {
auto level = cmd.substr(strlen(EVENT_MENU_OPEN));
if (action.compare(0, strlen(EVENT_OPEN), EVENT_OPEN) == 0) {
auto level = action.substr(strlen(EVENT_OPEN));
if (level.empty()) {
level = "0";
@ -126,7 +122,7 @@ namespace modules {
m_log.warn("%s: Cannot open unexisting menu level '%i'", name(), level);
m_level = -1;
}
} else if (cmd == EVENT_MENU_CLOSE) {
} else if (action == EVENT_CLOSE) {
m_log.info("%s: Closing menu tree", name());
m_level = -1;
} else {