From 32a3c604717c99e498a20069bc8895ae9deb0cb9 Mon Sep 17 00:00:00 2001 From: krolxon Date: Tue, 30 Apr 2024 22:40:56 +0530 Subject: add rename playlists feature --- src/handler.rs | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'src/handler.rs') diff --git a/src/handler.rs b/src/handler.rs index a5c4edb..86ab7cb 100755 --- a/src/handler.rs +++ b/src/handler.rs @@ -92,8 +92,8 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { } app.search_input.clear(); - app.inputmode = InputMode::Normal; app.reset_cursor(); + app.inputmode = InputMode::Normal; } KeyCode::Backspace => { @@ -110,10 +110,41 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { _ => {} } + } else if app.inputmode == InputMode::PlaylistRename { + match key_event.code { + KeyCode::Esc => { + app.pl_newname_input.clear(); + app.reset_cursor(); + app.inputmode = InputMode::Normal; + } + KeyCode::Char(to_insert) => { + app.enter_char(to_insert); + } + KeyCode::Enter => { + app.conn.conn.pl_rename(app.pl_list.list.get(app.pl_list.index).unwrap(), &app.pl_newname_input)?; + app.pl_list.list = App::get_playlist(&mut app.conn.conn)?; + app.pl_newname_input.clear(); + app.reset_cursor(); + app.inputmode = InputMode::Normal; + } + + KeyCode::Backspace => { + app.delete_char(); + } - // Playlist popup keybinds - // - // Keybind for when the "append to playlist" popup is visible + KeyCode::Left => { + app.move_cursor_left(); + } + + KeyCode::Right => { + app.move_cursor_right(); + } + + _ => {} + } + // Playlist popup keybinds + // + // Keybind for when the "append to playlist" popup is visible } else if app.playlist_popup { match key_event.code { KeyCode::Char('q') | KeyCode::Esc => { @@ -358,7 +389,11 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { // Search for songs KeyCode::Char('/') => { - app.inputmode = InputMode::toggle_editing_states(&app.inputmode); + if app.inputmode == InputMode::Normal { + app.inputmode = InputMode::Editing; + } else { + app.inputmode = InputMode::Normal; + } } // Remove from Current Playlsit @@ -366,9 +401,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.handle_add_or_remove_from_current_playlist()?; } - // Change playlist name - KeyCode::Char('e') => if app.selected_tab == SelectedTab::Playlists {}, - // go to top of list KeyCode::Char('g') => match app.selected_tab { SelectedTab::Queue => app.queue_list.index = 0, @@ -384,6 +416,9 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { } SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1, }, + + // Change playlist name + KeyCode::Char('e') => app.change_playlist_name()?, _ => {} } } -- cgit v1.2.3