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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT
use crate::Language;
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute, ptr};
glib::wrapper! {
///
///
/// ## Properties
///
///
/// #### `language`
/// The [`Language`][crate::Language] used.
///
/// Readable | Writeable | Construct
///
/// ## Signals
///
///
/// #### `session-cleared`
/// Emitted when the session dictionary is cleared.
///
///
///
///
/// #### `word-added-to-personal`
/// Emitted when a word is added to the personal dictionary.
///
///
///
///
/// #### `word-added-to-session`
/// Emitted when a word is added to the session dictionary. See
/// [`CheckerExt::add_word_to_session()`][crate::prelude::CheckerExt::add_word_to_session()].
///
///
///
/// # Implements
///
/// [`CheckerExt`][trait@crate::prelude::CheckerExt]
#[doc(alias = "GspellChecker")]
pub struct Checker(Object<ffi::GspellChecker, ffi::GspellCheckerClass>);
match fn {
type_ => || ffi::gspell_checker_get_type(),
}
}
impl Checker {
pub const NONE: Option<&'static Checker> = None;
/// Creates a new [`Checker`][crate::Checker]. If `language` is [`None`], the default language is
/// picked with [`Language::default()`][crate::Language::default()].
/// ## `language`
/// the [`Language`][crate::Language] to use, or [`None`].
///
/// # Returns
///
/// a new [`Checker`][crate::Checker] object.
#[doc(alias = "gspell_checker_new")]
pub fn new(language: Option<&Language>) -> Checker {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gspell_checker_new(language.to_glib_none().0)) }
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`Checker`] objects.
///
/// This method returns an instance of [`CheckerBuilder`](crate::builders::CheckerBuilder) which can be used to create [`Checker`] objects.
pub fn builder() -> CheckerBuilder {
CheckerBuilder::new()
}
}
impl Default for Checker {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Checker`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct CheckerBuilder {
builder: glib::object::ObjectBuilder<'static, Checker>,
}
impl CheckerBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
/// The [`Language`][crate::Language] used.
pub fn language(self, language: &Language) -> Self {
Self {
builder: self.builder.property("language", language),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`Checker`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Checker {
self.builder.build()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Checker>> Sealed for T {}
}
/// Trait containing all [`struct@Checker`] methods.
///
/// # Implementors
///
/// [`Checker`][struct@crate::Checker]
pub trait CheckerExt: IsA<Checker> + sealed::Sealed + 'static {
/// Adds a word to the personal dictionary. It is typically saved in the user's
/// home directory.
/// ## `word`
/// a word.
/// ## `word_length`
/// the byte length of `word`, or -1 if `word` is nul-terminated.
#[doc(alias = "gspell_checker_add_word_to_personal")]
fn add_word_to_personal(&self, word: &str) {
let word_length = word.len() as _;
unsafe {
ffi::gspell_checker_add_word_to_personal(
self.as_ref().to_glib_none().0,
word.to_glib_none().0,
word_length,
);
}
}
/// Adds a word to the session dictionary. Each [`Checker`][crate::Checker] instance has a
/// different session dictionary. The session dictionary is lost when the
/// [`language`][struct@crate::Checker#language] property changes or when `self` is destroyed or
/// when [`clear_session()`][Self::clear_session()] is called.
///
/// This function is typically called for an “Ignore All” action.
/// ## `word`
/// a word.
/// ## `word_length`
/// the byte length of `word`, or -1 if `word` is nul-terminated.
#[doc(alias = "gspell_checker_add_word_to_session")]
fn add_word_to_session(&self, word: &str) {
let word_length = word.len() as _;
unsafe {
ffi::gspell_checker_add_word_to_session(
self.as_ref().to_glib_none().0,
word.to_glib_none().0,
word_length,
);
}
}
/// If the [`language`][struct@crate::Checker#language] is [`None`], i.e. when no dictonaries are
/// available, this function returns [`true`] to limit the damage.
/// ## `word`
/// the word to check.
/// ## `word_length`
/// the byte length of `word`, or -1 if `word` is nul-terminated.
///
/// # Returns
///
/// [`true`] if `word` is correctly spelled, [`false`] otherwise.
#[doc(alias = "gspell_checker_check_word")]
fn check_word(&self, word: &str) -> Result<(), glib::Error> {
let word_length = word.len() as _;
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::gspell_checker_check_word(
self.as_ref().to_glib_none().0,
word.to_glib_none().0,
word_length,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Clears the session dictionary.
#[doc(alias = "gspell_checker_clear_session")]
fn clear_session(&self) {
unsafe {
ffi::gspell_checker_clear_session(self.as_ref().to_glib_none().0);
}
}
//#[doc(alias = "gspell_checker_get_enchant_dict")]
//#[doc(alias = "get_enchant_dict")]
//fn enchant_dict(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
// unsafe { TODO: call ffi:gspell_checker_get_enchant_dict() }
//}
///
/// # Returns
///
/// the [`Language`][crate::Language] currently used, or [`None`]
/// if no dictionaries are available.
#[doc(alias = "gspell_checker_get_language")]
#[doc(alias = "get_language")]
fn language(&self) -> Option<Language> {
unsafe {
from_glib_none(ffi::gspell_checker_get_language(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the suggestions for `word`. Free the return value with
/// g_slist_free_full(suggestions, g_free).
/// ## `word`
/// a misspelled word.
/// ## `word_length`
/// the byte length of `word`, or -1 if `word` is nul-terminated.
///
/// # Returns
///
/// the list of suggestions.
#[doc(alias = "gspell_checker_get_suggestions")]
#[doc(alias = "get_suggestions")]
fn suggestions(&self, word: &str) -> Vec<glib::GString> {
let word_length = word.len() as _;
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gspell_checker_get_suggestions(
self.as_ref().to_glib_none().0,
word.to_glib_none().0,
word_length,
))
}
}
/// Informs the spell checker that `word` is replaced/corrected by `replacement`.
/// ## `word`
/// a word.
/// ## `word_length`
/// the byte length of `word`, or -1 if `word` is nul-terminated.
/// ## `replacement`
/// the replacement word.
/// ## `replacement_length`
/// the byte length of `replacement`, or -1 if `replacement`
/// is nul-terminated.
#[doc(alias = "gspell_checker_set_correction")]
fn set_correction(&self, word: &str, replacement: &str) {
let word_length = word.len() as _;
let replacement_length = replacement.len() as _;
unsafe {
ffi::gspell_checker_set_correction(
self.as_ref().to_glib_none().0,
word.to_glib_none().0,
word_length,
replacement.to_glib_none().0,
replacement_length,
);
}
}
/// Sets the language to use for the spell checking. If `language` is [`None`], the
/// default language is picked with [`Language::default()`][crate::Language::default()].
/// ## `language`
/// the [`Language`][crate::Language] to use, or [`None`].
#[doc(alias = "gspell_checker_set_language")]
fn set_language(&self, language: Option<&Language>) {
unsafe {
ffi::gspell_checker_set_language(
self.as_ref().to_glib_none().0,
language.to_glib_none().0,
);
}
}
/// Emitted when the session dictionary is cleared.
#[doc(alias = "session-cleared")]
fn connect_session_cleared<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn session_cleared_trampoline<P: IsA<Checker>, F: Fn(&P) + 'static>(
this: *mut ffi::GspellChecker,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Checker::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"session-cleared\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
session_cleared_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// Emitted when a word is added to the personal dictionary.
/// ## `word`
/// the added word.
#[doc(alias = "word-added-to-personal")]
fn connect_word_added_to_personal<F: Fn(&Self, &str) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn word_added_to_personal_trampoline<
P: IsA<Checker>,
F: Fn(&P, &str) + 'static,
>(
this: *mut ffi::GspellChecker,
word: *mut libc::c_char,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
Checker::from_glib_borrow(this).unsafe_cast_ref(),
&glib::GString::from_glib_borrow(word),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"word-added-to-personal\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
word_added_to_personal_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// Emitted when a word is added to the session dictionary. See
/// [`add_word_to_session()`][Self::add_word_to_session()].
/// ## `word`
/// the added word.
#[doc(alias = "word-added-to-session")]
fn connect_word_added_to_session<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn word_added_to_session_trampoline<
P: IsA<Checker>,
F: Fn(&P, &str) + 'static,
>(
this: *mut ffi::GspellChecker,
word: *mut libc::c_char,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
Checker::from_glib_borrow(this).unsafe_cast_ref(),
&glib::GString::from_glib_borrow(word),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"word-added-to-session\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
word_added_to_session_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "language")]
fn connect_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_language_trampoline<P: IsA<Checker>, F: Fn(&P) + 'static>(
this: *mut ffi::GspellChecker,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Checker::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::language\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_language_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<Checker>> CheckerExt for O {}
impl fmt::Display for Checker {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Checker")
}
}