2024-03-16 20:00:53 +08:00
|
|
|
#include "StarClipboardLuaBindings.hpp"
|
|
|
|
#include "StarLuaConverters.hpp"
|
2024-12-10 18:49:29 +11:00
|
|
|
#include "StarInput.hpp"
|
2024-03-16 20:00:53 +08:00
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
2024-12-10 18:49:29 +11:00
|
|
|
LuaCallbacks LuaBindings::makeClipboardCallbacks(ApplicationControllerPtr appController, bool alwaysAllow) {
|
2024-03-16 20:00:53 +08:00
|
|
|
LuaCallbacks callbacks;
|
|
|
|
|
2024-12-10 18:49:29 +11:00
|
|
|
auto available = [alwaysAllow]() { return alwaysAllow || Input::singleton().getTag("clipboard") > 0; };
|
|
|
|
|
|
|
|
callbacks.registerCallback("available", [=]() -> bool {
|
|
|
|
return available();
|
|
|
|
});
|
|
|
|
|
|
|
|
callbacks.registerCallback("hasText", [=]() -> bool {
|
|
|
|
return available() && appController->hasClipboard();
|
2024-03-17 01:52:34 +11:00
|
|
|
});
|
2024-03-16 20:00:53 +08:00
|
|
|
|
2024-12-10 18:49:29 +11:00
|
|
|
callbacks.registerCallback("getText", [=]() -> Maybe<String> {
|
|
|
|
if (!available())
|
|
|
|
return {};
|
|
|
|
else
|
|
|
|
return appController->getClipboard();
|
2024-03-16 20:00:53 +08:00
|
|
|
});
|
|
|
|
|
2024-12-10 18:49:29 +11:00
|
|
|
callbacks.registerCallback("setText", [=](String const& text) -> bool {
|
|
|
|
if (available()) {
|
|
|
|
appController->setClipboard(text);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2024-03-16 20:00:53 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return callbacks;
|
|
|
|
};
|
|
|
|
|
2024-03-17 01:52:34 +11:00
|
|
|
}
|