mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-08 18:46:43 +01:00
refactor; EntryInfo -> Metadata
This commit is contained in:
parent
95aa9f8b02
commit
cf18e32e13
5 changed files with 384 additions and 351 deletions
89
src/model/column.rs
Normal file
89
src/model/column.rs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct Columns<T, G, S>(pub Vec<Column<T, G, S>>);
|
||||
|
||||
pub struct Column<T, G, S> {
|
||||
__: std::marker::PhantomData<T>,
|
||||
pub title: Arc<str>,
|
||||
pub width: usize,
|
||||
pub getter: G,
|
||||
pub setter: Option<S>,
|
||||
}
|
||||
|
||||
impl<T> Column<T, fn(&T)->Option<Arc<str>>, fn(&mut [T], usize, &str)> {
|
||||
pub fn new (
|
||||
title: &impl AsRef<str>,
|
||||
width: usize,
|
||||
getter: fn(&T)->Option<Arc<str>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
width,
|
||||
title: title.as_ref().into(),
|
||||
getter,
|
||||
setter: None,
|
||||
__: Default::default(),
|
||||
}
|
||||
}
|
||||
fn setter (mut self, setter: fn(&mut [T], usize, &str)) -> Self {
|
||||
self.setter = Some(setter);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Columns<Entry, fn(&Entry)->Option<Arc<str>>, fn(&mut [Entry], usize, &str)> {
|
||||
fn default () -> Self {
|
||||
Self(vec![
|
||||
|
||||
Column::new(&"HASH", 16, |entry: &Entry|entry.hash()),
|
||||
|
||||
Column::new(&"SIZE", 8, |entry: &Entry|entry.size()),
|
||||
|
||||
Column::new(&"FILE", 80, |entry: &Entry|entry.name()),
|
||||
|
||||
Column::new(&"ARTIST", 30, |entry: &Entry|entry.artist())
|
||||
.setter(|entries: &mut [Entry], index: usize, value: &str|{
|
||||
if let Some(entries) = paths_under(entries, index) {
|
||||
for entry in entries.iter() {
|
||||
entry.write().unwrap().set_artist(&value);
|
||||
}
|
||||
} else if let Some(entry) = entries.get_mut(index) {
|
||||
entry.set_artist(&value)
|
||||
}
|
||||
}),
|
||||
|
||||
Column::new(&"RELEASE", 30, |entry: &Entry|entry.album())
|
||||
.setter(|entries: &mut [Entry], index: usize, value: &str|{
|
||||
if let Some(entries) = paths_under(entries, index) {
|
||||
for entry in entries.iter() {
|
||||
entry.write().unwrap().set_album(&value);
|
||||
}
|
||||
} else if let Some(entry) = entries.get_mut(index) {
|
||||
entry.set_album(&value)
|
||||
}
|
||||
}),
|
||||
|
||||
Column::new(&"TRACK", 5, |entry: &Entry|entry.track())
|
||||
.setter(|entries: &mut [Entry], index: usize, value: &str|{
|
||||
if let Some(entries) = paths_under(entries, index) {
|
||||
for entry in entries.iter() {
|
||||
entry.write().unwrap().set_track(&value);
|
||||
}
|
||||
} else if let Some(entry) = entries.get_mut(index) {
|
||||
entry.set_track(&value)
|
||||
}
|
||||
}),
|
||||
|
||||
Column::new(&"TITLE", 80, |entry: &Entry|entry.title())
|
||||
.setter(|entries: &mut [Entry], index: usize, value: &str|{
|
||||
if let Some(entries) = paths_under(entries, index) {
|
||||
for entry in entries.iter() {
|
||||
entry.write().unwrap().set_title(&value);
|
||||
}
|
||||
} else if let Some(entry) = entries.get_mut(index) {
|
||||
entry.set_title(&value)
|
||||
}
|
||||
}),
|
||||
|
||||
])
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue