1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 03:34:57 +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)

View file

@ -107,7 +107,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::create(arguments));
auto const man_file = "/usr/share/man/man1/Applications/Browser.md"sv;
Config::pledge_domain("Browser");
Config::pledge_domains({ "Browser", "FileManager" });
Config::monitor_domain("Browser");
// Connect to LaunchServer immediately and let it know that we won't ask for anything other than opening
@ -126,8 +126,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::unveil("/tmp/session/%sid/portal/sql", "rw"));
TRY(Core::System::unveil("/home", "rwc"));
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/etc/group", "r"));
TRY(Core::System::unveil("/etc/passwd", "r"));
TRY(Core::System::unveil("/etc/timezone", "r"));
TRY(Core::System::unveil("/etc/FileIconProvider.ini", "r"));
TRY(Core::System::unveil("/bin/BrowserSettings", "x"));
TRY(Core::System::unveil("/bin/Browser", "x"));
TRY(Core::System::unveil(nullptr, nullptr));