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:
+20
-24
@@ -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,12 +36,25 @@ 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 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 {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate through dirs and files with Ctrl + Up/Down
|
||||||
let arrow_up_pressed = self.key_pressed(ctx, Key::ArrowUp);
|
let arrow_up_pressed = self.key_pressed(ctx, Key::ArrowUp);
|
||||||
let arrow_down_pressed = self.key_pressed(ctx, Key::ArrowDown);
|
let arrow_down_pressed = self.key_pressed(ctx, Key::ArrowDown);
|
||||||
|
if modifiers.ctrl && (arrow_up_pressed || arrow_down_pressed) {
|
||||||
if arrow_up_pressed || arrow_down_pressed {
|
|
||||||
if modifiers.shift && !self.app_state.dirs.is_empty() {
|
if modifiers.shift && !self.app_state.dirs.is_empty() {
|
||||||
let mut dirs: Vec<PathBuf> = self.app_state.dirs.iter().cloned().collect();
|
let mut dirs: Vec<PathBuf> = self.app_state.dirs.iter().cloned().collect();
|
||||||
dirs.sort();
|
dirs.sort();
|
||||||
@@ -84,8 +83,7 @@ impl SoundpadGui {
|
|||||||
|
|
||||||
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;
|
||||||
@@ -101,8 +99,8 @@ impl SoundpadGui {
|
|||||||
|
|
||||||
let mut new_files_index: i64;
|
let mut new_files_index: i64;
|
||||||
|
|
||||||
new_files_index = current_files_index - arrow_up_pressed as i64
|
new_files_index =
|
||||||
+ arrow_down_pressed as i64;
|
current_files_index - arrow_up_pressed as i64 + arrow_down_pressed as i64;
|
||||||
|
|
||||||
if new_files_index < 0 {
|
if new_files_index < 0 {
|
||||||
new_files_index = (files.len() - 1) as i64;
|
new_files_index = (files.len() - 1) as i64;
|
||||||
@@ -110,9 +108,7 @@ impl SoundpadGui {
|
|||||||
new_files_index = 0;
|
new_files_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.app_state.selected_file =
|
self.app_state.selected_file = Some(files[new_files_index as usize].clone());
|
||||||
Some(files[new_files_index as usize].clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user