diff options
author | James Mintram <me@jamesrm.com> | 2022-04-01 23:19:18 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-04-01 21:32:27 -0700 |
commit | 14dbd280330c2ebc32ae37013656865a5fa9def1 (patch) | |
tree | dd6f1164282bd700e1ebf2a7a3866e2c1fa7fb0f /Userland/Applications/3DFileViewer | |
parent | 75d0f2c7030cc3c14833510e5c25304d1f311f8b (diff) | |
download | serenity-14dbd280330c2ebc32ae37013656865a5fa9def1.zip |
3DViewer: Add support for dropping files
Diffstat (limited to 'Userland/Applications/3DFileViewer')
-rw-r--r-- | Userland/Applications/3DFileViewer/main.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Userland/Applications/3DFileViewer/main.cpp b/Userland/Applications/3DFileViewer/main.cpp index d91163c4a6..e434be23b5 100644 --- a/Userland/Applications/3DFileViewer/main.cpp +++ b/Userland/Applications/3DFileViewer/main.cpp @@ -91,6 +91,7 @@ private: glEndList(); } + virtual void drop_event(GUI::DropEvent&) override; virtual void paint_event(GUI::PaintEvent&) override; virtual void resize_event(GUI::ResizeEvent&) override; virtual void timer_event(Core::TimerEvent&) override; @@ -123,6 +124,27 @@ private: float m_zoom = 1; }; +void GLContextWidget::drop_event(GUI::DropEvent& event) +{ + if (!event.mime_data().has_urls()) + return; + + event.accept(); + + if (event.mime_data().urls().is_empty()) + return; + + for (auto& url : event.mime_data().urls()) { + if (url.protocol() != "file") + continue; + + auto response = FileSystemAccessClient::Client::the().try_request_file(window(), url.path(), Core::OpenMode::ReadOnly); + if (response.is_error()) + return; + load_file(response.value()); + } +} + void GLContextWidget::paint_event(GUI::PaintEvent& event) { GUI::Frame::paint_event(event); |