use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute, ptr};
glib::wrapper! {
#[doc(alias = "DzlShortcutContext")]
pub struct ShortcutContext(Object<ffi::DzlShortcutContext, ffi::DzlShortcutContextClass>);
match fn {
type_ => || ffi::dzl_shortcut_context_get_type(),
}
}
impl ShortcutContext {
#[doc(alias = "dzl_shortcut_context_new")]
pub fn new(name: &str) -> ShortcutContext {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::dzl_shortcut_context_new(name.to_glib_none().0)) }
}
#[doc(alias = "dzl_shortcut_context_add_action")]
pub fn add_action(&self, accel: &str, detailed_action_name: &str) {
unsafe {
ffi::dzl_shortcut_context_add_action(
self.to_glib_none().0,
accel.to_glib_none().0,
detailed_action_name.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_context_add_command")]
pub fn add_command(&self, accel: &str, command: &str) {
unsafe {
ffi::dzl_shortcut_context_add_command(
self.to_glib_none().0,
accel.to_glib_none().0,
command.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_context_get_name")]
#[doc(alias = "get_name")]
pub fn name(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::dzl_shortcut_context_get_name(self.to_glib_none().0)) }
}
#[doc(alias = "dzl_shortcut_context_load_from_data")]
pub fn load_from_data(&self, data: &str) -> Result<(), glib::Error> {
let len = data.len() as _;
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::dzl_shortcut_context_load_from_data(
self.to_glib_none().0,
data.to_glib_none().0,
len,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "dzl_shortcut_context_load_from_resource")]
pub fn load_from_resource(&self, resource_path: &str) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::dzl_shortcut_context_load_from_resource(
self.to_glib_none().0,
resource_path.to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "dzl_shortcut_context_remove")]
pub fn remove(&self, accel: &str) -> bool {
unsafe {
from_glib(ffi::dzl_shortcut_context_remove(
self.to_glib_none().0,
accel.to_glib_none().0,
))
}
}
#[doc(alias = "use-binding-sets")]
pub fn uses_binding_sets(&self) -> bool {
ObjectExt::property(self, "use-binding-sets")
}
#[doc(alias = "use-binding-sets")]
pub fn set_use_binding_sets(&self, use_binding_sets: bool) {
ObjectExt::set_property(self, "use-binding-sets", use_binding_sets)
}
#[doc(alias = "use-binding-sets")]
pub fn connect_use_binding_sets_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_use_binding_sets_trampoline<
F: Fn(&ShortcutContext) + 'static,
>(
this: *mut ffi::DzlShortcutContext,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::use-binding-sets\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_use_binding_sets_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for ShortcutContext {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("ShortcutContext")
}
}