refactor: remove selected file handling from FileAction and related input logic

This commit is contained in:
2026-05-15 22:05:30 +03:00
parent e320c85a6f
commit 05dd4319cc
4 changed files with 5 additions and 91 deletions
+3 -5
View File
@@ -99,15 +99,13 @@ pwsp-cli --help # View all commands
| Action | Keyboard | Mouse |
| :----------------------------------- | :--------------------- | :------------------- |
| **Play Track** (Stops others) | `Enter` | `Left Click` |
| **Add Track** (Plays simultaneously) | `Ctrl + Enter` | `Ctrl + Left Click` |
| **Replace Last Track** | `Shift + Enter` | `Shift + Left Click` |
| **Play Track** (Stops others) | | `Left Click` |
| **Add Track** (Plays simultaneously) | | `Ctrl + Left Click` |
| **Replace Last Track** | | `Shift + Left Click` |
| **Pause / Resume** | `Space` | |
| **Stop All Tracks** | `Backspace` | |
| **Open / Close Settings** | `I` | |
| **Search** | `/` | |
| **Navigate Files** | `Ctrl + ↑ / ↓` | |
| **Navigate Directories** | `Ctrl + Shift + ↑ / ↓` | |
---
+1 -14
View File
@@ -35,7 +35,6 @@ enum FileAction {
Play(PathBuf, bool),
StopAndPlay(u32, PathBuf, bool),
AssignHotkey(PathBuf),
SetSelected(PathBuf),
}
impl SoundpadGui {
@@ -817,9 +816,6 @@ impl SoundpadGui {
self.app_state.assigning_hotkey_for_file = Some(path);
self.app_state.hotkey_capture_active = true;
}
FileAction::SetSelected(path) => {
self.app_state.selected_file = Some(path);
}
}
}
});
@@ -928,12 +924,7 @@ impl SoundpadGui {
);
}
let mut file_button_text = RichText::new(&file_name);
if let Some(current_file) = &app_state.selected_file
&& current_file.eq(&path)
{
file_button_text = file_button_text.color(Color32::WHITE);
}
let file_button_text = RichText::new(&file_name);
let file_button = Button::new(file_button_text).frame(false).truncate();
let file_button_response = ui.add(file_button);
@@ -953,7 +944,6 @@ impl SoundpadGui {
actions.push(FileAction::Play(path.clone(), false));
}
});
actions.push(FileAction::SetSelected(path.clone()));
}
// Context menu
@@ -967,7 +957,6 @@ impl SoundpadGui {
.clicked()
{
actions.push(FileAction::Play(path.clone(), false));
actions.push(FileAction::SetSelected(path.clone()));
}
if ui
@@ -979,7 +968,6 @@ impl SoundpadGui {
.clicked()
{
actions.push(FileAction::Play(path.clone(), true));
actions.push(FileAction::SetSelected(path.clone()));
}
if ui
@@ -992,7 +980,6 @@ impl SoundpadGui {
&& let Some(last_track) = audio_player_state.tracks.last()
{
actions.push(FileAction::StopAndPlay(last_track.id, path.clone(), true));
actions.push(FileAction::SetSelected(path.clone()));
}
ui.separator();
+1 -71
View File
@@ -3,8 +3,6 @@ use egui::{Context, Id, Key, Modifiers};
use pwsp::types::socket::Request;
use pwsp::utils::gui::make_request_async;
use std::path::PathBuf;
/// Convert an egui Key + Modifiers to a normalized chord string like "Ctrl+Shift+A".
fn chord_from_event(modifiers: &Modifiers, key: &Key) -> Option<String> {
let key_name = key.name();
@@ -94,7 +92,7 @@ impl SoundpadGui {
}
pub fn handle_input(&mut self, ctx: &Context) {
let modifiers = self.modifiers(ctx);
let _modifiers = self.modifiers(ctx);
let search_focused = {
if let Some(focused_id) = self.get_focused(ctx)
&& let Some(search_id) = self.app_state.search_field_id
@@ -197,74 +195,6 @@ impl SoundpadGui {
}
}
// Play selected file on Enter
if self.key_pressed(ctx, Key::Enter)
&& let Some(path) = self.app_state.selected_file.clone()
{
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_down_pressed = self.key_pressed(ctx, Key::ArrowDown);
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.to_vec();
dirs.sort();
let current_dir_index = self
.app_state
.current_dir
.as_ref()
.and_then(|cd| dirs.iter().position(|x| x == cd));
let new_dir_index =
match (current_dir_index, arrow_up_pressed, arrow_down_pressed) {
(Some(i), true, false) => (i + dirs.len() - 1) % dirs.len(),
(Some(i), false, true) => (i + 1) % dirs.len(),
(Some(i), true, true) => i,
(None, true, _) => dirs.len() - 1,
(None, false, true) => 0,
_ => return,
};
self.open_dir(&dirs[new_dir_index]);
} else if self.app_state.current_dir.is_some() {
let files = self.get_filtered_files();
if files.is_empty() {
return;
}
let current_files_index = self
.app_state
.selected_file
.as_ref()
.and_then(|f| files.iter().position(|x| x == f));
let new_files_index =
match (current_files_index, arrow_up_pressed, arrow_down_pressed) {
(Some(i), true, false) => (i + files.len() - 1) % files.len(),
(Some(i), false, true) => (i + 1) % files.len(),
(Some(i), true, true) => i,
(None, true, _) => files.len() - 1,
(None, false, true) => 0,
_ => return,
};
self.app_state.selected_file = Some(files[new_files_index].clone());
}
}
// Check for hotkey chord triggers
let slots_to_play: Vec<String> = ctx.input(|i| {
let mut result = vec![];
-1
View File
@@ -43,7 +43,6 @@ pub struct AppState {
pub dirs: Vec<PathBuf>,
pub dirs_to_remove: HashSet<PathBuf>,
pub selected_file: Option<PathBuf>,
pub listed_files: HashSet<PathBuf>,
pub listed_dirs: HashSet<PathBuf>,
pub dir_cache: HashMap<PathBuf, Vec<PathBuf>>,