Allow removing tags via the button

This commit is contained in:
Elias Projahn 2023-10-08 15:25:00 +02:00
parent af57fe020c
commit a790d913af
3 changed files with 50 additions and 5 deletions

View file

@ -291,13 +291,19 @@ impl LibraryResults {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq)]
pub struct Person {
pub id: String,
pub first_name: String,
pub last_name: String,
}
impl PartialEq for Person {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Person {
pub fn from_row(row: &Row) -> rusqlite::Result<Self> {
Ok(Self {
@ -312,12 +318,18 @@ impl Person {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq)]
pub struct Ensemble {
pub id: String,
pub name: String,
}
impl PartialEq for Ensemble {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Ensemble {
pub fn from_row(row: &Row) -> rusqlite::Result<Self> {
Ok(Self {
@ -327,13 +339,19 @@ impl Ensemble {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq)]
pub struct Work {
pub id: String,
pub title: String,
pub composer: Person,
}
impl PartialEq for Work {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Work {
pub fn from_row(row: &Row) -> rusqlite::Result<Self> {
Ok(Self {
@ -348,12 +366,18 @@ impl Work {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq)]
pub struct Recording {
pub id: String,
pub work: Work,
}
impl PartialEq for Recording {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Recording {
pub fn from_row(row: &Row) -> rusqlite::Result<Self> {
Ok(Self {

View file

@ -147,6 +147,19 @@ impl MusicusSearchEntry {
pub fn add_tag(&self, tag: Tag) {
self.imp().text.set_text("");
let tag = MusicusSearchTag::new(tag);
tag.connect_remove(clone!(@weak self as self_ => move |tag| {
let imp = self_.imp();
imp.tags_box.remove(tag);
{
imp.tags.borrow_mut().retain(|t| t.tag() != tag.tag());
}
self_.emit_by_name::<()>("query-changed", &[]);
}));
self.imp().tags_box.append(&tag);
self.imp().tags.borrow_mut().push(tag);
self.emit_by_name::<()>("query-changed", &[]);

View file

@ -65,6 +65,14 @@ impl MusicusSearchTag {
obj
}
pub fn connect_remove<F: Fn(&Self) + 'static>(&self, f: F) -> glib::SignalHandlerId {
self.connect_local("remove", true, move |values| {
let obj = values[0].get::<Self>().unwrap();
f(&obj);
None
})
}
pub fn tag(&self) -> &Tag {
self.imp().tag.get().unwrap()
}
@ -75,7 +83,7 @@ impl MusicusSearchTag {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Tag {
Composer(Person),
Performer(Person),