use crate::{ffi, CompletionProvider};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "GtkSourceCompletionSnippets")]
pub struct CompletionSnippets(Object<ffi::GtkSourceCompletionSnippets, ffi::GtkSourceCompletionSnippetsClass>) @implements CompletionProvider;
match fn {
type_ => || ffi::gtk_source_completion_snippets_get_type(),
}
}
impl CompletionSnippets {
pub const NONE: Option<&'static CompletionSnippets> = None;
#[doc(alias = "gtk_source_completion_snippets_new")]
pub fn new() -> CompletionSnippets {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gtk_source_completion_snippets_new()) }
}
pub fn builder() -> CompletionSnippetsBuilder {
CompletionSnippetsBuilder::new()
}
}
impl Default for CompletionSnippets {
fn default() -> Self {
Self::new()
}
}
#[must_use = "The builder must be built to be used"]
pub struct CompletionSnippetsBuilder {
builder: glib::object::ObjectBuilder<'static, CompletionSnippets>,
}
impl CompletionSnippetsBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn priority(self, priority: i32) -> Self {
Self {
builder: self.builder.property("priority", priority),
}
}
pub fn title(self, title: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("title", title.into()),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> CompletionSnippets {
self.builder.build()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::CompletionSnippets>> Sealed for T {}
}
pub trait CompletionSnippetsExt: IsA<CompletionSnippets> + sealed::Sealed + 'static {
fn priority(&self) -> i32 {
ObjectExt::property(self.as_ref(), "priority")
}
fn set_priority(&self, priority: i32) {
ObjectExt::set_property(self.as_ref(), "priority", priority)
}
fn set_title(&self, title: Option<&str>) {
ObjectExt::set_property(self.as_ref(), "title", title)
}
#[doc(alias = "priority")]
fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_priority_trampoline<
P: IsA<CompletionSnippets>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkSourceCompletionSnippets,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(CompletionSnippets::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::priority\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_priority_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<CompletionSnippets>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkSourceCompletionSnippets,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(CompletionSnippets::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(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_title_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<CompletionSnippets>> CompletionSnippetsExt for O {}