100 lines
3.2 KiB
Rust
100 lines
3.2 KiB
Rust
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
|
|
|
use super::{InputContext, InputResult};
|
|
use crate::commands::AppCommand;
|
|
use crate::engine::AudioCommand;
|
|
use crate::page::Page;
|
|
use cagire_ratatui::TreeLineKind;
|
|
|
|
pub(super) fn handle_sample_explorer(ctx: &mut InputContext, key: KeyEvent) -> InputResult {
|
|
let state = match &mut ctx.app.sample_browser {
|
|
Some(s) => s,
|
|
None => return InputResult::Continue,
|
|
};
|
|
|
|
let ctrl = key.modifiers.contains(KeyModifiers::CONTROL);
|
|
|
|
if state.search_active {
|
|
match key.code {
|
|
KeyCode::Esc => {
|
|
state.clear_search();
|
|
}
|
|
KeyCode::Backspace => {
|
|
state.search_query.pop();
|
|
state.update_search();
|
|
}
|
|
KeyCode::Enter => {
|
|
state.search_active = false;
|
|
}
|
|
KeyCode::Char(c) => {
|
|
state.search_query.push(c);
|
|
state.update_search();
|
|
}
|
|
_ => {}
|
|
}
|
|
} else if ctrl {
|
|
match key.code {
|
|
KeyCode::Up => {
|
|
for _ in 0..10 {
|
|
state.move_up();
|
|
}
|
|
}
|
|
KeyCode::Down => {
|
|
for _ in 0..10 {
|
|
state.move_down();
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
} else {
|
|
match key.code {
|
|
KeyCode::Up | KeyCode::Char('k') => state.move_up(),
|
|
KeyCode::Down | KeyCode::Char('j') => state.move_down(),
|
|
KeyCode::PageUp => {
|
|
for _ in 0..20 {
|
|
state.move_up();
|
|
}
|
|
}
|
|
KeyCode::PageDown => {
|
|
for _ in 0..20 {
|
|
state.move_down();
|
|
}
|
|
}
|
|
KeyCode::Enter | KeyCode::Right => {
|
|
if let Some(entry) = state.current_entry() {
|
|
match entry.kind {
|
|
TreeLineKind::File => {
|
|
let folder = &entry.folder;
|
|
let idx = entry.index;
|
|
let cmd = format!("/sound/{folder}/n/{idx}/gain/1.00/dur/1");
|
|
let _ = ctx
|
|
.audio_tx
|
|
.load()
|
|
.send(AudioCommand::Evaluate { cmd, tick: None });
|
|
ctx.dispatch(AppCommand::SetStatus(format!(
|
|
"\u{25B8} {}/{}",
|
|
folder, entry.label
|
|
)));
|
|
}
|
|
_ => state.toggle_expand(),
|
|
}
|
|
}
|
|
}
|
|
KeyCode::Left => state.collapse_at_cursor(),
|
|
KeyCode::Char('/') => state.activate_search(),
|
|
KeyCode::Esc => {
|
|
if state.has_filter() {
|
|
state.clear_filter();
|
|
} else {
|
|
ctx.dispatch(AppCommand::GoToPage(Page::Main));
|
|
}
|
|
}
|
|
KeyCode::Tab => {
|
|
ctx.dispatch(AppCommand::GoToPage(Page::Main));
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
InputResult::Continue
|
|
}
|