summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2022-12-30 21:19:38 +0100
committerqkzk <qu3nt1n@gmail.com>2022-12-30 21:19:38 +0100
commit6403a6d69fde23c6e3a0c761b693f42b83420417 (patch)
tree74baf8e8b2ad4c06409bd1961991463683ad9aa5
parentd2e750a9741bdc2b8cca5ff8bf7124c25c65c121 (diff)
refresh view also refresh users cachecache-users
-rw-r--r--src/color_cache.rs9
-rw-r--r--src/event_dispatch.rs2
-rw-r--r--src/event_exec.rs7
-rw-r--r--src/fileinfo.rs6
-rw-r--r--src/status.rs9
-rw-r--r--src/tab.rs5
-rw-r--r--src/visited.rs5
7 files changed, 29 insertions, 14 deletions
diff --git a/src/color_cache.rs b/src/color_cache.rs
index 3889ebbc..53339d3b 100644
--- a/src/color_cache.rs
+++ b/src/color_cache.rs
@@ -7,18 +7,11 @@ use tuikit::attr::Color;
/// Holds a map of extension name to color.
/// Every extension is associated to a color which is only computed once
/// per run. This trades a bit of memory for a bit of CPU.
+#[derive(Default)]
pub struct ColorCache {
cache: RefCell<HashMap<String, Color>>,
}
-impl Default for ColorCache {
- fn default() -> Self {
- Self {
- cache: RefCell::new(HashMap::new()),
- }
- }
-}
-
impl ColorCache {
/// Returns a color for any possible extension.
/// The color is cached within the struct, avoiding multiple calculations.
diff --git a/src/event_dispatch.rs b/src/event_dispatch.rs
index 13e434b6..8ace282f 100644
--- a/src/event_dispatch.rs
+++ b/src/event_dispatch.rs
@@ -35,7 +35,7 @@ impl EventDispatcher {
Event::Key(Key::SingleClick(MouseButton::Right, row, _)) => {
EventExec::event_right_click(status, row)
}
- Event::User(_) => EventExec::refresh_selected_view(status),
+ Event::User(_) => EventExec::refresh_status(status),
Event::Resize { width, height } => EventExec::resize(status, width, height),
Event::Key(Key::Char(c)) => self.char(status, Key::Char(c)),
Event::Key(key) => self.key_matcher(status, key),
diff --git a/src/event_exec.rs b/src/event_exec.rs
index 2de9236d..7497a982 100644
--- a/src/event_exec.rs
+++ b/src/event_exec.rs
@@ -32,7 +32,8 @@ pub struct EventExec {}
impl EventExec {
/// Reset the selected tab view to the default.
- pub fn refresh_selected_view(status: &mut Status) -> FmResult<()> {
+ pub fn refresh_status(status: &mut Status) -> FmResult<()> {
+ status.refresh_users()?;
status.selected().refresh_view()
}
@@ -48,7 +49,7 @@ impl EventExec {
status.set_dual_pane(true);
}
status.selected().set_height(height);
- Self::refresh_selected_view(status)?;
+ Self::refresh_status(status)?;
Ok(())
}
@@ -1235,7 +1236,7 @@ impl EventExec {
/// Refresh the current view, reloading the files. Move the selection to top.
pub fn event_refreshview(status: &mut Status) -> FmResult<()> {
- Self::refresh_selected_view(status)
+ Self::refresh_status(status)
}
/// Open a thumbnail of an image, scaled up to the whole window.
diff --git a/src/fileinfo.rs b/src/fileinfo.rs
index 8ae9ed29..71ca3207 100644
--- a/src/fileinfo.rs
+++ b/src/fileinfo.rs
@@ -458,6 +458,12 @@ impl PathContent {
pub fn enumerate(&mut self) -> Enumerate<std::slice::Iter<'_, FileInfo>> {
self.content.iter().enumerate()
}
+
+ /// Refresh the existing users.
+ pub fn refresh_users(&mut self, users_cache: Rc<UsersCache>) -> FmResult<()> {
+ self.users_cache = users_cache;
+ self.reset_files()
+ }
}
impl_selectable_content!(FileInfo, PathContent);
diff --git a/src/status.rs b/src/status.rs
index 82416902..d1a052af 100644
--- a/src/status.rs
+++ b/src/status.rs
@@ -290,4 +290,13 @@ impl Status {
pub fn selected_path_str(&self) -> &str {
self.selected_non_mut().path_str().unwrap_or_default()
}
+
+ /// Refresh the existing users.
+ pub fn refresh_users(&mut self) -> FmResult<()> {
+ let users_cache = Rc::new(unsafe { UsersCache::with_all_users() });
+ for tab in self.tabs.iter_mut() {
+ tab.refresh_users(users_cache.clone())?;
+ }
+ Ok(())
+ }
}
diff --git a/src/tab.rs b/src/tab.rs
index 0e8795f6..bc9ed2cd 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -178,4 +178,9 @@ impl Tab {
self.path_content.select_index(index);
self.window.scroll_to(index);
}
+
+ /// Refresh the existing users.
+ pub fn refresh_users(&mut self, users_cache: Rc<UsersCache>) -> FmResult<()> {
+ self.path_content.refresh_users(users_cache)
+ }
}
diff --git a/src/visited.rs b/src/visited.rs
index 0832f77f..a42099bf 100644
--- a/src/visited.rs
+++ b/src/visited.rs
@@ -19,8 +19,9 @@ impl History {
/// Add a new path in the stack, without duplicates, and select the last
/// one.
pub fn push(&mut self, path: &std::path::Path) {
- if !self.content.contains(&path.to_path_buf()) {
- self.content.push(path.to_path_buf());
+ let path = path.to_path_buf();
+ if !self.content.contains(&path) {
+ self.content.push(path);
self.index = self.len() - 1
}
}