Class: GtkSource::SearchContext

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Constructor Details

#initialize(buffer, settings) ⇒ GtkSource::SearchContext

Creates a new search context, associated with buffer, and customized with settings.

If settings is nil, a new [classSearchSettings] object will be created, that you can retrieve with [methodSearchContext.get_settings].

Parameters:

Instance Method Details

#backward(iter, match_start, match_end, has_wrapped_around) ⇒ Boolean

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 [propertySearchSettings: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 [propertySearchSettings:wrap-around] property.

Parameters:

  • iter (Gtk::TextIter)

    start of search.

  • match_start (Gtk::TextIter)

    return location for start of match, or nil.

  • match_end (Gtk::TextIter)

    return location for end of match, or nil.

  • has_wrapped_around (Boolean)

    return location to know whether the search has wrapped around, or nil.

Returns:

  • (Boolean)

    whether a match was found.

#backward_async(iter, cancellable, callback, user_data) ⇒ nil

The asynchronous version of [methodSearchContext.backward].

See the [ifaceGio.AsyncResult] documentation to know how to use this function.

If the operation is cancelled, the callback will only be called if cancellable was not nil. The method takes ownership of cancellable, so you can unref it after calling this function.

Parameters:

  • iter (Gtk::TextIter)

    start of search.

  • cancellable (Gio::Cancellable)

    a #GCancellable, or nil.

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the operation is finished.

  • user_data (GObject)

    the data to pass to the callback function.

Returns:

  • (nil)

#backward_finish(result, match_start, match_end, has_wrapped_around) ⇒ Boolean

Finishes a backward search started with [methodSearchContext.backward_async].

See the documentation of [methodSearchContext.backward] for more details.

Parameters:

  • result (Gio::AsyncResult)

    a GAsync::Result.

  • match_start (Gtk::TextIter)

    return location for start of match, or nil.

  • match_end (Gtk::TextIter)

    return location for end of match, or nil.

  • has_wrapped_around (Boolean)

    return location to know whether the search has wrapped around, or nil.

Returns:

  • (Boolean)

    whether a match was found.

#bufferGtkSource::Buffer

The [classBuffer] associated to the search context.

Returns:

#buffer=(buffer) ⇒ GtkSource::Buffer

The [classBuffer] associated to the search context.

Parameters:

Returns:

#forward(iter, match_start, match_end, has_wrapped_around) ⇒ Boolean

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 [propertySearchSettings: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 [propertySearchSettings:wrap-around] property.

Parameters:

  • iter (Gtk::TextIter)

    start of search.

  • match_start (Gtk::TextIter)

    return location for start of match, or nil.

  • match_end (Gtk::TextIter)

    return location for end of match, or nil.

  • has_wrapped_around (Boolean)

    return location to know whether the search has wrapped around, or nil.

Returns:

  • (Boolean)

    whether a match was found.

#forward_async(iter, cancellable, callback, user_data) ⇒ nil

The asynchronous version of [methodSearchContext.forward].

See the [ifaceGio.AsyncResult] documentation to know how to use this function.

If the operation is cancelled, the callback will only be called if cancellable was not nil. The method takes ownership of cancellable, so you can unref it after calling this function.

Parameters:

  • iter (Gtk::TextIter)

    start of search.

  • cancellable (Gio::Cancellable)

    a #GCancellable, or nil.

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the operation is finished.

  • user_data (GObject)

    the data to pass to the callback function.

Returns:

  • (nil)

#forward_finish(result, match_start, match_end, has_wrapped_around) ⇒ Boolean

Finishes a forward search started with [methodSearchContext.forward_async].

See the documentation of [methodSearchContext.forward] for more details.

Parameters:

  • result (Gio::AsyncResult)

    a GAsync::Result.

  • match_start (Gtk::TextIter)

    return location for start of match, or nil.

  • match_end (Gtk::TextIter)

    return location for end of match, or nil.

  • has_wrapped_around (Boolean)

    return location to know whether the search has wrapped around, or nil.

Returns:

  • (Boolean)

    whether a match was found.

#get_occurrence_position(match_start, match_end) ⇒ Integer

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. 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.

Parameters:

  • match_start (Gtk::TextIter)

    the start of the occurrence.

  • match_end (Gtk::TextIter)

    the end of the occurrence.

Returns:

  • (Integer)

    the position of the search occurrence. The first occurrence has the

#highlightBoolean

Returns whether to highlight the search occurrences.

Returns:

  • (Boolean)

    whether to highlight the search occurrences.

#highlight=(highlight) ⇒ Boolean

Highlight the search occurrences.

Parameters:

  • highlight (Boolean)

Returns:

  • (Boolean)

    highlight

  • (Boolean)

    highlight

#highlight?Boolean

Highlight the search occurrences.

Returns:

  • (Boolean)

    highlight

#match_styleGtkSource::Style

A [classStyle], or nil for theme's scheme default style.

Returns:

#match_style=(match_style) ⇒ GtkSource::Style

A [classStyle], or nil for theme's scheme default style.

Parameters:

Returns:

#occurrences_countInteger

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.

Returns:

  • (Integer)

    occurrences-count

#occurrences_count=(occurrences_count) ⇒ Integer

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.

Parameters:

  • occurrences_count (Integer)

Returns:

  • (Integer)

    occurrences-count

  • (Integer)

    occurrences-count

#regex_errorGLib::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 nil.

Free with [methodGLib.Error.free].

Returns:

  • (GLib::Error)

    regex-error

#regex_error=(regex_error) ⇒ GLib::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 nil.

Free with [methodGLib.Error.free].

Parameters:

  • regex_error (GLib::Error)

Returns:

  • (GLib::Error)

    regex-error

  • (GLib::Error)

    regex-error

#replace(match_start, match_end, replace, replace_length) ⇒ Boolean

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 [funcGLib.Regex.check_replacement]. The replace text can contain backreferences.

Parameters:

  • match_start (Gtk::TextIter)

    the start of the match to replace.

  • match_end (Gtk::TextIter)

    the end of the match to replace.

  • replace (String)

    the replacement text.

  • replace_length (Integer)

    the length of replace in bytes, or -1.

Returns:

  • (Boolean)

    whether the match has been replaced.

#replace_all(replace, replace_length) ⇒ Integer

Replaces all search matches by another text.

It is a synchronous function, so it can block the user interface.

For a regular expression replacement, you can check if replace is valid by calling [funcGLib.Regex.check_replacement]. The replace text can contain backreferences.

Parameters:

  • replace (String)

    the replacement text.

  • replace_length (Integer)

    the length of replace in bytes, or -1.

Returns:

  • (Integer)

    the number of replaced matches.

#settingsGtkSource::SearchSettings

The [classSearchSettings] associated to the search context.

This property is construct-only since version 4.0.

Returns:

#settings=(settings) ⇒ GtkSource::SearchSettings

The [classSearchSettings] associated to the search context.

This property is construct-only since version 4.0.

Parameters:

Returns: