Skip to content

Commit

Permalink
feat!: use only one key for deletion (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski authored Sep 2, 2024
1 parent 4b18dbc commit 2af99a3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 53 deletions.
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
33 changes: 9 additions & 24 deletions rm-main/src/tui/tabs/torrents/popups/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -105,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 @@ -166,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
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

0 comments on commit 2af99a3

Please sign in to comment.