mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +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 {};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue