diff --git a/src/library.rs b/src/library.rs index 3c9df33..a9170ce 100644 --- a/src/library.rs +++ b/src/library.rs @@ -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 { 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 { 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 { 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 { Ok(Self { diff --git a/src/search_entry.rs b/src/search_entry.rs index fead481..df0dc50 100644 --- a/src/search_entry.rs +++ b/src/search_entry.rs @@ -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", &[]); diff --git a/src/search_tag.rs b/src/search_tag.rs index c81a676..69aa7fa 100644 --- a/src/search_tag.rs +++ b/src/search_tag.rs @@ -65,6 +65,14 @@ impl MusicusSearchTag { obj } + pub fn connect_remove(&self, f: F) -> glib::SignalHandlerId { + self.connect_local("remove", true, move |values| { + let obj = values[0].get::().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),