Move share command handling completely to ListView

This commit is contained in:
Rasmus Larsen
2019-05-10 12:55:22 +02:00
parent 90c1930c39
commit 224597ae92
2 changed files with 16 additions and 36 deletions

View File

@@ -198,25 +198,6 @@ impl CommandManager {
);
}
{
let queue = queue.clone();
self.register_command(
"share",
Some(Box::new(move |_, args| {
if let Some(url) = args.get(0).and_then(|source| match source.as_str() {
"current" => queue.get_current().and_then(|t| t.share_url()),
_ => None,
}) {
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
.unwrap();
}
Ok(None)
})),
)
}
{
let spotify = spotify.clone();
self.register_command(

View File

@@ -316,23 +316,22 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
}
if cmd == "share" {
return args.get(0).map_or_else(
|| Err("wrong number of parameters".to_string()),
|source| match source.as_str() {
"selected" => {
if let Some(url) = self.content.read().ok().and_then(|content| {
content.get(self.selected).and_then(ListItem::share_url)
}) {
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
.unwrap();
}
Ok(CommandResult::Consumed(None))
}
_ => Ok(CommandResult::Ignored),
},
);
return if let Some(url) = args.get(0).and_then(|source| match source.as_str() {
"selected" => self
.content
.read()
.ok()
.and_then(|content| content.get(self.selected).and_then(|i| i.share_url())), ,
"current" => self.queue.get_current().and_then(|t| t.share_url()),
_ => None,
}) {
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
.ok();
Ok(CommandResult::Consumed(None))
} else {
Ok(CommandResult::Ignored)
};
}
if cmd == "move" {