Skip to content

Commit 2122b43

Browse files
authored
Allow showing actions on the current context page (#857)
As suggested in issue #427 this PR introduces a new `ShowActionsOnCurrentContext` command, this allows the user to trigger the actions menu directly when viewing a context page. Closes #427
1 parent bbf4e04 commit 2122b43

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ List of supported commands:
374374
| `RestartIntegratedClient` | restart the integrated client (`streaming` feature only) | `R` |
375375
| `ShowActionsOnSelectedItem` | open a popup showing actions on a selected item | `g a`, `C-space` |
376376
| `ShowActionsOnCurrentTrack` | open a popup showing actions on the current track | `a` |
377+
| `ShowActionsOnCurrentContext` | open a popup showing actions on the current context | `A` |
377378
| `AddSelectedItemToQueue` | add the selected item to queue | `Z`, `C-z` |
378379
| `FocusNextWindow` | focus the next focusable window (if any) | `tab` |
379380
| `FocusPreviousWindow` | focus the previous focusable window (if any) | `backtab` |

spotify_player/src/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub enum Command {
5656

5757
ShowActionsOnSelectedItem,
5858
ShowActionsOnCurrentTrack,
59+
ShowActionsOnCurrentContext,
5960
AddSelectedItemToQueue,
6061
JumpToHighlightTrackInContext,
6162

@@ -334,6 +335,7 @@ impl Command {
334335
Self::RefreshPlayback => "manually refresh the current playback",
335336
Self::ShowActionsOnSelectedItem => "open a popup showing actions on a selected item",
336337
Self::ShowActionsOnCurrentTrack => "open a popup showing actions on the current track",
338+
Self::ShowActionsOnCurrentContext => "open a popup showing actions on the current context",
337339
Self::AddSelectedItemToQueue => "add the selected item to queue",
338340
Self::JumpToHighlightTrackInContext => "jump to the currently highlighted search result in the context",
339341
Self::FocusNextWindow => "focus the next focusable window (if any)",

spotify_player/src/config/keymap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ impl Default for KeymapConfig {
123123
key_sequence: "a".into(),
124124
command: Command::ShowActionsOnCurrentTrack,
125125
},
126+
Keymap {
127+
key_sequence: "A".into(),
128+
command: Command::ShowActionsOnCurrentContext,
129+
},
126130
#[cfg(feature = "streaming")]
127131
Keymap {
128132
key_sequence: "R".into(),

spotify_player/src/event/page.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use anyhow::Context as _;
22
use command::CommandOrAction;
33

4+
use crate::command::{construct_album_actions, construct_playlist_actions, construct_show_actions};
5+
46
use super::*;
57

68
pub fn handle_key_sequence_for_page(
@@ -364,6 +366,55 @@ fn handle_command_for_context_page(
364366
ui.new_search_popup();
365367
Ok(true)
366368
}
369+
Command::ShowActionsOnCurrentContext => {
370+
let context_id = match ui.current_page() {
371+
PageState::Context { id, .. } => match id {
372+
None => return Ok(false),
373+
Some(id) => id,
374+
},
375+
_ => anyhow::bail!("expect a context page"),
376+
};
377+
let data = state.data.read();
378+
379+
match data.caches.context.get(&context_id.uri()) {
380+
Some(context) => match context {
381+
Context::Playlist { playlist, .. } => {
382+
let actions = construct_playlist_actions(playlist, &data);
383+
ui.popup = Some(PopupState::ActionList(
384+
Box::new(ActionListItem::Playlist(playlist.clone(), actions)),
385+
ListState::default(),
386+
));
387+
Ok(true)
388+
}
389+
Context::Album { album, .. } => {
390+
let actions = construct_album_actions(album, &data);
391+
ui.popup = Some(PopupState::ActionList(
392+
Box::new(ActionListItem::Album(album.clone(), actions)),
393+
ListState::default(),
394+
));
395+
Ok(true)
396+
}
397+
Context::Artist { artist, .. } => {
398+
let actions = construct_artist_actions(artist, &data);
399+
ui.popup = Some(PopupState::ActionList(
400+
Box::new(ActionListItem::Artist(artist.clone(), actions)),
401+
ListState::default(),
402+
));
403+
Ok(true)
404+
}
405+
Context::Show { show, .. } => {
406+
let actions = construct_show_actions(show, &data);
407+
ui.popup = Some(PopupState::ActionList(
408+
Box::new(ActionListItem::Show(show.clone(), actions)),
409+
ListState::default(),
410+
));
411+
Ok(true)
412+
}
413+
Context::Tracks { tracks: _, desc: _ } => Ok(false),
414+
},
415+
None => Ok(false),
416+
}
417+
}
367418
_ => window::handle_command_for_focused_context_window(command, client_pub, ui, state),
368419
}
369420
}

0 commit comments

Comments
 (0)