general and tab specific keys seperated

This commit is contained in:
krolxon 2024-05-07 22:56:32 +05:30
parent c15bb2275f
commit cef5f73478
1 changed files with 223 additions and 204 deletions

View File

@ -8,14 +8,15 @@ use std::time::Duration;
use super::{pl_append_keys, pl_rename_keys, search_keys};
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
// Live search update
// searching, playlist renaming, playlist appending
if app.inputmode == InputMode::Editing {
search_keys::handle_search_keys(key_event, app)?;
} else if app.inputmode == InputMode::PlaylistRename {
pl_rename_keys::handle_pl_rename_keys(key_event, app)?;
} else if app.playlist_popup {
pl_append_keys::hande_pl_append_keys(key_event, app)?;
} else {
}
// General KeyMaps
match key_event.code {
// Quit
@ -31,50 +32,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
}
}
// Go Up
KeyCode::Char('j') | KeyCode::Down => match app.selected_tab {
SelectedTab::DirectoryBrowser => app.browser.next(),
SelectedTab::Queue => app.queue_list.next(),
SelectedTab::Playlists => app.pl_list.next(),
},
// Go down
KeyCode::Char('k') | KeyCode::Up => match app.selected_tab {
SelectedTab::DirectoryBrowser => app.browser.prev(),
SelectedTab::Queue => app.queue_list.prev(),
SelectedTab::Playlists => app.pl_list.prev(),
},
// Next directory
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
// app.update_queue();
match app.selected_tab {
SelectedTab::DirectoryBrowser => {
app.handle_enter()?;
}
SelectedTab::Queue => {
app.conn.conn.switch(app.queue_list.index as u32)?;
}
SelectedTab::Playlists => {
app.conn
.load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
}
}
app.conn.update_status();
}
// head back to previous directory
KeyCode::Char('h') | KeyCode::Left => match app.selected_tab {
SelectedTab::DirectoryBrowser => {
app.browser.handle_go_back(&mut app.conn)?;
}
SelectedTab::Queue => {}
SelectedTab::Playlists => {}
},
// Playback controls
// Toggle Pause
KeyCode::Char('p') => app.conn.toggle_pause(),
@ -163,6 +120,44 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
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();
}
// Delete highlighted song from the queue
KeyCode::Char('d') => {
if app.queue_list.index >= app.queue_list.list.len() - 1
@ -201,47 +196,71 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
app.update_queue();
}
// 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;
}
}
// Remove from Current Playlsit
KeyCode::Char(' ') | KeyCode::Backspace => {
app.handle_add_or_remove_from_current_playlist()?;
}
// go to top of list
KeyCode::Char('g') => match app.selected_tab {
SelectedTab::Queue => app.queue_list.index = 0,
SelectedTab::DirectoryBrowser => app.browser.selected = 0,
SelectedTab::Playlists => app.pl_list.index = 0,
},
KeyCode::Char('g') => app.queue_list.index = 0,
// go to bottom of list
KeyCode::Char('G') => match app.selected_tab {
SelectedTab::Queue => app.queue_list.index = app.queue_list.list.len() - 1,
SelectedTab::DirectoryBrowser => {
app.browser.selected = app.browser.filetree.len() - 1
KeyCode::Char('G') => app.queue_list.index = app.queue_list.list.len() - 1,
_ => {}
}
SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1,
},
}
SelectedTab::DirectoryBrowser => {
match key_event.code {
// Go Up
KeyCode::Char('j') | KeyCode::Down => app.browser.next(),
// Go down
KeyCode::Char('k') | KeyCode::Up => app.browser.prev(),
// Next directory
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
// app.update_queue();
app.handle_enter()?;
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,
_ => {}
}
}
SelectedTab::Playlists => {
match key_event.code {
// Go Up
KeyCode::Char('j') | KeyCode::Down => app.pl_list.next(),
// Go down
KeyCode::Char('k') | KeyCode::Up => app.pl_list.prev(),
// go to top of list
KeyCode::Char('g') => app.pl_list.index = 0,
// go to bottom of list
KeyCode::Char('G') => app.pl_list.index = app.pl_list.list.len() - 1,
// Change playlist name
KeyCode::Char('e') => app.change_playlist_name()?,
// add to current playlist
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Char(' ') => {
// app.update_queue();
app.conn
.load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
app.conn.update_status();
}
_ => {}
}
}
}
Ok(())
}