1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

Spreadsheet: Use FileSystemAccessClient for the reading of files

This commit is contained in:
Glenford Williams 2022-01-11 06:26:04 -05:00 committed by Ali Mohammad Pur
parent c4013f72a3
commit c55dfabdd5
9 changed files with 63 additions and 29 deletions

View file

@ -7,6 +7,7 @@
#include "SpreadsheetWidget.h"
#include "CellSyntaxHighlighter.h"
#include "HelpWindow.h"
#include "LibFileSystemAccessClient/Client.h"
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
@ -25,8 +26,8 @@
namespace Spreadsheet {
SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector<Sheet>&& sheets, bool should_add_sheet_if_empty)
: m_workbook(make<Workbook>(move(sheets), window()))
SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVector<Sheet>&& sheets, bool should_add_sheet_if_empty)
: m_workbook(make<Workbook>(move(sheets), parent_window))
{
set_fill_with_background_color(true);
set_layout<GUI::VerticalBoxLayout>().set_margins(2);
@ -123,7 +124,15 @@ SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector<Sheet>&& sheets, bool s
if (!load_path.has_value())
return;
load(load_path.value());
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window()->window_id(), *load_path);
if (response.error != 0) {
if (response.error != -1)
GUI::MessageBox::show_error(window(), String::formatted("Opening \"{}\" failed: {}", *response.chosen_file, strerror(response.error)));
return;
}
load_file(*response.fd, *load_path);
});
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
@ -391,9 +400,9 @@ void SpreadsheetWidget::save(StringView filename)
GUI::MessageBox::show_error(window(), result.error());
}
void SpreadsheetWidget::load(StringView filename)
void SpreadsheetWidget::load_file(int fd, StringView filename)
{
auto result = m_workbook->load(filename);
auto result = m_workbook->open_file(fd, filename);
if (result.is_error()) {
GUI::MessageBox::show_error(window(), result.error());
return;