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

Spreadsheet: Allow importing sheets into an existing workbook

This commit is contained in:
Ali Mohammad Pur 2022-06-25 22:06:18 +04:30 committed by Linus Groh
parent 135683795b
commit 64ef808aeb
4 changed files with 50 additions and 0 deletions

View file

@ -130,6 +130,14 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe
load_file(*response.value());
});
m_import_action = GUI::Action::create("Import sheets...", [&](auto&) {
auto response = FileSystemAccessClient::Client::the().try_open_file(window());
if (response.is_error())
return;
import_sheets(*response.value());
});
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
if (current_filename().is_empty()) {
m_save_as_action->activate();
@ -448,6 +456,30 @@ void SpreadsheetWidget::load_file(Core::File& file)
update_window_title();
}
void SpreadsheetWidget::import_sheets(Core::File& file)
{
auto result = m_workbook->import_file(file);
if (result.is_error()) {
GUI::MessageBox::show_error(window(), result.error());
return;
}
if (!result.value())
return;
window()->set_modified(true);
m_cell_value_editor->on_change = nullptr;
m_current_cell_label->set_text("");
m_should_change_selected_cells = false;
while (auto* widget = m_tab_widget->active_widget()) {
m_tab_widget->remove_tab(*widget);
}
setup_tabs(m_workbook->sheets());
update_window_title();
}
bool SpreadsheetWidget::request_close()
{
if (!undo_stack().is_current_modified())
@ -553,6 +585,8 @@ void SpreadsheetWidget::initialize_menubar(GUI::Window& window)
file_menu.add_action(*m_save_action);
file_menu.add_action(*m_save_as_action);
file_menu.add_separator();
file_menu.add_action(*m_import_action);
file_menu.add_separator();
file_menu.add_action(*m_quit_action);
auto& edit_menu = window.add_menu("&Edit");