rmptui46387d7
<Space> for adding entire directory to queue
+27 −13
1 file changed
- M src/app.rs +27 −13
| @@ -110,24 +110,38 @@ impl App { | |||
| 110 | 110 | pub fn handle_add_or_remove_from_current_playlist(&mut self) -> AppResult<()> { | |
| 111 | 111 | match self.selected_tab { | |
| 112 | 112 | SelectedTab::DirectoryBrowser => { | |
| 113 | − | let (_, file) = self.browser.filetree.get(self.browser.selected).unwrap(); | |
| 114 | − | ||
| 115 | − | let mut status = false; | |
| 116 | − | for (i, song) in self.queue_list.list.clone().iter().enumerate() { | |
| 117 | − | let song_path = song.file.split("/").last().unwrap_or_default(); | |
| 118 | − | if song_path.eq(file) { | |
| 119 | − | self.conn.conn.delete(i as u32).unwrap(); | |
| 120 | − | status = true; | |
| 113 | + | let (content_type, content) = | |
| 114 | + | self.browser.filetree.get(self.browser.selected).unwrap(); | |
| 115 | + | if content_type == "directory" { | |
| 116 | + | let file = format!("{}/{}", self.browser.path, content); | |
| 117 | + | let songs = self.conn.conn.listfiles(&file).unwrap_or_default(); | |
| 118 | + | for (t, f) in songs.iter() { | |
| 119 | + | if t == "file" { | |
| 120 | + | if let Some(full_path) = &self.conn.get_full_path(f) { | |
| 121 | + | let song = self.conn.get_song_with_only_filename(full_path); | |
| 122 | + | self.conn.conn.push(&song)?; | |
| 123 | + | } | |
| 124 | + | } | |
| 125 | + | } | |
| 126 | + | } else if content_type == "file" { | |
| 127 | + | let mut status = false; | |
| 128 | + | for (i, song) in self.queue_list.list.clone().iter().enumerate() { | |
| 129 | + | let song_path = song.file.split("/").last().unwrap_or_default(); | |
| 130 | + | if song_path.eq(content) { | |
| 131 | + | self.conn.conn.delete(i as u32).unwrap(); | |
| 132 | + | status = true; | |
| 133 | + | } | |
| 121 | 134 | } | |
| 122 | − | } | |
| 123 | 135 | ||
| 124 | − | if !status { | |
| 125 | − | if let Some(full_path) = &self.conn.get_full_path(file) { | |
| 126 | − | let song = self.conn.get_song_with_only_filename(full_path); | |
| 127 | − | self.conn.conn.push(&song)?; | |
| 136 | + | if !status { | |
| 137 | + | if let Some(full_path) = &self.conn.get_full_path(content) { | |
| 138 | + | let song = self.conn.get_song_with_only_filename(full_path); | |
| 139 | + | self.conn.conn.push(&song)?; | |
| 140 | + | } | |
| 128 | 141 | } | |
| 129 | 142 | } | |
| 130 | 143 | ||
| 144 | + | // Highlight next row if possible | |
| 131 | 145 | if self.browser.selected != self.browser.filetree.len() - 1 { | |
| 132 | 146 | self.browser.selected += 1; | |
| 133 | 147 | } | |