Move URL handling to relevant structs and share selected song

This commit is contained in:
Rasmus Larsen
2019-05-09 16:04:07 +02:00
parent a145d73072
commit 4897d97931
7 changed files with 58 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ use cursive::view::ScrollBase;
use cursive::{Cursive, Printer, Rect, Vec2};
use unicode_width::UnicodeWidthStr;
use clipboard::{ClipboardContext, ClipboardProvider};
use commands::CommandResult;
use library::Library;
use queue::Queue;
@@ -314,6 +315,26 @@ 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),
},
);
}
if cmd == "move" {
if let Some(dir) = args.get(0) {
let amount: usize = args