Krolyxon
Commit 96dd350

rmptuisrcmpdselection.rs

36 lines · 1.1 KB · Rust

1use super::{Command, commands};
2
3/// A set of songs chosen in the UI, to be added to the queue or a playlist.
4#[derive(Clone, Debug, PartialEq, Eq)]
5pub enum Selection {
6 /// Songs or directories (added recursively).
7 Uris(Vec<String>),
8 /// Every song matching a filter expression.
9 Filter(String),
10}
11
12impl Selection {
13 pub fn is_empty(&self) -> bool {
14 match self {
15 Self::Uris(uris) => uris.is_empty(),
16 Self::Filter(_) => false,
17 }
18 }
19
20 pub fn add_to_queue(&self) -> Vec<Command> {
21 match self {
22 Self::Uris(uris) => uris.iter().map(|uri| commands::add(uri)).collect(),
23 Self::Filter(filter) => vec![commands::find_add(filter)],
24 }
25 }
26
27 pub fn add_to_playlist(&self, playlist: &str) -> Vec<Command> {
28 match self {
29 Self::Uris(uris) => uris
30 .iter()
31 .map(|uri| commands::playlist_add(playlist, uri))
32 .collect(),
33 Self::Filter(filter) => vec![commands::playlist_add_filter(playlist, filter)],
34 }
35 }
36}