use crate::Buffer;
use crate::CompletionProvider;
use crate::View;
use glib::object::Cast;
use glib::object::IsA;
use glib::object::ObjectExt;
use glib::object::ObjectType as ObjectType_;
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;
use std::mem::transmute;
glib::wrapper! {
#[doc(alias = "GtkSourceCompletion")]
pub struct Completion(Object<ffi::GtkSourceCompletion, ffi::GtkSourceCompletionClass>);
match fn {
type_ => || ffi::gtk_source_completion_get_type(),
}
}
impl Completion {
pub fn builder() -> CompletionBuilder {
CompletionBuilder::default()
}
#[doc(alias = "gtk_source_completion_add_provider")]
pub fn add_provider(&self, provider: &impl IsA<CompletionProvider>) {
unsafe {
ffi::gtk_source_completion_add_provider(
self.to_glib_none().0,
provider.as_ref().to_glib_none().0,
);
}
}
#[doc(alias = "gtk_source_completion_block_interactive")]
pub fn block_interactive(&self) {
unsafe {
ffi::gtk_source_completion_block_interactive(self.to_glib_none().0);
}
}
#[doc(alias = "gtk_source_completion_get_buffer")]
#[doc(alias = "get_buffer")]
pub fn buffer(&self) -> Buffer {
unsafe { from_glib_none(ffi::gtk_source_completion_get_buffer(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_source_completion_get_page_size")]
#[doc(alias = "get_page_size")]
pub fn page_size(&self) -> u32 {
unsafe { ffi::gtk_source_completion_get_page_size(self.to_glib_none().0) }
}
#[doc(alias = "gtk_source_completion_get_view")]
#[doc(alias = "get_view")]
pub fn view(&self) -> View {
unsafe { from_glib_none(ffi::gtk_source_completion_get_view(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_source_completion_hide")]
pub fn hide(&self) {
unsafe {
ffi::gtk_source_completion_hide(self.to_glib_none().0);
}
}
#[doc(alias = "gtk_source_completion_remove_provider")]
pub fn remove_provider(&self, provider: &impl IsA<CompletionProvider>) {
unsafe {
ffi::gtk_source_completion_remove_provider(
self.to_glib_none().0,
provider.as_ref().to_glib_none().0,
);
}
}
#[doc(alias = "gtk_source_completion_set_page_size")]
pub fn set_page_size(&self, page_size: u32) {
unsafe {
ffi::gtk_source_completion_set_page_size(self.to_glib_none().0, page_size);
}
}
#[doc(alias = "gtk_source_completion_show")]
pub fn show(&self) {
unsafe {
ffi::gtk_source_completion_show(self.to_glib_none().0);
}
}
#[doc(alias = "gtk_source_completion_unblock_interactive")]
pub fn unblock_interactive(&self) {
unsafe {
ffi::gtk_source_completion_unblock_interactive(self.to_glib_none().0);
}
}
#[doc(alias = "remember-info-visibility")]
pub fn is_remember_info_visibility(&self) -> bool {
glib::ObjectExt::property(self, "remember-info-visibility")
}
#[doc(alias = "remember-info-visibility")]
pub fn set_remember_info_visibility(&self, remember_info_visibility: bool) {
glib::ObjectExt::set_property(self, "remember-info-visibility", &remember_info_visibility)
}
#[doc(alias = "select-on-show")]
pub fn selects_on_show(&self) -> bool {
glib::ObjectExt::property(self, "select-on-show")
}
#[doc(alias = "select-on-show")]
pub fn set_select_on_show(&self, select_on_show: bool) {
glib::ObjectExt::set_property(self, "select-on-show", &select_on_show)
}
#[doc(alias = "show-icons")]
pub fn shows_icons(&self) -> bool {
glib::ObjectExt::property(self, "show-icons")
}
#[doc(alias = "show-icons")]
pub fn set_show_icons(&self, show_icons: bool) {
glib::ObjectExt::set_property(self, "show-icons", &show_icons)
}
#[doc(alias = "gtk_source_completion_fuzzy_highlight")]
pub fn fuzzy_highlight(haystack: &str, casefold_query: &str) -> Option<pango::AttrList> {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gtk_source_completion_fuzzy_highlight(
haystack.to_glib_none().0,
casefold_query.to_glib_none().0,
))
}
}
#[doc(alias = "gtk_source_completion_fuzzy_match")]
pub fn fuzzy_match(haystack: Option<&str>, casefold_needle: &str) -> Option<u32> {
assert_initialized_main_thread!();
unsafe {
let mut priority = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gtk_source_completion_fuzzy_match(
haystack.to_glib_none().0,
casefold_needle.to_glib_none().0,
priority.as_mut_ptr(),
));
if ret {
Some(priority.assume_init())
} else {
None
}
}
}
#[doc(alias = "hide")]
pub fn connect_hide<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn hide_trampoline<F: Fn(&Completion) + 'static>(
this: *mut ffi::GtkSourceCompletion,
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"hide\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
hide_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
pub fn emit_hide(&self) {
self.emit_by_name::<()>("hide", &[]);
}
#[doc(alias = "provider-added")]
pub fn connect_provider_added<F: Fn(&Self, &CompletionProvider) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn provider_added_trampoline<
F: Fn(&Completion, &CompletionProvider) + 'static,
>(
this: *mut ffi::GtkSourceCompletion,
provider: *mut ffi::GtkSourceCompletionProvider,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), &from_glib_borrow(provider))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"provider-added\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
provider_added_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "provider-removed")]
pub fn connect_provider_removed<F: Fn(&Self, &CompletionProvider) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn provider_removed_trampoline<
F: Fn(&Completion, &CompletionProvider) + 'static,
>(
this: *mut ffi::GtkSourceCompletion,
provider: *mut ffi::GtkSourceCompletionProvider,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), &from_glib_borrow(provider))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"provider-removed\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
provider_removed_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "show")]
pub fn connect_show<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn show_trampoline<F: Fn(&Completion) + 'static>(
this: *mut ffi::GtkSourceCompletion,
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"show\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
show_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
pub fn emit_show(&self) {
self.emit_by_name::<()>("show", &[]);
}
#[doc(alias = "buffer")]
pub fn connect_buffer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_buffer_trampoline<F: Fn(&Completion) + 'static>(
this: *mut ffi::GtkSourceCompletion,
_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::buffer\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_buffer_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "page-size")]
pub fn connect_page_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_page_size_trampoline<F: Fn(&Completion) + 'static>(
this: *mut ffi::GtkSourceCompletion,
_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::page-size\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_page_size_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "remember-info-visibility")]
pub fn connect_remember_info_visibility_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_remember_info_visibility_trampoline<
F: Fn(&Completion) + 'static,
>(
this: *mut ffi::GtkSourceCompletion,
_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::remember-info-visibility\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_remember_info_visibility_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "select-on-show")]
pub fn connect_select_on_show_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_select_on_show_trampoline<F: Fn(&Completion) + 'static>(
this: *mut ffi::GtkSourceCompletion,
_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::select-on-show\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_select_on_show_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "show-icons")]
pub fn connect_show_icons_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_show_icons_trampoline<F: Fn(&Completion) + 'static>(
this: *mut ffi::GtkSourceCompletion,
_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::show-icons\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_show_icons_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
#[derive(Clone, Default)]
#[must_use = "The builder must be built to be used"]
pub struct CompletionBuilder {
page_size: Option<u32>,
remember_info_visibility: Option<bool>,
select_on_show: Option<bool>,
show_icons: Option<bool>,
view: Option<View>,
}
impl CompletionBuilder {
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) -> Completion {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
if let Some(ref page_size) = self.page_size {
properties.push(("page-size", page_size));
}
if let Some(ref remember_info_visibility) = self.remember_info_visibility {
properties.push(("remember-info-visibility", remember_info_visibility));
}
if let Some(ref select_on_show) = self.select_on_show {
properties.push(("select-on-show", select_on_show));
}
if let Some(ref show_icons) = self.show_icons {
properties.push(("show-icons", show_icons));
}
if let Some(ref view) = self.view {
properties.push(("view", view));
}
glib::Object::new::<Completion>(&properties)
}
pub fn page_size(mut self, page_size: u32) -> Self {
self.page_size = Some(page_size);
self
}
pub fn remember_info_visibility(mut self, remember_info_visibility: bool) -> Self {
self.remember_info_visibility = Some(remember_info_visibility);
self
}
pub fn select_on_show(mut self, select_on_show: bool) -> Self {
self.select_on_show = Some(select_on_show);
self
}
pub fn show_icons(mut self, show_icons: bool) -> Self {
self.show_icons = Some(show_icons);
self
}
pub fn view(mut self, view: &impl IsA<View>) -> Self {
self.view = Some(view.clone().upcast());
self
}
}
impl fmt::Display for Completion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Completion")
}
}