rmptuic047f63
add entire directory to playlists
+44 −15
1 file changed
- M src/handler.rs +44 −15
| @@ -1,4 +1,5 @@ | |||
| 1 | − | use std::time::Duration; | |
| 1 | + | use crate::browser::FileExtension; | |
| 2 | + | use std::{path::Path, time::Duration}; | |
| 2 | 3 | ||
| 3 | 4 | use crate::{ | |
| 4 | 5 | app::{App, AppResult, SelectedTab}, | |
| @@ -118,35 +119,63 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 118 | 119 | ||
| 119 | 120 | KeyCode::Enter => { | |
| 120 | 121 | let pl_index = app.append_list.index; | |
| 121 | − | let pl_name = app.append_list.list.get(pl_index).unwrap(); | |
| 122 | + | let pl_name = &app.append_list.list.get(pl_index).unwrap(); | |
| 122 | 123 | ||
| 123 | 124 | let s_index: usize; | |
| 124 | − | let mut short_path: String = String::new(); | |
| 125 | 125 | match app.selected_tab { | |
| 126 | 126 | SelectedTab::Queue => { | |
| 127 | 127 | s_index = app.queue_list.index; | |
| 128 | − | short_path = app.queue_list.list.get(s_index).unwrap().to_string(); | |
| 128 | + | let short_path = app.queue_list.list.get(s_index).unwrap().to_string(); | |
| 129 | + | ||
| 130 | + | if let Some(full_path) = app.conn.get_full_path(&short_path) { | |
| 131 | + | let song = app.conn.get_song_with_only_filename(&full_path); | |
| 132 | + | ||
| 133 | + | if pl_name.to_string() == "Current Playlist" { | |
| 134 | + | app.conn.conn.push(&song)?; | |
| 135 | + | app.update_queue(); | |
| 136 | + | } else { | |
| 137 | + | app.conn.add_to_playlist(pl_name, &song)?; | |
| 138 | + | } | |
| 139 | + | } | |
| 129 | 140 | } | |
| 130 | 141 | ||
| 131 | 142 | SelectedTab::DirectoryBrowser => { | |
| 132 | 143 | let (t, f) = app.browser.filetree.get(app.browser.selected).unwrap(); | |
| 133 | 144 | if t == "file" { | |
| 134 | − | short_path = f.to_string(); | |
| 145 | + | let short_path = f; | |
| 146 | + | if let Some(full_path) = app.conn.get_full_path(short_path) { | |
| 147 | + | let song = app.conn.get_song_with_only_filename(&full_path); | |
| 148 | + | ||
| 149 | + | if pl_name.to_string() == "Current Playlist" { | |
| 150 | + | app.conn.conn.push(&song)?; | |
| 151 | + | app.update_queue(); | |
| 152 | + | } else { | |
| 153 | + | app.conn.add_to_playlist(pl_name, &song)?; | |
| 154 | + | } | |
| 155 | + | } | |
| 156 | + | } else if t == "directory" { | |
| 157 | + | for (t, f) in app.conn.conn.listfiles(f)?.iter() { | |
| 158 | + | // dir_vec.push((t, f)); | |
| 159 | + | if t == "file" | |
| 160 | + | && Path::new(&f).has_extension(&[ | |
| 161 | + | "mp3", "ogg", "flac", "m4a", "wav", "aac", "opus", "ape", | |
| 162 | + | "wma", "mpc", "aiff", "dff", "mp2", "mka", | |
| 163 | + | ]) | |
| 164 | + | { | |
| 165 | + | let full_path = app.conn.get_full_path(&f).unwrap_or_default(); | |
| 166 | + | let song = app.conn.get_song_with_only_filename(&full_path); | |
| 167 | + | if pl_name.to_string() == "Current Playlist" { | |
| 168 | + | app.conn.conn.push(&song)?; | |
| 169 | + | } else { | |
| 170 | + | app.conn.add_to_playlist(pl_name, &song)?; | |
| 171 | + | } | |
| 172 | + | } | |
| 173 | + | } | |
| 135 | 174 | } | |
| 136 | 175 | } | |
| 137 | 176 | _ => {} | |
| 138 | 177 | } | |
| 139 | 178 | ||
| 140 | − | if let Some(full_path) = app.conn.get_full_path(&short_path) { | |
| 141 | − | let song = app.conn.get_song_with_only_filename(&full_path); | |
| 142 | − | ||
| 143 | − | if pl_name == "Current Playlist" { | |
| 144 | − | app.conn.conn.push(&song)?; | |
| 145 | − | app.update_queue(); | |
| 146 | − | } else { | |
| 147 | − | app.conn.add_to_playlist(pl_name, &song)?; | |
| 148 | − | } | |
| 149 | − | } | |
| 150 | 179 | // hide the playlist popup | |
| 151 | 180 | app.playlist_popup = false; | |
| 152 | 181 | app.append_list.index = 0; | |