use crate::{ShortcutContext, ShortcutPhase};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute, ptr};
glib::wrapper! {
#[doc(alias = "DzlShortcutTheme")]
pub struct ShortcutTheme(Object<ffi::DzlShortcutTheme, ffi::DzlShortcutThemeClass>);
match fn {
type_ => || ffi::dzl_shortcut_theme_get_type(),
}
}
impl ShortcutTheme {
pub const NONE: Option<&'static ShortcutTheme> = None;
#[doc(alias = "dzl_shortcut_theme_new")]
pub fn new(name: &str) -> ShortcutTheme {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::dzl_shortcut_theme_new(name.to_glib_none().0)) }
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::ShortcutTheme>> Sealed for T {}
}
pub trait ShortcutThemeExt: IsA<ShortcutTheme> + sealed::Sealed + 'static {
#[doc(alias = "dzl_shortcut_theme_add_command")]
fn add_command(&self, accelerator: &str, command: &str) {
unsafe {
ffi::dzl_shortcut_theme_add_command(
self.as_ref().to_glib_none().0,
accelerator.to_glib_none().0,
command.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_theme_add_context")]
fn add_context(&self, context: &ShortcutContext) {
unsafe {
ffi::dzl_shortcut_theme_add_context(
self.as_ref().to_glib_none().0,
context.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_theme_add_css_resource")]
fn add_css_resource(&self, path: &str) {
unsafe {
ffi::dzl_shortcut_theme_add_css_resource(
self.as_ref().to_glib_none().0,
path.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_theme_find_context_by_name")]
fn find_context_by_name(&self, name: &str) -> Option<ShortcutContext> {
unsafe {
from_glib_none(ffi::dzl_shortcut_theme_find_context_by_name(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_theme_find_default_context")]
fn find_default_context(&self, widget: &impl IsA<gtk::Widget>) -> Option<ShortcutContext> {
unsafe {
from_glib_none(ffi::dzl_shortcut_theme_find_default_context(
self.as_ref().to_glib_none().0,
widget.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_theme_get_name")]
#[doc(alias = "get_name")]
fn name(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::dzl_shortcut_theme_get_name(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_theme_get_parent")]
#[doc(alias = "get_parent")]
#[must_use]
fn parent(&self) -> Option<ShortcutTheme> {
unsafe {
from_glib_none(ffi::dzl_shortcut_theme_get_parent(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_theme_get_parent_name")]
#[doc(alias = "get_parent_name")]
fn parent_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::dzl_shortcut_theme_get_parent_name(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_theme_get_subtitle")]
#[doc(alias = "get_subtitle")]
fn subtitle(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::dzl_shortcut_theme_get_subtitle(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_theme_get_title")]
#[doc(alias = "get_title")]
fn title(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::dzl_shortcut_theme_get_title(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_theme_load_from_data")]
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_theme_load_from_data(
self.as_ref().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_theme_load_from_file")]
fn load_from_file(
&self,
file: &impl IsA<gio::File>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::dzl_shortcut_theme_load_from_file(
self.as_ref().to_glib_none().0,
file.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).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_theme_load_from_path")]
fn load_from_path(
&self,
path: &str,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::dzl_shortcut_theme_load_from_path(
self.as_ref().to_glib_none().0,
path.to_glib_none().0,
cancellable.map(|p| p.as_ref()).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_theme_remove_css_resource")]
fn remove_css_resource(&self, path: &str) {
unsafe {
ffi::dzl_shortcut_theme_remove_css_resource(
self.as_ref().to_glib_none().0,
path.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_theme_save_to_file")]
fn save_to_file(
&self,
file: &impl IsA<gio::File>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::dzl_shortcut_theme_save_to_file(
self.as_ref().to_glib_none().0,
file.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).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_theme_save_to_path")]
fn save_to_path(
&self,
path: &str,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::dzl_shortcut_theme_save_to_path(
self.as_ref().to_glib_none().0,
path.to_glib_none().0,
cancellable.map(|p| p.as_ref()).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_theme_save_to_stream")]
fn save_to_stream(
&self,
stream: &impl IsA<gio::OutputStream>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::dzl_shortcut_theme_save_to_stream(
self.as_ref().to_glib_none().0,
stream.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).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_theme_set_accel_for_action")]
fn set_accel_for_action(&self, detailed_action_name: &str, accel: &str, phase: ShortcutPhase) {
unsafe {
ffi::dzl_shortcut_theme_set_accel_for_action(
self.as_ref().to_glib_none().0,
detailed_action_name.to_glib_none().0,
accel.to_glib_none().0,
phase.into_glib(),
);
}
}
#[doc(alias = "dzl_shortcut_theme_set_accel_for_command")]
fn set_accel_for_command(
&self,
command: Option<&str>,
accel: Option<&str>,
phase: ShortcutPhase,
) {
unsafe {
ffi::dzl_shortcut_theme_set_accel_for_command(
self.as_ref().to_glib_none().0,
command.to_glib_none().0,
accel.to_glib_none().0,
phase.into_glib(),
);
}
}
#[doc(alias = "dzl_shortcut_theme_set_parent_name")]
fn set_parent_name(&self, parent_name: &str) {
unsafe {
ffi::dzl_shortcut_theme_set_parent_name(
self.as_ref().to_glib_none().0,
parent_name.to_glib_none().0,
);
}
}
fn set_subtitle(&self, subtitle: Option<&str>) {
ObjectExt::set_property(self.as_ref(), "subtitle", subtitle)
}
fn set_title(&self, title: Option<&str>) {
ObjectExt::set_property(self.as_ref(), "title", title)
}
#[doc(alias = "parent-name")]
fn connect_parent_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_parent_name_trampoline<
P: IsA<ShortcutTheme>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::DzlShortcutTheme,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ShortcutTheme::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::parent-name\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_parent_name_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "subtitle")]
fn connect_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_subtitle_trampoline<
P: IsA<ShortcutTheme>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::DzlShortcutTheme,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ShortcutTheme::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::subtitle\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_subtitle_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "title")]
fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_title_trampoline<P: IsA<ShortcutTheme>, F: Fn(&P) + 'static>(
this: *mut ffi::DzlShortcutTheme,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ShortcutTheme::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::title\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_title_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<ShortcutTheme>> ShortcutThemeExt for O {}
impl fmt::Display for ShortcutTheme {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("ShortcutTheme")
}
}