Functions

  encoding_get_all ()
  encoding_get_default_candidates ()
  file_loader_error_quark ()
  file_saver_error_quark ()
  finalize ()
  init ()
  iter_get_line_indentation (iter)
  menu_shell_append_edit_actions (menu_shell)
  metadata_manager_init (metadata_path)
  metadata_manager_shutdown ()
  utils_get_file_extension (filename)
  utils_get_file_shortname (filename)
  utils_replace_home_dir_with_tilde (filename)
  utils_str_end_truncate (str, truncate_length)
  utils_str_middle_truncate (str, truncate_length)
  utils_str_replace (string, search, replacement)

Details

Tepl.encoding_get_all()
Returns:a list of Tepl.Encoding’s.
Return type:[Tepl.Encoding]

Gets a list of all encodings known by Tepl.Encoding.

New in version 2.0.

Tepl.encoding_get_default_candidates()
Returns:the list of default candidate encodings.
Return type:[Tepl.Encoding]

Gets the list of default candidate encodings to try when loading a file. See GtkSource.FileLoader.set_candidate_encodings().

This function returns a different list depending on the current locale (i.e. language, country and default encoding). The UTF-8 encoding and the current locale encoding are guaranteed to be present in the returned list.

Note that the returned list doesn’t contain all encodings known by Tepl.Encoding, it is a limited list that contains only the encodings that have the most likelihood to fit for the current locale.

New in version 2.0.

Tepl.file_loader_error_quark()
Return type:int
Tepl.file_saver_error_quark()
Return type:int
Tepl.finalize()

Free the resources allocated by Tepl. For example it unrefs the singleton objects. It also properly shutdowns the metadata manager by calling Tepl.metadata_manager_shutdown().

This function also calls Amtk.finalize() and GtkSource.finalize().

It is not mandatory to call this function, it’s just to be friendlier to memory debugging tools (but if you don’t call this function and you use the metadata manager, you should call Tepl.metadata_manager_shutdown()). This function is meant to be called at the end of main(). It can be called several times.

New in version 3.0.

Tepl.init()

Initializes the Tepl library (e.g. for the internationalization).

This function can be called several times, but is meant to be called at the beginning of main(), before any other Tepl function call.

This function also calls Amtk.init() and GtkSource.init().

New in version 3.0.

Tepl.iter_get_line_indentation(iter)
Parameters:iter (Gtk.TextIter) – a Gtk.TextIter.
Returns:the line indentation at iter. Free with GLib.free().
Return type:str

Gets the indentation, as a string, of the line at iter. iter can be anywhere in the line.

Possible use-case: to implement an action that inserts some text in a Gtk.TextBuffer. If the text to insert spans multiple lines, it is usually desired to keep the same indentation level.

New in version 2.0.

Tepl.menu_shell_append_edit_actions(menu_shell)
Parameters:menu_shell (Gtk.MenuShell) – a Gtk.MenuShell.

Appends Gtk.MenuItem’s to menu_shell for the following Gio.Action’s:

  • "win.tepl-cut"
  • "win.tepl-copy"
  • "win.tepl-paste"
  • "win.tepl-delete"
  • "win.tepl-select-all"

See the ‘list of GActions implemented in TeplApplicationWindow [tepl-application-window-gactions]’. This function correctly uses the Amtk.FactoryFlags.IGNORE_ACCELS_FOR_APP flag to create the Gtk.MenuItem’s.

New in version 3.0.

Tepl.metadata_manager_init(metadata_path)
Parameters:metadata_path (str) – the filename where the metadata is stored.

This function initializes the metadata manager.

The metadata_path must be different for each process. It is advised for your application to rely on Gio.Application process uniqueness.

A good place to store the metadata is in a sub-directory of the user data directory. See GLib.get_user_data_dir().

New in version 1.0.

Tepl.metadata_manager_shutdown()

This function saves synchronously metadata if they need to be saved, and frees the internal data of the metadata manager.

See also Tepl.finalize(), which calls this function.

New in version 1.0.

Tepl.utils_get_file_extension(filename)
Parameters:filename (str) – a filename.
Returns:the filename’s extension with the dot, in lowercase. Free with GLib.free().
Return type:str

Examples:

  • “file.pdf” returns “.pdf”.
  • “file.PDF” returns “.pdf”.
  • “file.tar.gz” returns “.gz”.
  • “path/to/file.pdf” returns “.pdf”.
  • “file” (without an extension) returns “” (the empty string).

New in version 4.4.

Tepl.utils_get_file_shortname(filename)
Parameters:filename (str) – a filename.
Returns:the filename without its extension. Free with GLib.free().
Return type:str

Returns filename without its extension. With the “extension” having the same definition as in Tepl.utils_get_file_extension(); in other words it returns the other part of filename.

New in version 4.4.

Tepl.utils_replace_home_dir_with_tilde(filename)
Parameters:filename (str) – the filename.
Returns:the new filename. Free with GLib.free().
Return type:str

Replaces the home directory with a tilde, if the home directory is present in the filename.

New in version 4.4.

Tepl.utils_str_end_truncate(str, truncate_length)
Parameters:
  • str (str) – a UTF-8 string.
  • truncate_length (int) – truncate the string at that length, in UTF-8 characters (not bytes).
Returns:

the truncated string. Free with GLib.free().

Return type:

str

Like Tepl.utils_str_middle_truncate() but the “…” character is at the end.

New in version 4.4.

Tepl.utils_str_middle_truncate(str, truncate_length)
Parameters:
  • str (str) – a UTF-8 string.
  • truncate_length (int) – truncate the string at that length, in UTF-8 characters (not bytes).
Returns:

the truncated string. Free with GLib.free().

Return type:

str

If str is longer than truncate_length, then this function returns str truncated in the middle with a “…” character. Otherwise it just returns a copy of str.

New in version 4.4.

Tepl.utils_str_replace(string, search, replacement)
Parameters:
  • string (str) – a string
  • search (str) – the search string
  • replacement (str) – the replacement string
Returns:

A newly allocated string with the replacements. Free with GLib.free().

Return type:

str

Replaces all occurences of search by replacement.

The function does only one pass, for example:

tepl_utils_str_replace ("aaaa", "aa", "a");

returns “aa”, not “a”.

New in version 4.4.