mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-06 11:12:54 +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
Notes:
sideshowbarker
2024-07-19 09:52:53 +09:00
Author: https://github.com/bugaevc
Commit: dec95cb8b3
Pull-request: https://github.com/SerenityOS/serenity/pull/1115
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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue