GtkSource.SearchContext¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/co |
The associated |
||
r/w/c |
Highlight search occurrences |
||
r/w/c |
The text style for matches |
||
r |
Total number of search occurrences |
||
r |
Regular expression error |
||
r/w/c |
The associated |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class GtkSource.SearchContext(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
- classmethod new(buffer, settings)¶
- Parameters:
buffer (
GtkSource.Buffer
) – aGtkSource.Buffer
.settings (
GtkSource.SearchSettings
orNone
) – aGtkSource.SearchSettings
, orNone
.
- Returns:
a new search context.
- Return type:
Creates a new search context, associated with buffer, and customized with settings. If settings is
None
, a newGtkSource.SearchSettings
object will be created, that you can retrieve withGtkSource.SearchContext.get_settings
().New in version 3.10.
- backward(iter)¶
- Parameters:
iter (
Gtk.TextIter
) – start of search.- Returns:
whether a match was found.
- Return type:
(
bool
, match_start:Gtk.TextIter
, match_end:Gtk.TextIter
)
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.
New in version 3.10.
Deprecated since version 3.22: Use
GtkSource.SearchContext.backward2
() instead.
- backward2(iter)¶
- Parameters:
iter (
Gtk.TextIter
) – start of search.- Returns:
whether a match was found.
- Return type:
(
bool
, match_start:Gtk.TextIter
, match_end:Gtk.TextIter
, has_wrapped_around:bool
)
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.
The difference with
GtkSource.SearchContext.backward
() is that the has_wrapped_around out parameter has been added for convenience.If the
GtkSource.SearchSettings
:wrap-around
property isFalse
, 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 theGtkSource.SearchSettings
:wrap-around
property.New in version 3.22.
- backward_async(iter, cancellable, callback, *user_data)¶
- Parameters:
iter (
Gtk.TextIter
) – start of search.cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
.callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the operation is finished.user_data (
object
orNone
) – the data to pass to the callback function.
The asynchronous version of
GtkSource.SearchContext.backward2
().See the documentation of
GtkSource.SearchContext.backward2
() for more details.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
.GtkSource.SearchContext.backward_async
() takes ownership of cancellable, so you can unref it after calling this function.New in version 3.10.
- backward_finish(result)¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
.- Raises:
- Returns:
whether a match was found.
- Return type:
(
bool
, match_start:Gtk.TextIter
, match_end:Gtk.TextIter
)
Finishes a backward search started with
GtkSource.SearchContext.backward_async
().New in version 3.10.
Deprecated since version 3.22: Use
GtkSource.SearchContext.backward_finish2
() instead.
- backward_finish2(result)¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
.- Raises:
- Returns:
whether a match was found.
- Return type:
(
bool
, match_start:Gtk.TextIter
, match_end:Gtk.TextIter
, has_wrapped_around:bool
)
Finishes a backward search started with
GtkSource.SearchContext.backward_async
().See the documentation of
GtkSource.SearchContext.backward2
() for more details.New in version 3.22.
- forward(iter)¶
- Parameters:
iter (
Gtk.TextIter
) – start of search.- Returns:
whether a match was found.
- Return type:
(
bool
, match_start:Gtk.TextIter
, match_end:Gtk.TextIter
)
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.
New in version 3.10.
Deprecated since version 3.22: Use
GtkSource.SearchContext.forward2
() instead.
- forward2(iter)¶
- Parameters:
iter (
Gtk.TextIter
) – start of search.- Returns:
whether a match was found.
- Return type:
(
bool
, match_start:Gtk.TextIter
, match_end:Gtk.TextIter
, has_wrapped_around:bool
)
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.
The difference with
GtkSource.SearchContext.forward
() is that the has_wrapped_around out parameter has been added for convenience.If the
GtkSource.SearchSettings
:wrap-around
property isFalse
, 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 theGtkSource.SearchSettings
:wrap-around
property.New in version 3.22.
- forward_async(iter, cancellable, callback, *user_data)¶
- Parameters:
iter (
Gtk.TextIter
) – start of search.cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
.callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the operation is finished.user_data (
object
orNone
) – the data to pass to the callback function.
The asynchronous version of
GtkSource.SearchContext.forward2
().See the documentation of
GtkSource.SearchContext.forward2
() for more details.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
.GtkSource.SearchContext.forward_async
() takes ownership of cancellable, so you can unref it after calling this function.New in version 3.10.
- forward_finish(result)¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
.- Raises:
- Returns:
whether a match was found.
- Return type:
(
bool
, match_start:Gtk.TextIter
, match_end:Gtk.TextIter
)
Finishes a forward search started with
GtkSource.SearchContext.forward_async
().New in version 3.10.
Deprecated since version 3.22: Use
GtkSource.SearchContext.forward_finish2
() instead.
- forward_finish2(result)¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
.- Raises:
- Returns:
whether a match was found.
- Return type:
(
bool
, match_start:Gtk.TextIter
, match_end:Gtk.TextIter
, has_wrapped_around:bool
)
Finishes a forward search started with
GtkSource.SearchContext.forward_async
().See the documentation of
GtkSource.SearchContext.forward2
() for more details.New in version 3.22.
- get_buffer()¶
- Returns:
the associated buffer.
- Return type:
New in version 3.10.
- get_highlight()¶
- Returns:
whether to highlight the search occurrences.
- Return type:
New in version 3.10.
- get_match_style()¶
- Returns:
the
GtkSource.Style
to apply on search matches.- Return type:
New in version 3.16.
- get_occurrence_position(match_start, match_end)¶
- Parameters:
match_start (
Gtk.TextIter
) – the start of the occurrence.match_end (
Gtk.TextIter
) – 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.
- Return type:
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.
New in version 3.10.
- get_occurrences_count()¶
- Returns:
the total number of search occurrences, or -1 if unknown.
- Return type:
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.
New in version 3.10.
- get_regex_error()¶
- Returns:
the
GLib.Error
, orNone
if the pattern is valid.- Return type:
GLib.Error
orNone
Regular expression patterns must follow certain rules. If
GtkSource.SearchSettings
:search-text
breaks a rule, the error can be retrieved with this function. The error domain is #G_REGEX_ERROR.Free the return value with
GLib.Error.free
().New in version 3.10.
- get_settings()¶
- Returns:
the search settings.
- Return type:
New in version 3.10.
- replace(match_start, match_end, replace, replace_length)¶
- Parameters:
match_start (
Gtk.TextIter
) – the start of the match to replace.match_end (
Gtk.TextIter
) – the end of the match to replace.replace (
str
) – the replacement text.replace_length (
int
) – the length of replace in bytes, or -1.
- Raises:
- Returns:
whether the match has been replaced.
- Return type:
Replaces a search match by another text. If match_start and match_end doesn’t correspond to a search match,
False
is returned.For a regular expression replacement, you can check if replace is valid by calling
GLib.Regex.check_replacement
(). The replace text can contain backreferences; read theGLib.Regex.replace
() documentation for more details.New in version 3.10.
Deprecated since version 3.22: Use
GtkSource.SearchContext.replace2
() instead.
- replace2(match_start, match_end, replace, replace_length)¶
- Parameters:
match_start (
Gtk.TextIter
) – the start of the match to replace.match_end (
Gtk.TextIter
) – the end of the match to replace.replace (
str
) – the replacement text.replace_length (
int
) – the length of replace in bytes, or -1.
- Raises:
- Returns:
whether the match has been replaced.
- Return type:
Replaces a search match by another text. If match_start and match_end doesn’t correspond to a search match,
False
is returned.Unlike with
GtkSource.SearchContext.replace
(), the 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; read theGLib.Regex.replace
() documentation for more details.New in version 3.22.
- replace_all(replace, replace_length)¶
- Parameters:
- Raises:
- Returns:
the number of replaced matches.
- Return type:
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
GLib.Regex.check_replacement
(). The replace text can contain backreferences; read theGLib.Regex.replace
() documentation for more details.New in version 3.10.
- set_highlight(highlight)¶
- Parameters:
highlight (
bool
) – the setting.
Enables or disables the search occurrences highlighting.
New in version 3.10.
- set_match_style(match_style)¶
- Parameters:
match_style (
GtkSource.Style
orNone
) – aGtkSource.Style
, orNone
.
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, useGtkSource.SearchContext.set_highlight
().New in version 3.16.
- set_settings(settings)¶
- Parameters:
settings (
GtkSource.SearchSettings
orNone
) – the newGtkSource.SearchSettings
, orNone
.
Associate a
GtkSource.SearchSettings
with the search context. If settings isNone
, a new one will be created.The search context holds a reference to settings.
New in version 3.10.
Deprecated since version 3.24: The
GtkSource.SearchContext
:settings
property will become a construct-only property in a future version. Create a newGtkSource.SearchContext
instead, or change theGtkSource.SearchSettings
properties. When theGtkSource.SearchContext
:settings
property will become construct-only, it will be possible to simplify some code that needed to listen to the notify::settings signal.
Property Details¶
- GtkSource.SearchContext.props.buffer¶
- Name:
buffer
- Type:
- Default Value:
- Flags:
The
GtkSource.Buffer
associated to the search context.New in version 3.10.
- GtkSource.SearchContext.props.highlight¶
-
Highlight the search occurrences.
New in version 3.10.
- GtkSource.SearchContext.props.match_style¶
- Name:
match-style
- Type:
- Default Value:
- Flags:
A
GtkSource.Style
, orNone
for theme’s scheme default style.New in version 3.16.
- GtkSource.SearchContext.props.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.
New in version 3.10.
- GtkSource.SearchContext.props.regex_error¶
-
If the regex search pattern doesn’t follow all the rules, this property will be set. If the pattern is valid, the value is
None
.Free with
GLib.Error.free
().New in version 3.10.
- GtkSource.SearchContext.props.settings¶
- Name:
settings
- Type:
- Default Value:
- Flags:
The
GtkSource.SearchSettings
associated to the search context.New in version 3.10.