actions: make askYesNoQuestion use boost::format
This commit is contained in:
@@ -252,12 +252,12 @@ void setWindowsDimensions()
|
|||||||
FooterHeight = Config.statusbar_visibility ? 2 : 1;
|
FooterHeight = Config.statusbar_visibility ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool askYesNoQuestion(const std::string &question, void (*callback)())
|
bool askYesNoQuestion(const boost::format &fmt, void (*callback)())
|
||||||
{
|
{
|
||||||
using Global::wFooter;
|
using Global::wFooter;
|
||||||
|
|
||||||
Statusbar::lock();
|
Statusbar::lock();
|
||||||
Statusbar::put() << question << " [" << NC::Format::Bold << 'y' << NC::Format::NoBold << '/' << NC::Format::Bold << 'n' << NC::Format::NoBold << "]";
|
Statusbar::put() << fmt.str() << " [" << NC::Format::Bold << 'y' << NC::Format::NoBold << '/' << NC::Format::Bold << 'n' << NC::Format::NoBold << "]";
|
||||||
wFooter->refresh();
|
wFooter->refresh();
|
||||||
int answer = 0;
|
int answer = 0;
|
||||||
do
|
do
|
||||||
@@ -660,18 +660,15 @@ bool DeleteBrowserItems::canBeRun() const
|
|||||||
|
|
||||||
void DeleteBrowserItems::run()
|
void DeleteBrowserItems::run()
|
||||||
{
|
{
|
||||||
std::string question;
|
boost::format question;
|
||||||
if (hasSelected(myBrowser->main().begin(), myBrowser->main().end()))
|
if (hasSelected(myBrowser->main().begin(), myBrowser->main().end()))
|
||||||
question = "Delete selected items?";
|
question = boost::format("Delete selected items?");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MPD::Item &item = myBrowser->main().current().value();
|
MPD::Item &item = myBrowser->main().current().value();
|
||||||
std::string iname = item.type == MPD::itSong ? item.song->getName() : item.name;
|
std::string iname = item.type == MPD::itSong ? item.song->getName() : item.name;
|
||||||
question = "Delete ";
|
question = boost::format("Delete %1% \"%2%\"?")
|
||||||
question += itemTypeToString(item.type);
|
% itemTypeToString(item.type) % wideShorten(iname, COLS-question.size()-10);
|
||||||
question += " \"";
|
|
||||||
question += ToString(wideShorten(ToWString(iname), COLS-question.size()-10));
|
|
||||||
question += "\"?";
|
|
||||||
}
|
}
|
||||||
bool yes = askYesNoQuestion(question, Status::trace);
|
bool yes = askYesNoQuestion(question, Status::trace);
|
||||||
if (yes)
|
if (yes)
|
||||||
@@ -715,15 +712,12 @@ bool DeleteStoredPlaylist::canBeRun() const
|
|||||||
|
|
||||||
void DeleteStoredPlaylist::run()
|
void DeleteStoredPlaylist::run()
|
||||||
{
|
{
|
||||||
std::string question;
|
boost::format question;
|
||||||
if (hasSelected(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end()))
|
if (hasSelected(myPlaylistEditor->Playlists.begin(), myPlaylistEditor->Playlists.end()))
|
||||||
question = "Delete selected playlists?";
|
question = boost::format("Delete selected playlists?");
|
||||||
else
|
else
|
||||||
{
|
question = boost::format("Delete playlist \"%1%\"?")
|
||||||
question = "Delete playlist \"";
|
% wideShorten(myPlaylistEditor->Playlists.current().value(), COLS-question.size()-10);
|
||||||
question += ToString(wideShorten(ToWString(myPlaylistEditor->Playlists.current().value()), COLS-question.size()-10));
|
|
||||||
question += "\"?";
|
|
||||||
}
|
|
||||||
bool yes = askYesNoQuestion(question, Status::trace);
|
bool yes = askYesNoQuestion(question, Status::trace);
|
||||||
if (yes)
|
if (yes)
|
||||||
{
|
{
|
||||||
@@ -793,7 +787,10 @@ void SavePlaylist::run()
|
|||||||
{
|
{
|
||||||
if (e.code() == MPD_SERVER_ERROR_EXIST)
|
if (e.code() == MPD_SERVER_ERROR_EXIST)
|
||||||
{
|
{
|
||||||
bool yes = askYesNoQuestion("Playlist \"" + playlist_name + "\" already exists, overwrite?", Status::trace);
|
bool yes = askYesNoQuestion(
|
||||||
|
boost::format("Playlist \"%1%\" already exists, overwrite?") % playlist_name,
|
||||||
|
Status::trace
|
||||||
|
);
|
||||||
if (yes)
|
if (yes)
|
||||||
{
|
{
|
||||||
Mpd.DeletePlaylist(playlist_name);
|
Mpd.DeletePlaylist(playlist_name);
|
||||||
@@ -1711,7 +1708,10 @@ void CropPlaylist::run()
|
|||||||
std::string playlist = myPlaylistEditor->Playlists.current().value();
|
std::string playlist = myPlaylistEditor->Playlists.current().value();
|
||||||
bool yes = true;
|
bool yes = true;
|
||||||
if (Config.ask_before_clearing_main_playlist)
|
if (Config.ask_before_clearing_main_playlist)
|
||||||
yes = askYesNoQuestion("Do you really want to crop playlist \"" + playlist + "\"?", Status::trace);
|
yes = askYesNoQuestion(
|
||||||
|
boost::format("Do you really want to crop playlist \"%1%\"?") % playlist,
|
||||||
|
Status::trace
|
||||||
|
);
|
||||||
if (yes)
|
if (yes)
|
||||||
{
|
{
|
||||||
auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
|
auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
|
||||||
@@ -1748,7 +1748,10 @@ void ClearPlaylist::run()
|
|||||||
std::string playlist = myPlaylistEditor->Playlists.current().value();
|
std::string playlist = myPlaylistEditor->Playlists.current().value();
|
||||||
bool yes = true;
|
bool yes = true;
|
||||||
if (Config.ask_before_clearing_main_playlist)
|
if (Config.ask_before_clearing_main_playlist)
|
||||||
yes = askYesNoQuestion("Do you really want to clear playlist \"" + playlist + "\"?", Status::trace);
|
yes = askYesNoQuestion(
|
||||||
|
boost::format("Do you really want to clear playlist \"%1%\"?") % playlist,
|
||||||
|
Status::trace
|
||||||
|
);
|
||||||
if (yes)
|
if (yes)
|
||||||
{
|
{
|
||||||
auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
|
auto delete_fun = boost::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#ifndef NCMPCPP_ACTIONS_H
|
#ifndef NCMPCPP_ACTIONS_H
|
||||||
#define NCMPCPP_ACTIONS_H
|
#define NCMPCPP_ACTIONS_H
|
||||||
|
|
||||||
|
#include <boost/format.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
@@ -66,7 +67,12 @@ void setResizeFlags();
|
|||||||
void resizeScreen(bool reload_main_window);
|
void resizeScreen(bool reload_main_window);
|
||||||
void setWindowsDimensions();
|
void setWindowsDimensions();
|
||||||
|
|
||||||
bool askYesNoQuestion(const std::string &question, void (*callback)());
|
bool askYesNoQuestion(const boost::format &question, void (*callback)());
|
||||||
|
inline bool askYesNoQuestion(const std::string &question, void (*callback)())
|
||||||
|
{
|
||||||
|
return askYesNoQuestion(boost::format(question), callback);
|
||||||
|
}
|
||||||
|
|
||||||
bool isMPDMusicDirSet();
|
bool isMPDMusicDirSet();
|
||||||
|
|
||||||
extern bool OriginalStatusbarVisibility;
|
extern bool OriginalStatusbarVisibility;
|
||||||
|
|||||||
Reference in New Issue
Block a user