1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ffi, Provider};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
///
///
/// ## Properties
///
///
/// #### `language`
/// The "language" to use when checking words with the configured
/// #SpellingProvider. For example, `en_US`.
///
/// Readable | Writeable
///
///
/// #### `provider`
/// The "provider" property contains the provider that is providing
/// information to the spell checker.
///
/// Currently, only Enchant is supported, and requires using the
/// #SpellingEnchantProvider. Setting this to [`None`] will get
/// the default provider.
///
/// Readable | Writeable | Construct Only
#[doc(alias = "SpellingChecker")]
pub struct Checker(Object<ffi::SpellingChecker, ffi::SpellingCheckerClass>);
match fn {
type_ => || ffi::spelling_checker_get_type(),
}
}
impl Checker {
/// Create a new #SpellingChecker.
///
/// # Returns
///
/// a newly created #SpellingChecker
#[doc(alias = "spelling_checker_new")]
pub fn new(provider: &Provider, language: &str) -> Checker {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::spelling_checker_new(
provider.to_glib_none().0,
language.to_glib_none().0,
))
}
}
#[doc(alias = "spelling_checker_add_word")]
pub fn add_word(&self, word: &str) {
unsafe {
ffi::spelling_checker_add_word(self.to_glib_none().0, word.to_glib_none().0);
}
}
#[doc(alias = "spelling_checker_check_word")]
pub fn check_word(&self, word: &str) -> bool {
let word_len = word.len() as _;
unsafe {
from_glib(ffi::spelling_checker_check_word(
self.to_glib_none().0,
word.to_glib_none().0,
word_len,
))
}
}
#[doc(alias = "spelling_checker_get_extra_word_chars")]
#[doc(alias = "get_extra_word_chars")]
pub fn extra_word_chars(&self) -> glib::GString {
unsafe {
from_glib_none(ffi::spelling_checker_get_extra_word_chars(
self.to_glib_none().0,
))
}
}
/// Gets the language being used by the spell checker.
///
/// # Returns
///
/// a string describing the current language.
#[doc(alias = "spelling_checker_get_language")]
#[doc(alias = "get_language")]
pub fn language(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::spelling_checker_get_language(self.to_glib_none().0)) }
}
/// Gets the spell provider used by the spell checker.
///
/// Currently, only Enchant-2 is supported.
///
/// # Returns
///
/// an #SpellingProvider
#[doc(alias = "spelling_checker_get_provider")]
#[doc(alias = "get_provider")]
pub fn provider(&self) -> Provider {
unsafe { from_glib_none(ffi::spelling_checker_get_provider(self.to_glib_none().0)) }
}
#[doc(alias = "spelling_checker_ignore_word")]
pub fn ignore_word(&self, word: &str) {
unsafe {
ffi::spelling_checker_ignore_word(self.to_glib_none().0, word.to_glib_none().0);
}
}
/// Retrieves a list of possible corrections for @word.
/// ## `word`
/// a word to be checked
///
/// # Returns
///
///
/// A list of possible corrections, or [`None`].
#[doc(alias = "spelling_checker_list_corrections")]
pub fn list_corrections(&self, word: &str) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::spelling_checker_list_corrections(
self.to_glib_none().0,
word.to_glib_none().0,
))
}
}
/// Sets the language code to use when communicating with the provider,
/// such as `en_US`.
/// ## `language`
/// the language to use
#[doc(alias = "spelling_checker_set_language")]
#[doc(alias = "language")]
pub fn set_language(&self, language: &str) {
unsafe {
ffi::spelling_checker_set_language(self.to_glib_none().0, language.to_glib_none().0);
}
}
/// Gets a default #SpellingChecker using the default provider and language.
///
/// # Returns
///
/// a #SpellingChecker
#[doc(alias = "spelling_checker_get_default")]
#[doc(alias = "get_default")]
#[allow(clippy::should_implement_trait)]
pub fn default() -> Checker {
assert_initialized_main_thread!();
unsafe { from_glib_none(ffi::spelling_checker_get_default()) }
}
#[doc(alias = "language")]
pub fn connect_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_language_trampoline<F: Fn(&Checker) + 'static>(
this: *mut ffi::SpellingChecker,
_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::language\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_language_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}