mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 08:45:09 +00:00
LibGUI: Let GModel specify the drag data type
GModel subclasses can now override drag_data_type() to specify which type GAbstractView should set for drag data. The default implementation returns a null string, which disables dragging from this widget.
This commit is contained in:
parent
d3ce7ae0e3
commit
dec95cb8b3
5 changed files with 14 additions and 2 deletions
|
@ -191,7 +191,7 @@ void GAbstractView::mousedown_event(GMouseEvent& event)
|
|||
m_selection.clear();
|
||||
} else if (event.modifiers() & Mod_Ctrl) {
|
||||
m_selection.toggle(index);
|
||||
} else if (event.button() == GMouseButton::Left) {
|
||||
} else if (event.button() == GMouseButton::Left && !m_model->drag_data_type().is_null()) {
|
||||
// We might be starting a drag, so don't throw away other selected items yet.
|
||||
m_might_drag = true;
|
||||
m_selection.add(index);
|
||||
|
@ -219,6 +219,9 @@ void GAbstractView::mousemove_event(GMouseEvent& event)
|
|||
if (distance_travelled_squared <= drag_distance_threshold)
|
||||
return GScrollableWidget::mousemove_event(event);
|
||||
|
||||
auto data_type = m_model->drag_data_type();
|
||||
ASSERT(!data_type.is_null());
|
||||
|
||||
dbg() << "Initiate drag!";
|
||||
auto drag_operation = GDragOperation::construct();
|
||||
|
||||
|
@ -248,7 +251,7 @@ void GAbstractView::mousemove_event(GMouseEvent& event)
|
|||
|
||||
drag_operation->set_text(text_builder.to_string());
|
||||
drag_operation->set_bitmap(bitmap);
|
||||
drag_operation->set_data("url-list", data_builder.to_string());
|
||||
drag_operation->set_data(data_type, data_builder.to_string());
|
||||
|
||||
auto outcome = drag_operation->exec();
|
||||
|
||||
|
|
|
@ -117,6 +117,7 @@ public:
|
|||
virtual void update() override;
|
||||
virtual GModelIndex parent_index(const GModelIndex&) const override;
|
||||
virtual GModelIndex index(int row, int column = 0, const GModelIndex& parent = GModelIndex()) const override;
|
||||
virtual StringView drag_data_type() const override { return "url-list"; }
|
||||
|
||||
static String timestamp_string(time_t timestamp)
|
||||
{
|
||||
|
|
|
@ -94,6 +94,8 @@ public:
|
|||
virtual GSortOrder sort_order() const { return GSortOrder::None; }
|
||||
virtual void set_key_column_and_sort_order(int, GSortOrder) {}
|
||||
|
||||
virtual StringView drag_data_type() const { return {}; }
|
||||
|
||||
void register_view(Badge<GAbstractView>, GAbstractView&);
|
||||
void unregister_view(Badge<GAbstractView>, GAbstractView&);
|
||||
|
||||
|
|
|
@ -87,6 +87,11 @@ void GSortingProxyModel::update()
|
|||
target().update();
|
||||
}
|
||||
|
||||
StringView GSortingProxyModel::drag_data_type() const
|
||||
{
|
||||
return target().drag_data_type();
|
||||
}
|
||||
|
||||
void GSortingProxyModel::set_key_column_and_sort_order(int column, GSortOrder sort_order)
|
||||
{
|
||||
if (column == m_key_column && sort_order == m_sort_order)
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
virtual ColumnMetadata column_metadata(int) const override;
|
||||
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
||||
virtual void update() override;
|
||||
virtual StringView drag_data_type() const override;
|
||||
|
||||
virtual int key_column() const override { return m_key_column; }
|
||||
virtual GSortOrder sort_order() const override { return m_sort_order; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue