diff --git a/src/command.rs b/src/command.rs index 2ea2968..1f63e40 100644 --- a/src/command.rs +++ b/src/command.rs @@ -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, 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), diff --git a/src/commands.rs b/src/commands.rs index 99fa94b..94d6632 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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 diff --git a/src/ui/listview.rs b/src/ui/listview.rs index 328a3e0..479101a 100644 --- a/src/ui/listview.rs +++ b/src/ui/listview.rs @@ -520,6 +520,25 @@ impl ViewExt for ListView { 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();