Kaynağa Gözat

Spreadsheet: Add CellUndoMetadataCommand class

Enables the ability to undo changes in metadata without undoing chages
in data. Previously there was only CellUndoData which cannot undo things
such as changes in cell background color.
huttongrabiel 2 yıl önce
ebeveyn
işleme
7c204745ee

+ 19 - 0
Userland/Applications/Spreadsheet/SpreadsheetModel.cpp

@@ -221,4 +221,23 @@ void CellsUndoCommand::redo()
     }
 }
 
+CellsUndoMetadataCommand::CellsUndoMetadataCommand(Vector<CellChange> cell_changes)
+{
+    m_cell_changes = move(cell_changes);
+}
+
+void CellsUndoMetadataCommand::undo()
+{
+    for (size_t i = 0; i < m_cell_changes.size(); ++i) {
+        m_cell_changes[i].cell().set_type_metadata(m_cell_changes[i].previous_type_metadata());
+    }
+}
+
+void CellsUndoMetadataCommand::redo()
+{
+    for (size_t i = 0; i < m_cell_changes.size(); ++i) {
+        m_cell_changes[i].cell().set_type_metadata(m_cell_changes[i].new_type_metadata());
+    }
+}
+
 }

+ 11 - 0
Userland/Applications/Spreadsheet/SpreadsheetModel.h

@@ -58,4 +58,15 @@ private:
     Vector<CellChange> m_cell_changes;
 };
 
+class CellsUndoMetadataCommand : public GUI::Command {
+public:
+    CellsUndoMetadataCommand(Vector<CellChange>);
+
+    virtual void undo() override;
+    virtual void redo() override;
+
+private:
+    Vector<CellChange> m_cell_changes;
+};
+
 }