1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 11:35:06 +00:00

WindowServer+LibGUI: Add data_type and data fields to drag operations

These fields are intended to carry the real meat of a drag operation,
and the "text" is just for what we show on screen (alongside the cursor
during the actual drag.)

The data field is just a String for now, but in the future we should
make it something more flexible.
This commit is contained in:
Andreas Kling 2019-12-19 20:09:31 +01:00
parent af7cb7ce1b
commit cfcb38dff1
13 changed files with 50 additions and 15 deletions

View file

@ -115,11 +115,16 @@ void GItemView::mousemove_event(GMouseEvent& event)
RefPtr<GraphicsBitmap> bitmap;
StringBuilder builder;
StringBuilder text_builder;
StringBuilder data_builder;
selection().for_each_index([&](auto& index) {
auto data = model()->data(index);
builder.append(data.to_string());
builder.append(" ");
auto text_data = model()->data(index);
text_builder.append(text_data.to_string());
text_builder.append(" ");
auto drag_data = model()->data(index, GModel::Role::DragData);
data_builder.append(drag_data.to_string());
data_builder.append('\n');
if (!bitmap) {
GVariant icon_data = model()->data(index, GModel::Role::Icon);
@ -128,8 +133,9 @@ void GItemView::mousemove_event(GMouseEvent& event)
}
});
drag_operation->set_text(builder.to_string());
drag_operation->set_text(text_builder.to_string());
drag_operation->set_bitmap(bitmap);
drag_operation->set_data("url-list", data_builder.to_string());
auto outcome = drag_operation->exec();
switch (outcome) {
case GDragOperation::Outcome::Accepted: