mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Ladybird/Qt: Implement the <input type=file> UI
This commit is contained in:
parent
ab4d4f0711
commit
834f76ef24
Notes:
sideshowbarker
2024-07-17 00:37:23 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/834f76ef24 Pull-request: https://github.com/SerenityOS/serenity/pull/23346
1 changed files with 27 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <AK/TemporaryChange.h>
|
||||
#include <LibGfx/ImageFormats/BMPWriter.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibWeb/HTML/SelectedFile.h>
|
||||
#include <LibWebView/SearchEngine.h>
|
||||
#include <LibWebView/SourceHighlighter.h>
|
||||
#include <LibWebView/URL.h>
|
||||
|
@ -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<Web::HTML::SelectedFile> 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<size_t>(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())
|
||||
|
|
Loading…
Reference in a new issue