mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-14 20:03:29 +00:00
LibCore: Support write-only Object properties
Some properties are set and then never retrieved, e.g. GUI icon paths. Add a helper to create such properties, similar to the read-only helper.
This commit is contained in:
parent
58f5deba70
commit
746364d7c1
|
@ -311,6 +311,15 @@ requires IsBaseOf<Object, T>
|
|||
[this] { return this->getter(); }, \
|
||||
{});
|
||||
|
||||
#define REGISTER_WRITE_ONLY_STRING_PROPERTY(property_name, setter) \
|
||||
register_property( \
|
||||
property_name, \
|
||||
{}, \
|
||||
[this](auto& value) { \
|
||||
this->setter(value.to_deprecated_string()); \
|
||||
return true; \
|
||||
});
|
||||
|
||||
#define REGISTER_READONLY_SIZE_PROPERTY(property_name, getter) \
|
||||
register_property( \
|
||||
property_name, \
|
||||
|
|
|
@ -26,7 +26,12 @@ public:
|
|||
return m_setter(value);
|
||||
}
|
||||
|
||||
JsonValue get() const { return m_getter(); }
|
||||
JsonValue get() const
|
||||
{
|
||||
if (!m_getter)
|
||||
return {};
|
||||
return m_getter();
|
||||
}
|
||||
|
||||
DeprecatedString const& name() const { return m_name; }
|
||||
bool is_readonly() const { return !m_setter; }
|
||||
|
|
Loading…
Reference in a new issue