mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 03:09:08 +00:00
LibGUI: Add GModelSelection to help implementing multiple-select views
Each GAbstractView now has a GModelSelection backed by a simple HashTable<GModelIndex>. When the selection changes somehow, the view gets notified via the notify_selection_changed() callback. In the future it will probably make sense to move to using some kind of ranges as the internal representation instead.
This commit is contained in:
39
Libraries/LibGUI/GModelSelection.cpp
Normal file
39
Libraries/LibGUI/GModelSelection.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <LibGUI/GAbstractView.h>
|
||||
#include <LibGUI/GModelSelection.h>
|
||||
|
||||
void GModelSelection::set(const GModelIndex& index)
|
||||
{
|
||||
ASSERT(index.is_valid());
|
||||
if (m_indexes.size() == 1 && m_indexes.contains(index))
|
||||
return;
|
||||
m_indexes.clear();
|
||||
m_indexes.set(index);
|
||||
m_view.notify_selection_changed({});
|
||||
}
|
||||
|
||||
void GModelSelection::add(const GModelIndex& index)
|
||||
{
|
||||
ASSERT(index.is_valid());
|
||||
if (m_indexes.contains(index))
|
||||
return;
|
||||
m_indexes.set(index);
|
||||
m_view.notify_selection_changed({});
|
||||
}
|
||||
|
||||
bool GModelSelection::remove(const GModelIndex& index)
|
||||
{
|
||||
ASSERT(index.is_valid());
|
||||
if (!m_indexes.contains(index))
|
||||
return false;
|
||||
m_indexes.remove(index);
|
||||
m_view.notify_selection_changed({});
|
||||
return true;
|
||||
}
|
||||
|
||||
void GModelSelection::clear()
|
||||
{
|
||||
if (m_indexes.is_empty())
|
||||
return;
|
||||
m_indexes.clear();
|
||||
m_view.notify_selection_changed({});
|
||||
}
|
||||
Reference in New Issue
Block a user