mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-12 03:39:58 +00:00
Added support for deleting and renaming playlists in browse view.
This commit is contained in:
parent
33468e0263
commit
1ae8dee1fc
@ -193,10 +193,6 @@ void BrowseLayout::ScrollTo(const std::string& fieldType, int64_t fieldId) {
|
||||
this->categoryTitle->SetText(title, text::AlignCenter);
|
||||
}
|
||||
|
||||
IWindowPtr BrowseLayout::GetFocus() {
|
||||
return this->focused ? this->focused : LayoutBase::GetFocus();
|
||||
}
|
||||
|
||||
void BrowseLayout::OnVisibilityChanged(bool visible) {
|
||||
LayoutBase::OnVisibilityChanged(visible);
|
||||
|
||||
@ -296,14 +292,14 @@ bool BrowseLayout::IsEditable() {
|
||||
|
||||
bool BrowseLayout::ProcessPlaylistOperation(const std::string& key) {
|
||||
if (IsEditable()) {
|
||||
if (Hotkeys::Is(Hotkeys::PlayQueuePlaylistNew, key)) {
|
||||
if (Hotkeys::Is(Hotkeys::BrowsePlaylistsNew, key)) {
|
||||
auto lastId = this->categoryList->GetSelectedId();
|
||||
PlayQueueOverlays::ShowCreatePlaylistOverlay(library, [this, lastId](auto query) {
|
||||
this->categoryList->Requery(this->categoryList->GetFilter(), lastId);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
else if (Hotkeys::Is(Hotkeys::PlayQueuePlaylistSave, key)) {
|
||||
else if (Hotkeys::Is(Hotkeys::BrowsePlaylistsSave, key)) {
|
||||
this->ShowModifiedLabel(false);
|
||||
auto tracks = this->trackList->GetTrackList().get();
|
||||
this->library->Enqueue(SavePlaylistQuery::Replace(
|
||||
@ -311,6 +307,28 @@ bool BrowseLayout::ProcessPlaylistOperation(const std::string& key) {
|
||||
std::shared_ptr<TrackList>(new TrackList(tracks))));
|
||||
return true;
|
||||
}
|
||||
else if (Hotkeys::Is(Hotkeys::BrowsePlaylistsRename, key)) {
|
||||
auto id = this->categoryList->GetSelectedId();
|
||||
if (id != -1) {
|
||||
PlayQueueOverlays::ShowRenamePlaylistOverlay(
|
||||
library, id, this->categoryList->GetSelectedValue(),
|
||||
[this, id](auto query) {
|
||||
this->categoryList->Requery(this->categoryList->GetFilter(), id);
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (Hotkeys::Is(Hotkeys::BrowsePlaylistsDelete, key)) {
|
||||
if (this->GetFocus() == this->categoryList) {
|
||||
auto id = this->categoryList->GetSelectedId();
|
||||
if (id != -1) {
|
||||
PlayQueueOverlays::ShowConfirmDeletePlaylistOverlay(
|
||||
library, this->categoryList->GetSelectedValue(), id,
|
||||
[this](auto query) {
|
||||
this->categoryList->Requery();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -63,7 +63,6 @@ namespace musik {
|
||||
virtual ~BrowseLayout();
|
||||
|
||||
virtual void OnVisibilityChanged(bool visible);
|
||||
virtual cursespp::IWindowPtr GetFocus();
|
||||
virtual bool KeyPress(const std::string& key);
|
||||
virtual void ProcessMessage(musik::core::runtime::IMessage &message);
|
||||
void ScrollTo(const std::string& fieldType, int64_t fieldId);
|
||||
@ -98,7 +97,6 @@ namespace musik {
|
||||
std::shared_ptr<cursespp::TextLabel> categoryTitle;
|
||||
std::shared_ptr<cursespp::TextLabel> tracksTitle;
|
||||
std::shared_ptr<cursespp::TextLabel> modifiedLabel;
|
||||
cursespp::IWindowPtr focused;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -182,10 +182,11 @@ static void createNewPlaylist(
|
||||
cursespp::App::Overlays().Push(dialog);
|
||||
}
|
||||
|
||||
static void renamePlaylist(
|
||||
void PlayQueueOverlays::ShowRenamePlaylistOverlay(
|
||||
musik::core::ILibraryPtr library,
|
||||
const int64_t playlistId,
|
||||
const std::string& oldName)
|
||||
const std::string& oldName,
|
||||
QueryCallback callback)
|
||||
{
|
||||
std::shared_ptr<InputOverlay> dialog(new InputOverlay());
|
||||
|
||||
@ -193,19 +194,20 @@ static void renamePlaylist(
|
||||
.SetWidth(_DIMEN("playqueue_playlist_name_overlay", DEFAULT_OVERLAY_WIDTH))
|
||||
.SetText(oldName)
|
||||
.SetInputAcceptedCallback(
|
||||
[library, playlistId](const std::string& name) {
|
||||
[library, playlistId, callback](const std::string& name) {
|
||||
if (name.size()) {
|
||||
library->Enqueue(SavePlaylistQuery::Rename(playlistId, name));
|
||||
library->Enqueue(SavePlaylistQuery::Rename(playlistId, name), 0, callback);
|
||||
}
|
||||
});
|
||||
|
||||
cursespp::App::Overlays().Push(dialog);
|
||||
}
|
||||
|
||||
static void confirmDeletePlaylist(
|
||||
void PlayQueueOverlays::ShowConfirmDeletePlaylistOverlay(
|
||||
musik::core::ILibraryPtr library,
|
||||
const std::string& playlistName,
|
||||
const int64_t playlistId)
|
||||
const int64_t playlistId,
|
||||
QueryCallback callback )
|
||||
{
|
||||
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
|
||||
|
||||
@ -219,9 +221,9 @@ static void confirmDeletePlaylist(
|
||||
"KEY_ENTER",
|
||||
"ENTER",
|
||||
_TSTR("button_yes"),
|
||||
[library, playlistId](const std::string& str) {
|
||||
[library, playlistId, callback](const std::string& str) {
|
||||
library->Enqueue(std::shared_ptr<DeletePlaylistQuery>(
|
||||
new DeletePlaylistQuery(playlistId)));
|
||||
new DeletePlaylistQuery(playlistId)), 0, callback);
|
||||
});
|
||||
|
||||
App::Overlays().Push(dialog);
|
||||
@ -605,7 +607,7 @@ void PlayQueueOverlays::ShowRenamePlaylistOverlay(musik::core::ILibraryPtr libra
|
||||
if (index != ListWindow::NO_SELECTION) {
|
||||
int64_t playlistId = (*result)[index]->id;
|
||||
std::string playlistName = (*result)[index]->displayValue;
|
||||
renamePlaylist(library, playlistId, playlistName);
|
||||
ShowRenamePlaylistOverlay(library, playlistId, playlistName);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -631,7 +633,7 @@ void PlayQueueOverlays::ShowDeletePlaylistOverlay(musik::core::ILibraryPtr libra
|
||||
if (index != ListWindow::NO_SELECTION) {
|
||||
int64_t playlistId = (*result)[index]->id;
|
||||
std::string playlistName = (*result)[index]->displayValue;
|
||||
confirmDeletePlaylist(library, playlistName, playlistId);
|
||||
ShowConfirmDeletePlaylistOverlay(library, playlistName, playlistId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -77,9 +77,21 @@ namespace musik {
|
||||
static void ShowRenamePlaylistOverlay(
|
||||
musik::core::ILibraryPtr library);
|
||||
|
||||
static void ShowRenamePlaylistOverlay(
|
||||
musik::core::ILibraryPtr library,
|
||||
const int64_t playlistId,
|
||||
const std::string& old,
|
||||
QueryCallback callback = QueryCallback());
|
||||
|
||||
static void ShowDeletePlaylistOverlay(
|
||||
musik::core::ILibraryPtr library);
|
||||
|
||||
static void ShowConfirmDeletePlaylistOverlay(
|
||||
musik::core::ILibraryPtr library,
|
||||
const std::string& playlistName,
|
||||
const int64_t playlistId,
|
||||
QueryCallback callback = QueryCallback());
|
||||
|
||||
static void ShowCreatePlaylistOverlay(
|
||||
musik::core::ILibraryPtr library,
|
||||
QueryCallback callback = QueryCallback());
|
||||
|
@ -75,7 +75,11 @@ static std::unordered_map<std::string, Id> NAME_TO_ID = {
|
||||
{ "play_queue_playlist_save", Id::PlayQueuePlaylistSave },
|
||||
{ "play_queue_playlist_rename", Id::PlayQueuePlaylistRename },
|
||||
{ "play_queue_playlist_delete", Id::PlayQueuePlaylistDelete },
|
||||
{ "play_queue_playlist_new", Id::PlayQueuePlaylistNew },
|
||||
|
||||
{ "browse_playlists_new", Id::BrowsePlaylistsNew },
|
||||
{ "browse_playlists_save", Id::BrowsePlaylistsSave },
|
||||
{ "browse_playlists_rename", Id::BrowsePlaylistsRename },
|
||||
{ "browse_playlists_delete", Id::BrowsePlaylistsDelete },
|
||||
|
||||
{ "playback_toggle_mute", Id::ToggleMute },
|
||||
{ "playback_toggle_pause", Id::TogglePause },
|
||||
@ -129,7 +133,15 @@ static std::unordered_map<Id, std::string, EnumHasher> ID_TO_DEFAULT = {
|
||||
{ Id::PlayQueuePlaylistSave, "M-s" },
|
||||
{ Id::PlayQueuePlaylistRename, "M-r" },
|
||||
{ Id::PlayQueuePlaylistDelete, "M-x" },
|
||||
{ Id::PlayQueuePlaylistNew, "M-n" },
|
||||
|
||||
{ Id::BrowsePlaylistsSave, "M-s" },
|
||||
{ Id::BrowsePlaylistsNew, "M-n" },
|
||||
{ Id::BrowsePlaylistsRename, "M-r" },
|
||||
#ifdef __APPLE__
|
||||
{ Id::BrowsePlaylistsDelete, "KEY_BACKSPACE" },
|
||||
#else
|
||||
{ Id::BrowsePlaylistsDelete, "KEY_DC" },
|
||||
#endif
|
||||
|
||||
{ Id::ToggleMute, "m" },
|
||||
{ Id::TogglePause, "^P" },
|
||||
|
@ -79,12 +79,17 @@ namespace musik {
|
||||
PlayQueueMoveUp,
|
||||
PlayQueueMoveDown,
|
||||
PlayQueueDelete,
|
||||
PlayQueuePlaylistNew,
|
||||
PlayQueuePlaylistLoad,
|
||||
PlayQueuePlaylistSave,
|
||||
PlayQueuePlaylistRename,
|
||||
PlayQueuePlaylistDelete,
|
||||
|
||||
/* browse ->playlists */
|
||||
BrowsePlaylistsNew,
|
||||
BrowsePlaylistsSave,
|
||||
BrowsePlaylistsRename,
|
||||
BrowsePlaylistsDelete,
|
||||
|
||||
/* indexer */
|
||||
RescanMetadata,
|
||||
|
||||
|
@ -112,6 +112,14 @@ int64_t CategoryListView::GetSelectedId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string CategoryListView::GetSelectedValue() {
|
||||
size_t index = this->GetSelectedIndex();
|
||||
if (index != NO_SELECTION && this->metadata && index < this->metadata->size()) {
|
||||
return this->metadata->at(index)->displayValue;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string CategoryListView::GetFieldName() {
|
||||
return this->fieldName;
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ namespace musik {
|
||||
void Reset();
|
||||
|
||||
int64_t GetSelectedId();
|
||||
std::string GetSelectedValue();
|
||||
std::string GetFilter();
|
||||
std::string GetFieldName();
|
||||
void SetFieldName(const std::string& fieldName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user