mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:48:11 +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:
parent
19b69741ed
commit
82559e211d
5 changed files with 95 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <AK/Function.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
#include <LibGUI/GModelSelection.h>
|
||||
#include <LibGUI/GScrollableWidget.h>
|
||||
|
||||
class GModelEditingDelegate;
|
||||
|
@ -9,6 +10,7 @@ class GModelEditingDelegate;
|
|||
class GAbstractView : public GScrollableWidget {
|
||||
C_OBJECT(GAbstractView)
|
||||
friend class GModel;
|
||||
|
||||
public:
|
||||
explicit GAbstractView(GWidget* parent);
|
||||
virtual ~GAbstractView() override;
|
||||
|
@ -17,6 +19,9 @@ public:
|
|||
GModel* model() { return m_model.ptr(); }
|
||||
const GModel* model() const { return m_model.ptr(); }
|
||||
|
||||
GModelSelection& selection() { return m_selection; }
|
||||
const GModelSelection& selection() const { return m_selection; }
|
||||
|
||||
bool is_editable() const { return m_editable; }
|
||||
void set_editable(bool editable) { m_editable = editable; }
|
||||
|
||||
|
@ -37,6 +42,8 @@ public:
|
|||
|
||||
Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate;
|
||||
|
||||
void notify_selection_changed(Badge<GModelSelection>);
|
||||
|
||||
protected:
|
||||
virtual void did_scroll() override;
|
||||
void activate(const GModelIndex&);
|
||||
|
@ -50,5 +57,6 @@ protected:
|
|||
private:
|
||||
RefPtr<GModel> m_model;
|
||||
OwnPtr<GModelEditingDelegate> m_editing_delegate;
|
||||
GModelSelection m_selection;
|
||||
bool m_activates_on_selection { false };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue