file_model: Remove next() and previous() functions

These functions required iterating to find the
index of a file and then adding one to it.
We can be smarter, using an index we already
have and adding or subtracting where appropriate.
This commit is contained in:
Christopher Davis 2022-06-29 13:37:55 -04:00
parent 10cdb2c519
commit e13ecb4df4
2 changed files with 6 additions and 23 deletions

View file

@ -115,24 +115,6 @@ impl LpFileModel {
model
}
pub fn previous(&self, current: &gio::File) -> Option<gio::File> {
let imp = self.imp();
let vec = imp.inner.borrow();
let index = vec.iter().position(|f| f.equal(current))?;
vec.get(index.checked_sub(1)?).cloned()
}
pub fn next(&self, current: &gio::File) -> Option<gio::File> {
let imp = self.imp();
let vec = imp.inner.borrow();
let index = vec.iter().position(|f| f.equal(current))?;
vec.get(index + 1).cloned()
}
pub fn directory(&self) -> Option<gio::File> {
self.imp().directory.get().cloned()
}