mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
refactor: refactor input handling for Enter key and directory navigation
This commit is contained in:
+59
-63
@@ -20,20 +20,6 @@ impl SoundpadGui {
|
|||||||
self.app_state.show_settings = !self.app_state.show_settings;
|
self.app_state.show_settings = !self.app_state.show_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.key_pressed(ctx, Key::Enter) && self.app_state.selected_file.is_some() {
|
|
||||||
let path = &self.app_state.selected_file.clone().unwrap();
|
|
||||||
if modifiers.ctrl {
|
|
||||||
self.play_file(path, true);
|
|
||||||
} else if modifiers.shift
|
|
||||||
&& let Some(last_track) = self.audio_player_state.tracks.last()
|
|
||||||
{
|
|
||||||
self.stop(Some(last_track.id));
|
|
||||||
self.play_file(path, true);
|
|
||||||
} else {
|
|
||||||
self.play_file(path, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.app_state.show_settings {
|
if !self.app_state.show_settings {
|
||||||
// Pause / resume audio on space
|
// Pause / resume audio on space
|
||||||
if self.key_pressed(ctx, Key::Space) {
|
if self.key_pressed(ctx, Key::Space) {
|
||||||
@@ -50,69 +36,79 @@ impl SoundpadGui {
|
|||||||
self.app_state.force_focus_search = true;
|
self.app_state.force_focus_search = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through dirs if there are some
|
// Play selected file on Enter
|
||||||
if modifiers.ctrl {
|
if self.key_pressed(ctx, Key::Enter) && self.app_state.selected_file.is_some() {
|
||||||
let arrow_up_pressed = self.key_pressed(ctx, Key::ArrowUp);
|
let path = &self.app_state.selected_file.clone().unwrap();
|
||||||
let arrow_down_pressed = self.key_pressed(ctx, Key::ArrowDown);
|
if modifiers.ctrl {
|
||||||
|
self.play_file(path, true);
|
||||||
|
} else if modifiers.shift
|
||||||
|
&& let Some(last_track) = self.audio_player_state.tracks.last()
|
||||||
|
{
|
||||||
|
self.stop(Some(last_track.id));
|
||||||
|
self.play_file(path, true);
|
||||||
|
} else {
|
||||||
|
self.play_file(path, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if arrow_up_pressed || arrow_down_pressed {
|
// Iterate through dirs and files with Ctrl + Up/Down
|
||||||
if modifiers.shift && !self.app_state.dirs.is_empty() {
|
let arrow_up_pressed = self.key_pressed(ctx, Key::ArrowUp);
|
||||||
let mut dirs: Vec<PathBuf> = self.app_state.dirs.iter().cloned().collect();
|
let arrow_down_pressed = self.key_pressed(ctx, Key::ArrowDown);
|
||||||
dirs.sort();
|
if modifiers.ctrl && (arrow_up_pressed || arrow_down_pressed) {
|
||||||
|
if modifiers.shift && !self.app_state.dirs.is_empty() {
|
||||||
|
let mut dirs: Vec<PathBuf> = self.app_state.dirs.iter().cloned().collect();
|
||||||
|
dirs.sort();
|
||||||
|
|
||||||
let current_dir_index: i8;
|
let current_dir_index: i8;
|
||||||
if let Some(current_dir) = &self.app_state.current_dir {
|
if let Some(current_dir) = &self.app_state.current_dir {
|
||||||
if let Some(index) = dirs.iter().position(|x| x == current_dir) {
|
if let Some(index) = dirs.iter().position(|x| x == current_dir) {
|
||||||
current_dir_index = index as i8;
|
current_dir_index = index as i8;
|
||||||
} else {
|
|
||||||
current_dir_index = -1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
current_dir_index = -1;
|
current_dir_index = -1;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
current_dir_index = -1;
|
||||||
|
}
|
||||||
|
|
||||||
let mut new_dir_index: i8;
|
let mut new_dir_index: i8;
|
||||||
|
|
||||||
new_dir_index =
|
new_dir_index =
|
||||||
current_dir_index - arrow_up_pressed as i8 + arrow_down_pressed as i8;
|
current_dir_index - arrow_up_pressed as i8 + arrow_down_pressed as i8;
|
||||||
|
|
||||||
if new_dir_index < 0 {
|
if new_dir_index < 0 {
|
||||||
new_dir_index = (dirs.len() - 1) as i8;
|
new_dir_index = (dirs.len() - 1) as i8;
|
||||||
} else if new_dir_index >= dirs.len() as i8 {
|
} else if new_dir_index >= dirs.len() as i8 {
|
||||||
new_dir_index = 0;
|
new_dir_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.open_dir(&dirs[new_dir_index as usize]);
|
self.open_dir(&dirs[new_dir_index as usize]);
|
||||||
} else if self.app_state.current_dir.is_some() {
|
} else if self.app_state.current_dir.is_some() {
|
||||||
let mut files: Vec<PathBuf> =
|
let mut files: Vec<PathBuf> = self.app_state.files.iter().cloned().collect();
|
||||||
self.app_state.files.iter().cloned().collect();
|
files.sort();
|
||||||
files.sort();
|
|
||||||
|
|
||||||
let current_files_index: i64;
|
let current_files_index: i64;
|
||||||
if let Some(selected_file) = &self.app_state.selected_file {
|
if let Some(selected_file) = &self.app_state.selected_file {
|
||||||
if let Some(index) = files.iter().position(|x| x == selected_file) {
|
if let Some(index) = files.iter().position(|x| x == selected_file) {
|
||||||
current_files_index = index as i64;
|
current_files_index = index as i64;
|
||||||
} else {
|
|
||||||
current_files_index = -1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
current_files_index = -1;
|
current_files_index = -1;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
let mut new_files_index: i64;
|
current_files_index = -1;
|
||||||
|
|
||||||
new_files_index = current_files_index - arrow_up_pressed as i64
|
|
||||||
+ arrow_down_pressed as i64;
|
|
||||||
|
|
||||||
if new_files_index < 0 {
|
|
||||||
new_files_index = (files.len() - 1) as i64;
|
|
||||||
} else if new_files_index >= files.len() as i64 {
|
|
||||||
new_files_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.app_state.selected_file =
|
|
||||||
Some(files[new_files_index as usize].clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut new_files_index: i64;
|
||||||
|
|
||||||
|
new_files_index =
|
||||||
|
current_files_index - arrow_up_pressed as i64 + arrow_down_pressed as i64;
|
||||||
|
|
||||||
|
if new_files_index < 0 {
|
||||||
|
new_files_index = (files.len() - 1) as i64;
|
||||||
|
} else if new_files_index >= files.len() as i64 {
|
||||||
|
new_files_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.app_state.selected_file = Some(files[new_files_index as usize].clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user