summaryrefslogtreecommitdiff
path: root/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp
diff options
context:
space:
mode:
authormartinfalisse <martinmotteditfalisse@gmail.com>2022-04-07 23:04:36 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-04-13 09:26:44 +0430
commit22575c9370bd82a9052969ac8213833c4ad825ac (patch)
treefe5735cf767c04b4ef81f97006ed0d0f85f082d6 /Userland/Applications/Spreadsheet/SpreadsheetModel.cpp
parent7bd0ebb1abd1df5a13fa909256d8131d2335f915 (diff)
downloadserenity-22575c9370bd82a9052969ac8213833c4ad825ac.zip
Spreadsheet: Make undo operation handle multiple cells at a time
Instead of having the undo operation only be able to undo one cell for a given undo, make it able to handle multiple cells at a time. Please enter the commit message for your changes. Lines starting
Diffstat (limited to 'Userland/Applications/Spreadsheet/SpreadsheetModel.cpp')
-rw-r--r--Userland/Applications/Spreadsheet/SpreadsheetModel.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp b/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp
index b190788b7a..e643f0cf95 100644
--- a/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp
+++ b/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp
@@ -165,4 +165,29 @@ void SheetModel::update()
m_sheet->update();
did_update(UpdateFlag::DontInvalidateIndices);
}
+
+CellsUndoCommand::CellsUndoCommand(Vector<CellChange> cell_changes)
+{
+ m_cell_changes = cell_changes;
+}
+
+CellsUndoCommand::CellsUndoCommand(Cell& cell, String const& previous_data)
+{
+ m_cell_changes.append(CellChange(cell, previous_data));
+}
+
+void CellsUndoCommand::undo()
+{
+ for (size_t i = 0; i < m_cell_changes.size(); ++i) {
+ m_cell_changes[i].cell().set_data(m_cell_changes[i].previous_data());
+ }
+}
+
+void CellsUndoCommand::redo()
+{
+ for (size_t i = 0; i < m_cell_changes.size(); ++i) {
+ m_cell_changes[i].cell().set_data(m_cell_changes[i].new_data());
+ }
+}
+
}