GtkSourceFileLoader

GtkSourceFileLoader — Load a file into a GtkSourceBuffer

Functions

Properties

GtkSourceBuffer * buffer Read / Write / Construct Only
GtkSourceFile * file Read / Write / Construct Only
GInputStream * input-stream Read / Write / Construct Only
GFile * location Read / Write / Construct Only

Types and Values

Object Hierarchy

    GEnum
    ╰── GtkSourceFileLoaderError
    GObject
    ╰── GtkSourceFileLoader

Includes

#include <gtksourceview/gtksource.h>

Description

A GtkSourceFileLoader object permits to load the contents of a GFile or a GInputStream into a GtkSourceBuffer.

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 gtk_source_file_loader_load_async().

Running a GtkSourceFileLoader is an undoable action for the GtkSourceBuffer. That is, gtk_source_buffer_begin_not_undoable_action() and gtk_source_buffer_end_not_undoable_action() are called, which delete the undo/redo history.

After a file loading, the buffer is reset to the contents provided by the GFile or GInputStream, so the buffer is set as “unmodified”, that is, gtk_text_buffer_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 gtk_text_buffer_set_modified() with TRUE after calling gtk_source_file_loader_load_finish().

Functions

gtk_source_file_loader_new ()

GtkSourceFileLoader *
gtk_source_file_loader_new (GtkSourceBuffer *buffer,
                            GtkSourceFile *file);

Creates a new GtkSourceFileLoader object. The contents is read from the GtkSourceFile's location. If not already done, call gtk_source_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.

Parameters

buffer

the GtkSourceBuffer to load the contents into.

 

file

the GtkSourceFile.

 

Returns

a new GtkSourceFileLoader object.

Since: 3.14


gtk_source_file_loader_new_from_stream ()

GtkSourceFileLoader *
gtk_source_file_loader_new_from_stream
                               (GtkSourceBuffer *buffer,
                                GtkSourceFile *file,
                                GInputStream *stream);

Creates a new GtkSourceFileLoader object. The contents is read from stream .

Parameters

buffer

the GtkSourceBuffer to load the contents into.

 

file

the GtkSourceFile.

 

stream

the GInputStream to load, e.g. stdin.

 

Returns

a new GtkSourceFileLoader object.

Since: 3.14


gtk_source_file_loader_set_candidate_encodings ()

void
gtk_source_file_loader_set_candidate_encodings
                               (GtkSourceFileLoader *loader,
                                GSList *candidate_encodings);

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):

  1. If set, the GtkSourceFile's encoding as returned by gtk_source_file_get_encoding().

  2. The default candidates as returned by gtk_source_encoding_get_default_candidates().

Parameters

loader

a GtkSourceFileLoader.

 

candidate_encodings

a list of GtkSourceEncodings.

[element-type GtkSourceEncoding]

Since: 3.14


gtk_source_file_loader_get_buffer ()

GtkSourceBuffer *
gtk_source_file_loader_get_buffer (GtkSourceFileLoader *loader);

Parameters

loader

a GtkSourceFileLoader.

 

Returns

the GtkSourceBuffer to load the contents into.

[transfer none]

Since: 3.14


gtk_source_file_loader_get_file ()

GtkSourceFile *
gtk_source_file_loader_get_file (GtkSourceFileLoader *loader);

Parameters

loader

a GtkSourceFileLoader.

 

Returns

the GtkSourceFile.

[transfer none]

Since: 3.14


gtk_source_file_loader_get_location ()

GFile *
gtk_source_file_loader_get_location (GtkSourceFileLoader *loader);

Parameters

loader

a GtkSourceFileLoader.

 

Returns

the GFile to load, or NULL if an input stream is used.

[nullable][transfer none]

Since: 3.14


gtk_source_file_loader_get_input_stream ()

GInputStream *
gtk_source_file_loader_get_input_stream
                               (GtkSourceFileLoader *loader);

Parameters

loader

a GtkSourceFileLoader.

 

Returns

the GInputStream to load, or NULL if a GFile is used.

[nullable][transfer none]

Since: 3.14


gtk_source_file_loader_load_async ()

void
gtk_source_file_loader_load_async (GtkSourceFileLoader *loader,
                                   gint io_priority,
                                   GCancellable *cancellable,
                                   GFileProgressCallback progress_callback,
                                   gpointer progress_callback_data,
                                   GDestroyNotify progress_callback_notify,
                                   GAsyncReadyCallback callback,
                                   gpointer user_data);

Loads asynchronously the file or input stream contents into the GtkSourceBuffer. See the GAsyncResult documentation to know how to use this function.

Parameters

loader

a GtkSourceFileLoader.

 

io_priority

the I/O priority of the request. E.g. G_PRIORITY_LOW, G_PRIORITY_DEFAULT or G_PRIORITY_HIGH.

 

cancellable

optional GCancellable object, NULL to ignore.

[nullable]

progress_callback

function to call back with progress information, or NULL if progress information is not needed.

[scope notified][nullable]

progress_callback_data

user data to pass to progress_callback .

[closure]

progress_callback_notify

function to call on progress_callback_data when the progress_callback is no longer needed, or NULL.

[nullable]

callback

a GAsyncReadyCallback to call when the request is satisfied.

[scope async]

user_data

user data to pass to callback .

 

Since: 3.14


gtk_source_file_loader_load_finish ()

gboolean
gtk_source_file_loader_load_finish (GtkSourceFileLoader *loader,
                                    GAsyncResult *result,
                                    GError **error);

Finishes a file loading started with gtk_source_file_loader_load_async().

If the contents has been loaded, the following GtkSourceFile properties will be updated: the location, the encoding, the newline type and the compression type.

Parameters

loader

a GtkSourceFileLoader.

 

result

a GAsyncResult.

 

error

a GError, or NULL.

 

Returns

whether the contents has been loaded successfully.

Since: 3.14


gtk_source_file_loader_get_encoding ()

const GtkSourceEncoding *
gtk_source_file_loader_get_encoding (GtkSourceFileLoader *loader);

Parameters

loader

a GtkSourceFileLoader.

 

Returns

the detected file encoding.

Since: 3.14


gtk_source_file_loader_get_newline_type ()

GtkSourceNewlineType
gtk_source_file_loader_get_newline_type
                               (GtkSourceFileLoader *loader);

Parameters

loader

a GtkSourceFileLoader.

 

Returns

the detected newline type.

Since: 3.14


gtk_source_file_loader_get_compression_type ()

GtkSourceCompressionType
gtk_source_file_loader_get_compression_type
                               (GtkSourceFileLoader *loader);

Parameters

loader

a GtkSourceFileLoader.

 

Returns

the detected compression type.

Since: 3.14

Types and Values

GtkSourceFileLoader

typedef struct _GtkSourceFileLoader GtkSourceFileLoader;

GTK_SOURCE_FILE_LOADER_ERROR

#define GTK_SOURCE_FILE_LOADER_ERROR gtk_source_file_loader_error_quark ()

enum GtkSourceFileLoaderError

An error code used with the GTK_SOURCE_FILE_LOADER_ERROR domain.

Members

GTK_SOURCE_FILE_LOADER_ERROR_TOO_BIG

The file is too big.

 

GTK_SOURCE_FILE_LOADER_ERROR_ENCODING_AUTO_DETECTION_FAILED

It is not possible to detect the encoding automatically.

 

GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK

There was an encoding conversion error and it was needed to use a fallback character.

 

Property Details

The “buffer” property

  “buffer”                   GtkSourceBuffer *

The GtkSourceBuffer to load the contents into. The GtkSourceFileLoader object has a weak reference to the buffer.

Owner: GtkSourceFileLoader

Flags: Read / Write / Construct Only

Since: 3.14


The “file” property

  “file”                     GtkSourceFile *

The GtkSourceFile. The GtkSourceFileLoader object has a weak reference to the file.

Owner: GtkSourceFileLoader

Flags: Read / Write / Construct Only

Since: 3.14


The “input-stream” property

  “input-stream”             GInputStream *

The GInputStream to load. Useful for reading stdin. If this property is set, the “location” property is ignored.

Owner: GtkSourceFileLoader

Flags: Read / Write / Construct Only

Since: 3.14


The “location” property

  “location”                 GFile *

The GFile to load. If the “input-stream” is NULL, by default the location is taken from the GtkSourceFile at construction time.

Owner: GtkSourceFileLoader

Flags: Read / Write / Construct Only

Since: 3.14

See Also

GtkSourceFile, GtkSourceFileSaver