fix keys being registerd in editing modes

This commit is contained in:
krolxon 2024-05-09 12:22:27 +05:30
parent 1187e4f0b5
commit 83c86d3c2d
1 changed files with 227 additions and 225 deletions

View File

@ -15,250 +15,252 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
pl_rename_keys::handle_pl_rename_keys(key_event, app)?; pl_rename_keys::handle_pl_rename_keys(key_event, app)?;
} else if app.playlist_popup { } else if app.playlist_popup {
pl_append_keys::hande_pl_append_keys(key_event, app)?; pl_append_keys::hande_pl_append_keys(key_event, app)?;
} } else {
// General KeyMaps
// General KeyMaps match key_event.code {
match key_event.code { // Quit
// Quit KeyCode::Char('q') => app.quit(),
KeyCode::Char('q') => app.quit(), KeyCode::Char('c') | KeyCode::Char('C') => {
KeyCode::Char('c') | KeyCode::Char('C') => { if key_event.modifiers == KeyModifiers::CONTROL {
if key_event.modifiers == KeyModifiers::CONTROL { app.quit();
app.quit(); } else {
} else { app.conn.conn.clear()?;
app.conn.conn.clear()?;
app.conn.update_status();
app.queue_list.list.clear();
app.queue_list.reset_index();
}
}
// Playback controls
// Toggle Pause
KeyCode::Char('p') => app.conn.toggle_pause(),
// Pause
KeyCode::Char('s') => app.conn.pause(),
// Toggle rpeat
KeyCode::Char('r') => {
app.conn.toggle_repeat();
app.conn.update_status();
}
// Toggle random
KeyCode::Char('z') => {
app.conn.toggle_random();
app.conn.update_status();
}
// Dmenu prompt
KeyCode::Char('D') => app.conn.play_dmenu()?,
// add to queue
KeyCode::Char('a') => app.playlist_popup = true,
// Fast forward
KeyCode::Char('f') => {
let place = app.conn.conn.status().unwrap().song.unwrap().pos;
let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
app.conn.conn.seek(place, pos)?;
}
// backward
KeyCode::Char('b') => {
let place = app.conn.conn.status().unwrap().song.unwrap().pos;
let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
app.conn.conn.seek(place, pos)?;
}
// Cycle through tabs
KeyCode::Tab => {
app.cycle_tabls();
}
// Directory browser tab
KeyCode::Char('1') => {
app.selected_tab = SelectedTab::Queue;
}
// Playing queue tab
KeyCode::Char('2') => {
app.selected_tab = SelectedTab::DirectoryBrowser;
}
// Playlists tab
KeyCode::Char('3') => {
app.selected_tab = SelectedTab::Playlists;
}
// Play next song
KeyCode::Char('>') => {
if !app.queue_list.list.is_empty() {
app.conn.conn.next()?;
app.update_queue();
}
}
// Play previous song
KeyCode::Char('<') => {
if !app.queue_list.list.is_empty() {
app.conn.conn.prev()?;
app.update_queue();
}
}
// Volume controls
KeyCode::Char('=') => {
app.conn.inc_volume(2);
app.conn.update_status();
}
KeyCode::Char('-') => {
app.conn.dec_volume(2);
app.conn.update_status();
}
// Update MPD database
KeyCode::Char('U') => {
app.conn.conn.rescan()?;
app.browser.update_directory(&mut app.conn)?;
}
// Search for songs
KeyCode::Char('/') => {
if app.inputmode == InputMode::Normal {
app.inputmode = InputMode::Editing;
} else {
app.inputmode = InputMode::Normal;
}
}
// Add or Remove from Current Playlist
KeyCode::Char(' ') | KeyCode::Backspace => {
app.handle_add_or_remove_from_current_playlist()?;
}
_ => {}
}
// Tab specific keymaps
match app.selected_tab {
SelectedTab::Queue => {
match key_event.code {
// Go Up
KeyCode::Char('j') | KeyCode::Down => app.queue_list.next(),
// Go down
KeyCode::Char('k') | KeyCode::Up => app.queue_list.prev(),
// Next directory
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
app.conn.conn.switch(app.queue_list.index as u32)?;
app.conn.update_status(); app.conn.update_status();
app.queue_list.list.clear();
app.queue_list.reset_index();
} }
}
// Delete highlighted song from the queue // Playback controls
KeyCode::Char('d') => { // Toggle Pause
if app.queue_list.index >= app.queue_list.list.len() - 1 KeyCode::Char('p') => app.conn.toggle_pause(),
&& app.queue_list.index != 0
{ // Pause
app.queue_list.index -= 1; KeyCode::Char('s') => app.conn.pause(),
// Toggle rpeat
KeyCode::Char('r') => {
app.conn.toggle_repeat();
app.conn.update_status();
}
// Toggle random
KeyCode::Char('z') => {
app.conn.toggle_random();
app.conn.update_status();
}
// Dmenu prompt
KeyCode::Char('D') => app.conn.play_dmenu()?,
// add to queue
KeyCode::Char('a') => app.playlist_popup = true,
// Fast forward
KeyCode::Char('f') => {
let place = app.conn.conn.status().unwrap().song.unwrap().pos;
let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
app.conn.conn.seek(place, pos)?;
}
// backward
KeyCode::Char('b') => {
let place = app.conn.conn.status().unwrap().song.unwrap().pos;
let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
app.conn.conn.seek(place, pos)?;
}
// Cycle through tabs
KeyCode::Tab => {
app.cycle_tabls();
}
// Directory browser tab
KeyCode::Char('1') => {
app.selected_tab = SelectedTab::Queue;
}
// Playing queue tab
KeyCode::Char('2') => {
app.selected_tab = SelectedTab::DirectoryBrowser;
}
// Playlists tab
KeyCode::Char('3') => {
app.selected_tab = SelectedTab::Playlists;
}
// Play next song
KeyCode::Char('>') => {
if !app.queue_list.list.is_empty() {
app.conn.conn.next()?;
app.update_queue();
}
}
// Play previous song
KeyCode::Char('<') => {
if !app.queue_list.list.is_empty() {
app.conn.conn.prev()?;
app.update_queue();
}
}
// Volume controls
KeyCode::Char('=') => {
app.conn.inc_volume(2);
app.conn.update_status();
}
KeyCode::Char('-') => {
app.conn.dec_volume(2);
app.conn.update_status();
}
// Update MPD database
KeyCode::Char('U') => {
app.conn.conn.rescan()?;
app.browser.update_directory(&mut app.conn)?;
}
// Search for songs
KeyCode::Char('/') => {
if app.inputmode == InputMode::Normal {
app.inputmode = InputMode::Editing;
} else {
app.inputmode = InputMode::Normal;
}
}
// Add or Remove from Current Playlist
KeyCode::Char(' ') | KeyCode::Backspace => {
app.handle_add_or_remove_from_current_playlist()?;
}
_ => {}
}
// Tab specific keymaps
match app.selected_tab {
SelectedTab::Queue => {
match key_event.code {
// Go Up
KeyCode::Char('j') | KeyCode::Down => app.queue_list.next(),
// Go down
KeyCode::Char('k') | KeyCode::Up => app.queue_list.prev(),
// Next directory
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
app.conn.conn.switch(app.queue_list.index as u32)?;
app.conn.update_status();
} }
app.conn.conn.delete(app.queue_list.index as u32)?; // Delete highlighted song from the queue
app.update_queue(); KeyCode::Char('d') => {
if app.queue_list.index >= app.queue_list.list.len() - 1
&& app.queue_list.index != 0
{
app.queue_list.index -= 1;
}
app.conn.conn.delete(app.queue_list.index as u32)?;
app.update_queue();
}
// Swap highlighted song with next one
KeyCode::Char('J') => {
let current: u32 = app.queue_list.index as u32;
let next: u32 = if (current + 1) as usize == app.queue_list.list.len() {
app.queue_list.index as u32
} else {
app.queue_list.index += 1;
current + 1
};
app.conn.conn.swap(current, next)?;
app.update_queue();
}
// Swap highlighted song with previous one
KeyCode::Char('K') => {
let current: u32 = app.queue_list.index as u32;
let prev: u32 = if current == 0 {
app.queue_list.index as u32
} else {
app.queue_list.index -= 1;
current - 1
};
app.conn.conn.swap(current, prev)?;
app.update_queue();
}
// go to top of list
KeyCode::Char('g') => app.queue_list.index = 0,
// go to bottom of list
KeyCode::Char('G') => app.queue_list.index = app.queue_list.list.len() - 1,
_ => {}
} }
// Swap highlighted song with next one
KeyCode::Char('J') => {
let current: u32 = app.queue_list.index as u32;
let next: u32 = if (current + 1) as usize == app.queue_list.list.len() {
app.queue_list.index as u32
} else {
app.queue_list.index += 1;
current + 1
};
app.conn.conn.swap(current, next)?;
app.update_queue();
}
// Swap highlighted song with previous one
KeyCode::Char('K') => {
let current: u32 = app.queue_list.index as u32;
let prev: u32 = if current == 0 {
app.queue_list.index as u32
} else {
app.queue_list.index -= 1;
current - 1
};
app.conn.conn.swap(current, prev)?;
app.update_queue();
}
// go to top of list
KeyCode::Char('g') => app.queue_list.index = 0,
// go to bottom of list
KeyCode::Char('G') => app.queue_list.index = app.queue_list.list.len() - 1,
_ => {}
} }
}
SelectedTab::DirectoryBrowser => { SelectedTab::DirectoryBrowser => {
match key_event.code { match key_event.code {
// Go Up // Go Up
KeyCode::Char('j') | KeyCode::Down => app.browser.next(), KeyCode::Char('j') | KeyCode::Down => app.browser.next(),
// Go down // Go down
KeyCode::Char('k') | KeyCode::Up => app.browser.prev(), KeyCode::Char('k') | KeyCode::Up => app.browser.prev(),
// Next directory // Next directory
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => { KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
// app.update_queue(); // app.update_queue();
app.handle_enter()?; app.handle_enter()?;
app.conn.update_status(); app.conn.update_status();
}
// head back to previous directory
KeyCode::Char('h') | KeyCode::Left => {
app.browser.handle_go_back(&mut app.conn)?
}
// go to top of list
KeyCode::Char('g') => app.browser.selected = 0,
// go to bottom of list
KeyCode::Char('G') => app.browser.selected = app.browser.filetree.len() - 1,
_ => {}
} }
// head back to previous directory
KeyCode::Char('h') | KeyCode::Left => app.browser.handle_go_back(&mut app.conn)?,
// go to top of list
KeyCode::Char('g') => app.browser.selected = 0,
// go to bottom of list
KeyCode::Char('G') => app.browser.selected = app.browser.filetree.len() - 1,
_ => {}
} }
}
SelectedTab::Playlists => { SelectedTab::Playlists => {
match key_event.code { match key_event.code {
// Go Up // Go Up
KeyCode::Char('j') | KeyCode::Down => app.pl_list.next(), KeyCode::Char('j') | KeyCode::Down => app.pl_list.next(),
// Go down // Go down
KeyCode::Char('k') | KeyCode::Up => app.pl_list.prev(), KeyCode::Char('k') | KeyCode::Up => app.pl_list.prev(),
// go to top of list // go to top of list
KeyCode::Char('g') => app.pl_list.index = 0, KeyCode::Char('g') => app.pl_list.index = 0,
// go to bottom of list // go to bottom of list
KeyCode::Char('G') => app.pl_list.index = app.pl_list.list.len() - 1, KeyCode::Char('G') => app.pl_list.index = app.pl_list.list.len() - 1,
// Change playlist name // Change playlist name
KeyCode::Char('e') => app.change_playlist_name()?, KeyCode::Char('e') => app.change_playlist_name()?,
// add to current playlist // add to current playlist
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Char(' ') => { KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Char(' ') => {
// app.update_queue(); // app.update_queue();
app.conn app.conn
.load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
app.conn.update_status(); app.conn.update_status();
}
_ => {}
} }
_ => {}
} }
} }
} }