add unadded songs to queue on <space>
This commit is contained in:
parent
5eafc1898b
commit
6e631a0520
31
src/app.rs
31
src/app.rs
|
|
@ -114,34 +114,47 @@ impl App {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_from_current_playlist(&mut self) {
|
pub fn handle_remove_or_from_current_playlist(&mut self) -> AppResult<()> {
|
||||||
let mut file = String::new();
|
|
||||||
match self.selected_tab {
|
match self.selected_tab {
|
||||||
SelectedTab::DirectoryBrowser => {
|
SelectedTab::DirectoryBrowser => {
|
||||||
let (_, f) = self.browser.filetree.get(self.browser.selected).unwrap();
|
let (_, file) = self.browser.filetree.get(self.browser.selected).unwrap();
|
||||||
file.push_str(f);
|
|
||||||
self.browser.selected += 1;
|
self.browser.selected += 1;
|
||||||
|
let mut status = false;
|
||||||
|
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
|
||||||
|
if song.contains(file) {
|
||||||
|
self.conn.conn.delete(i as u32).unwrap();
|
||||||
|
status = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !status {
|
||||||
|
let song = self
|
||||||
|
.conn
|
||||||
|
.get_song_with_only_filename(&self.conn.get_full_path(&file).unwrap());
|
||||||
|
self.conn.conn.push(&song)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectedTab::Queue => {
|
SelectedTab::Queue => {
|
||||||
file = self
|
let file = self
|
||||||
.queue_list
|
.queue_list
|
||||||
.list
|
.list
|
||||||
.get(self.queue_list.index)
|
.get(self.queue_list.index)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string();
|
.to_string();
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
|
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
|
||||||
if song.contains(&file) {
|
if song.contains(&file) {
|
||||||
self.conn.conn.delete(i as u32).unwrap();
|
self.conn.conn.delete(i as u32).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
self.update_queue();
|
self.update_queue();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cycle_tabls(&mut self) {
|
pub fn cycle_tabls(&mut self) {
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
|
|
||||||
// Remove from Current Playlsit
|
// Remove from Current Playlsit
|
||||||
KeyCode::Char(' ') | KeyCode::Backspace => {
|
KeyCode::Char(' ') | KeyCode::Backspace => {
|
||||||
app.remove_from_current_playlist();
|
app.handle_remove_or_from_current_playlist()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change playlist name
|
// Change playlist name
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,9 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if status {
|
if status {
|
||||||
list.push(ListItem::new(s.clone().bold()));
|
list.push(ListItem::new(s.clone().magenta().bold()));
|
||||||
} else {
|
} else {
|
||||||
list.push(ListItem::new(Line::styled(s, Style::default())));
|
list.push(ListItem::new(s.clone()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list.push(ListItem::new(Line::styled(
|
list.push(ListItem::new(Line::styled(
|
||||||
|
|
@ -115,7 +115,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
let mut items: Vec<ListItem> = vec![];
|
let mut items: Vec<ListItem> = vec![];
|
||||||
for item in app.queue_list.list.iter() {
|
for item in app.queue_list.list.iter() {
|
||||||
if item.contains(&app.conn.current_song.file) {
|
if item.contains(&app.conn.current_song.file) {
|
||||||
items.push(ListItem::new(item.clone().bold()))
|
items.push(ListItem::new(item.clone().magenta().bold()))
|
||||||
} else {
|
} else {
|
||||||
items.push(ListItem::new(item.clone()));
|
items.push(ListItem::new(item.clone()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in New Issue