Krolyxon
Commit 46387d7

rmptui46387d7

<Space> for adding entire directory to queue

Author
krolxon
Date
2024-05-19 19:55 +0530
Parent
1cd2b03
Commit
46387d72162dbaa04fc46ef3414a0d38aaac13cb

+27 −13

1 file changed

  1. M src/app.rs +27 −13
M src/app.rs View
@@ -110,24 +110,38 @@ impl App {
110110 pub fn handle_add_or_remove_from_current_playlist(&mut self) -> AppResult<()> {
111111 match self.selected_tab {
112112 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+ }
121134 }
122− }
123135
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+ }
128141 }
129142 }
130143
144+ // Highlight next row if possible
131145 if self.browser.selected != self.browser.filetree.len() - 1 {
132146 self.browser.selected += 1;
133147 }