diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-03-20 14:00:49 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-22 07:43:58 +0100 |
commit | 9b68f91c0bf3f666267a7fb6fbb522623fff0263 (patch) | |
tree | 5d2c5624ab00c3fddec60663f3feb6b22bf51385 /Userland/Applications/Spreadsheet/Workbook.cpp | |
parent | bba3a7a2cbb2f8c7e67083d2ff4e65f20150c9a3 (diff) | |
download | serenity-9b68f91c0bf3f666267a7fb6fbb522623fff0263.zip |
Spreadsheet: Add an export wizard, and support for custom CSV exports
Fixes #4269.
Diffstat (limited to 'Userland/Applications/Spreadsheet/Workbook.cpp')
-rw-r--r-- | Userland/Applications/Spreadsheet/Workbook.cpp | 32 |
1 files changed, 5 insertions, 27 deletions
diff --git a/Userland/Applications/Spreadsheet/Workbook.cpp b/Userland/Applications/Spreadsheet/Workbook.cpp index 878526da22..0f023d727a 100644 --- a/Userland/Applications/Spreadsheet/Workbook.cpp +++ b/Userland/Applications/Spreadsheet/Workbook.cpp @@ -25,6 +25,7 @@ */ #include "Workbook.h" +#include "ExportDialog.h" #include "ImportDialog.h" #include "JSIntegration.h" #include "Readers/CSV.h" @@ -111,33 +112,10 @@ Result<bool, String> Workbook::save(const StringView& filename) return sb.to_string(); } - if (mime == "text/csv") { - // FIXME: Prompt the user for settings and which sheet to export. - Core::OutputFileStream stream { file }; - auto data = m_sheets[0].to_xsv(); - auto header_string = data.take_first(); - Vector<StringView> headers; - for (auto& str : header_string) - headers.append(str); - Writer::CSV csv { stream, data, headers }; - if (csv.has_error()) - return String::formatted("Unable to save file, CSV writer error: {}", csv.error_string()); - } else { - JsonArray array; - for (auto& sheet : m_sheets) - array.append(sheet.to_json()); - - auto file_content = array.to_string(); - bool result = file->write(file_content); - if (!result) { - int error_number = errno; - StringBuilder sb; - sb.append("Unable to save file. Error: "); - sb.append(strerror(error_number)); - - return sb.to_string(); - } - } + // Make an export dialog, we might need to import it. + auto result = ExportDialog::make_and_run_for(mime, *file, *this); + if (result.is_error()) + return result.error(); set_filename(filename); set_dirty(false); |