summaryrefslogtreecommitdiff
path: root/Applications/Spreadsheet/SpreadsheetWidget.cpp
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-08-26 07:32:38 +0430
committerAndreas Kling <kling@serenityos.org>2020-08-27 10:27:20 +0200
commitcb7fe4fe7c50dc3c9da8f129aa60c74e93ef1304 (patch)
treee22ee7d77c29e0f412c43555a422b438de9d5806 /Applications/Spreadsheet/SpreadsheetWidget.cpp
parente1f5f709eeecdd9aea0714b924f6bbb2096abdbf (diff)
downloadserenity-cb7fe4fe7c50dc3c9da8f129aa60c74e93ef1304.zip
Spreadsheet: Add support for multiple sheets
This also refactors the js integration stuff to allow sheets to reference each other safely.
Diffstat (limited to 'Applications/Spreadsheet/SpreadsheetWidget.cpp')
-rw-r--r--Applications/Spreadsheet/SpreadsheetWidget.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Applications/Spreadsheet/SpreadsheetWidget.cpp
index b56c93857a..7cf6149ee1 100644
--- a/Applications/Spreadsheet/SpreadsheetWidget.cpp
+++ b/Applications/Spreadsheet/SpreadsheetWidget.cpp
@@ -81,13 +81,13 @@ SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector<Sheet>&& sheets, bool s
if (!m_workbook->has_sheets() && should_add_sheet_if_empty)
m_workbook->add_sheet("Sheet 1");
- setup_tabs();
+ setup_tabs(m_workbook->sheets());
}
-void SpreadsheetWidget::setup_tabs()
+void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
{
RefPtr<GUI::Widget> first_tab_widget;
- for (auto& sheet : m_workbook->sheets()) {
+ for (auto& sheet : new_sheets) {
auto& tab = m_tab_widget->add_tab<SpreadsheetView>(sheet.name(), sheet);
if (!first_tab_widget)
first_tab_widget = &tab;
@@ -148,7 +148,20 @@ void SpreadsheetWidget::load(const StringView& filename)
m_tab_widget->remove_tab(*widget);
}
- setup_tabs();
+ setup_tabs(m_workbook->sheets());
+}
+
+void SpreadsheetWidget::add_sheet()
+{
+ StringBuilder name;
+ name.append("Sheet");
+ name.appendf(" %d", m_workbook->sheets().size() + 1);
+
+ auto& sheet = m_workbook->add_sheet(name.string_view());
+
+ NonnullRefPtrVector<Sheet> new_sheets;
+ new_sheets.append(sheet);
+ setup_tabs(new_sheets);
}
void SpreadsheetWidget::set_filename(const String& filename)