GtkSource.FileLoader

g GObject.Object GObject.Object GtkSource.FileLoader GtkSource.FileLoader GObject.Object->GtkSource.FileLoader

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (buffer, file)

class

new_from_stream (buffer, file, stream)

get_buffer ()

get_compression_type ()

get_encoding ()

get_file ()

get_input_stream ()

get_location ()

get_max_size ()

get_newline_type ()

load_async (io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)

load_finish (result)

set_candidate_encodings (candidate_encodings)

set_max_size (max_size)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

buffer

GtkSource.Buffer

r/w/co

file

GtkSource.File

r/w/co

input-stream

Gio.InputStream

r/w/co

location

Gio.File

r/w/co

max-size

int

r/w/en

Maximum expanded size in bytes

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class GtkSource.FileLoader(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

GtkSource.FileLoaderClass

Load a file into a GtkSource.Buffer.

A GtkSourceFileLoader object permits to load the contents of a [iface`Gio`.File] or a [class`Gio`.InputStream] into a [class`Buffer`].

A file loader should be used only for one load operation, including errors handling. If an error occurs, you can reconfigure the loader and relaunch the operation with [method`FileLoader`.load_async].

Running a GtkSourceFileLoader is an undoable action for the [class`Buffer`].

After a file loading, the buffer is reset to the contents provided by the [iface`Gio`.File] or [class`Gio`.InputStream], so the buffer is set as “unmodified”, that is, [method`Gtk`.TextBuffer.set_modified] is called with False. If the contents isn’t saved somewhere (for example if you load from stdin), then you should probably call [method`Gtk`.TextBuffer.set_modified] with True after calling [method`FileLoader`.load_finish].

classmethod new(buffer, file)
Parameters:
Returns:

a new GtkSource.FileLoader object.

Return type:

GtkSource.FileLoader

Creates a new GtkSourceFileLoader object. The contents is read from the [class`File`]’s location.

If not already done, call [method`File`.set_location] before calling this constructor. The previous location is anyway not needed, because as soon as the file loading begins, the buffer is emptied.

For path-based [iface`Gio`.File] instances, the regular-file safety check is subject to time-of-check/time-of-use races if the path is replaced while the load operation is running.

classmethod new_from_stream(buffer, file, stream)
Parameters:
Returns:

a new GtkSource.FileLoader object.

Return type:

GtkSource.FileLoader

Creates a new GtkSource.FileLoader object. The contents is read from stream.

get_buffer()
Returns:

the GtkSource.Buffer to load the contents into.

Return type:

GtkSource.Buffer

get_compression_type()
Returns:

the detected compression type.

Return type:

GtkSource.CompressionType

get_encoding()
Returns:

the detected file encoding.

Return type:

GtkSource.Encoding

get_file()
Returns:

the GtkSource.File.

Return type:

GtkSource.File

get_input_stream()
Returns:

the Gio.InputStream to load, or None if a Gio.File is used.

Return type:

Gio.InputStream or None

get_location()
Returns:

the Gio.File to load, or None if an input stream is used.

Return type:

Gio.File or None

get_max_size()
Returns:

the maximum expanded size in bytes, or 0 if the limit is disabled.

Return type:

int

Gets the maximum expanded size that self will insert into the buffer.

Added in version 5.22.

get_newline_type()
Returns:

the detected newline type.

Return type:

GtkSource.NewlineType

load_async(io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)
Parameters:

Loads asynchronously the file or input stream contents into the [class`Buffer`].

See the [iface`Gio`.AsyncResult] documentation to know how to use this function.

load_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult.

Raises:

GLib.Error

Returns:

whether the contents has been loaded successfully.

Return type:

bool

Finishes a file loading started with [method`FileLoader`.load_async].

If the contents has been loaded, the following [class`File`] properties will be updated: the location, the encoding, the newline type and the compression type.

set_candidate_encodings(candidate_encodings)
Parameters:

candidate_encodings ([GtkSource.Encoding]) – a list of GtkSource.Encoding s.

Sets the candidate encodings for the file loading.

The encodings are tried in the same order as the list.

For convenience, candidate_encodings can contain duplicates. Only the first occurrence of a duplicated encoding is kept in the list.

By default the candidate encodings are (in that order in the list):

If set, the [class`File`]’s encoding as returned by [method`File`.get_encoding].

The default candidates as returned by [func`Encoding`.get_default_candidates].

set_max_size(max_size)
Parameters:

max_size (int) – maximum expanded size in bytes, or 0 to disable the limit.

Sets the maximum expanded size that self will insert into the buffer.

The limit is checked after decompression, so compressed files are limited by the size of their uncompressed contents rather than their on-disk size.

Added in version 5.22.

Property Details

GtkSource.FileLoader.props.buffer
Name:

buffer

Type:

GtkSource.Buffer

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The GtkSource.Buffer to load the contents into. The GtkSource.FileLoader object has a weak reference to the buffer.

GtkSource.FileLoader.props.file
Name:

file

Type:

GtkSource.File

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The GtkSource.File. The GtkSource.FileLoader object has a weak reference to the file.

GtkSource.FileLoader.props.input_stream
Name:

input-stream

Type:

Gio.InputStream

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The Gio.InputStream to load. Useful for reading stdin. If this property is set, the GtkSource.FileLoader :location property is ignored.

GtkSource.FileLoader.props.location
Name:

location

Type:

Gio.File

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The Gio.File to load. If the GtkSource.FileLoader :input-stream is None, by default the location is taken from the GtkSource.File at construction time.

GtkSource.FileLoader.props.max_size
Name:

max-size

Type:

int

Default Value:

1073741824

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The maximum expanded size, in bytes, that the loader will insert into the buffer. A value of 0 disables the limit.

Added in version 5.22.