mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
emit tasks for columns
This commit is contained in:
parent
e16e8131aa
commit
59c2fdcbcd
6 changed files with 79 additions and 55 deletions
|
|
@ -44,7 +44,7 @@ impl Handle<TuiIn> for Taggart {
|
||||||
press!(Left) => { self.column = self.column.saturating_sub(1); },
|
press!(Left) => { self.column = self.column.saturating_sub(1); },
|
||||||
press!(Right) => { self.column = self.column + 1; },
|
press!(Right) => { self.column = self.column + 1; },
|
||||||
press!(Enter) => { self.edit_begin() },
|
press!(Enter) => { self.edit_begin() },
|
||||||
press!(Char(' ')) => { open(&self.entries[self.cursor].path)?; }
|
press!(Char(' ')) => { open(self.entries[self.cursor].path.as_ref())?; }
|
||||||
press!(Char(']')) => { self.columns.0[self.column].width += 1; }
|
press!(Char(']')) => { self.columns.0[self.column].width += 1; }
|
||||||
press!(Char('[')) => { self.columns.0[self.column].width =
|
press!(Char('[')) => { self.columns.0[self.column].width =
|
||||||
self.columns.0[self.column].width.saturating_sub(1).max(5); }
|
self.columns.0[self.column].width.saturating_sub(1).max(5); }
|
||||||
|
|
|
||||||
23
src/model.rs
23
src/model.rs
|
|
@ -48,26 +48,3 @@ impl Taggart {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn entries_under (
|
|
||||||
entries: &mut [Entry], index: usize
|
|
||||||
) -> Option<Vec<Arc<RwLock<Metadata>>>> {
|
|
||||||
let path = if let Some(Entry { path, info, .. }) = entries.get(index)
|
|
||||||
&& let Metadata::Directory { .. } = &*info.read().unwrap()
|
|
||||||
{
|
|
||||||
Some(path.clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
if let Some(path) = path {
|
|
||||||
let mut others = vec![];
|
|
||||||
for other in entries.iter_mut() {
|
|
||||||
if other.path.starts_with(&path) && !other.is_directory() {
|
|
||||||
others.push(other.info.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(others)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,14 @@ macro_rules! setter {
|
||||||
value: &str
|
value: &str
|
||||||
) {
|
) {
|
||||||
if let Some(entries) = entries_under(&mut state.entries, index) {
|
if let Some(entries) = entries_under(&mut state.entries, index) {
|
||||||
for entry in entries.iter() {
|
for (path, entry) in entries.into_iter() {
|
||||||
if let Some(task) = entry.write().unwrap().$name(&value) {
|
if let Some(item) = entry.write().unwrap().$name(&value) {
|
||||||
state.tasks.push(task);
|
state.tasks.push(Task { path, item, });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else if let Some(entry) = state.entries.get_mut(index) {
|
} else if let Some(entry) = state.entries.get_mut(index) {
|
||||||
if let Some(task) = entry.$name(&value) {
|
if let Some(item) = entry.$name(&value) {
|
||||||
state.tasks.push(task);
|
state.tasks.push(Task { path: entry.path.clone(), item, });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,8 +53,37 @@ macro_rules! setter {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn entries_under (
|
||||||
|
entries: &mut [Entry],
|
||||||
|
index: usize
|
||||||
|
) -> Option<Vec<(Arc<PathBuf>, Arc<RwLock<Metadata>>)>> {
|
||||||
|
let path = if let Some(Entry { path, info, .. }) = entries.get(index)
|
||||||
|
&& let Metadata::Directory { .. } = &*info.read().unwrap()
|
||||||
|
{
|
||||||
|
Some(path.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
if let Some(path) = path {
|
||||||
|
let mut others = vec![];
|
||||||
|
for other in entries.iter_mut() {
|
||||||
|
if other.path.starts_with(path.as_ref()) && !other.is_directory() {
|
||||||
|
others.push((other.path.clone(), other.info.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(others)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Columns<G, S>(pub Vec<Column<G, S>>);
|
pub struct Columns<G, S>(pub Vec<Column<G, S>>);
|
||||||
|
|
||||||
|
impl<G, S> Columns<G, S> {
|
||||||
|
const SCROLL_LEFT: &'static str = "❮";
|
||||||
|
const SCROLL_RIGHT: &'static str = "❯";
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Columns<fn(&Entry)->Option<Arc<str>>, fn(&mut Taggart, usize, &str)> {
|
impl Default for Columns<fn(&Entry)->Option<Arc<str>>, fn(&mut Taggart, usize, &str)> {
|
||||||
fn default () -> Self {
|
fn default () -> Self {
|
||||||
Self(vec![
|
Self(vec![
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use std::cmp::{Eq, PartialEq, Ord, PartialOrd, Ordering};
|
use std::cmp::{Eq, PartialEq, Ord, PartialOrd, Ordering};
|
||||||
|
use lofty::tag::TagItem;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Entry {
|
pub struct Entry {
|
||||||
pub path: PathBuf,
|
/// How many levels deep is this from the working directory
|
||||||
pub depth: usize,
|
pub depth: usize,
|
||||||
pub info: Arc<RwLock<Metadata>>,
|
/// Full path to this entry
|
||||||
|
pub path: Arc<PathBuf>,
|
||||||
|
/// Type-specific metadata
|
||||||
|
pub info: Arc<RwLock<Metadata>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entry {
|
impl Entry {
|
||||||
|
|
@ -22,7 +26,7 @@ impl Entry {
|
||||||
fn new_dir (_: &impl AsRef<Path>, path: &Path, depth: usize) -> Perhaps<Self> {
|
fn new_dir (_: &impl AsRef<Path>, path: &Path, depth: usize) -> Perhaps<Self> {
|
||||||
Ok(Some(Self {
|
Ok(Some(Self {
|
||||||
depth,
|
depth,
|
||||||
path: path.into(),
|
path: path.to_path_buf().into(),
|
||||||
info: Arc::new(RwLock::new(Metadata::Directory {
|
info: Arc::new(RwLock::new(Metadata::Directory {
|
||||||
hash_file: None,
|
hash_file: None,
|
||||||
catalog_file: None,
|
catalog_file: None,
|
||||||
|
|
@ -34,8 +38,8 @@ impl Entry {
|
||||||
fn new_file (_: &impl AsRef<Path>, path: &Path, depth: usize) -> Perhaps<Self> {
|
fn new_file (_: &impl AsRef<Path>, path: &Path, depth: usize) -> Perhaps<Self> {
|
||||||
Ok(Some(Self {
|
Ok(Some(Self {
|
||||||
depth,
|
depth,
|
||||||
|
path: path.to_path_buf().into(),
|
||||||
info: Arc::new(RwLock::new(Metadata::new(path)?)),
|
info: Arc::new(RwLock::new(Metadata::new(path)?)),
|
||||||
path: path.into(),
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
pub fn is_directory (&self) -> bool {
|
pub fn is_directory (&self) -> bool {
|
||||||
|
|
@ -68,19 +72,19 @@ impl Entry {
|
||||||
pub fn track (&self) -> Option<Arc<str>> {
|
pub fn track (&self) -> Option<Arc<str>> {
|
||||||
self.info.read().unwrap().track()
|
self.info.read().unwrap().track()
|
||||||
}
|
}
|
||||||
pub fn set_artist (&self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_artist (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
self.info.write().unwrap().set_artist(value)
|
self.info.write().unwrap().set_artist(value)
|
||||||
}
|
}
|
||||||
pub fn set_year (&self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_year (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
self.info.write().unwrap().set_year(value)
|
self.info.write().unwrap().set_year(value)
|
||||||
}
|
}
|
||||||
pub fn set_album (&self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_album (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
self.info.write().unwrap().set_album(value)
|
self.info.write().unwrap().set_album(value)
|
||||||
}
|
}
|
||||||
pub fn set_title (&self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_title (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
self.info.write().unwrap().set_title(value)
|
self.info.write().unwrap().set_title(value)
|
||||||
}
|
}
|
||||||
pub fn set_track (&self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_track (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
self.info.write().unwrap().set_track(value)
|
self.info.write().unwrap().set_track(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
use lofty::{file::TaggedFileExt, probe::Probe, tag::Accessor};
|
|
||||||
use byte_unit::{Byte, Unit::MB};
|
use byte_unit::{Byte, Unit::MB};
|
||||||
|
use lofty::{file::TaggedFileExt, probe::Probe, tag::{Accessor, TagItem, ItemKey, ItemValue}};
|
||||||
|
|
||||||
#[derive(Ord, Eq, PartialEq, PartialOrd, Debug)]
|
#[derive(Ord, Eq, PartialEq, PartialOrd, Debug)]
|
||||||
pub enum Metadata {
|
pub enum Metadata {
|
||||||
|
|
@ -159,56 +159,70 @@ impl Metadata {
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_artist (&mut self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_artist (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
match self {
|
match self {
|
||||||
Metadata::Music { artist, .. } => {
|
Metadata::Music { artist, .. } => {
|
||||||
*artist = Some(value.as_ref().into());
|
if artist.as_deref() != Some(value.as_ref()) {
|
||||||
|
*artist = Some(value.as_ref().into());
|
||||||
|
Some(TagItem::new(
|
||||||
|
ItemKey::TrackArtist,
|
||||||
|
ItemValue::Text(value.as_ref().into())
|
||||||
|
));
|
||||||
|
}
|
||||||
//todo!("emit task");
|
//todo!("emit task");
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_year (&mut self, value: &impl AsRef<str> ) -> Option<Task> {
|
pub fn set_year (&mut self, value: &impl AsRef<str> ) -> Option<TagItem> {
|
||||||
match self {
|
match self {
|
||||||
Metadata::Music { year, .. } => {
|
Metadata::Music { year, .. } => {
|
||||||
if let Ok(value) = value.as_ref().trim().parse::<u32>() {
|
if let Ok(value) = value.as_ref().trim().parse::<u32>() {
|
||||||
*year = Some(value);
|
*year = Some(value);
|
||||||
}
|
}
|
||||||
//todo!("emit task");
|
Some(TagItem::new(
|
||||||
None
|
ItemKey::Year,
|
||||||
|
ItemValue::Text(value.as_ref().into())
|
||||||
|
))
|
||||||
},
|
},
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_album (&mut self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_album (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
match self {
|
match self {
|
||||||
Metadata::Music { album, .. } => {
|
Metadata::Music { album, .. } => {
|
||||||
*album = Some(value.as_ref().into());
|
*album = Some(value.as_ref().into());
|
||||||
//todo!("emit task");
|
Some(TagItem::new(
|
||||||
None
|
ItemKey::AlbumTitle,
|
||||||
|
ItemValue::Text(value.as_ref().into())
|
||||||
|
))
|
||||||
},
|
},
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_title (&mut self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_title (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
match self {
|
match self {
|
||||||
Metadata::Music { title, .. } => {
|
Metadata::Music { title, .. } => {
|
||||||
*title = Some(value.as_ref().into());
|
*title = Some(value.as_ref().into());
|
||||||
//todo!("emit task");
|
Some(TagItem::new(
|
||||||
None
|
ItemKey::TrackTitle,
|
||||||
|
ItemValue::Text(value.as_ref().into())
|
||||||
|
))
|
||||||
},
|
},
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_track (&mut self, value: &impl AsRef<str>) -> Option<Task> {
|
pub fn set_track (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
match self {
|
match self {
|
||||||
Metadata::Music { track, .. } => {
|
Metadata::Music { track, .. } => {
|
||||||
if let Ok(value) = value.as_ref().trim().parse::<u32>() {
|
if let Ok(value) = value.as_ref().trim().parse::<u32>() {
|
||||||
*track = Some(value);
|
*track = Some(value);
|
||||||
}
|
}
|
||||||
//todo!("emit task");
|
Some(TagItem::new(
|
||||||
None
|
ItemKey::TrackNumber,
|
||||||
|
ItemValue::Text(value.as_ref().into())
|
||||||
|
))
|
||||||
},
|
},
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@ use lofty::tag::TagItem;
|
||||||
|
|
||||||
/// An update to a file's metadata to be performed.
|
/// An update to a file's metadata to be performed.
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
pub path: PathBuf,
|
pub path: Arc<PathBuf>,
|
||||||
pub item: TagItem
|
pub item: TagItem
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
fn new (path: &impl AsRef<Path>, item: TagItem) -> Self {
|
fn new (path: &impl AsRef<Path>, item: TagItem) -> Self {
|
||||||
Self {
|
Self {
|
||||||
path: path.as_ref().into(),
|
path: path.as_ref().to_path_buf().into(),
|
||||||
item
|
item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue