mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Allow removing tags via the button
This commit is contained in:
parent
af57fe020c
commit
a790d913af
3 changed files with 50 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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", &[]);
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue