mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibCore+LibGUI: Add fallible versions of Widget::load_from_gml()
The existing `load_from_gml()` methods look the same as before from the outside. Inside though, they now forward to `try_load_from_gml()` which returns Error when things go wrong. It also now calls the `try_create()` factory method for Objects instead of the `construct()` one.
This commit is contained in:
parent
e58fe1cdd7
commit
b32f5dbcff
8 changed files with 73 additions and 69 deletions
|
@ -202,18 +202,18 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
// Uses IterationDecision to allow the callback to interrupt the iteration, like a for-loop break.
|
||||
template<IteratorFunction<NonnullRefPtr<Object>> Callback>
|
||||
void for_each_child_object_interruptible(Callback callback)
|
||||
template<FallibleFunction<NonnullRefPtr<Object>> Callback>
|
||||
ErrorOr<void> try_for_each_child_object(Callback callback)
|
||||
{
|
||||
for (NonnullRefPtr<Node> child : m_sub_objects) {
|
||||
// doesn't capture layout as intended, as that's behind a kv-pair
|
||||
if (is<Object>(child.ptr())) {
|
||||
auto object = static_ptr_cast<Object>(child);
|
||||
if (callback(object) == IterationDecision::Break)
|
||||
return;
|
||||
TRY(callback(object));
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
RefPtr<Object> layout_object() const
|
||||
|
|
|
@ -143,8 +143,8 @@ void AutocompleteProvider::provide_completions(Function<void(Vector<CodeComprehe
|
|||
// FIXME: Don't show properties that are already specified in the scope.
|
||||
auto registration = Core::ObjectClassRegistration::find(class_name);
|
||||
if (registration && (registration->is_derived_from(widget_class) || registration->is_derived_from(layout_class))) {
|
||||
if (auto instance = registration->construct()) {
|
||||
for (auto& it : instance->properties()) {
|
||||
if (auto instance = registration->construct(); !instance.is_error()) {
|
||||
for (auto& it : instance.value()->properties()) {
|
||||
if (!it.value->is_readonly() && it.key.matches(pattern))
|
||||
identifier_entries.empend(DeprecatedString::formatted("{}: ", it.key), partial_input_length, CodeComprehension::Language::Unspecified, it.key);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue