summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2024-01-10 09:02:13 +0100
committerPiotr Wach <pwach@bloomberg.net>2024-01-10 20:48:54 +0000
commit30d8dd5fb54ef6db8b4444524407f15db25d7b02 (patch)
tree97f69a9f6d2948b62e06c8dde56039aea3357047 /src
parent0ad90ba23e59b98ccca198ce075e582c93d13c5c (diff)
add `R` to trigger a full refresh (PoC)
- it doesn't deal with sub-trees - for that it would need awareness of the method that integrates tree events. - selection handling isn't implemented, so the selection just disappears. - if the root to be refreshed still exists, it should probably keep it selected instead of removing it. - it seems useful to have some control over the scope of the refresh, and these are sketched with the `Refresh` enum.
Diffstat (limited to 'src')
-rw-r--r--src/interactive/app/eventloop.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index bdb278e..b370f78 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -270,6 +270,8 @@ impl AppState {
Char('o') | Char('l') | Enter | Right => {
self.enter_node_with_traversal(&tree_view)
}
+ Char('R') => self.refresh(&mut tree_view, Refresh::AllInView)?,
+ Char('r') => self.refresh(&mut tree_view, Refresh::Selected)?,
Char('H') | Home => self.change_entry_selection(CursorDirection::ToTop),
Char('G') | End => self.change_entry_selection(CursorDirection::ToBottom),
PageUp => self.change_entry_selection(CursorDirection::PageUp),
@@ -306,6 +308,32 @@ impl AppState {
Ok(None)
}
+ fn refresh(&mut self, tree: &mut TreeView<'_>, what: Refresh) -> anyhow::Result<()> {
+ match what {
+ Refresh::Selected => {
+ if let Some(selected) = self.navigation().selected {
+ let parent_idx = tree
+ .fs_parent_of(selected)
+ .expect("there is always a parent to a selection");
+ let path = tree.path_of(selected);
+ tree.remove_entries(selected);
+ tree.recompute_sizes_recursively(parent_idx);
+ self.entries = tree.sorted_entries(parent_idx, self.sorting);
+ self.navigation_mut().selected = self.entries.first().map(|e| e.index);
+ self.active_traversal = Some(BackgroundTraversal::start(
+ parent_idx,
+ &self.walk_options,
+ vec![path],
+ )?);
+ }
+ }
+ Refresh::AllInView => {
+ log::info!("Not implemented")
+ }
+ }
+ Ok(())
+ }
+
fn tree_view<'a>(&mut self, traversal: &'a mut Traversal) -> TreeView<'a> {
TreeView {
traversal,
@@ -397,6 +425,13 @@ impl AppState {
}
}
+enum Refresh {
+ /// Refresh the directory currently in view
+ AllInView,
+ /// Refresh only the selected item
+ Selected,
+}
+
pub fn draw_window<B>(
window: &mut MainWindow,
props: MainWindowProps<'_>,