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:
Sergey Bugaev 2020-01-22 21:15:46 +03:00 committed by Andreas Kling
parent d3ce7ae0e3
commit dec95cb8b3
Notes: sideshowbarker 2024-07-19 09:52:53 +09:00
5 changed files with 14 additions and 2 deletions

View file

@ -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();