use crate::{ShortcutTheme, ShortcutsWindow};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute};
glib::wrapper! {
#[doc(alias = "DzlShortcutManager")]
pub struct ShortcutManager(Object<ffi::DzlShortcutManager, ffi::DzlShortcutManagerClass>) @implements gio::ListModel;
match fn {
type_ => || ffi::dzl_shortcut_manager_get_type(),
}
}
impl ShortcutManager {
pub const NONE: Option<&'static ShortcutManager> = None;
#[doc(alias = "dzl_shortcut_manager_get_default")]
#[doc(alias = "get_default")]
#[allow(clippy::should_implement_trait)]
pub fn default() -> Option<ShortcutManager> {
assert_initialized_main_thread!();
unsafe { from_glib_none(ffi::dzl_shortcut_manager_get_default()) }
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::ShortcutManager>> Sealed for T {}
}
pub trait ShortcutManagerExt: IsA<ShortcutManager> + sealed::Sealed + 'static {
#[doc(alias = "dzl_shortcut_manager_add_action")]
fn add_action(
&self,
detailed_action_name: &str,
section: &str,
group: &str,
title: &str,
subtitle: &str,
) {
unsafe {
ffi::dzl_shortcut_manager_add_action(
self.as_ref().to_glib_none().0,
detailed_action_name.to_glib_none().0,
section.to_glib_none().0,
group.to_glib_none().0,
title.to_glib_none().0,
subtitle.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_add_command")]
fn add_command(&self, command: &str, section: &str, group: &str, title: &str, subtitle: &str) {
unsafe {
ffi::dzl_shortcut_manager_add_command(
self.as_ref().to_glib_none().0,
command.to_glib_none().0,
section.to_glib_none().0,
group.to_glib_none().0,
title.to_glib_none().0,
subtitle.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_add_shortcuts_to_window")]
fn add_shortcuts_to_window(&self, window: &impl IsA<ShortcutsWindow>) {
unsafe {
ffi::dzl_shortcut_manager_add_shortcuts_to_window(
self.as_ref().to_glib_none().0,
window.as_ref().to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_append_search_path")]
fn append_search_path(&self, directory: &str) {
unsafe {
ffi::dzl_shortcut_manager_append_search_path(
self.as_ref().to_glib_none().0,
directory.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_get_theme")]
#[doc(alias = "get_theme")]
fn theme(&self) -> Option<ShortcutTheme> {
unsafe {
from_glib_none(ffi::dzl_shortcut_manager_get_theme(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_manager_get_theme_by_name")]
#[doc(alias = "get_theme_by_name")]
fn theme_by_name(&self, theme_name: Option<&str>) -> Option<ShortcutTheme> {
unsafe {
from_glib_none(ffi::dzl_shortcut_manager_get_theme_by_name(
self.as_ref().to_glib_none().0,
theme_name.to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_manager_get_theme_name")]
#[doc(alias = "get_theme_name")]
fn theme_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::dzl_shortcut_manager_get_theme_name(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_manager_get_user_dir")]
#[doc(alias = "get_user_dir")]
fn user_dir(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::dzl_shortcut_manager_get_user_dir(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_manager_handle_event")]
fn handle_event(&self, event: &gdk::EventKey, toplevel: &impl IsA<gtk::Widget>) -> bool {
unsafe {
from_glib(ffi::dzl_shortcut_manager_handle_event(
self.as_ref().to_glib_none().0,
event.to_glib_none().0,
toplevel.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_shortcut_manager_prepend_search_path")]
fn prepend_search_path(&self, directory: &str) {
unsafe {
ffi::dzl_shortcut_manager_prepend_search_path(
self.as_ref().to_glib_none().0,
directory.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_queue_reload")]
fn queue_reload(&self) {
unsafe {
ffi::dzl_shortcut_manager_queue_reload(self.as_ref().to_glib_none().0);
}
}
#[doc(alias = "dzl_shortcut_manager_reload")]
fn reload(&self, cancellable: Option<&impl IsA<gio::Cancellable>>) {
unsafe {
ffi::dzl_shortcut_manager_reload(
self.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_remove_search_path")]
fn remove_search_path(&self, directory: &str) {
unsafe {
ffi::dzl_shortcut_manager_remove_search_path(
self.as_ref().to_glib_none().0,
directory.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_set_theme")]
fn set_theme(&self, theme: &impl IsA<ShortcutTheme>) {
unsafe {
ffi::dzl_shortcut_manager_set_theme(
self.as_ref().to_glib_none().0,
theme.as_ref().to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_set_theme_name")]
fn set_theme_name(&self, theme_name: &str) {
unsafe {
ffi::dzl_shortcut_manager_set_theme_name(
self.as_ref().to_glib_none().0,
theme_name.to_glib_none().0,
);
}
}
#[doc(alias = "dzl_shortcut_manager_set_user_dir")]
fn set_user_dir(&self, user_dir: &str) {
unsafe {
ffi::dzl_shortcut_manager_set_user_dir(
self.as_ref().to_glib_none().0,
user_dir.to_glib_none().0,
);
}
}
#[doc(alias = "changed")]
fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn changed_trampoline<P: IsA<ShortcutManager>, F: Fn(&P) + 'static>(
this: *mut ffi::DzlShortcutManager,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ShortcutManager::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"changed\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
changed_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "theme")]
fn connect_theme_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_theme_trampoline<
P: IsA<ShortcutManager>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::DzlShortcutManager,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ShortcutManager::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::theme\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_theme_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "theme-name")]
fn connect_theme_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_theme_name_trampoline<
P: IsA<ShortcutManager>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::DzlShortcutManager,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ShortcutManager::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::theme-name\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_theme_name_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "user-dir")]
fn connect_user_dir_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_user_dir_trampoline<
P: IsA<ShortcutManager>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::DzlShortcutManager,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ShortcutManager::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::user-dir\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_user_dir_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<ShortcutManager>> ShortcutManagerExt for O {}
impl fmt::Display for ShortcutManager {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("ShortcutManager")
}
}