Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30d8dd5

Browse files
Byronpiotrwach
authored andcommitted
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.
1 parent 0ad90ba commit 30d8dd5

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/interactive/app/eventloop.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ impl AppState {
270270
Char('o') | Char('l') | Enter | Right => {
271271
self.enter_node_with_traversal(&tree_view)
272272
}
273+
Char('R') => self.refresh(&mut tree_view, Refresh::AllInView)?,
274+
Char('r') => self.refresh(&mut tree_view, Refresh::Selected)?,
273275
Char('H') | Home => self.change_entry_selection(CursorDirection::ToTop),
274276
Char('G') | End => self.change_entry_selection(CursorDirection::ToBottom),
275277
PageUp => self.change_entry_selection(CursorDirection::PageUp),
@@ -306,6 +308,32 @@ impl AppState {
306308
Ok(None)
307309
}
308310

311+
fn refresh(&mut self, tree: &mut TreeView<'_>, what: Refresh) -> anyhow::Result<()> {
312+
match what {
313+
Refresh::Selected => {
314+
if let Some(selected) = self.navigation().selected {
315+
let parent_idx = tree
316+
.fs_parent_of(selected)
317+
.expect("there is always a parent to a selection");
318+
let path = tree.path_of(selected);
319+
tree.remove_entries(selected);
320+
tree.recompute_sizes_recursively(parent_idx);
321+
self.entries = tree.sorted_entries(parent_idx, self.sorting);
322+
self.navigation_mut().selected = self.entries.first().map(|e| e.index);
323+
self.active_traversal = Some(BackgroundTraversal::start(
324+
parent_idx,
325+
&self.walk_options,
326+
vec![path],
327+
)?);
328+
}
329+
}
330+
Refresh::AllInView => {
331+
log::info!("Not implemented")
332+
}
333+
}
334+
Ok(())
335+
}
336+
309337
fn tree_view<'a>(&mut self, traversal: &'a mut Traversal) -> TreeView<'a> {
310338
TreeView {
311339
traversal,
@@ -397,6 +425,13 @@ impl AppState {
397425
}
398426
}
399427

428+
enum Refresh {
429+
/// Refresh the directory currently in view
430+
AllInView,
431+
/// Refresh only the selected item
432+
Selected,
433+
}
434+
400435
pub fn draw_window<B>(
401436
window: &mut MainWindow,
402437
props: MainWindowProps<'_>,

0 commit comments

Comments
 (0)