diff options
author | martinfalisse <martinmotteditfalisse@gmail.com> | 2022-04-07 23:04:36 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-04-13 09:26:44 +0430 |
commit | 22575c9370bd82a9052969ac8213833c4ad825ac (patch) | |
tree | fe5735cf767c04b4ef81f97006ed0d0f85f082d6 /Userland/Applications/Spreadsheet/SpreadsheetModel.cpp | |
parent | 7bd0ebb1abd1df5a13fa909256d8131d2335f915 (diff) | |
download | serenity-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.cpp | 25 |
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()); + } +} + } |