From 58f7ed268d21e4bbe6f005f91ee738bc554e5d79 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 27 Oct 2023 17:02:12 +0200 Subject: [PATCH] window_layouter: use modern list-model interface Issue #4317 --- repos/gems/src/app/window_layouter/assign.h | 12 +++- .../src/app/window_layouter/assign_list.h | 40 +++-------- repos/gems/src/app/window_layouter/window.h | 13 ++++ .../src/app/window_layouter/window_list.h | 69 +++++++------------ 4 files changed, 58 insertions(+), 76 deletions(-) diff --git a/repos/gems/src/app/window_layouter/assign.h b/repos/gems/src/app/window_layouter/assign.h index 8ecea234af..9cd29953ed 100644 --- a/repos/gems/src/app/window_layouter/assign.h +++ b/repos/gems/src/app/window_layouter/assign.h @@ -85,8 +85,8 @@ class Window_layouter::Assign : public List_model::Element _size = Area::from_xml(assign); } - /* - * Used by 'Assign_list::update_from_xml' + /** + * List_model::Element */ bool matches(Xml_node node) const { @@ -95,6 +95,14 @@ class Window_layouter::Assign : public List_model::Element && node.attribute_value("label_suffix", Label()) == _label_suffix; } + /** + * List_model::Element + */ + static bool type_matches(Xml_node const &node) + { + return node.has_type("assign"); + } + /** * Calculate window geometry */ diff --git a/repos/gems/src/app/window_layouter/assign_list.h b/repos/gems/src/app/window_layouter/assign_list.h index 4bc28af458..c1105db376 100644 --- a/repos/gems/src/app/window_layouter/assign_list.h +++ b/repos/gems/src/app/window_layouter/assign_list.h @@ -29,43 +29,21 @@ class Window_layouter::Assign_list : Noncopyable List_model _assignments { }; - struct Update_policy : List_model::Update_policy - { - Allocator &_alloc; - - Update_policy(Allocator &alloc) : _alloc(alloc) { } - - void destroy_element(Assign &elem) { destroy(_alloc, &elem); } - - Assign &create_element(Xml_node node) - { - return *new (_alloc) Assign(node); - } - - void update_element(Assign &assign, Xml_node node) - { - assign.update(node); - } - - static bool element_matches_xml_node(Assign const &elem, Xml_node node) - { - return elem.matches(node); - } - - bool node_is_element(Xml_node node) - { - return node.has_type("assign"); - } - }; - public: Assign_list(Allocator &alloc) : _alloc(alloc) { } void update_from_xml(Xml_node node) { - Update_policy policy(_alloc); - _assignments.update_from_xml(policy, node); + update_list_model_from_xml(_assignments, node, + + [&] (Xml_node const &node) -> Assign & { + return *new (_alloc) Assign(node); }, + + [&] (Assign &assign) { destroy(_alloc, &assign); }, + + [&] (Assign &assign, Xml_node const &node) { assign.update(node); } + ); } void assign_windows(Window_list &windows) diff --git a/repos/gems/src/app/window_layouter/window.h b/repos/gems/src/app/window_layouter/window.h index 957046995b..160a5e5bf1 100644 --- a/repos/gems/src/app/window_layouter/window.h +++ b/repos/gems/src/app/window_layouter/window.h @@ -502,6 +502,19 @@ class Window_layouter::Window : public List_model::Element _assign_member.construct(registry, *this); } + + /** + * List_model::Element + */ + bool matches(Xml_node const &node) const + { + return node.attribute_value("id", 0U) == _id; + } + + /** + * List_model::Element + */ + static bool type_matches(Xml_node const &) { return true; } }; #endif /* _WINDOW_H_ */ diff --git a/repos/gems/src/app/window_layouter/window_list.h b/repos/gems/src/app/window_layouter/window_list.h index 851b2ee1bd..b9f43f289b 100644 --- a/repos/gems/src/app/window_layouter/window_list.h +++ b/repos/gems/src/app/window_layouter/window_list.h @@ -50,54 +50,37 @@ class Window_layouter::Window_list _rom.update(); /* import window-list changes */ - Update_policy policy(*this); - _list.update_from_xml(policy, _rom.xml()); + update_list_model_from_xml(_list, _rom.xml(), + + [&] (Xml_node const &node) -> Window & + { + unsigned const id = node.attribute_value("id", 0U); + Area const initial_size = Area::from_xml(node); + + Window::Label const label = + node.attribute_value("label",Window::Label()); + + return *new (_alloc) + Window(id, label, initial_size, + _focus_history, _decorator_margins); + }, + + [&] (Window &window) { destroy(_alloc, &window); }, + + [&] (Window &w, Xml_node const &node) + { + w.client_size(Area::from_xml(node)); + w.title (node.attribute_value("title", Window::Title(""))); + w.has_alpha (node.attribute_value("has_alpha", false)); + w.hidden (node.attribute_value("hidden", false)); + w.resizeable (node.attribute_value("resizeable", false)); + } + ); /* notify main program */ _change_handler.window_list_changed(); } - struct Update_policy : List_model::Update_policy - { - Window_list &_window_list; - - Update_policy(Window_list &window_list) - : _window_list(window_list) { } - - void destroy_element(Window &elem) - { - destroy(_window_list._alloc, &elem); - } - - Window &create_element(Xml_node node) - { - unsigned const id = node.attribute_value("id", 0U); - Area const initial_size = Area::from_xml(node); - - Window::Label const label = - node.attribute_value("label",Window::Label()); - - return *new (_window_list._alloc) - Window(id, label, initial_size, - _window_list._focus_history, - _window_list._decorator_margins); - } - - void update_element(Window &win, Xml_node node) - { - win.client_size(Area::from_xml(node)); - win.title (node.attribute_value("title", Window::Title(""))); - win.has_alpha (node.attribute_value("has_alpha", false)); - win.hidden (node.attribute_value("hidden", false)); - win.resizeable (node.attribute_value("resizeable", false)); - } - - static bool element_matches_xml_node(Window const &elem, Xml_node node) - { - return elem.has_id(node.attribute_value("id", 0U)); - } - }; - public: Window_list(Env &env,