From 0d81f9d65fac9cdd13137600fcaac97a38544b4b Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 12 Sep 2012 16:36:58 +0200 Subject: [PATCH] tag editor: guard before discarding pending changes accidentally --- src/mutable_song.cpp | 2 +- src/tag_editor.cpp | 43 ++++++++++++++++++++++++++++++------------- src/tag_editor.h | 9 ++++++--- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/mutable_song.cpp b/src/mutable_song.cpp index cd8024a9..dfa18d8b 100644 --- a/src/mutable_song.cpp +++ b/src/mutable_song.cpp @@ -175,7 +175,7 @@ void MutableSong::setTags(SetFunction set, const std::string &value, const std:: bool MutableSong::isModified() const { - return !m_uri.empty() && !m_tags.empty(); + return !m_uri.empty() || !m_tags.empty(); } void MutableSong::clearModifications() diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index d64d3638..bd655f25 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -74,6 +74,8 @@ size_t FParserHeight; std::list Patterns; std::string PatternsFile = "patterns.list"; +bool isAnyModified(const NC::Menu &m); + std::string CapitalizeFirstLetters(const std::string &s); void CapitalizeFirstLetters(MPD::MutableSong &s); void LowerAllLetters(MPD::MutableSong &s); @@ -586,7 +588,8 @@ void TagEditor::EnterPressed() } else if (id == 19) // reset { - Tags->clear(); + for (auto it = Tags->beginV(); it != Tags->endV(); ++it) + it->clearModifications(); Statusbar::msg("Changes reset"); } else if (id == 20) // save @@ -835,23 +838,30 @@ MPD::SongList TagEditor::getSelectedSongs() /***********************************************************************/ +bool TagEditor::ifAnyModifiedAskForDiscarding() +{ + bool result = true; + if (isAnyModified(*Tags)) + result = Action::AskYesNoQuestion("There are pending changes, are you sure?", Status::trace); + return result; +} + bool TagEditor::isNextColumnAvailable() { + bool result = false; if (w == Dirs) { if (!TagTypes->reallyEmpty() && !Tags->reallyEmpty()) - return true; + result = true; } else if (w == TagTypes) { if (!Tags->reallyEmpty()) - return true; + result = true; } else if (w == FParser) - { - return true; - } - return false; + result = true; + return result; } bool TagEditor::NextColumn() @@ -886,21 +896,20 @@ bool TagEditor::NextColumn() bool TagEditor::isPrevColumnAvailable() { + bool result = false; if (w == Tags) { if (!TagTypes->reallyEmpty() && !Dirs->reallyEmpty()) - return true; + result = true; } else if (w == TagTypes) { if (!Dirs->reallyEmpty()) - return true; + result = ifAnyModifiedAskForDiscarding(); } else if (w == FParserHelper) - { - return true; - } - return false; + result = true; + return result; } bool TagEditor::PrevColumn() @@ -1108,6 +1117,14 @@ bool TagEditor::WriteTags(MPD::MutableSong &s) namespace {// +bool isAnyModified(const NC::Menu &m) +{ + for (auto it = m.beginV(); it != m.endV(); ++it) + if (it->isModified()) + return true; + return false; +} + std::string CapitalizeFirstLetters(const std::string &s) { std::wstring ws = ToWString(s); diff --git a/src/tag_editor.h b/src/tag_editor.h index e3a098a4..b6e7b38b 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -51,18 +51,18 @@ class TagEditor : public Screen, public Filterable, public HasSongs, virtual void MouseButtonPressed(MEVENT); virtual bool isTabbable() { return true; } - /// Filterable implementation + // Filterable implementation virtual bool allowsFiltering(); virtual std::string currentFilter(); virtual void applyFilter(const std::string &filter); - /// Searchable implementation + // Searchable implementation virtual bool allowsSearching(); virtual bool search(const std::string &constraint); virtual void nextFound(bool wrap); virtual void prevFound(bool wrap); - /// HasSongs implementation + // HasSongs implementation virtual std::shared_ptr getProxySongList(); virtual bool allowsSelection(); @@ -71,6 +71,9 @@ class TagEditor : public Screen, public Filterable, public HasSongs, virtual bool isMergable() { return true; } + // private members + bool ifAnyModifiedAskForDiscarding(); + bool isNextColumnAvailable(); bool NextColumn(); bool isPrevColumnAvailable();