RenamePlaylist.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "main.h"
  2. #include "resource.h"
  3. using namespace Nullsoft::Utility;
  4. static INT_PTR CALLBACK RenamePlaylistDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  5. {
  6. static GUID playlist_guid = INVALID_GUID;
  7. switch (uMsg)
  8. {
  9. case WM_INITDIALOG:
  10. {
  11. playlist_guid = *(GUID *)lParam;
  12. AutoLockT<api_playlists> lock (AGAVE_API_PLAYLISTS);
  13. PlaylistInfo playlist(playlist_guid);
  14. if (playlist.Valid())
  15. {
  16. size_t index = playlist.GetIndex();
  17. const wchar_t *title = AGAVE_API_PLAYLISTS->GetName(index);
  18. SetDlgItemText(hwndDlg, IDC_NAME, title);
  19. SendMessage(GetDlgItem(hwndDlg, IDC_NAME), EM_SETSEL, 0, -1);
  20. SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_NAME), TRUE);
  21. }
  22. else
  23. EndDialog(hwndDlg, 1);
  24. }
  25. break;
  26. case WM_COMMAND:
  27. switch (LOWORD(wParam))
  28. {
  29. case IDOK:
  30. {
  31. wchar_t name[1024] = {0};
  32. GetDlgItemText(hwndDlg, IDC_NAME, name, 1023);
  33. name[1023] = 0;
  34. if (!name[0])
  35. {
  36. wchar_t titleStr[32] = {0};
  37. MessageBox(hwndDlg, WASABI_API_LNGSTRINGW(IDS_ENTER_A_NAME),
  38. WASABI_API_LNGSTRINGW_BUF(IDS_ERROR,titleStr,32), MB_OK);
  39. break;
  40. }
  41. AutoLockT<api_playlists> lock (AGAVE_API_PLAYLISTS);
  42. PlaylistInfo playlist(playlist_guid);
  43. if (playlist.Valid())
  44. {
  45. size_t index = playlist.GetIndex();
  46. AGAVE_API_PLAYLISTS->RenamePlaylist(index, name);
  47. AGAVE_API_PLAYLISTS->Flush(); // TODO: save immediately? or only at the end?
  48. }
  49. EndDialog(hwndDlg, 1);
  50. }
  51. break;
  52. case IDCANCEL:
  53. EndDialog(hwndDlg, 0);
  54. break;
  55. }
  56. break;
  57. }
  58. return FALSE;
  59. };
  60. void RenamePlaylist(GUID _guid, HWND parent)
  61. {
  62. WASABI_API_DIALOGBOXPARAMW(IDD_RENAME_PLAYLIST, parent, RenamePlaylistDialogProc, (LPARAM)&_guid);
  63. }