mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-07 10:06:44 +01:00
implement setters
This commit is contained in:
parent
7c4451e46f
commit
f9885713cc
2 changed files with 42 additions and 6 deletions
28
src/model.rs
28
src/model.rs
|
|
@ -128,24 +128,52 @@ impl Entry {
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn set_artist (&mut self, value: &impl AsRef<str> ) {
|
||||||
|
match self.info {
|
||||||
|
EntryInfo::Music { ref mut artist, .. } => *artist = Some(value.as_ref().into()),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn album (&self) -> Option<Arc<str>> {
|
pub fn album (&self) -> Option<Arc<str>> {
|
||||||
match self.info {
|
match self.info {
|
||||||
EntryInfo::Music { ref album, .. } => album.clone(),
|
EntryInfo::Music { ref album, .. } => album.clone(),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn set_album (&mut self, value: &impl AsRef<str> ) {
|
||||||
|
match self.info {
|
||||||
|
EntryInfo::Music { ref mut album, .. } => *album = Some(value.as_ref().into()),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn title (&self) -> Option<Arc<str>> {
|
pub fn title (&self) -> Option<Arc<str>> {
|
||||||
match self.info {
|
match self.info {
|
||||||
EntryInfo::Music { ref title, .. } => title.clone(),
|
EntryInfo::Music { ref title, .. } => title.clone(),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn set_title (&mut self, value: &impl AsRef<str> ) {
|
||||||
|
match self.info {
|
||||||
|
EntryInfo::Music { ref mut title, .. } => *title = Some(value.as_ref().into()),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn track (&self) -> Option<Arc<str>> {
|
pub fn track (&self) -> Option<Arc<str>> {
|
||||||
match self.info {
|
match self.info {
|
||||||
EntryInfo::Music { ref track, .. } => track.map(|t|format!("{t}").into()).clone(),
|
EntryInfo::Music { ref track, .. } => track.map(|t|format!("{t}").into()).clone(),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn set_track (&mut self, value: &impl AsRef<str> ) {
|
||||||
|
match self.info {
|
||||||
|
EntryInfo::Music { ref mut track, .. } => {
|
||||||
|
if let Ok(value) = value.as_ref().trim().parse::<u32>() {
|
||||||
|
*track = Some(value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl EntryInfo {
|
impl EntryInfo {
|
||||||
pub fn new (path: &Path) -> Usually<Self> {
|
pub fn new (path: &Path) -> Usually<Self> {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ pub struct Column<T> {
|
||||||
pub title: Arc<str>,
|
pub title: Arc<str>,
|
||||||
pub width: usize,
|
pub width: usize,
|
||||||
pub getter: fn(&T)->Option<Arc<str>>,
|
pub getter: fn(&T)->Option<Arc<str>>,
|
||||||
pub setter: Option<fn(&T)->Option<Arc<str>>>,
|
pub setter: Option<fn(&mut T, &str)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Column<T> {
|
impl<T> Column<T> {
|
||||||
|
|
@ -84,7 +84,7 @@ impl<T> Column<T> {
|
||||||
title: &impl AsRef<str>,
|
title: &impl AsRef<str>,
|
||||||
width: usize,
|
width: usize,
|
||||||
getter: fn(&T)->Option<Arc<str>>,
|
getter: fn(&T)->Option<Arc<str>>,
|
||||||
setter: Option<fn(&T)->Option<Arc<str>>>,
|
setter: Option<fn(&mut T, &str)>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
width,
|
width,
|
||||||
|
|
@ -102,10 +102,18 @@ impl Default for Columns<Entry> {
|
||||||
Self(vec![
|
Self(vec![
|
||||||
Column::new(&"HASH", 16, |entry: &Entry|entry.hash(), None),
|
Column::new(&"HASH", 16, |entry: &Entry|entry.hash(), None),
|
||||||
Column::new(&"FILE", 80, |entry: &Entry|entry.name(), None),
|
Column::new(&"FILE", 80, |entry: &Entry|entry.name(), None),
|
||||||
Column::new(&"ARTIST", 30, |entry: &Entry|entry.artist(), None),
|
Column::new(&"ARTIST", 30,
|
||||||
Column::new(&"RELEASE", 30, |entry: &Entry|entry.album(), None),
|
|entry: &Entry|entry.artist(),
|
||||||
Column::new(&"TRACK", 5, |entry: &Entry|entry.track(), None),
|
Some(|entry: &mut Entry, value: &str|entry.set_artist(&value))),
|
||||||
Column::new(&"TITLE", 80, |entry: &Entry|entry.title(), None),
|
Column::new(&"RELEASE", 30,
|
||||||
|
|entry: &Entry|entry.album(),
|
||||||
|
Some(|entry: &mut Entry, value: &str|entry.set_album(&value))),
|
||||||
|
Column::new(&"TRACK", 5,
|
||||||
|
|entry: &Entry|entry.track(),
|
||||||
|
Some(|entry: &mut Entry, value: &str|entry.set_track(&value))),
|
||||||
|
Column::new(&"TITLE", 80,
|
||||||
|
|entry: &Entry|entry.title(),
|
||||||
|
Some(|entry: &mut Entry, value: &str|entry.set_title(&value))),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue