mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 22:45:06 +00:00
Ladybird/Qt: Implement the <input type=file> UI
This commit is contained in:
parent
ab4d4f0711
commit
834f76ef24
1 changed files with 27 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <AK/TemporaryChange.h>
|
#include <AK/TemporaryChange.h>
|
||||||
#include <LibGfx/ImageFormats/BMPWriter.h>
|
#include <LibGfx/ImageFormats/BMPWriter.h>
|
||||||
#include <LibGfx/Painter.h>
|
#include <LibGfx/Painter.h>
|
||||||
|
#include <LibWeb/HTML/SelectedFile.h>
|
||||||
#include <LibWebView/SearchEngine.h>
|
#include <LibWebView/SearchEngine.h>
|
||||||
#include <LibWebView/SourceHighlighter.h>
|
#include <LibWebView/SourceHighlighter.h>
|
||||||
#include <LibWebView/URL.h>
|
#include <LibWebView/URL.h>
|
||||||
|
@ -231,6 +232,32 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
||||||
m_dialog = nullptr;
|
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);
|
m_select_dropdown = new QMenu("Select Dropdown", this);
|
||||||
QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() {
|
QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() {
|
||||||
if (!m_select_dropdown->activeAction())
|
if (!m_select_dropdown->activeAction())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue