diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-11-05 18:25:50 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-11-05 18:25:50 +0100 |
commit | 72024f2b37f2ff71e23b6f4f194133b80a96d334 (patch) | |
tree | a852848209daa50602d20cefd52705b48d7d7179 /src | |
parent | 6ed77663393df5bb73f7a329c6e590dc06d86e8f (diff) |
sort for trees
Diffstat (limited to 'src')
-rw-r--r-- | src/event_exec.rs | 6 | ||||
-rw-r--r-- | src/status.rs | 11 | ||||
-rw-r--r-- | src/tab.rs | 31 | ||||
-rw-r--r-- | src/term_manager.rs | 4 |
4 files changed, 25 insertions, 27 deletions
diff --git a/src/event_exec.rs b/src/event_exec.rs index 247d4f7..d3e3a3d 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -302,7 +302,7 @@ impl EventAction { .reset_files(&tab.filter, tab.show_hidden, &tab.users)?; tab.window.reset(tab.path_content.content.len()); if let Mode::Tree = tab.mode { - tab.make_tree()? + tab.make_tree(None)? } Ok(()) } @@ -1454,7 +1454,7 @@ impl LeaveMode { EventAction::open_file(status) } else { tab.set_pathcontent(&node.filepath())?; - tab.make_tree()?; + tab.make_tree(None)?; Ok(()) } } @@ -1525,7 +1525,7 @@ impl LeaveMode { tab.path_content .reset_files(&tab.filter, tab.show_hidden, &tab.users)?; if let Mode::Tree = tab.previous_mode { - tab.make_tree()?; + tab.make_tree(None)?; } tab.window.reset(tab.path_content.content.len()); Ok(()) diff --git a/src/status.rs b/src/status.rs index 132ea1a..9fe1871 100644 --- a/src/status.rs +++ b/src/status.rs @@ -41,6 +41,7 @@ use crate::skim::Skimer; use crate::tab::Tab; use crate::term_manager::MIN_WIDTH_FOR_DUAL_PANE; use crate::trash::Trash; +use crate::trees::FileSystem; use crate::users::Users; use crate::utils::{current_username, disk_space, filename_from_path, is_program_in_path}; @@ -617,17 +618,15 @@ impl Status { pub fn tree(&mut self) -> Result<()> { if let Mode::Tree = self.selected_non_mut().mode { { - let tab: &mut Tab = self.selected(); + let tab = self.selected(); + tab.tree = FileSystem::empty(); tab.refresh_view() }?; self.selected().set_mode(Mode::Normal) } else { self.display_full = true; - // self.selected().make_tree()?; - self.selected().make_tree()?; + self.selected().make_tree(None)?; self.selected().set_mode(Mode::Tree); - let len = self.selected_non_mut().directory.len(); - self.selected().window.reset(len); } Ok(()) } @@ -929,7 +928,7 @@ impl Status { self.refresh_users()?; self.selected().refresh_view()?; if let Mode::Tree = self.selected_non_mut().mode { - self.selected().make_tree()? + self.selected().make_tree(None)? } Ok(()) } @@ -334,7 +334,7 @@ impl Tab { self.scroll_to(index); self.history.content.pop(); if let Mode::Tree = self.mode { - self.make_tree()? + self.make_tree(None)? } Ok(()) @@ -346,7 +346,7 @@ impl Tab { self.directory.unselect_children(); if self.directory.tree.position.len() <= 1 { self.move_to_parent()?; - self.make_tree()? + self.make_tree(None)? } self.directory.select_parent() } @@ -430,18 +430,14 @@ impl Tab { } /// Makes a new tree of the current path. - pub fn make_tree(&mut self) -> Result<()> { + pub fn make_tree(&mut self, sort_kind: Option<SortKind>) -> Result<()> { + let sort_kind = match sort_kind { + Some(sort_kind) => sort_kind, + None => SortKind::tree_default(), + }; let path = self.path_content.path.clone(); let users = &self.users; - // self.directory = Directory::new(&path, users, &self.filter, self.show_hidden, None)?; - self.tree = FileSystem::new( - path, - 5, - SortKind::tree_default(), - users, - self.show_hidden, - &self.filter, - ); + self.tree = FileSystem::new(path, 5, sort_kind, users, self.show_hidden, &self.filter); Ok(()) } @@ -697,10 +693,13 @@ impl Tab { self.path_content.select_index(0); } Mode::Tree => { - self.directory.tree.update_sort_from_char(c); - self.directory.tree.sort(); - self.tree_select_root()?; - self.directory.tree.into_navigable_content(); + self.path_content.update_sort_from_char(c); + self.make_tree(Some(self.path_content.sort_kind.clone()))?; + + // self.directory.tree.update_sort_from_char(c); + // self.directory.tree.sort(); + // self.tree_select_root()?; + // self.directory.tree.into_navigable_content(); } _ => (), } diff --git a/src/term_manager.rs b/src/term_manager.rs index bc119f4..e7b5749 100644 --- a/src/term_manager.rs +++ b/src/term_manager.rs @@ -142,7 +142,7 @@ impl<'a> Draw for WinMain<'a> { Mode::Tree => self.trees(self.status, self.tab, canvas), Mode::Normal => self.files(self.status, self.tab, canvas), _ => match self.tab.previous_mode { - Mode::Tree => self.tree(self.status, self.tab, canvas), + Mode::Tree => self.trees(self.status, self.tab, canvas), _ => self.files(self.status, self.tab, canvas), }, }?; @@ -394,7 +394,7 @@ impl<'a> WinMain<'a> { Ok(()) } - fn tree(&self, status: &Status, tab: &Tab, canvas: &mut dyn Canvas) -> Result<()> { + fn _tree(&self, status: &Status, tab: &Tab, canvas: &mut dyn Canvas) -> Result<()> { let left_margin = if status.display_full { 1 } else { 3 }; let (_, height) = canvas.size()?; let (top, bottom, len) = tab.directory.calculate_tree_window(height); |