From a0290c09d253cc34b3841e7d463b0abbc1c7115f Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 19 Apr 2016 18:14:35 -0400 Subject: [PATCH] Bug1382: Should not make an undo item when exporting with no metadata changes --- src/Menus.cpp | 8 +++++--- src/Tags.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/Tags.h | 5 +++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 417a5cc23..0aa3ef6e1 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -5597,9 +5597,11 @@ bool AudacityProject::DoEditMetadata auto newTags = mTags->Duplicate(); if (newTags->ShowEditDialog(this, title, force)) { - // Commit the change to project state only now. - mTags = newTags; - PushState(title, shortUndoDescription); + if (*mTags != *newTags) { + // Commit the change to project state only now. + mTags = newTags; + PushState(title, shortUndoDescription); + } return true; } diff --git a/src/Tags.cpp b/src/Tags.cpp index c6af6bf2b..8651c75eb 100644 --- a/src/Tags.cpp +++ b/src/Tags.cpp @@ -302,6 +302,42 @@ void Tags::Clear() mMap.clear(); } +namespace { + bool EqualMaps(const TagMap &map1, const TagMap &map2) + { + for (auto it1 = map1.begin(), end1 = map1.end(), + it2 = map2.begin(), end2 = map2.end(); + it1 != end1 || it2 != end2;) { + if (it1 == end1 || it2 == end2) + return false; + else if (it1->first != it2->first) + return false; + else if (it1->second != it2->second) + return false; + else + ++it1, ++it2; + } + return true; + } +} + +bool operator== (const Tags &lhs, const Tags &rhs) +{ + if (!EqualMaps(lhs.mXref, rhs.mXref)) + return false; + + if (!EqualMaps(lhs.mMap, rhs.mMap)) + return false; + + return + lhs.mGenres == rhs.mGenres + && + lhs.mEditTitle == rhs.mEditTitle + && + lhs.mEditTrackNumber == rhs.mEditTrackNumber + ; +} + void Tags::AllowEditTitle(bool editTitle) { mEditTitle = editTitle; diff --git a/src/Tags.h b/src/Tags.h index 642988e7c..1ce23e883 100644 --- a/src/Tags.h +++ b/src/Tags.h @@ -118,6 +118,8 @@ class AUDACITY_DLL_API Tags final : public XMLTagHandler { bool IsEmpty(); void Clear(); + friend bool operator == (const Tags &lhs, const Tags &rhs); + private: void LoadDefaults(); @@ -130,6 +132,9 @@ class AUDACITY_DLL_API Tags final : public XMLTagHandler { bool mEditTrackNumber; }; +inline bool operator != (const Tags &lhs, const Tags &rhs) +{ return !(lhs == rhs); } + class TagsEditor final : public wxDialog { public: