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 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
// 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::{ffi, Buffer, SearchSettings, Style};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, pin::Pin};
glib::wrapper! {
/// Search context.
///
/// A [`SearchContext`][crate::SearchContext] is used for the search and replace in a
/// [`Buffer`][crate::Buffer]. The search settings are represented by a
/// [`SearchSettings`][crate::SearchSettings] object. There can be a many-to-many relationship
/// between buffers and search settings, with the search contexts in-between: a
/// search settings object can be shared between several search contexts; and a
/// buffer can contain several search contexts at the same time.
///
/// The total number of search occurrences can be retrieved with
/// [`occurrences_count()`][Self::occurrences_count()]. To know the position of a
/// certain match, use [`occurrence_position()`][Self::occurrence_position()].
///
/// The buffer is scanned asynchronously, so it doesn't block the user interface.
/// For each search, the buffer is scanned at most once. After that, navigating
/// through the occurrences doesn't require to re-scan the buffer entirely.
///
/// To search forward, use [`forward()`][Self::forward()] or
/// [`forward_async()`][Self::forward_async()] for the asynchronous version.
/// The backward search is done similarly. To replace a search match, or all
/// matches, use [`replace()`][Self::replace()] and
/// [`replace_all()`][Self::replace_all()].
///
/// The search occurrences are highlighted by default. To disable it, use
/// [`set_highlight()`][Self::set_highlight()]. You can enable the search
/// highlighting for several [`SearchContext`][crate::SearchContext]s attached to the
/// same buffer. Moreover, each of those [`SearchContext`][crate::SearchContext]s can
/// have a different text style associated. Use
/// [`set_match_style()`][Self::set_match_style()] to specify the [`Style`][crate::Style]
/// to apply on search matches.
///
/// Note that the [`highlight`][struct@crate::SearchContext#highlight] and
/// [`match-style`][struct@crate::SearchContext#match-style] properties are in the
/// [`SearchContext`][crate::SearchContext] class, not [`SearchSettings`][crate::SearchSettings]. Appearance
/// settings should be tied to one, and only one buffer, as different buffers can
/// have different style scheme associated (a [`SearchSettings`][crate::SearchSettings] object
/// can be bound indirectly to several buffers).
///
/// The concept of "current match" doesn't exist yet. A way to highlight
/// differently the current match is to select it.
///
/// A search occurrence's position doesn't depend on the cursor position or other
/// parameters. Take for instance the buffer "aaaa" with the search text "aa".
/// The two occurrences are at positions [0:2] and [2:4]. If you begin to search
/// at position 1, you will get the occurrence [2:4], not [1:3]. This is a
/// prerequisite for regular expression searches. The pattern ".*" matches the
/// entire line. If the cursor is at the middle of the line, you don't want the
/// rest of the line as the occurrence, you want an entire line. (As a side note,
/// regular expression searches can also match multiple lines.)
///
/// In the GtkSourceView source code, there is an example of how to use the
/// search and replace API: see the tests/test-search.c file. It is a mini
/// application for the search and replace, with a basic user interface.
///
/// ## Properties
///
///
/// #### `buffer`
/// The [`Buffer`][crate::Buffer] associated to the search context.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `highlight`
/// Highlight the search occurrences.
///
/// Readable | Writeable | Construct
///
///
/// #### `match-style`
/// A [`Style`][crate::Style], or [`None`] for theme's scheme default style.
///
/// Readable | Writeable | Construct
///
///
/// #### `occurrences-count`
/// The total number of search occurrences. If the search is disabled,
/// the value is 0. If the buffer is not already fully scanned, the value
/// is -1.
///
/// Readable
///
///
/// #### `regex-error`
/// If the regex search pattern doesn't follow all the rules, this
/// #GError property will be set. If the pattern is valid, the value is
/// [`None`].
///
/// Free with `GLib::Error::free()`.
///
/// Readable
///
///
/// #### `settings`
/// The [`SearchSettings`][crate::SearchSettings] associated to the search context.
///
/// This property is construct-only since version 4.0.
///
/// Readable | Writeable | Construct Only
///
/// # Implements
///
/// [`trait@glib::ObjectExt`]
#[doc(alias = "GtkSourceSearchContext")]
pub struct SearchContext(Object<ffi::GtkSourceSearchContext, ffi::GtkSourceSearchContextClass>);
match fn {
type_ => || ffi::gtk_source_search_context_get_type(),
}
}
impl SearchContext {
/// Creates a new search context, associated with @buffer, and customized with
/// @settings.
///
/// If @settings is [`None`], a new [`SearchSettings`][crate::SearchSettings] object will
/// be created, that you can retrieve with [`settings()`][Self::settings()].
/// ## `buffer`
/// a #GtkSourceBuffer.
/// ## `settings`
/// a #GtkSourceSearchSettings, or [`None`].
///
/// # Returns
///
/// a new search context.
#[doc(alias = "gtk_source_search_context_new")]
pub fn new(
buffer: &impl IsA<Buffer>,
settings: Option<&impl IsA<SearchSettings>>,
) -> SearchContext {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::gtk_source_search_context_new(
buffer.as_ref().to_glib_none().0,
settings.map(|p| p.as_ref()).to_glib_none().0,
))
}
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`SearchContext`] objects.
///
/// This method returns an instance of [`SearchContextBuilder`](crate::builders::SearchContextBuilder) which can be used to create [`SearchContext`] objects.
pub fn builder() -> SearchContextBuilder {
SearchContextBuilder::new()
}
/// Synchronous backward search.
///
/// It is recommended to use the asynchronous functions instead, to not block the user interface.
/// However, if you are sure that the @buffer is small, this function is more convenient to use.
///
/// If the [`wrap-around`][struct@crate::SearchSettings#wrap-around] property is [`false`], this function
/// doesn't try to wrap around.
///
/// The @has_wrapped_around out parameter is set independently of whether a match
/// is found. So if this function returns [`false`], @has_wrapped_around will have
/// the same value as the [`wrap-around`][struct@crate::SearchSettings#wrap-around] property.
/// ## `iter`
/// start of search.
///
/// # Returns
///
/// whether a match was found.
///
/// ## `match_start`
/// return location for start of match, or [`None`].
///
/// ## `match_end`
/// return location for end of match, or [`None`].
///
/// ## `has_wrapped_around`
/// return location to know whether the
/// search has wrapped around, or [`None`].
#[doc(alias = "gtk_source_search_context_backward")]
pub fn backward(&self, iter: >k::TextIter) -> Option<(gtk::TextIter, gtk::TextIter, bool)> {
unsafe {
let mut match_start = gtk::TextIter::uninitialized();
let mut match_end = gtk::TextIter::uninitialized();
let mut has_wrapped_around = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gtk_source_search_context_backward(
self.to_glib_none().0,
iter.to_glib_none().0,
match_start.to_glib_none_mut().0,
match_end.to_glib_none_mut().0,
has_wrapped_around.as_mut_ptr(),
));
if ret {
Some((
match_start,
match_end,
from_glib(has_wrapped_around.assume_init()),
))
} else {
None
}
}
}
/// The asynchronous version of [`backward()`][Self::backward()].
///
/// See the `Gio::AsyncResult` documentation to know how to use this function.
///
/// If the operation is cancelled, the @callback will only be called if
/// @cancellable was not [`None`]. The method takes
/// ownership of @cancellable, so you can unref it after calling this function.
/// ## `iter`
/// start of search.
/// ## `cancellable`
/// a #GCancellable, or [`None`].
/// ## `callback`
/// a #GAsyncReadyCallback to call when the operation is finished.
#[doc(alias = "gtk_source_search_context_backward_async")]
pub fn backward_async<
P: FnOnce(Result<(gtk::TextIter, gtk::TextIter, bool), glib::Error>) + 'static,
>(
&self,
iter: >k::TextIter,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn backward_async_trampoline<
P: FnOnce(Result<(gtk::TextIter, gtk::TextIter, bool), glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let mut match_start = gtk::TextIter::uninitialized();
let mut match_end = gtk::TextIter::uninitialized();
let mut has_wrapped_around = std::mem::MaybeUninit::uninit();
let _ = ffi::gtk_source_search_context_backward_finish(
_source_object as *mut _,
res,
match_start.to_glib_none_mut().0,
match_end.to_glib_none_mut().0,
has_wrapped_around.as_mut_ptr(),
&mut error,
);
let result = if error.is_null() {
Ok((
match_start,
match_end,
from_glib(has_wrapped_around.assume_init()),
))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = backward_async_trampoline::<P>;
unsafe {
ffi::gtk_source_search_context_backward_async(
self.to_glib_none().0,
iter.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
pub fn backward_future(
&self,
iter: >k::TextIter,
) -> Pin<
Box_<
dyn std::future::Future<
Output = Result<(gtk::TextIter, gtk::TextIter, bool), glib::Error>,
> + 'static,
>,
> {
let iter = iter.clone();
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.backward_async(&iter, Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
/// Synchronous forward search.
///
/// It is recommended to use the asynchronous functions instead, to not block the user interface.
/// However, if you are sure that the @buffer is small, this function is more convenient to use.
///
/// If the [`wrap-around`][struct@crate::SearchSettings#wrap-around] property is [`false`], this function
/// doesn't try to wrap around.
///
/// The @has_wrapped_around out parameter is set independently of whether a match
/// is found. So if this function returns [`false`], @has_wrapped_around will have
/// the same value as the [`wrap-around`][struct@crate::SearchSettings#wrap-around] property.
/// ## `iter`
/// start of search.
///
/// # Returns
///
/// whether a match was found.
///
/// ## `match_start`
/// return location for start of match, or [`None`].
///
/// ## `match_end`
/// return location for end of match, or [`None`].
///
/// ## `has_wrapped_around`
/// return location to know whether the
/// search has wrapped around, or [`None`].
#[doc(alias = "gtk_source_search_context_forward")]
pub fn forward(&self, iter: >k::TextIter) -> Option<(gtk::TextIter, gtk::TextIter, bool)> {
unsafe {
let mut match_start = gtk::TextIter::uninitialized();
let mut match_end = gtk::TextIter::uninitialized();
let mut has_wrapped_around = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gtk_source_search_context_forward(
self.to_glib_none().0,
iter.to_glib_none().0,
match_start.to_glib_none_mut().0,
match_end.to_glib_none_mut().0,
has_wrapped_around.as_mut_ptr(),
));
if ret {
Some((
match_start,
match_end,
from_glib(has_wrapped_around.assume_init()),
))
} else {
None
}
}
}
/// The asynchronous version of [`forward()`][Self::forward()].
///
/// See the `Gio::AsyncResult` documentation to know how to use this function.
///
/// If the operation is cancelled, the @callback will only be called if
/// @cancellable was not [`None`]. The method takes
/// ownership of @cancellable, so you can unref it after calling this function.
/// ## `iter`
/// start of search.
/// ## `cancellable`
/// a #GCancellable, or [`None`].
/// ## `callback`
/// a #GAsyncReadyCallback to call when the operation is finished.
#[doc(alias = "gtk_source_search_context_forward_async")]
pub fn forward_async<
P: FnOnce(Result<(gtk::TextIter, gtk::TextIter, bool), glib::Error>) + 'static,
>(
&self,
iter: >k::TextIter,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn forward_async_trampoline<
P: FnOnce(Result<(gtk::TextIter, gtk::TextIter, bool), glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let mut match_start = gtk::TextIter::uninitialized();
let mut match_end = gtk::TextIter::uninitialized();
let mut has_wrapped_around = std::mem::MaybeUninit::uninit();
let _ = ffi::gtk_source_search_context_forward_finish(
_source_object as *mut _,
res,
match_start.to_glib_none_mut().0,
match_end.to_glib_none_mut().0,
has_wrapped_around.as_mut_ptr(),
&mut error,
);
let result = if error.is_null() {
Ok((
match_start,
match_end,
from_glib(has_wrapped_around.assume_init()),
))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = forward_async_trampoline::<P>;
unsafe {
ffi::gtk_source_search_context_forward_async(
self.to_glib_none().0,
iter.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
pub fn forward_future(
&self,
iter: >k::TextIter,
) -> Pin<
Box_<
dyn std::future::Future<
Output = Result<(gtk::TextIter, gtk::TextIter, bool), glib::Error>,
> + 'static,
>,
> {
let iter = iter.clone();
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.forward_async(&iter, Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
///
/// # Returns
///
/// the associated buffer.
#[doc(alias = "gtk_source_search_context_get_buffer")]
#[doc(alias = "get_buffer")]
pub fn buffer(&self) -> Buffer {
unsafe {
from_glib_none(ffi::gtk_source_search_context_get_buffer(
self.to_glib_none().0,
))
}
}
///
/// # Returns
///
/// whether to highlight the search occurrences.
#[doc(alias = "gtk_source_search_context_get_highlight")]
#[doc(alias = "get_highlight")]
#[doc(alias = "highlight")]
pub fn is_highlight(&self) -> bool {
unsafe {
from_glib(ffi::gtk_source_search_context_get_highlight(
self.to_glib_none().0,
))
}
}
///
/// # Returns
///
/// the #GtkSourceStyle to apply on search matches.
#[doc(alias = "gtk_source_search_context_get_match_style")]
#[doc(alias = "get_match_style")]
#[doc(alias = "match-style")]
pub fn match_style(&self) -> Style {
unsafe {
from_glib_none(ffi::gtk_source_search_context_get_match_style(
self.to_glib_none().0,
))
}
}
/// Gets the position of a search occurrence.
///
/// If the buffer is not already fully scanned, the position may be unknown,
/// and -1 is returned. If 0 is returned, it means that this part of the buffer
/// has already been scanned, and that @match_start and @match_end don't delimit an occurrence.
/// ## `match_start`
/// the start of the occurrence.
/// ## `match_end`
/// the end of the occurrence.
///
/// # Returns
///
/// the position of the search occurrence. The first occurrence has the
/// position 1 (not 0). Returns 0 if @match_start and @match_end don't delimit
/// an occurrence. Returns -1 if the position is not yet known.
#[doc(alias = "gtk_source_search_context_get_occurrence_position")]
#[doc(alias = "get_occurrence_position")]
pub fn occurrence_position(
&self,
match_start: >k::TextIter,
match_end: >k::TextIter,
) -> i32 {
unsafe {
ffi::gtk_source_search_context_get_occurrence_position(
self.to_glib_none().0,
match_start.to_glib_none().0,
match_end.to_glib_none().0,
)
}
}
/// Gets the total number of search occurrences.
///
/// If the buffer is not already fully scanned, the total number of occurrences is
/// unknown, and -1 is returned.
///
/// # Returns
///
/// the total number of search occurrences, or -1 if unknown.
#[doc(alias = "gtk_source_search_context_get_occurrences_count")]
#[doc(alias = "get_occurrences_count")]
#[doc(alias = "occurrences-count")]
pub fn occurrences_count(&self) -> i32 {
unsafe { ffi::gtk_source_search_context_get_occurrences_count(self.to_glib_none().0) }
}
/// Regular expression patterns must follow certain rules. If
/// [`search-text`][struct@crate::SearchSettings#search-text] breaks a rule, the error can be
/// retrieved with this function.
///
/// The error domain is `GLib::RegexError`.
///
/// Free the return value with `GLib::Error::free()`.
///
/// # Returns
///
/// the #GError, or [`None`] if the
/// pattern is valid.
#[doc(alias = "gtk_source_search_context_get_regex_error")]
#[doc(alias = "get_regex_error")]
#[doc(alias = "regex-error")]
pub fn regex_error(&self) -> Option<glib::Error> {
unsafe {
from_glib_full(ffi::gtk_source_search_context_get_regex_error(
self.to_glib_none().0,
))
}
}
///
/// # Returns
///
/// the search settings.
#[doc(alias = "gtk_source_search_context_get_settings")]
#[doc(alias = "get_settings")]
pub fn settings(&self) -> SearchSettings {
unsafe {
from_glib_none(ffi::gtk_source_search_context_get_settings(
self.to_glib_none().0,
))
}
}
/// Replaces a search match by another text. If @match_start and @match_end
/// doesn't correspond to a search match, [`false`] is returned.
///
/// @match_start and @match_end iters are revalidated to point to the replacement
/// text boundaries.
///
/// For a regular expression replacement, you can check if @replace is valid by
/// calling `GLib::Regex::check_replacement()`. The @replace text can contain
/// backreferences.
/// ## `match_start`
/// the start of the match to replace.
/// ## `match_end`
/// the end of the match to replace.
/// ## `replace`
/// the replacement text.
/// ## `replace_length`
/// the length of @replace in bytes, or -1.
///
/// # Returns
///
/// whether the match has been replaced.
#[doc(alias = "gtk_source_search_context_replace")]
pub fn replace(
&self,
match_start: &mut gtk::TextIter,
match_end: &mut gtk::TextIter,
replace: &str,
) -> Result<(), glib::Error> {
let replace_length = replace.len() as _;
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::gtk_source_search_context_replace(
self.to_glib_none().0,
match_start.to_glib_none_mut().0,
match_end.to_glib_none_mut().0,
replace.to_glib_none().0,
replace_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))
}
}
}
/// Enables or disables the search occurrences highlighting.
/// ## `highlight`
/// the setting.
#[doc(alias = "gtk_source_search_context_set_highlight")]
#[doc(alias = "highlight")]
pub fn set_highlight(&self, highlight: bool) {
unsafe {
ffi::gtk_source_search_context_set_highlight(
self.to_glib_none().0,
highlight.into_glib(),
);
}
}
/// Set the style to apply on search matches.
///
/// If @match_style is [`None`], default theme's scheme 'match-style' will be used.
/// To enable or disable the search highlighting, use [`set_highlight()`][Self::set_highlight()].
/// ## `match_style`
/// a #GtkSourceStyle, or [`None`].
#[doc(alias = "gtk_source_search_context_set_match_style")]
#[doc(alias = "match-style")]
pub fn set_match_style(&self, match_style: Option<&Style>) {
unsafe {
ffi::gtk_source_search_context_set_match_style(
self.to_glib_none().0,
match_style.to_glib_none().0,
);
}
}
#[doc(alias = "highlight")]
pub fn connect_highlight_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_highlight_trampoline<F: Fn(&SearchContext) + 'static>(
this: *mut ffi::GtkSourceSearchContext,
_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::highlight\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_highlight_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "match-style")]
pub fn connect_match_style_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_match_style_trampoline<F: Fn(&SearchContext) + 'static>(
this: *mut ffi::GtkSourceSearchContext,
_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::match-style\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_match_style_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "occurrences-count")]
pub fn connect_occurrences_count_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_occurrences_count_trampoline<
F: Fn(&SearchContext) + 'static,
>(
this: *mut ffi::GtkSourceSearchContext,
_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::occurrences-count\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_occurrences_count_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "regex-error")]
pub fn connect_regex_error_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_regex_error_trampoline<F: Fn(&SearchContext) + 'static>(
this: *mut ffi::GtkSourceSearchContext,
_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::regex-error\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_regex_error_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl Default for SearchContext {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`SearchContext`] 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 SearchContextBuilder {
builder: glib::object::ObjectBuilder<'static, SearchContext>,
}
impl SearchContextBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
/// The [`Buffer`][crate::Buffer] associated to the search context.
pub fn buffer(self, buffer: &impl IsA<Buffer>) -> Self {
Self {
builder: self.builder.property("buffer", buffer.clone().upcast()),
}
}
/// Highlight the search occurrences.
pub fn highlight(self, highlight: bool) -> Self {
Self {
builder: self.builder.property("highlight", highlight),
}
}
/// A [`Style`][crate::Style], or [`None`] for theme's scheme default style.
pub fn match_style(self, match_style: &Style) -> Self {
Self {
builder: self.builder.property("match-style", match_style.clone()),
}
}
/// The [`SearchSettings`][crate::SearchSettings] associated to the search context.
///
/// This property is construct-only since version 4.0.
pub fn settings(self, settings: &impl IsA<SearchSettings>) -> Self {
Self {
builder: self.builder.property("settings", settings.clone().upcast()),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`SearchContext`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> SearchContext {
self.builder.build()
}
}