Skip to content

Commit

Permalink
从磁盘删除文件时如果只有一个文件显示要删除文件的文件名;删除正在播放的曲目时增加确认消息框
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Aug 21, 2024
1 parent b3eee4d commit 247501e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 8 additions & 1 deletion MusicPlayer2/MusicPlayerCmdHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,14 @@ bool CMusicPlayerCmdHelper::DeleteSongsFromDisk(const std::vector<SongInfo>& fil
if (theApp.m_media_lib_setting_data.disable_delete_from_disk)
return false;

wstring info = theApp.m_str_table.LoadTextFormat(L"MSG_DELETE_SEL_AUDIO_FILE_INQUIRY", { files.size() });
if (files.empty())
return false;

wstring info;
if (files.size() == 1)
info = theApp.m_str_table.LoadTextFormat(L"MSG_DELETE_SINGLE_FILE_INQUIRY", { files.front().file_path });
else
info = theApp.m_str_table.LoadTextFormat(L"MSG_DELETE_SEL_AUDIO_FILE_INQUIRY", { files.size() });
if (GetOwner()->MessageBox(info.c_str(), NULL, MB_ICONWARNING | MB_OKCANCEL) != IDOK)
return false;

Expand Down
23 changes: 20 additions & 3 deletions MusicPlayer2/MusicPlayerDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3610,7 +3610,17 @@ void CMusicPlayerDlg::OnDeleteFromDisk()

if (m_item_selected < 0 || m_item_selected >= CPlayer::GetInstance().GetSongNum())
return;
wstring info = theApp.m_str_table.LoadTextFormat(L"MSG_DELETE_SEL_AUDIO_FILE_INQUIRY", { m_items_selected.size() });

wstring info;
if (m_items_selected.size() == 1)
{
const auto& song = CPlayer::GetInstance().GetPlayList()[m_items_selected.front()];
info = theApp.m_str_table.LoadTextFormat(L"MSG_DELETE_SINGLE_FILE_INQUIRY", { song.file_path });
}
else
{
info = theApp.m_str_table.LoadTextFormat(L"MSG_DELETE_SEL_AUDIO_FILE_INQUIRY", { m_items_selected.size() });
}
if (MessageBoxW(info.c_str(), NULL, MB_ICONWARNING | MB_OKCANCEL) != IDOK) return;
// 以下操作可能涉及MusicControl,先取得锁
if (!CPlayer::GetInstance().GetPlayStatusMutex().try_lock_for(std::chrono::milliseconds(1000))) return;
Expand Down Expand Up @@ -5918,8 +5928,15 @@ void CMusicPlayerDlg::OnRemoveCurrentFromPlaylist()
// TODO: 在此添加命令处理程序代码
if (CPlayer::GetInstance().IsPlaylistMode())
{
CPlayer::GetInstance().RemoveSong(CPlayer::GetInstance().GetIndex());
ShowPlayList(false);
const SongInfo& song = CPlayer::GetInstance().GetCurrentSongInfo();
std::wstring song_display_name = CSongInfoHelper::GetDisplayStr(song, theApp.m_media_lib_setting_data.display_format);
std::wstring playlist_name = CPlaylistMgr::GetPlaylistDisplayName(CPlayer::GetInstance().GetPlaylistPath());
std::wstring info = theApp.m_str_table.LoadTextFormat(L"MSG_REMOVE_SINGLE_ITEM_FROM_PLAYLIST_INQUIRY", { playlist_name, song_display_name });
if (MessageBox(info.c_str(), NULL, MB_ICONQUESTION | MB_YESNO) == IDYES)
{
CPlayer::GetInstance().RemoveSong(CPlayer::GetInstance().GetIndex());
ShowPlayList(false);
}
}
}

Expand Down

0 comments on commit 247501e

Please sign in to comment.