1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:37:34 +00:00

Browser: Implement the <input type=file> UI

This commit is contained in:
Timothy Flynn 2024-02-25 13:26:02 -05:00 committed by Andreas Kling
parent 108521a566
commit ab4d4f0711
2 changed files with 25 additions and 1 deletions

View file

@ -31,6 +31,7 @@
#include <LibGUI/Clipboard.h>
#include <LibGUI/ColorPicker.h>
#include <LibGUI/Dialog.h>
#include <LibGUI/FilePicker.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Menu.h>
#include <LibGUI/MessageBox.h>
@ -40,6 +41,7 @@
#include <LibGUI/ToolbarContainer.h>
#include <LibGUI/Window.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/SelectedFile.h>
#include <LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.h>
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/Viewport.h>
@ -554,6 +556,26 @@ Tab::Tab(BrowserWindow& window)
m_dialog = nullptr;
};
view().on_request_file_picker = [this](auto allow_multiple_files) {
// FIXME: GUI::FilePicker does not allow selecting multiple files at once.
(void)allow_multiple_files;
Vector<Web::HTML::SelectedFile> selected_files;
auto& window = this->window();
auto create_selected_file = [&](auto file_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 (auto path = GUI::FilePicker::get_open_filepath(&window, "Select file"); path.has_value())
create_selected_file(path.release_value());
view().file_picker_closed(std::move(selected_files));
};
m_select_dropdown = GUI::Menu::construct();
m_select_dropdown->on_visibility_change = [this](bool visible) {
if (!visible && !m_select_dropdown_closed_by_action)