window_layouter: use modern list-model interface

Issue #4317
This commit is contained in:
Norman Feske 2023-10-27 17:02:12 +02:00 committed by Christian Helmuth
parent 47ac55e9c5
commit 58f7ed268d
4 changed files with 58 additions and 76 deletions

View File

@ -85,8 +85,8 @@ class Window_layouter::Assign : public List_model<Assign>::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<Assign>::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
*/

View File

@ -29,43 +29,21 @@ class Window_layouter::Assign_list : Noncopyable
List_model<Assign> _assignments { };
struct Update_policy : List_model<Assign>::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)

View File

@ -502,6 +502,19 @@ class Window_layouter::Window : public List_model<Window>::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_ */

View File

@ -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<Window>::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,