mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
PDFViewer: Accept file drops
This commit is contained in:
parent
fa0606ea36
commit
40d732a73c
2 changed files with 31 additions and 0 deletions
|
@ -423,3 +423,32 @@ PDF::PDFErrorOr<void> PDFViewerWidget::try_open_file(StringView path, NonnullOwn
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFViewerWidget::drag_enter_event(GUI::DragEvent& event)
|
||||||
|
{
|
||||||
|
auto const& mime_types = event.mime_types();
|
||||||
|
if (mime_types.contains_slow("text/uri-list"sv))
|
||||||
|
event.accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFViewerWidget::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(), "PDF Viewer can only open one file at a time!"sv, "One at a time please!"sv, GUI::MessageBox::Type::Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().serialize_path());
|
||||||
|
if (response.is_error())
|
||||||
|
return;
|
||||||
|
if (auto result = try_open_file(response.value().filename(), response.value().release_stream()); result.is_error())
|
||||||
|
GUI::MessageBox::show(window(), "Unable to open file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PDFViewerWidget();
|
PDFViewerWidget();
|
||||||
|
virtual void drag_enter_event(GUI::DragEvent&) override;
|
||||||
|
virtual void drop_event(GUI::DropEvent&) override;
|
||||||
|
|
||||||
void initialize_toolbar(GUI::Toolbar&);
|
void initialize_toolbar(GUI::Toolbar&);
|
||||||
PDF::PDFErrorOr<void> try_open_file(StringView path, NonnullOwnPtr<Core::File> file);
|
PDF::PDFErrorOr<void> try_open_file(StringView path, NonnullOwnPtr<Core::File> file);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue