diff options
author | rabite <rabite@posteo.de> | 2019-05-08 13:47:36 +0200 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-05-08 13:48:46 +0200 |
commit | 572a217e17b0cc2c30cd94b57e5a94ede75e0707 (patch) | |
tree | fcf713135acb4516d4f935565d6b836eba525c21 /src/files.rs | |
parent | 7d08e6b064a0def48df927cd19572b1964aedcc8 (diff) |
add incremental search/filter
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/files.rs b/src/files.rs index a3cd0ab..a191873 100644 --- a/src/files.rs +++ b/src/files.rs @@ -235,8 +235,10 @@ impl Files { let file = self.files .iter_mut() - .filter(|f| !(filter.is_some() && - !f.name.contains(filter.as_ref().unwrap()))) + .filter(|f| + f.kind == Kind::Placeholder || + !(filter.is_some() && + !f.name.contains(filter.as_ref().unwrap()))) .filter(|f| !(!show_hidden && f.name.starts_with("."))) .nth(index); file @@ -245,8 +247,10 @@ impl Files { pub fn get_files(&self) -> Vec<&File> { self.files .iter() - .filter(|f| !(self.filter.is_some() && - !f.name.contains(self.filter.as_ref().unwrap()))) + .filter(|f| + f.kind == Kind::Placeholder || + (!(self.filter.is_some() && + !f.name.contains(self.filter.as_ref().unwrap())))) .filter(|f| !(!self.show_hidden && f.name.starts_with("."))) .collect() } @@ -256,8 +260,10 @@ impl Files { let show_hidden = self.show_hidden; self.files .iter_mut() - .filter(|f| !(filter.is_some() && - !f.name.contains(filter.as_ref().unwrap()))) + .filter(|f| + f.kind == Kind::Placeholder || + !(filter.is_some() && + !f.name.contains(filter.as_ref().unwrap()))) .filter(|f| !(!show_hidden && f.name.starts_with("."))) .collect() } @@ -344,7 +350,7 @@ impl Files { self.show_hidden = !self.show_hidden; self.set_dirty(); - if self.show_hidden == true { + if self.show_hidden == true && self.len() > 1 { self.remove_placeholder(); } } @@ -433,6 +439,13 @@ impl Files { } } + pub fn find_file_with_name(&self, name: &str) -> Option<&File> { + self.get_files() + .iter() + .find(|f| f.name.to_lowercase().contains(name)) + .cloned() + } + pub fn find_file_with_path(&mut self, path: &Path) -> Option<&mut File> { self.files.iter_mut().find(|file| file.path == path) } @@ -495,6 +508,15 @@ impl Files { pub fn set_filter(&mut self, filter: Option<String>) { self.filter = filter; + + // Do this first, so we know len() == 0 needs a placeholder + self.remove_placeholder(); + + if self.len() == 0 { + let placeholder = File::new_placeholder(&self.directory.path).unwrap(); + self.files.push(placeholder); + } + self.set_dirty(); } |