Skip to content

Commit

Permalink
simplify the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski committed Aug 19, 2024
1 parent 3abacfa commit 823157a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
16 changes: 4 additions & 12 deletions rm-main/src/tui/components/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,11 @@ impl<T: Clone> GenericTable<T> {
}
}

pub fn scroll_to_home(&mut self) {
let mut state = self.state.borrow_mut();
if !self.items.is_empty() {
state.select(Some(0));
}
pub fn select_first(&mut self) {
self.state.borrow_mut().select_first();
}

pub fn scroll_to_end(&mut self) {
if self.items.is_empty() {
return;
}

let mut state = self.state.borrow_mut();
state.select(Some(self.items.len() - 1));
pub fn select_last(&mut self) {
self.state.borrow_mut().select_last();
}
}
4 changes: 2 additions & 2 deletions rm-main/src/tui/tabs/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ impl SearchTab {
}

fn scroll_to_end(&mut self) {
self.table.scroll_to_end();
self.table.select_last();
self.ctx.send_action(Action::Render);
}

fn scroll_to_home(&mut self) {
self.table.scroll_to_home();
self.table.select_first();
self.ctx.send_action(Action::Render);
}

Expand Down
8 changes: 4 additions & 4 deletions rm-main/src/tui/tabs/torrents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Component for TorrentsTab {
self.task_manager.move_torrent(torrent);
}
}
A::XdgOpen => self.open_current_torrent(),
A::XdgOpen => self.xdg_open_current_torrent(),
other => {
self.task_manager.handle_actions(other);
}
Expand Down Expand Up @@ -263,14 +263,14 @@ impl TorrentsTab {
}

fn scroll_to_home(&mut self) {
self.table_manager.table.scroll_to_home();
self.table_manager.table.select_first();
self.bottom_stats
.update_selected_indicator(&self.table_manager);
self.ctx.send_action(Action::Render);
}

fn scroll_to_end(&mut self) {
self.table_manager.table.scroll_to_end();
self.table_manager.table.select_last();
self.bottom_stats
.update_selected_indicator(&self.table_manager);
self.ctx.send_action(Action::Render);
Expand All @@ -296,7 +296,7 @@ impl TorrentsTab {
}
}

fn open_current_torrent(&mut self) {
fn xdg_open_current_torrent(&mut self) {
if let Some(torrent) = self.table_manager.current_torrent() {
let torrent_location = torrent.torrent_location();
match open::that_detached(&torrent_location) {
Expand Down

0 comments on commit 823157a

Please sign in to comment.