mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-22 13:22:28 +00:00
coalesce visit_stack
and position_stack
(#6)
This commit is contained in:
parent
70d3abfca4
commit
6d1f3a0cef
|
@ -50,7 +50,7 @@ pub struct AppState {
|
||||||
current_tab: ListState,
|
current_tab: ListState,
|
||||||
/// This stack keeps track of our "current directory". You can think of it as `pwd`. but not
|
/// This stack keeps track of our "current directory". You can think of it as `pwd`. but not
|
||||||
/// just the current directory, all paths that took us here, so we can "cd .."
|
/// just the current directory, all paths that took us here, so we can "cd .."
|
||||||
visit_stack: Vec<NodeId>,
|
visit_stack: Vec<(NodeId, usize)>,
|
||||||
/// This is the state asociated with the list widget, used to display the selection in the
|
/// This is the state asociated with the list widget, used to display the selection in the
|
||||||
/// widget
|
/// widget
|
||||||
selection: ListState,
|
selection: ListState,
|
||||||
|
@ -60,7 +60,6 @@ pub struct AppState {
|
||||||
drawable: bool,
|
drawable: bool,
|
||||||
#[cfg(feature = "tips")]
|
#[cfg(feature = "tips")]
|
||||||
tip: &'static str,
|
tip: &'static str,
|
||||||
position_stack: Vec<usize>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Focus {
|
pub enum Focus {
|
||||||
|
@ -94,7 +93,7 @@ impl AppState {
|
||||||
focus: Focus::List,
|
focus: Focus::List,
|
||||||
tabs,
|
tabs,
|
||||||
current_tab: ListState::default().with_selected(Some(0)),
|
current_tab: ListState::default().with_selected(Some(0)),
|
||||||
visit_stack: vec![root_id],
|
visit_stack: vec![(root_id, 0usize)],
|
||||||
selection: ListState::default().with_selected(Some(0)),
|
selection: ListState::default().with_selected(Some(0)),
|
||||||
filter: Filter::new(),
|
filter: Filter::new(),
|
||||||
multi_select: false,
|
multi_select: false,
|
||||||
|
@ -102,7 +101,6 @@ impl AppState {
|
||||||
drawable: false,
|
drawable: false,
|
||||||
#[cfg(feature = "tips")]
|
#[cfg(feature = "tips")]
|
||||||
tip: get_random_tip(),
|
tip: get_random_tip(),
|
||||||
position_stack: vec![0],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
state.update_items();
|
state.update_items();
|
||||||
|
@ -557,7 +555,7 @@ impl AppState {
|
||||||
self.filter.update_items(
|
self.filter.update_items(
|
||||||
&self.tabs,
|
&self.tabs,
|
||||||
self.current_tab.selected().unwrap(),
|
self.current_tab.selected().unwrap(),
|
||||||
*self.visit_stack.last().unwrap(),
|
self.visit_stack.last().unwrap().0,
|
||||||
);
|
);
|
||||||
if !self.is_current_tab_multi_selectable() {
|
if !self.is_current_tab_multi_selectable() {
|
||||||
self.multi_select = false;
|
self.multi_select = false;
|
||||||
|
@ -581,8 +579,7 @@ impl AppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_parent_directory(&mut self) {
|
fn enter_parent_directory(&mut self) {
|
||||||
if let Some(previous_position) = self.position_stack.pop() {
|
if let Some((_, previous_position)) = self.visit_stack.pop() {
|
||||||
self.visit_stack.pop();
|
|
||||||
self.selection.select(Some(previous_position));
|
self.selection.select(Some(previous_position));
|
||||||
self.update_items();
|
self.update_items();
|
||||||
}
|
}
|
||||||
|
@ -627,8 +624,7 @@ impl AppState {
|
||||||
|
|
||||||
if let Some(item) = self.filter.item_list().get(actual_index) {
|
if let Some(item) = self.filter.item_list().get(actual_index) {
|
||||||
if item.has_children {
|
if item.has_children {
|
||||||
self.visit_stack.push(item.id);
|
self.visit_stack.push((item.id, selected_index));
|
||||||
self.position_stack.push(selected_index);
|
|
||||||
self.selection.select(Some(0));
|
self.selection.select(Some(0));
|
||||||
self.update_items();
|
self.update_items();
|
||||||
}
|
}
|
||||||
|
@ -746,10 +742,13 @@ impl AppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refresh_tab(&mut self) {
|
fn refresh_tab(&mut self) {
|
||||||
self.visit_stack = vec![self.tabs[self.current_tab.selected().unwrap()]
|
self.visit_stack = vec![(
|
||||||
|
self.tabs[self.current_tab.selected().unwrap()]
|
||||||
.tree
|
.tree
|
||||||
.root()
|
.root()
|
||||||
.id()];
|
.id(),
|
||||||
|
0usize,
|
||||||
|
)];
|
||||||
self.selection.select(Some(0));
|
self.selection.select(Some(0));
|
||||||
self.update_items();
|
self.update_items();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user