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
|
bool MutableSong::isModified() const
|
||||||
{
|
{
|
||||||
return !m_uri.empty() && !m_tags.empty();
|
return !m_uri.empty() || !m_tags.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MutableSong::clearModifications()
|
void MutableSong::clearModifications()
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ size_t FParserHeight;
|
|||||||
std::list<std::string> Patterns;
|
std::list<std::string> Patterns;
|
||||||
std::string PatternsFile = "patterns.list";
|
std::string PatternsFile = "patterns.list";
|
||||||
|
|
||||||
|
bool isAnyModified(const NC::Menu<MPD::MutableSong> &m);
|
||||||
|
|
||||||
std::string CapitalizeFirstLetters(const std::string &s);
|
std::string CapitalizeFirstLetters(const std::string &s);
|
||||||
void CapitalizeFirstLetters(MPD::MutableSong &s);
|
void CapitalizeFirstLetters(MPD::MutableSong &s);
|
||||||
void LowerAllLetters(MPD::MutableSong &s);
|
void LowerAllLetters(MPD::MutableSong &s);
|
||||||
@@ -586,7 +588,8 @@ void TagEditor::EnterPressed()
|
|||||||
}
|
}
|
||||||
else if (id == 19) // reset
|
else if (id == 19) // reset
|
||||||
{
|
{
|
||||||
Tags->clear();
|
for (auto it = Tags->beginV(); it != Tags->endV(); ++it)
|
||||||
|
it->clearModifications();
|
||||||
Statusbar::msg("Changes reset");
|
Statusbar::msg("Changes reset");
|
||||||
}
|
}
|
||||||
else if (id == 20) // save
|
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 TagEditor::isNextColumnAvailable()
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
if (w == Dirs)
|
if (w == Dirs)
|
||||||
{
|
{
|
||||||
if (!TagTypes->reallyEmpty() && !Tags->reallyEmpty())
|
if (!TagTypes->reallyEmpty() && !Tags->reallyEmpty())
|
||||||
return true;
|
result = true;
|
||||||
}
|
}
|
||||||
else if (w == TagTypes)
|
else if (w == TagTypes)
|
||||||
{
|
{
|
||||||
if (!Tags->reallyEmpty())
|
if (!Tags->reallyEmpty())
|
||||||
return true;
|
result = true;
|
||||||
}
|
}
|
||||||
else if (w == FParser)
|
else if (w == FParser)
|
||||||
{
|
result = true;
|
||||||
return true;
|
return result;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TagEditor::NextColumn()
|
bool TagEditor::NextColumn()
|
||||||
@@ -886,21 +896,20 @@ bool TagEditor::NextColumn()
|
|||||||
|
|
||||||
bool TagEditor::isPrevColumnAvailable()
|
bool TagEditor::isPrevColumnAvailable()
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
if (w == Tags)
|
if (w == Tags)
|
||||||
{
|
{
|
||||||
if (!TagTypes->reallyEmpty() && !Dirs->reallyEmpty())
|
if (!TagTypes->reallyEmpty() && !Dirs->reallyEmpty())
|
||||||
return true;
|
result = true;
|
||||||
}
|
}
|
||||||
else if (w == TagTypes)
|
else if (w == TagTypes)
|
||||||
{
|
{
|
||||||
if (!Dirs->reallyEmpty())
|
if (!Dirs->reallyEmpty())
|
||||||
return true;
|
result = ifAnyModifiedAskForDiscarding();
|
||||||
}
|
}
|
||||||
else if (w == FParserHelper)
|
else if (w == FParserHelper)
|
||||||
{
|
result = true;
|
||||||
return true;
|
return result;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TagEditor::PrevColumn()
|
bool TagEditor::PrevColumn()
|
||||||
@@ -1108,6 +1117,14 @@ bool TagEditor::WriteTags(MPD::MutableSong &s)
|
|||||||
|
|
||||||
namespace {//
|
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::string CapitalizeFirstLetters(const std::string &s)
|
||||||
{
|
{
|
||||||
std::wstring ws = ToWString(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 void MouseButtonPressed(MEVENT);
|
||||||
virtual bool isTabbable() { return true; }
|
virtual bool isTabbable() { return true; }
|
||||||
|
|
||||||
/// Filterable implementation
|
// Filterable implementation
|
||||||
virtual bool allowsFiltering();
|
virtual bool allowsFiltering();
|
||||||
virtual std::string currentFilter();
|
virtual std::string currentFilter();
|
||||||
virtual void applyFilter(const std::string &filter);
|
virtual void applyFilter(const std::string &filter);
|
||||||
|
|
||||||
/// Searchable implementation
|
// Searchable implementation
|
||||||
virtual bool allowsSearching();
|
virtual bool allowsSearching();
|
||||||
virtual bool search(const std::string &constraint);
|
virtual bool search(const std::string &constraint);
|
||||||
virtual void nextFound(bool wrap);
|
virtual void nextFound(bool wrap);
|
||||||
virtual void prevFound(bool wrap);
|
virtual void prevFound(bool wrap);
|
||||||
|
|
||||||
/// HasSongs implementation
|
// HasSongs implementation
|
||||||
virtual std::shared_ptr<ProxySongList> getProxySongList();
|
virtual std::shared_ptr<ProxySongList> getProxySongList();
|
||||||
|
|
||||||
virtual bool allowsSelection();
|
virtual bool allowsSelection();
|
||||||
@@ -71,6 +71,9 @@ class TagEditor : public Screen<NC::Window>, public Filterable, public HasSongs,
|
|||||||
|
|
||||||
virtual bool isMergable() { return true; }
|
virtual bool isMergable() { return true; }
|
||||||
|
|
||||||
|
// private members
|
||||||
|
bool ifAnyModifiedAskForDiscarding();
|
||||||
|
|
||||||
bool isNextColumnAvailable();
|
bool isNextColumnAvailable();
|
||||||
bool NextColumn();
|
bool NextColumn();
|
||||||
bool isPrevColumnAvailable();
|
bool isPrevColumnAvailable();
|
||||||
|
|||||||
Reference in New Issue
Block a user