Use command system for queue saving
This commit is contained in:
@@ -58,6 +58,7 @@ impl CommandManager {
|
||||
self.register_command("shift", None);
|
||||
self.register_command("play", None);
|
||||
self.register_command("queue", None);
|
||||
self.register_command("save", None);
|
||||
self.register_command("delete", None);
|
||||
|
||||
self.register_command(
|
||||
@@ -293,6 +294,8 @@ impl CommandManager {
|
||||
kb.insert("c".into(), "clear".into());
|
||||
kb.insert(" ".into(), "queue".into());
|
||||
kb.insert("Enter".into(), "play".into());
|
||||
kb.insert("s".into(), "save".into());
|
||||
kb.insert("Ctrl+s".into(), "save queue".into());
|
||||
kb.insert("d".into(), "delete".into());
|
||||
kb.insert("/".into(), "focus search".into());
|
||||
kb.insert(".".into(), "seek +500".into());
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use cursive::event::{Callback, Event, EventResult};
|
||||
use cursive::traits::{Boxable, Identifiable, View};
|
||||
use cursive::traits::{Boxable, Identifiable};
|
||||
use cursive::view::ViewWrapper;
|
||||
use cursive::views::{Dialog, EditView, ScrollView, SelectView};
|
||||
use cursive::Cursive;
|
||||
@@ -86,22 +85,6 @@ impl QueueView {
|
||||
|
||||
impl ViewWrapper for QueueView {
|
||||
wrap_impl!(self.list: ListView<Track>);
|
||||
|
||||
fn wrap_on_event(&mut self, ch: Event) -> EventResult {
|
||||
match ch {
|
||||
Event::Char('s') => {
|
||||
debug!("save list");
|
||||
let queue = self.queue.clone();
|
||||
let library = self.library.clone();
|
||||
let cb = move |s: &mut Cursive| {
|
||||
let dialog = Self::save_dialog(queue.clone(), library.clone());
|
||||
s.add_layer(dialog)
|
||||
};
|
||||
EventResult::Consumed(Some(Callback::from_fn(cb)))
|
||||
}
|
||||
_ => self.list.on_event(ch),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewExt for QueueView {
|
||||
@@ -147,6 +130,12 @@ impl ViewExt for QueueView {
|
||||
}
|
||||
}
|
||||
|
||||
if cmd == "save" && args.get(0).unwrap_or(&"".to_string()) == "queue" {
|
||||
let dialog = Self::save_dialog(self.queue.clone(), self.library.clone());
|
||||
s.add_layer(dialog);
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
}
|
||||
|
||||
self.with_view_mut(move |v| v.on_command(s, cmd, args))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user