mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-06 06:58:15 +00:00
[lua] Add stopPropagation function to the beforecommand event
Related to: https://github.com/aseprite/Attachment-System/issues/121 https://github.com/aseprite/Attachment-System/issues/127
This commit is contained in:
parent
961dee4354
commit
d329f38075
@ -145,6 +145,9 @@ private:
|
||||
std::vector<EventListeners> m_listeners;
|
||||
};
|
||||
|
||||
// Used in BeforeCommand
|
||||
static bool s_stopPropagationFlag = false;
|
||||
|
||||
class AppEvents : public Events
|
||||
, private ContextObserver {
|
||||
public:
|
||||
@ -232,8 +235,17 @@ private:
|
||||
}
|
||||
|
||||
void onBeforeCommand(CommandExecutionEvent& ev) {
|
||||
s_stopPropagationFlag = false;
|
||||
call(BeforeCommand, { { "name", ev.command()->id() },
|
||||
{ "params", ev.params() } });
|
||||
{ "params", ev.params() },
|
||||
{ "stopPropagation",
|
||||
(lua_CFunction)
|
||||
[](lua_State*) -> int {
|
||||
s_stopPropagationFlag = true;
|
||||
return 0;
|
||||
} } });
|
||||
if (s_stopPropagationFlag)
|
||||
ev.cancel();
|
||||
}
|
||||
|
||||
void onAfterCommand(CommandExecutionEvent& ev) {
|
||||
|
@ -168,6 +168,8 @@ void push_value_to_lua(lua_State* L, const std::any& value) {
|
||||
push_value_to_lua(L, *v);
|
||||
else if (auto v = std::any_cast<std::string>(&value))
|
||||
push_value_to_lua(L, *v);
|
||||
else if (auto v = std::any_cast<lua_CFunction>(&value))
|
||||
lua_pushcfunction(L, *v);
|
||||
else if (auto v = std::any_cast<const doc::Remap*>(&value))
|
||||
push_value_to_lua(L, **v);
|
||||
else if (auto v = std::any_cast<const doc::Tileset*>(&value))
|
||||
|
Loading…
Reference in New Issue
Block a user