Add add command for adding song to playlist (#1232)
* Add command for adding song to playlist * edits for code style * Return playlist dialog via `CommandResult::Modal` --------- Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
This commit is contained in:
@@ -134,6 +134,8 @@ pub enum Command {
|
||||
Save,
|
||||
SaveCurrent,
|
||||
SaveQueue,
|
||||
Add,
|
||||
AddCurrent,
|
||||
Delete,
|
||||
Focus(String),
|
||||
Seek(SeekDirection),
|
||||
@@ -216,6 +218,8 @@ impl fmt::Display for Command {
|
||||
| Command::Save
|
||||
| Command::SaveCurrent
|
||||
| Command::SaveQueue
|
||||
| Command::Add
|
||||
| Command::AddCurrent
|
||||
| Command::Delete
|
||||
| Command::Back
|
||||
| Command::Help
|
||||
@@ -246,6 +250,8 @@ impl Command {
|
||||
Command::Save => "save",
|
||||
Command::SaveCurrent => "save current",
|
||||
Command::SaveQueue => "save queue",
|
||||
Command::Add => "add",
|
||||
Command::AddCurrent => "add current",
|
||||
Command::Delete => "delete",
|
||||
Command::Focus(_) => "focus",
|
||||
Command::Seek(_) => "seek",
|
||||
@@ -389,6 +395,14 @@ pub fn parse(input: &str) -> Result<Vec<Command>, CommandParseError> {
|
||||
"playnext" => Command::PlayNext,
|
||||
"play" => Command::Play,
|
||||
"update" => Command::UpdateLibrary,
|
||||
"add" => match args.first().cloned() {
|
||||
Some("current") => Ok(Command::AddCurrent),
|
||||
Some(arg) => Err(BadEnumArg {
|
||||
arg: arg.into(),
|
||||
accept: vec!["**omit**".into(), "queue".into()],
|
||||
}),
|
||||
None => Ok(Command::Add),
|
||||
}?,
|
||||
"save" => match args.first().cloned() {
|
||||
Some("queue") => Ok(Command::SaveQueue),
|
||||
Some("current") => Ok(Command::SaveCurrent),
|
||||
|
||||
@@ -272,6 +272,19 @@ impl CommandManager {
|
||||
self.spotify.shutdown();
|
||||
Ok(None)
|
||||
}
|
||||
Command::AddCurrent => {
|
||||
if let Some(track) = self.queue.get_current() {
|
||||
if let Some(track) = track.track() {
|
||||
let dialog = ContextMenu::add_track_dialog(
|
||||
self.library.clone(),
|
||||
self.queue.get_spotify(),
|
||||
track,
|
||||
);
|
||||
s.add_layer(dialog);
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
Command::SaveCurrent => {
|
||||
if let Some(mut track) = self.queue.get_current() {
|
||||
track.save(&self.library);
|
||||
@@ -284,6 +297,7 @@ impl CommandManager {
|
||||
| Command::Play
|
||||
| Command::Save
|
||||
| Command::SaveQueue
|
||||
| Command::Add
|
||||
| Command::Delete
|
||||
| Command::Focus(_)
|
||||
| Command::Back
|
||||
|
||||
@@ -520,6 +520,25 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
||||
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
}
|
||||
Command::Add => {
|
||||
let item = {
|
||||
let content = self.content.read().unwrap();
|
||||
content.get(self.selected).cloned()
|
||||
};
|
||||
|
||||
if let Some(track) = item {
|
||||
if let Some(track) = track.track() {
|
||||
let dialog = ContextMenu::add_track_dialog(
|
||||
self.library.clone(),
|
||||
self.queue.get_spotify(),
|
||||
track,
|
||||
);
|
||||
return Ok(CommandResult::Modal(Box::new(dialog)));
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
}
|
||||
Command::Delete => {
|
||||
let mut item = {
|
||||
let content = self.content.read().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user