LibGUI: Allow dropping drags on AbstractView

You can now drop things on an AbstractView, which will ask its model if
the drag is acceptable to drop at the index where it's dropped.

If it's accepted by the model, the view will fire the on_drop hook.
This commit is contained in:
Andreas Kling 2020-02-13 21:49:14 +01:00
parent 8b3864c70a
commit f0ae353c9e
Notes: sideshowbarker 2024-07-19 09:21:33 +09:00
2 changed files with 17 additions and 0 deletions

View File

@ -326,4 +326,19 @@ void AbstractView::context_menu_event(ContextMenuEvent& event)
on_context_menu_request(index, event);
}
void AbstractView::drop_event(DropEvent& event)
{
event.accept();
if (!model())
return;
auto index = index_at_event_position(event.position());
if (!index.is_valid())
return;
if (on_drop)
on_drop(index, event);
}
}

View File

@ -67,6 +67,7 @@ public:
Function<void(const ModelIndex&)> on_activation;
Function<void(const ModelIndex&)> on_selection;
Function<void(const ModelIndex&, const ContextMenuEvent&)> on_context_menu_request;
Function<void(const ModelIndex&, const DropEvent&)> on_drop;
Function<OwnPtr<ModelEditingDelegate>(const ModelIndex&)> aid_create_editing_delegate;
@ -83,6 +84,7 @@ protected:
virtual void mouseup_event(MouseEvent&) override;
virtual void doubleclick_event(MouseEvent&) override;
virtual void context_menu_event(ContextMenuEvent&) override;
virtual void drop_event(DropEvent&) override;
virtual void did_scroll() override;
void activate(const ModelIndex&);