From a94d8b77ea847d6a54146e11a83073a8d31e6405 Mon Sep 17 00:00:00 2001 From: kageru Date: Mon, 27 Apr 2020 12:34:58 +0200 Subject: [PATCH] Only allow toggling for todo items --- src/listview.rs | 1 - src/timesheet.rs | 6 ------ src/todolist.rs | 8 ++++---- src/tracc.rs | 2 +- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/listview.rs b/src/listview.rs index 057ba13..46b39ab 100644 --- a/src/listview.rs +++ b/src/listview.rs @@ -10,7 +10,6 @@ pub trait ListView { fn backspace(&mut self); fn append_to_current(&mut self, chr: char); fn normal_mode(&mut self); - fn toggle_current(&mut self); // selection manipulation fn selection_up(&mut self) { diff --git a/src/timesheet.rs b/src/timesheet.rs index 505131a..753707e 100644 --- a/src/timesheet.rs +++ b/src/timesheet.rs @@ -9,7 +9,6 @@ pub struct TimeSheet { pub times: Vec, pub selected: usize, pub register: Option, - pub editing_time: bool, } const PAUSE_TEXTS: [&str; 3] = ["lunch", "mittag", "pause"]; @@ -71,7 +70,6 @@ impl TimeSheet { times: read_times(path).unwrap_or_else(|| vec![TimePoint::new("start")]), selected: 0, register: None, - editing_time: false, } } @@ -140,10 +138,6 @@ impl ListView for TimeSheet { self.times.sort_by_key(|t| t.time); } - fn toggle_current(&mut self) { - self.editing_time = !self.editing_time; - } - fn append_to_current(&mut self, chr: char) { self.times[self.selected].text.push(chr); } diff --git a/src/todolist.rs b/src/todolist.rs index 45a0aef..8cd6c21 100644 --- a/src/todolist.rs +++ b/src/todolist.rs @@ -48,6 +48,10 @@ impl TodoList { } } + pub fn toggle_current(&mut self) { + self.todos[self.selected].done = !self.todos[self.selected].done; + } + fn current(&self) -> &Todo { &self.todos[self.selected] } @@ -80,8 +84,4 @@ impl ListView for TodoList { fn backspace(&mut self) { self.todos[self.selected].text.pop(); } - - fn toggle_current(&mut self) { - self.todos[self.selected].done = !self.todos[self.selected].done; - } } diff --git a/src/tracc.rs b/src/tracc.rs index fdccfd4..8691217 100644 --- a/src/tracc.rs +++ b/src/tracc.rs @@ -68,7 +68,7 @@ impl Tracc { self.set_mode(Mode::Insert)?; } Key::Char('a') | Key::Char('A') => self.set_mode(Mode::Insert)?, - Key::Char(' ') => with_focused!(ListView::toggle_current), + Key::Char(' ') if self.focus == Focus::Top => self.todos.toggle_current(), // dd Key::Char('d') => { if let Some(Ok(Key::Char('d'))) = inputs.next() {