tag editor: guard before discarding pending changes accidentally
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -74,6 +74,8 @@ size_t FParserHeight;
|
||||
std::list<std::string> Patterns;
|
||||
std::string PatternsFile = "patterns.list";
|
||||
|
||||
bool isAnyModified(const NC::Menu<MPD::MutableSong> &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<MPD::MutableSong> &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);
|
||||
|
||||
@@ -51,18 +51,18 @@ class TagEditor : public Screen<NC::Window>, 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<ProxySongList> getProxySongList();
|
||||
|
||||
virtual bool allowsSelection();
|
||||
@@ -71,6 +71,9 @@ class TagEditor : public Screen<NC::Window>, public Filterable, public HasSongs,
|
||||
|
||||
virtual bool isMergable() { return true; }
|
||||
|
||||
// private members
|
||||
bool ifAnyModifiedAskForDiscarding();
|
||||
|
||||
bool isNextColumnAvailable();
|
||||
bool NextColumn();
|
||||
bool isPrevColumnAvailable();
|
||||
|
||||
Reference in New Issue
Block a user