use crate::CompletionProvider;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
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::default()
}
}
impl Default for CompletionSnippets {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Default)]
#[must_use = "The builder must be built to be used"]
pub struct CompletionSnippetsBuilder {
priority: Option<i32>,
title: Option<String>,
}
impl CompletionSnippetsBuilder {
pub fn new() -> Self {
Self::default()
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> CompletionSnippets {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
if let Some(ref priority) = self.priority {
properties.push(("priority", priority));
}
if let Some(ref title) = self.title {
properties.push(("title", title));
}
glib::Object::new::<CompletionSnippets>(&properties)
}
pub fn priority(mut self, priority: i32) -> Self {
self.priority = Some(priority);
self
}
pub fn title(mut self, title: &str) -> Self {
self.title = Some(title.to_string());
self
}
}
pub trait CompletionSnippetsExt: 'static {
fn priority(&self) -> i32;
fn set_priority(&self, priority: i32);
fn set_title(&self, title: Option<&str>);
#[doc(alias = "priority")]
fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "title")]
fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<CompletionSnippets>> CompletionSnippetsExt for O {
fn priority(&self) -> i32 {
glib::ObjectExt::property(self.as_ref(), "priority")
}
fn set_priority(&self, priority: i32) {
glib::ObjectExt::set_property(self.as_ref(), "priority", &priority)
}
fn set_title(&self, title: Option<&str>) {
glib::ObjectExt::set_property(self.as_ref(), "title", &title)
}
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(transmute::<_, unsafe extern "C" fn()>(
notify_priority_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
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(transmute::<_, unsafe extern "C" fn()>(
notify_title_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for CompletionSnippets {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("CompletionSnippets")
}
}