account-switcher: Make sure to unparent the popover when the button is disposed of

Avoids a warning that occurs sometimes when closing Fractal.
This commit is contained in:
Kévin Commaille 2025-05-13 11:45:32 +02:00
parent 4a5a4b4cde
commit ca387e3261
No known key found for this signature in database
GPG Key ID: F26F4BE20A08255B

View File

@ -43,7 +43,11 @@ mod imp {
}
#[glib::derived_properties]
impl ObjectImpl for AccountSwitcherButton {}
impl ObjectImpl for AccountSwitcherButton {
fn dispose(&self) {
self.reset();
}
}
impl WidgetImpl for AccountSwitcherButton {}
impl ButtonImpl for AccountSwitcherButton {}
@ -53,19 +57,13 @@ mod imp {
impl AccountSwitcherButton {
/// Set the popover of this button.
fn set_popover(&self, popover: Option<&AccountSwitcherPopover>) {
let old_popover = self.popover.obj();
if old_popover.as_ref() == popover {
if self.popover.obj().as_ref() == popover {
return;
}
let obj = self.obj();
// Reset the state.
if let Some(popover) = old_popover {
popover.unparent();
}
self.popover.disconnect_signals();
obj.set_active(false);
self.reset();
let obj = self.obj();
if let Some(popover) = popover {
// We need to remove the popover from the previous button, if any.
@ -109,6 +107,15 @@ mod imp {
popover.popdown();
}
}
/// Reset the state of this button.
fn reset(&self) {
if let Some(popover) = self.popover.obj() {
popover.unparent();
}
self.popover.disconnect_signals();
self.obj().set_active(false);
}
}
}