actions: rename askYesNoQuestion to confirmAction and make it throw on 'n'
This commit is contained in:
175
src/actions.cpp
175
src/actions.cpp
@@ -252,15 +252,16 @@ void setWindowsDimensions()
|
|||||||
FooterHeight = Config.statusbar_visibility ? 2 : 1;
|
FooterHeight = Config.statusbar_visibility ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool askYesNoQuestion(const boost::format &fmt)
|
void confirmAction(const boost::format &description)
|
||||||
{
|
{
|
||||||
Statusbar::ScopedLock lock;
|
Statusbar::ScopedLock lock;
|
||||||
Statusbar::put() << fmt.str()
|
Statusbar::put() << description.str()
|
||||||
<< " [" << NC::Format::Bold << 'y' << NC::Format::NoBold
|
<< " [" << NC::Format::Bold << 'y' << NC::Format::NoBold
|
||||||
<< '/' << NC::Format::Bold << 'n' << NC::Format::NoBold
|
<< '/' << NC::Format::Bold << 'n' << NC::Format::NoBold
|
||||||
<< "] ";
|
<< "] ";
|
||||||
auto answer = Statusbar::Helpers::promptReturnOneOf({"y", "n"});
|
auto answer = Statusbar::Helpers::promptReturnOneOf({"y", "n"});
|
||||||
return answer == "y";
|
if (answer == "n")
|
||||||
|
throw NC::PromptAborted(std::move(answer));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isMPDMusicDirSet()
|
bool isMPDMusicDirSet()
|
||||||
@@ -678,38 +679,37 @@ void DeleteBrowserItems::run()
|
|||||||
question = boost::format("Delete %1% \"%2%\"?")
|
question = boost::format("Delete %1% \"%2%\"?")
|
||||||
% itemTypeToString(item.type) % wideShorten(iname, COLS-question.size()-10);
|
% itemTypeToString(item.type) % wideShorten(iname, COLS-question.size()-10);
|
||||||
}
|
}
|
||||||
bool yes = askYesNoQuestion(question);
|
confirmAction(question);
|
||||||
if (yes)
|
bool success = true;
|
||||||
|
auto list = getSelectedOrCurrent(
|
||||||
|
myBrowser->main().begin(),
|
||||||
|
myBrowser->main().end(),
|
||||||
|
myBrowser->main().currentI()
|
||||||
|
);
|
||||||
|
for (const auto &item : list)
|
||||||
{
|
{
|
||||||
bool success = true;
|
const MPD::Item &i = item->value();
|
||||||
auto list = getSelectedOrCurrent(myBrowser->main().begin(), myBrowser->main().end(), myBrowser->main().currentI());
|
std::string iname = i.type == MPD::itSong ? i.song->getName() : i.name;
|
||||||
for (auto it = list.begin(); it != list.end(); ++it)
|
std::string errmsg;
|
||||||
|
if (myBrowser->deleteItem(i, errmsg))
|
||||||
{
|
{
|
||||||
const MPD::Item &i = (*it)->value();
|
const char msg[] = "\"%1%\" deleted";
|
||||||
std::string iname = i.type == MPD::itSong ? i.song->getName() : i.name;
|
Statusbar::printf(msg, wideShorten(iname, COLS-const_strlen(msg)));
|
||||||
std::string errmsg;
|
|
||||||
if (myBrowser->deleteItem(i, errmsg))
|
|
||||||
{
|
|
||||||
const char msg[] = "\"%1%\" deleted";
|
|
||||||
Statusbar::printf(msg, wideShorten(iname, COLS-const_strlen(msg)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Statusbar::print(errmsg);
|
|
||||||
success = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (success)
|
else
|
||||||
{
|
{
|
||||||
if (myBrowser->isLocal())
|
Statusbar::print(errmsg);
|
||||||
myBrowser->GetDirectory(myBrowser->CurrentDir());
|
success = false;
|
||||||
else
|
break;
|
||||||
Mpd.UpdateDirectory(myBrowser->CurrentDir());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
if (success)
|
||||||
Statusbar::print("Aborted");
|
{
|
||||||
|
if (myBrowser->isLocal())
|
||||||
|
myBrowser->GetDirectory(myBrowser->CurrentDir());
|
||||||
|
else
|
||||||
|
Mpd.UpdateDirectory(myBrowser->CurrentDir());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeleteStoredPlaylist::canBeRun() const
|
bool DeleteStoredPlaylist::canBeRun() const
|
||||||
@@ -727,20 +727,19 @@ void DeleteStoredPlaylist::run()
|
|||||||
else
|
else
|
||||||
question = boost::format("Delete playlist \"%1%\"?")
|
question = boost::format("Delete playlist \"%1%\"?")
|
||||||
% wideShorten(myPlaylistEditor->Playlists.current().value(), COLS-question.size()-10);
|
% wideShorten(myPlaylistEditor->Playlists.current().value(), COLS-question.size()-10);
|
||||||
bool yes = askYesNoQuestion(question);
|
confirmAction(question);
|
||||||
if (yes)
|
auto list = getSelectedOrCurrent(
|
||||||
{
|
myPlaylistEditor->Playlists.begin(),
|
||||||
auto list = getSelectedOrCurrent(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end(), myPlaylistEditor->Playlists.currentI());
|
myPlaylistEditor->Playlists.end(),
|
||||||
for (auto it = list.begin(); it != list.end(); ++it)
|
myPlaylistEditor->Playlists.currentI()
|
||||||
Mpd.DeletePlaylist((*it)->value());
|
);
|
||||||
Statusbar::printf("%1% deleted", list.size() == 1 ? "Playlist" : "Playlists");
|
for (const auto &item : list)
|
||||||
// force playlists update. this happens automatically, but only after call
|
Mpd.DeletePlaylist(item->value());
|
||||||
// to Key::read, therefore when we call PlaylistEditor::Update, it won't
|
Statusbar::printf("%1% deleted", list.size() == 1 ? "Playlist" : "Playlists");
|
||||||
// yet see it, so let's point that it needs to update it.
|
// force playlists update. this happens automatically, but only after call
|
||||||
myPlaylistEditor->requestPlaylistsUpdate();
|
// to Key::read, therefore when we call PlaylistEditor::Update, it won't
|
||||||
}
|
// yet see it, so let's point that it needs to update it.
|
||||||
else
|
myPlaylistEditor->requestPlaylistsUpdate();
|
||||||
Statusbar::print("Aborted");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplaySong::run()
|
void ReplaySong::run()
|
||||||
@@ -774,16 +773,11 @@ void SavePlaylist::run()
|
|||||||
Statusbar::put() << "Save playlist as: ";
|
Statusbar::put() << "Save playlist as: ";
|
||||||
playlist_name = wFooter->prompt();
|
playlist_name = wFooter->prompt();
|
||||||
}
|
}
|
||||||
if (playlist_name.find("/") != std::string::npos)
|
|
||||||
{
|
|
||||||
Statusbar::print("Playlist name must not contain slashes");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (myPlaylist->main().isFiltered())
|
if (myPlaylist->main().isFiltered())
|
||||||
{
|
{
|
||||||
Mpd.StartCommandsList();
|
Mpd.StartCommandsList();
|
||||||
for (size_t i = 0; i < myPlaylist->main().size(); ++i)
|
for (const auto &item : myPlaylist->main())
|
||||||
Mpd.AddToPlaylist(playlist_name, myPlaylist->main()[i].value());
|
Mpd.AddToPlaylist(playlist_name, item.value());
|
||||||
Mpd.CommitCommandsList();
|
Mpd.CommitCommandsList();
|
||||||
Statusbar::printf("Filtered items added to playlist \"%1%\"", playlist_name);
|
Statusbar::printf("Filtered items added to playlist \"%1%\"", playlist_name);
|
||||||
}
|
}
|
||||||
@@ -798,19 +792,12 @@ void SavePlaylist::run()
|
|||||||
{
|
{
|
||||||
if (e.code() == MPD_SERVER_ERROR_EXIST)
|
if (e.code() == MPD_SERVER_ERROR_EXIST)
|
||||||
{
|
{
|
||||||
bool yes = askYesNoQuestion(
|
confirmAction(
|
||||||
boost::format("Playlist \"%1%\" already exists, overwrite?") % playlist_name
|
boost::format("Playlist \"%1%\" already exists, overwrite?") % playlist_name
|
||||||
);
|
);
|
||||||
if (yes)
|
Mpd.DeletePlaylist(playlist_name);
|
||||||
{
|
Mpd.SavePlaylist(playlist_name);
|
||||||
Mpd.DeletePlaylist(playlist_name);
|
Statusbar::print("Playlist overwritten");
|
||||||
Mpd.SavePlaylist(playlist_name);
|
|
||||||
Statusbar::print("Playlist overwritten");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Statusbar::print("Aborted");
|
|
||||||
if (myScreen == myPlaylist)
|
|
||||||
myPlaylist->EnableHighlighting();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw e;
|
throw e;
|
||||||
@@ -1751,16 +1738,12 @@ void CropMainPlaylist::run()
|
|||||||
// cropping doesn't make sense in this case
|
// cropping doesn't make sense in this case
|
||||||
if (w.size() <= 1)
|
if (w.size() <= 1)
|
||||||
return;
|
return;
|
||||||
bool yes = true;
|
|
||||||
if (Config.ask_before_clearing_playlists)
|
if (Config.ask_before_clearing_playlists)
|
||||||
yes = askYesNoQuestion("Do you really want to crop main playlist?");
|
confirmAction("Do you really want to crop main playlist?");
|
||||||
if (yes)
|
Statusbar::print("Cropping playlist...");
|
||||||
{
|
selectCurrentIfNoneSelected(w);
|
||||||
Statusbar::print("Cropping playlist...");
|
cropPlaylist(w, boost::bind(&MPD::Connection::Delete, _1, _2));
|
||||||
selectCurrentIfNoneSelected(w);
|
Statusbar::print("Playlist cropped");
|
||||||
cropPlaylist(w, boost::bind(&MPD::Connection::Delete, _1, _2));
|
|
||||||
Statusbar::print("Playlist cropped");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CropPlaylist::canBeRun() const
|
bool CropPlaylist::canBeRun() const
|
||||||
@@ -1776,34 +1759,24 @@ void CropPlaylist::run()
|
|||||||
return;
|
return;
|
||||||
assert(!myPlaylistEditor->Playlists.empty());
|
assert(!myPlaylistEditor->Playlists.empty());
|
||||||
std::string playlist = myPlaylistEditor->Playlists.current().value();
|
std::string playlist = myPlaylistEditor->Playlists.current().value();
|
||||||
bool yes = true;
|
|
||||||
if (Config.ask_before_clearing_playlists)
|
if (Config.ask_before_clearing_playlists)
|
||||||
yes = askYesNoQuestion(
|
confirmAction(boost::format("Do you really want to crop playlist \"%1%\"?") % playlist);
|
||||||
boost::format("Do you really want to crop playlist \"%1%\"?") % playlist
|
selectCurrentIfNoneSelected(w);
|
||||||
);
|
Statusbar::printf("Cropping playlist \"%1%\"...", playlist);
|
||||||
if (yes)
|
cropPlaylist(w, boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2));
|
||||||
{
|
Statusbar::printf("Playlist \"%1%\" cropped", playlist);
|
||||||
selectCurrentIfNoneSelected(w);
|
|
||||||
Statusbar::printf("Cropping playlist \"%1%\"...", playlist);
|
|
||||||
cropPlaylist(w, boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2));
|
|
||||||
Statusbar::printf("Playlist \"%1%\" cropped", playlist);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearMainPlaylist::run()
|
void ClearMainPlaylist::run()
|
||||||
{
|
{
|
||||||
bool yes = true;
|
|
||||||
if (Config.ask_before_clearing_playlists)
|
if (Config.ask_before_clearing_playlists)
|
||||||
yes = askYesNoQuestion("Do you really want to clear main playlist?");
|
confirmAction("Do you really want to clear main playlist?");
|
||||||
if (yes)
|
auto delete_fun = boost::bind(&MPD::Connection::Delete, _1, _2);
|
||||||
{
|
auto clear_fun = boost::bind(&MPD::Connection::ClearMainPlaylist, _1);
|
||||||
auto delete_fun = boost::bind(&MPD::Connection::Delete, _1, _2);
|
Statusbar::printf("Deleting items...");
|
||||||
auto clear_fun = boost::bind(&MPD::Connection::ClearMainPlaylist, _1);
|
clearPlaylist(myPlaylist->main(), delete_fun, clear_fun);
|
||||||
Statusbar::printf("Deleting items...");
|
Statusbar::printf("Items deleted");
|
||||||
clearPlaylist(myPlaylist->main(), delete_fun, clear_fun);
|
myPlaylist->main().reset();
|
||||||
Statusbar::printf("Items deleted");
|
|
||||||
myPlaylist->main().reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClearPlaylist::canBeRun() const
|
bool ClearPlaylist::canBeRun() const
|
||||||
@@ -1816,19 +1789,13 @@ void ClearPlaylist::run()
|
|||||||
if (myPlaylistEditor->Playlists.empty())
|
if (myPlaylistEditor->Playlists.empty())
|
||||||
return;
|
return;
|
||||||
std::string playlist = myPlaylistEditor->Playlists.current().value();
|
std::string playlist = myPlaylistEditor->Playlists.current().value();
|
||||||
bool yes = true;
|
|
||||||
if (Config.ask_before_clearing_playlists)
|
if (Config.ask_before_clearing_playlists)
|
||||||
yes = askYesNoQuestion(
|
confirmAction(boost::format("Do you really want to clear playlist \"%1%\"?") % playlist);
|
||||||
boost::format("Do you really want to clear playlist \"%1%\"?") % playlist
|
auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
|
||||||
);
|
auto clear_fun = boost::bind(&MPD::Connection::ClearPlaylist, _1, playlist);
|
||||||
if (yes)
|
Statusbar::printf("Deleting items from \"%1%\"...", playlist);
|
||||||
{
|
clearPlaylist(myPlaylistEditor->Content, delete_fun, clear_fun);
|
||||||
auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
|
Statusbar::printf("Items deleted from \"%1%\"", playlist);
|
||||||
auto clear_fun = boost::bind(&MPD::Connection::ClearPlaylist, _1, playlist);
|
|
||||||
Statusbar::printf("Deleting items from \"%1%\"...", playlist);
|
|
||||||
clearPlaylist(myPlaylistEditor->Content, delete_fun, clear_fun);
|
|
||||||
Statusbar::printf("Items deleted from \"%1%\"", playlist);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SortPlaylist::canBeRun() const
|
bool SortPlaylist::canBeRun() const
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ void setResizeFlags();
|
|||||||
void resizeScreen(bool reload_main_window);
|
void resizeScreen(bool reload_main_window);
|
||||||
void setWindowsDimensions();
|
void setWindowsDimensions();
|
||||||
|
|
||||||
bool askYesNoQuestion(const boost::format &question);
|
void confirmAction(const boost::format &description);
|
||||||
inline bool askYesNoQuestion(const std::string &question)
|
inline void confirmAction(const std::string &description)
|
||||||
{
|
{
|
||||||
return askYesNoQuestion(boost::format(question));
|
confirmAction(boost::format(description));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isMPDMusicDirSet();
|
bool isMPDMusicDirSet();
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ void Playlist::switchTo()
|
|||||||
{
|
{
|
||||||
SwitchTo::execute(this);
|
SwitchTo::execute(this);
|
||||||
m_scroll_begin = 0;
|
m_scroll_begin = 0;
|
||||||
EnableHighlighting();
|
|
||||||
drawHeader();
|
drawHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -468,21 +468,16 @@ void TagEditor::enterPressed()
|
|||||||
|
|
||||||
if (w == TagTypes && id == 5)
|
if (w == TagTypes && id == 5)
|
||||||
{
|
{
|
||||||
bool yes = Actions::askYesNoQuestion("Number tracks?");
|
Actions::confirmAction("Number tracks?");
|
||||||
if (yes)
|
auto it = EditedSongs.begin();
|
||||||
|
for (unsigned i = 1; i <= EditedSongs.size(); ++i, ++it)
|
||||||
{
|
{
|
||||||
auto it = EditedSongs.begin();
|
if (Config.tag_editor_extended_numeration)
|
||||||
for (unsigned i = 1; i <= EditedSongs.size(); ++i, ++it)
|
(*it)->setTrack(boost::lexical_cast<std::string>(i) + "/" + boost::lexical_cast<std::string>(EditedSongs.size()));
|
||||||
{
|
else
|
||||||
if (Config.tag_editor_extended_numeration)
|
(*it)->setTrack(boost::lexical_cast<std::string>(i));
|
||||||
(*it)->setTrack(boost::lexical_cast<std::string>(i) + "/" + boost::lexical_cast<std::string>(EditedSongs.size()));
|
|
||||||
else
|
|
||||||
(*it)->setTrack(boost::lexical_cast<std::string>(i));
|
|
||||||
}
|
|
||||||
Statusbar::print("Tracks numbered");
|
|
||||||
}
|
}
|
||||||
else
|
Statusbar::print("Tracks numbered");
|
||||||
Statusbar::print("Aborted");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -879,8 +874,9 @@ bool TagEditor::previousColumnAvailable()
|
|||||||
}
|
}
|
||||||
else if (w == TagTypes)
|
else if (w == TagTypes)
|
||||||
{
|
{
|
||||||
if (!Dirs->reallyEmpty())
|
if (!Dirs->reallyEmpty() && isAnyModified(*Tags))
|
||||||
result = ifAnyModifiedAskForDiscarding();
|
Actions::confirmAction("There are pending changes, are you sure?");
|
||||||
|
result = true;
|
||||||
}
|
}
|
||||||
else if (w == FParserHelper)
|
else if (w == FParserHelper)
|
||||||
result = true;
|
result = true;
|
||||||
@@ -959,14 +955,6 @@ void TagEditor::nextColumn()
|
|||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
|
||||||
bool TagEditor::ifAnyModifiedAskForDiscarding()
|
|
||||||
{
|
|
||||||
bool result = true;
|
|
||||||
if (isAnyModified(*Tags))
|
|
||||||
result = Actions::askYesNoQuestion("There are pending changes, are you sure?");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TagEditor::LocateSong(const MPD::Song &s)
|
void TagEditor::LocateSong(const MPD::Song &s)
|
||||||
{
|
{
|
||||||
if (myScreen == this)
|
if (myScreen == this)
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ struct TagEditor: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Search
|
|||||||
virtual void nextColumn() OVERRIDE;
|
virtual void nextColumn() OVERRIDE;
|
||||||
|
|
||||||
// private members
|
// private members
|
||||||
bool ifAnyModifiedAskForDiscarding();
|
|
||||||
void LocateSong(const MPD::Song &s);
|
void LocateSong(const MPD::Song &s);
|
||||||
const std::string &CurrentDir() { return itsBrowsedDir; }
|
const std::string &CurrentDir() { return itsBrowsedDir; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user