diff options
author | Karol Kosek <krkk@serenityos.org> | 2022-12-29 12:23:32 +0100 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-12-29 10:22:49 -0500 |
commit | 780d46c42499d085e0d230d02071c675a1c9aa1c (patch) | |
tree | 761fee6e52e7721e056a8c04b6d6d1a763d32e83 | |
parent | feb0eb930971c49f2e9626435aa44ea0a01300a1 (diff) | |
download | serenity-780d46c42499d085e0d230d02071c675a1c9aa1c.zip |
Presenter: Accept file drops
-rw-r--r-- | Userland/Applications/Presenter/PresenterWidget.cpp | 22 | ||||
-rw-r--r-- | Userland/Applications/Presenter/PresenterWidget.h | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Userland/Applications/Presenter/PresenterWidget.cpp b/Userland/Applications/Presenter/PresenterWidget.cpp index 66c112af15..bfd0b8101c 100644 --- a/Userland/Applications/Presenter/PresenterWidget.cpp +++ b/Userland/Applications/Presenter/PresenterWidget.cpp @@ -8,6 +8,7 @@ #include "LibGUI/MessageBox.h" #include "Presentation.h" #include <AK/Format.h> +#include <LibCore/MimeData.h> #include <LibFileSystemAccessClient/Client.h> #include <LibGUI/Action.h> #include <LibGUI/Event.h> @@ -132,3 +133,24 @@ void PresenterWidget::paint_event([[maybe_unused]] GUI::PaintEvent& event) m_current_presentation->paint(painter); } + +void PresenterWidget::drag_enter_event(GUI::DragEvent& event) +{ + auto const& mime_types = event.mime_types(); + if (mime_types.contains_slow("text/uri-list")) + event.accept(); +} + +void PresenterWidget::drop_event(GUI::DropEvent& event) +{ + event.accept(); + + if (event.mime_data().has_urls()) { + auto urls = event.mime_data().urls(); + if (urls.is_empty()) + return; + + window()->move_to_front(); + set_file(urls.first().path()); + } +} diff --git a/Userland/Applications/Presenter/PresenterWidget.h b/Userland/Applications/Presenter/PresenterWidget.h index af497a6afa..a3a5196748 100644 --- a/Userland/Applications/Presenter/PresenterWidget.h +++ b/Userland/Applications/Presenter/PresenterWidget.h @@ -30,6 +30,8 @@ public: protected: virtual void paint_event(GUI::PaintEvent&) override; virtual void keydown_event(GUI::KeyEvent&) override; + virtual void drag_enter_event(GUI::DragEvent&) override; + virtual void drop_event(GUI::DropEvent&) override; private: OwnPtr<Presentation> m_current_presentation; |