Wed, 10 Apr 2013 02:40:52 +0300
Allow undo of set color
gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
history.cpp | file | annotate | diff | comparison | revisions | |
history.h | file | annotate | diff | comparison | revisions |
--- a/gui_editactions.cpp Wed Apr 10 02:22:35 2013 +0300 +++ b/gui_editactions.cpp Wed Apr 10 02:40:52 2013 +0300 @@ -221,10 +221,19 @@ // Show the dialog to the user now and ask for a color. if (ColorSelectDialog::staticDialog (dColor, dDefault, g_ForgeWindow)) { - for (LDObject* obj : objs) - if (obj->dColor != -1) + std::vector<ulong> ulaIndices; + std::vector<short> daColors; + + for (LDObject* obj : objs) { + if (obj->dColor != -1) { + ulaIndices.push_back (obj->getIndex (g_CurrentFile)); + daColors.push_back (obj->dColor); + obj->dColor = dColor; + } + } + History::addEntry (new SetColorHistory (ulaIndices, daColors, dColor)); g_ForgeWindow->refresh (); } }
--- a/history.cpp Wed Apr 10 02:22:35 2013 +0300 +++ b/history.cpp Wed Apr 10 02:40:52 2013 +0300 @@ -23,6 +23,8 @@ #include "gui.h" // ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void DeleteHistory::undo () { for (ulong i = 0; i < cache.size(); ++i) { LDObject* obj = cache[i]->clone (); @@ -53,6 +55,25 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= +void SetColorHistory::undo () { + // Restore colors + for (ulong i = 0; i < ulaIndices.size (); ++i) + g_CurrentFile->objects[ulaIndices[i]]->dColor = daColors[i]; + + g_ForgeWindow->refresh (); +} + +void SetColorHistory::redo () { + // Re-set post color + for (ulong i = 0; i < ulaIndices.size (); ++i) + g_CurrentFile->objects[ulaIndices[i]]->dColor = dNewColor; + + g_ForgeWindow->refresh (); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= namespace History { std::vector<HistoryEntry*> entries;
--- a/history.h Wed Apr 10 02:22:35 2013 +0300 +++ b/history.h Wed Apr 10 02:40:52 2013 +0300 @@ -28,8 +28,12 @@ enum HistoryType_e { HISTORY_Delete, + HISTORY_SetColor, }; +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= class HistoryEntry { public: virtual void undo () {} @@ -41,6 +45,9 @@ }; }; +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= class DeleteHistory : public HistoryEntry { public: IMPLEMENT_HISTORY_TYPE (Delete) @@ -55,6 +62,27 @@ virtual void redo (); }; +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +class SetColorHistory : public HistoryEntry { +public: + IMPLEMENT_HISTORY_TYPE (SetColor) + + vector<ulong> ulaIndices; + vector<short> daColors; + short dNewColor; + + SetColorHistory (vector<ulong> ulaIndices, vector<short> daColors, short dNewColor) : + ulaIndices (ulaIndices), daColors (daColors), dNewColor (dNewColor) {} + virtual ~SetColorHistory () {} + virtual void undo (); + virtual void redo (); +}; + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= namespace History { extern std::vector<HistoryEntry*> entries;