Skip to content

Commit

Permalink
Implement remaining commands (#45)
Browse files Browse the repository at this point in the history
Implemented SwapSongUp, SwapSongDown, OpenHelpModal, OpenHotkeyModal and
PlayFromModal commands. The only remaining command is now OpenInEditor!
  • Loading branch information
LeoRiether authored Feb 11, 2024
1 parent c04293f commit 0f20c2d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tori/src/app/modal/hotkey_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct HotkeyModal {
}

impl Modal for HotkeyModal {
fn handle_event(&mut self, tx: Tx, event: Event) -> Result<Option<Action>> {
fn handle_event(&mut self, _tx: Tx, event: Event) -> Result<Option<Action>> {
if let Event::Key(key) = event {
if let KeyCode::Esc = key.code {
return Ok(Some(Action::CloseModal));
Expand Down
1 change: 1 addition & 0 deletions tori/src/events/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum Action {
ScrollDown,
ScrollUp,

Play(String),
RefreshSongs,
RefreshPlaylists,
SelectSong(usize),
Expand Down
26 changes: 25 additions & 1 deletion tori/src/update/browse_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
error::Result,
events::{channel::Tx, Action, Command},
input::Input,
m3u::playlist_management,
player::Player,
state::{
browse_screen::{BrowseScreen, Focus},
Expand Down Expand Up @@ -161,7 +162,7 @@ fn browse_screen_command(
Some(p) => p.to_string(),
};

state.modal = InputModal::new(" Add song to playlist ")
state.modal = InputModal::new(" Add song ")
.style(Style::default().fg(Color::LightBlue))
.on_commit(move |song| Action::AddSongToPlaylist { song, playlist })
.some_box();
Expand Down Expand Up @@ -237,6 +238,29 @@ fn browse_screen_command(
}
}

SwapSongUp => {
if let Some(playlist) = screen.selected_playlist() {
if let Some(i) = screen.selected_song_index() {
if i > 0 {
playlist_management::swap_song(playlist, i - 1)?;
screen.songs.swap(i - 1, i);
screen.shown_songs.select_prev();
}
}
}
}
SwapSongDown => {
if let Some(playlist) = screen.selected_playlist() {
if let Some(i) = screen.selected_song_index() {
if i + 1 < screen.songs.len() {
playlist_management::swap_song(playlist, i)?;
screen.songs.swap(i, i + 1);
screen.shown_songs.select_next();
}
}
}
}

_ => {}
}

Expand Down
24 changes: 16 additions & 8 deletions tori/src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use browse_screen::browse_screen_action;
use std::mem;

use crate::{
app::modal::{HelpModal, HotkeyModal, InputModal, Modal},
config::Config,
error::Result,
events::{action::Level, channel::Tx, Action, Command},
Expand Down Expand Up @@ -94,6 +95,10 @@ pub fn update(state: &mut State<'_>, tx: Tx, act: Action) -> Result<Option<Actio
};
}

Play(song) => {
state.player.play(&song)?;
}

CloseModal => {
state.modal = None;
}
Expand Down Expand Up @@ -162,7 +167,7 @@ fn handle_command(state: &mut State<'_>, tx: Tx, cmd: Command) -> Result<Option<
match cmd {
Esc | Play | QueueSong | QueueShown | OpenInBrowser | CopyUrl | CopyTitle
| NextSortingMode | SelectLeft | SelectNext | SelectRight | SelectPrev | Search
| GotoStart | GotoEnd | Add | Rename | Delete => {
| GotoStart | GotoEnd | Add | Rename | Delete | SwapSongDown | SwapSongUp => {
return screen_action(state, tx, Action::Command(cmd))
}

Expand Down Expand Up @@ -222,14 +227,17 @@ fn handle_command(state: &mut State<'_>, tx: Tx, cmd: Command) -> Result<Option<

ToggleVisualizer => state.visualizer.toggle()?,

OpenHelpModal => todo!(),
OpenHotkeyModal => todo!(),
PlayFromModal => todo!(),

SwapSongDown => todo!(),
SwapSongUp => todo!(),
OpenHelpModal => {
state.modal = HelpModal::new().some_box();
}
OpenHotkeyModal => {
state.modal = HotkeyModal::default().some_box();
}
PlayFromModal => {
state.modal = InputModal::new(" Play ").on_commit(Action::Play).some_box();
}

OpenInEditor => todo!(),
OpenInEditor => todo!("OpenInEditor is not yet implemented"),
}

Ok(None)
Expand Down

0 comments on commit 0f20c2d

Please sign in to comment.