diff options
Diffstat (limited to 'Userland/DevTools/GMLPlayground')
-rw-r--r-- | Userland/DevTools/GMLPlayground/MainWidget.cpp | 30 | ||||
-rw-r--r-- | Userland/DevTools/GMLPlayground/MainWidget.h | 3 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Userland/DevTools/GMLPlayground/MainWidget.cpp b/Userland/DevTools/GMLPlayground/MainWidget.cpp index 02ed2d7802..fd8c9a0e35 100644 --- a/Userland/DevTools/GMLPlayground/MainWidget.cpp +++ b/Userland/DevTools/GMLPlayground/MainWidget.cpp @@ -303,3 +303,33 @@ GUI::Window::CloseRequestDecision MainWidget::request_close() return GUI::Window::CloseRequestDecision::StayOpen; } + +void MainWidget::drag_enter_event(GUI::DragEvent& event) +{ + auto const& mime_types = event.mime_types(); + if (mime_types.contains_slow("text/uri-list")) + event.accept(); +} + +void MainWidget::drop_event(GUI::DropEvent& event) +{ + event.accept(); + window()->move_to_front(); + + if (event.mime_data().has_urls()) { + auto urls = event.mime_data().urls(); + if (urls.is_empty()) + return; + if (urls.size() > 1) { + GUI::MessageBox::show(window(), "GML Playground can only open one file at a time!"sv, "One at a time please!"sv, GUI::MessageBox::Type::Error); + return; + } + if (request_close() == GUI::Window::CloseRequestDecision::StayOpen) + return; + + auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().serialize_path()); + if (response.is_error()) + return; + load_file(response.release_value()); + } +} diff --git a/Userland/DevTools/GMLPlayground/MainWidget.h b/Userland/DevTools/GMLPlayground/MainWidget.h index 8c3d687a63..c3ae4851a2 100644 --- a/Userland/DevTools/GMLPlayground/MainWidget.h +++ b/Userland/DevTools/GMLPlayground/MainWidget.h @@ -30,6 +30,9 @@ public: GUI::TextEditor& editor() const { return *m_editor; } private: + virtual void drag_enter_event(GUI::DragEvent&) override; + virtual void drop_event(GUI::DropEvent&) override; + RefPtr<GUI::Action> m_save_action; RefPtr<GUI::TextEditor> m_editor; RefPtr<GUI::Toolbar> m_toolbar; |