Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use only one key for deletion #111

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions rm-config/src/keymap/actions/torrents_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ pub enum TorrentsAction {
AddMagnet,
MoveTorrent,
Pause,
DeleteWithFiles,
DeleteWithoutFiles,
Delete,
ShowFiles,
ShowStats,
ChangeCategory,
Expand All @@ -21,8 +20,7 @@ impl UserAction for TorrentsAction {
TorrentsAction::AddMagnet => "add a magnet",
TorrentsAction::MoveTorrent => "move torrent download directory",
TorrentsAction::Pause => "pause/unpause",
TorrentsAction::DeleteWithFiles => "delete with files",
TorrentsAction::DeleteWithoutFiles => "delete without files",
TorrentsAction::Delete => "delete",
TorrentsAction::ShowFiles => "show files",
TorrentsAction::ShowStats => "show statistics",
TorrentsAction::ChangeCategory => "change category",
Expand All @@ -36,8 +34,7 @@ impl From<TorrentsAction> for Action {
TorrentsAction::AddMagnet => Action::AddMagnet,
TorrentsAction::MoveTorrent => Action::MoveTorrent,
TorrentsAction::Pause => Action::Pause,
TorrentsAction::DeleteWithFiles => Action::DeleteWithFiles,
TorrentsAction::DeleteWithoutFiles => Action::DeleteWithoutFiles,
TorrentsAction::Delete => Action::Delete,
TorrentsAction::ShowFiles => Action::ShowFiles,
TorrentsAction::ShowStats => Action::ShowStats,
TorrentsAction::ChangeCategory => Action::ChangeCategory,
Expand Down
9 changes: 2 additions & 7 deletions rm-main/src/tui/tabs/torrents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,9 @@ impl Component for TorrentsTab {
A::ShowFiles => self.show_files_popup(),
A::Confirm => self.show_details_popup(),
A::Pause => self.pause_current_torrent(),
A::DeleteWithFiles => {
A::Delete => {
if let Some(torrent) = self.table_manager.current_torrent() {
self.task_manager.delete_torrent(torrent, true);
}
}
A::DeleteWithoutFiles => {
if let Some(torrent) = self.table_manager.current_torrent() {
self.task_manager.delete_torrent(torrent, false);
self.task_manager.delete_torrent(torrent);
}
}
A::AddMagnet => self.task_manager.add_magnet(),
Expand Down
40 changes: 14 additions & 26 deletions rm-main/src/tui/tabs/torrents/popups/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ratatui::{
widgets::{block::Title, Block, BorderType, Clear, Paragraph, Wrap},
};
use rm_config::CONFIG;
use rm_shared::action::Action;
use rm_shared::{action::Action, utils::bytes_to_human_format};
use style::Styled;

use crate::tui::{
Expand All @@ -29,12 +29,12 @@ impl Component for DetailsPopup {
match action {
_ if action.is_soft_quit() => ComponentAction::Quit,
Action::Confirm => ComponentAction::Quit,
Action::ShowFiles => {
self.ctx.send_action(Action::ShowFiles);
Action::Delete => {
self.ctx.send_action(Action::Delete);
ComponentAction::Quit
}
Action::DeleteWithoutFiles => {
self.ctx.send_action(Action::DeleteWithoutFiles);
Action::ShowFiles => {
self.ctx.send_action(Action::ShowFiles);
ComponentAction::Quit
}
Action::ChangeCategory => {
Expand All @@ -45,10 +45,6 @@ impl Component for DetailsPopup {
self.ctx.send_action(Action::MoveTorrent);
ComponentAction::Quit
}
Action::DeleteWithFiles => {
self.ctx.send_action(Action::DeleteWithFiles);
ComponentAction::Quit
}
_ => ComponentAction::Nothing,
}
}
Expand Down Expand Up @@ -76,7 +72,10 @@ impl Component for DetailsPopup {

let ratio = Line::from(format!("Ratio: {}", self.torrent.upload_ratio));

let size_line = Line::from(format!("Size: {}", self.torrent.size_when_done));
let size_line = Line::from(format!(
"Size: {}",
bytes_to_human_format(self.torrent.size_when_done)
));

let activity_line = Line::from(format!("Last activity: {}", self.torrent.activity_date));

Expand All @@ -102,22 +101,12 @@ impl Component for DetailsPopup {
keybinding_style(),
));

let mut delete_without_files_line = Line::default();
delete_without_files_line.push_span(Span::raw("Delete without files: "));
delete_without_files_line.push_span(Span::styled(
CONFIG
.keybindings
.get_keys_for_action(Action::DeleteWithoutFiles)
.unwrap_or_default(),
keybinding_style(),
));

let mut delete_with_files_line = Line::default();
delete_with_files_line.push_span(Span::raw("Delete with files: "));
delete_with_files_line.push_span(Span::styled(
let mut delete_line = Line::default();
delete_line.push_span(Span::raw("Delete: "));
delete_line.push_span(Span::styled(
CONFIG
.keybindings
.get_keys_for_action(Action::DeleteWithFiles)
.get_keys_for_action(Action::Delete)
.unwrap_or_default(),
keybinding_style(),
));
Expand Down Expand Up @@ -163,11 +152,10 @@ impl Component for DetailsPopup {
lines.push(added_line);
lines.push(activity_line);
lines.push(padding_line);
lines.push(delete_line);
lines.push(show_files_line);
lines.push(move_location_line);
lines.push(change_category_line);
lines.push(delete_with_files_line);
lines.push(delete_without_files_line);

let paragraph = Paragraph::new(lines).wrap(Wrap { trim: false });

Expand Down
9 changes: 3 additions & 6 deletions rm-main/src/tui/tabs/torrents/task_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,9 @@ impl TaskManager {
self.ctx.send_update_action(UpdateAction::SwitchToInputMode);
}

pub fn delete_torrent(&mut self, torrent: &RustmissionTorrent, delete_with_files: bool) {
self.current_task = CurrentTask::Delete(tasks::Delete::new(
self.ctx.clone(),
vec![torrent.clone()],
delete_with_files,
));
pub fn delete_torrent(&mut self, torrent: &RustmissionTorrent) {
self.current_task =
CurrentTask::Delete(tasks::Delete::new(self.ctx.clone(), vec![torrent.clone()]));
self.ctx.send_update_action(UpdateAction::SwitchToInputMode);
}

Expand Down
2 changes: 1 addition & 1 deletion rm-main/src/tui/tabs/torrents/tasks/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Component for Default {
line.push_span(Span::raw(format!("{} ", CONFIG.icons.help)));
}
line.push_span(Span::styled(keys, keybinding_style()));
line.push_span(Span::raw(" - details"));
line.push_span(Span::raw(" - view torrent"));
}
}
f.render_widget(line, rect);
Expand Down
14 changes: 6 additions & 8 deletions rm-main/src/tui/tabs/torrents/tasks/delete_torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ pub struct Delete {
}

impl Delete {
pub fn new(ctx: app::Ctx, to_delete: Vec<RustmissionTorrent>, delete_with_files: bool) -> Self {
let prompt = if delete_with_files {
"Really delete selected WITH files? (y/n) ".to_string()
} else {
"Really delete selected without files? (y/n) ".to_string()
};
pub fn new(ctx: app::Ctx, to_delete: Vec<RustmissionTorrent>) -> Self {
let prompt = String::from("Delete selected with files? (Y/n) ");

Self {
torrents_to_delete: to_delete,
input_mgr: InputManager::new(prompt),
ctx,
delete_with_files,
delete_with_files: false,
}
}

Expand Down Expand Up @@ -60,10 +56,12 @@ impl Component for Delete {
return ComponentAction::Quit;
} else if input.code == KeyCode::Enter {
let text = self.input_mgr.text().to_lowercase();
if text == "y" || text == "yes" {
if text == "y" || text == "yes" || text.is_empty() {
self.delete_with_files = true;
self.delete();
return ComponentAction::Quit;
} else if text == "n" || text == "no" {
self.delete();
return ComponentAction::Quit;
}
}
Expand Down
3 changes: 1 addition & 2 deletions rm-shared/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ pub enum Action {
ShowStats,
ShowFiles,
Pause,
DeleteWithoutFiles,
DeleteWithFiles,
Delete,
AddMagnet,
MoveTorrent,
ChangeCategory,
Expand Down
Loading