@@ -45,7 +45,8 @@ have them configurable.
|
|||||||
* `d` deletes the currently selected playlist
|
* `d` deletes the currently selected playlist
|
||||||
* Tracks and playlists can be played using `Return` and queued using `Space`
|
* Tracks and playlists can be played using `Return` and queued using `Space`
|
||||||
* `s` will save or remove the currently selected track to your library
|
* `s` will save or remove the currently selected track to your library
|
||||||
* `o` will open a detail view for the selected item
|
* `o` will open a detail view or context menu for the selected item
|
||||||
|
* `Shift-o` will open a context menu for the currently playing track
|
||||||
* `a` will open the album view for the selected item
|
* `a` will open the album view for the selected item
|
||||||
* `A` will open the artist view for the selected item
|
* `A` will open the artist view for the selected item
|
||||||
* `Backspace` closes the current view
|
* `Backspace` closes the current view
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ pub enum Command {
|
|||||||
Shuffle(Option<bool>),
|
Shuffle(Option<bool>),
|
||||||
Share(TargetMode),
|
Share(TargetMode),
|
||||||
Back,
|
Back,
|
||||||
Open,
|
Open(TargetMode),
|
||||||
Goto(GotoMode),
|
Goto(GotoMode),
|
||||||
Move(MoveMode, Option<i32>),
|
Move(MoveMode, Option<i32>),
|
||||||
Shift(ShiftMode, Option<i32>),
|
Shift(ShiftMode, Option<i32>),
|
||||||
@@ -123,7 +123,14 @@ pub fn parse(input: &str) -> Option<Command> {
|
|||||||
"play" => Some(Command::Play),
|
"play" => Some(Command::Play),
|
||||||
"delete" => Some(Command::Delete),
|
"delete" => Some(Command::Delete),
|
||||||
"back" => Some(Command::Back),
|
"back" => Some(Command::Back),
|
||||||
"open" => Some(Command::Open),
|
"open" => args
|
||||||
|
.get(0)
|
||||||
|
.and_then(|target| match *target {
|
||||||
|
"selected" => Some(TargetMode::Selected),
|
||||||
|
"current" => Some(TargetMode::Current),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.map(Command::Open),
|
||||||
"search" => args.get(0).map(|query| Command::Search(query.to_string())),
|
"search" => args.get(0).map(|query| Command::Search(query.to_string())),
|
||||||
"shift" => {
|
"shift" => {
|
||||||
let amount = args.get(1).and_then(|amount| amount.parse().ok());
|
let amount = args.get(1).and_then(|amount| amount.parse().ok());
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ impl CommandManager {
|
|||||||
| Command::Save
|
| Command::Save
|
||||||
| Command::Delete
|
| Command::Delete
|
||||||
| Command::Back
|
| Command::Back
|
||||||
| Command::Open
|
| Command::Open(_)
|
||||||
| Command::Goto(_) => Ok(None),
|
| Command::Goto(_) => Ok(None),
|
||||||
_ => Err("Unknown Command".into()),
|
_ => Err("Unknown Command".into()),
|
||||||
}
|
}
|
||||||
@@ -192,9 +192,12 @@ impl CommandManager {
|
|||||||
let mut kb = HashMap::new();
|
let mut kb = HashMap::new();
|
||||||
|
|
||||||
kb.insert("q".into(), Command::Quit);
|
kb.insert("q".into(), Command::Quit);
|
||||||
kb.insert("P".into(), Command::TogglePlay);
|
kb.insert("Shift+p".into(), Command::TogglePlay);
|
||||||
kb.insert("R".into(), Command::Playlists(PlaylistCommands::Update));
|
kb.insert(
|
||||||
kb.insert("S".into(), Command::Stop);
|
"Shift+r".into(),
|
||||||
|
Command::Playlists(PlaylistCommands::Update),
|
||||||
|
);
|
||||||
|
kb.insert("Shift+s".into(), Command::Stop);
|
||||||
kb.insert("<".into(), Command::Previous);
|
kb.insert("<".into(), Command::Previous);
|
||||||
kb.insert(">".into(), Command::Next);
|
kb.insert(">".into(), Command::Next);
|
||||||
kb.insert("c".into(), Command::Clear);
|
kb.insert("c".into(), Command::Clear);
|
||||||
@@ -216,7 +219,8 @@ impl CommandManager {
|
|||||||
kb.insert("F3".into(), Command::Focus("library".into()));
|
kb.insert("F3".into(), Command::Focus("library".into()));
|
||||||
kb.insert("Backspace".into(), Command::Back);
|
kb.insert("Backspace".into(), Command::Back);
|
||||||
|
|
||||||
kb.insert("o".into(), Command::Open);
|
kb.insert("o".into(), Command::Open(TargetMode::Selected));
|
||||||
|
kb.insert("Shift+o".into(), Command::Open(TargetMode::Current));
|
||||||
kb.insert("a".into(), Command::Goto(GotoMode::Album));
|
kb.insert("a".into(), Command::Goto(GotoMode::Album));
|
||||||
kb.insert("A".into(), Command::Goto(GotoMode::Artist));
|
kb.insert("A".into(), Command::Goto(GotoMode::Artist));
|
||||||
|
|
||||||
|
|||||||
53
src/ui/contextmenu.rs
Normal file
53
src/ui/contextmenu.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use cursive::view::ViewWrapper;
|
||||||
|
use cursive::views::{Dialog, SelectView};
|
||||||
|
use cursive::Cursive;
|
||||||
|
|
||||||
|
use library::Library;
|
||||||
|
use queue::Queue;
|
||||||
|
use traits::ListItem;
|
||||||
|
use ui::layout::Layout;
|
||||||
|
use ui::modal::Modal;
|
||||||
|
|
||||||
|
pub struct ContextMenu {
|
||||||
|
dialog: Modal<Dialog>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ContextMenu {
|
||||||
|
pub fn new(item: &Box<ListItem>, queue: Arc<Queue>, library: Arc<Library>) -> Self {
|
||||||
|
let mut content: SelectView<Box<ListItem>> = SelectView::new().autojump();
|
||||||
|
if let Some(a) = item.artist() {
|
||||||
|
content.add_item("Artist", Box::new(a))
|
||||||
|
}
|
||||||
|
if let Some(a) = item.album(queue.clone()) {
|
||||||
|
content.add_item("Album", Box::new(a))
|
||||||
|
}
|
||||||
|
|
||||||
|
// open detail view of artist/album
|
||||||
|
content.set_on_submit(move |s: &mut Cursive, selected: &Box<ListItem>| {
|
||||||
|
s.pop_layer();
|
||||||
|
let queue = queue.clone();
|
||||||
|
let library = library.clone();
|
||||||
|
s.call_on_id("main", move |v: &mut Layout| {
|
||||||
|
let view = selected.open(queue, library);
|
||||||
|
if let Some(view) = view {
|
||||||
|
v.push_view(view)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let dialog = Dialog::new()
|
||||||
|
.title(item.display_left())
|
||||||
|
.dismiss_button("Cancel")
|
||||||
|
.padding((1, 1, 1, 0))
|
||||||
|
.content(content);
|
||||||
|
Self {
|
||||||
|
dialog: Modal::new(dialog),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ViewWrapper for ContextMenu {
|
||||||
|
wrap_impl!(self.dialog: Modal<Dialog>);
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ use track::Track;
|
|||||||
use traits::{IntoBoxedViewExt, ListItem, ViewExt};
|
use traits::{IntoBoxedViewExt, ListItem, ViewExt};
|
||||||
use ui::album::AlbumView;
|
use ui::album::AlbumView;
|
||||||
use ui::artist::ArtistView;
|
use ui::artist::ArtistView;
|
||||||
|
use ui::contextmenu::ContextMenu;
|
||||||
|
|
||||||
pub type Paginator<I> = Box<Fn(Arc<RwLock<Vec<I>>>) + Send + Sync>;
|
pub type Paginator<I> = Box<Fn(Arc<RwLock<Vec<I>>>) + Send + Sync>;
|
||||||
pub struct Pagination<I: ListItem> {
|
pub struct Pagination<I: ListItem> {
|
||||||
@@ -352,14 +353,31 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::Open => {
|
Command::Open(mode) => {
|
||||||
let mut content = self.content.write().unwrap();
|
let queue = self.queue.clone();
|
||||||
if let Some(item) = content.get_mut(self.selected) {
|
let library = self.library.clone();
|
||||||
let queue = self.queue.clone();
|
let target: Option<Box<dyn ListItem>> = match mode {
|
||||||
let library = self.library.clone();
|
TargetMode::Current => {
|
||||||
if let Some(view) = item.open(queue, library) {
|
self.queue.get_current().and_then(|t| Some(t.as_listitem()))
|
||||||
return Ok(CommandResult::View(view));
|
|
||||||
}
|
}
|
||||||
|
TargetMode::Selected => {
|
||||||
|
let content = self.content.read().unwrap();
|
||||||
|
content
|
||||||
|
.get(self.selected)
|
||||||
|
.and_then(|t| Some(t.as_listitem()))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// if item has a dedicated view, show it; otherwise open the context menu
|
||||||
|
if let Some(target) = target {
|
||||||
|
let view = target.open(queue.clone(), library.clone());
|
||||||
|
return match view {
|
||||||
|
Some(view) => Ok(CommandResult::View(view)),
|
||||||
|
None => {
|
||||||
|
let contextmenu = ContextMenu::new(&target, queue, library);
|
||||||
|
Ok(CommandResult::Modal(Box::new(contextmenu)))
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::Goto(mode) => {
|
Command::Goto(mode) => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
pub mod album;
|
pub mod album;
|
||||||
pub mod artist;
|
pub mod artist;
|
||||||
|
pub mod contextmenu;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
pub mod library;
|
pub mod library;
|
||||||
pub mod listview;
|
pub mod listview;
|
||||||
|
|||||||
Reference in New Issue
Block a user