[fractal/fractal-next] components: Fix ContextMenuBin
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] components: Fix ContextMenuBin
- Date: Mon, 31 May 2021 16:18:15 +0000 (UTC)
commit f0dfbdb46882508e8d0d400afc3257b72bf31afa
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Sat May 29 14:28:53 2021 +0200
components: Fix ContextMenuBin
src/components/context_menu_bin.rs | 40 ++++++++++++++++++++++++--------------
src/components/mod.rs | 2 +-
2 files changed, 26 insertions(+), 16 deletions(-)
---
diff --git a/src/components/context_menu_bin.rs b/src/components/context_menu_bin.rs
index 420e8d08..f5e1bc0a 100644
--- a/src/components/context_menu_bin.rs
+++ b/src/components/context_menu_bin.rs
@@ -140,22 +140,12 @@ glib::wrapper! {
@extends gtk::Widget, adw::Bin, @implements gtk::Accessible;
}
-/// A Bin widget that adds a conext menu
+/// A Bin widget that adds a context menu
impl ContextMenuBin {
pub fn new() -> Self {
glib::Object::new(&[]).expect("Failed to create ContextMenuBin")
}
- pub fn set_context_menu(&self, menu: Option<gio::MenuModel>) {
- let priv_ = imp::ContextMenuBin::from_instance(self);
- priv_.popover.set_menu_model(menu.as_ref());
- }
-
- pub fn context_menu(&self) -> Option<gio::MenuModel> {
- let priv_ = imp::ContextMenuBin::from_instance(self);
- priv_.popover.menu_model()
- }
-
fn open_menu_at(&self, x: i32, y: i32) {
let priv_ = imp::ContextMenuBin::from_instance(self);
let popover = &priv_.popover;
@@ -176,13 +166,33 @@ impl ContextMenuBin {
}
}
+pub trait ContextMenuBinExt: 'static {
+ /// Set the `MenuModel` used in the context menu.
+ fn set_context_menu(&self, menu: Option<gio::MenuModel>);
+
+ /// Get the `MenuModel` used in the context menu.
+ fn context_menu(&self) -> Option<gio::MenuModel>;
+}
+
+impl<O: IsA<ContextMenuBin>> ContextMenuBinExt for O {
+ fn set_context_menu(&self, menu: Option<gio::MenuModel>) {
+ let priv_ = imp::ContextMenuBin::from_instance(self.upcast_ref());
+ priv_.popover.set_menu_model(menu.as_ref());
+ }
+
+ fn context_menu(&self) -> Option<gio::MenuModel> {
+ let priv_ = imp::ContextMenuBin::from_instance(self.upcast_ref());
+ priv_.popover.menu_model()
+ }
+}
+
+pub trait ContextMenuBinImpl: BinImpl {}
+
unsafe impl<T: ContextMenuBinImpl> IsSubclassable<T> for ContextMenuBin {
fn class_init(class: &mut glib::Class<Self>) {
- <glib::Object as IsSubclassable<T>>::class_init(class);
+ <gtk::Widget as IsSubclassable<T>>::class_init(class);
}
fn instance_init(instance: &mut glib::subclass::InitializingObject<T>) {
- <glib::Object as IsSubclassable<T>>::instance_init(instance);
+ <gtk::Widget as IsSubclassable<T>>::instance_init(instance);
}
}
-
-pub trait ContextMenuBinImpl: BinImpl {}
diff --git a/src/components/mod.rs b/src/components/mod.rs
index 158f2a50..bf600ffe 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -4,7 +4,7 @@ mod label_with_widgets;
mod pill;
mod spinner_button;
-pub use self::context_menu_bin::{ContextMenuBin, ContextMenuBinImpl};
+pub use self::context_menu_bin::{ContextMenuBin, ContextMenuBinExt, ContextMenuBinImpl};
pub use self::in_app_notification::InAppNotification;
pub use self::label_with_widgets::LabelWithWidgets;
pub use self::pill::Pill;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]