diff --git a/Ladybird/Qt/Tab.cpp b/Ladybird/Qt/Tab.cpp index 9a8869f98c..36a13d1b2d 100644 --- a/Ladybird/Qt/Tab.cpp +++ b/Ladybird/Qt/Tab.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -231,6 +232,32 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St m_dialog = nullptr; }; + view().on_request_file_picker = [this](auto allow_multiple_files) { + Vector selected_files; + + auto create_selected_file = [&](auto const& qfile_path) { + auto file_path = ak_byte_string_from_qstring(qfile_path); + + if (auto file = Web::HTML::SelectedFile::from_file_path(file_path); file.is_error()) + warnln("Unable to open file {}: {}", file_path, file.error()); + else + selected_files.append(file.release_value()); + }; + + if (allow_multiple_files == Web::HTML::AllowMultipleFiles::Yes) { + auto paths = QFileDialog::getOpenFileNames(this, "Select files", QDir::homePath(), "All Files (*.*)"); + selected_files.ensure_capacity(static_cast(paths.size())); + + for (auto const& path : paths) + create_selected_file(path); + } else { + auto path = QFileDialog::getOpenFileName(this, "Select file", QDir::homePath(), "All Files (*.*)"); + create_selected_file(path); + } + + view().file_picker_closed(std::move(selected_files)); + }; + m_select_dropdown = new QMenu("Select Dropdown", this); QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() { if (!m_select_dropdown->activeAction())