Part II. Writing Extensions

# Writing Extensions

This section explains the basic steps required to write an extension for the Thunar File Manager using the C language interface. It is just a short introduction and not meant to provide extensive details about the internal workings of the file manager.

## Basic Concepts

### Extensions and Providers

Thunar Extensions are shared libraries that extend the basic functionality provided by the Thunar File Manager. An extension exports one or more GObjects, called providers to Thunar.

Providers implement one or more of the GInterfaces included with the `thunarx` library. The currently exported interfaces include the ThunarxMenuProvider for adding context menu items to the file views and the ThunarxPropertyPageProvider for adding pages to the file properties dialog.

### ThunarxFileInfo

Thunar passes file references to the provider using ThunarxFileInfo objects. The ThunarxFileInfo interface provides access to the file information that Thunar has already read - mime type, URI, name, etc. Extensions should use the data from from the ThunarxFileInfo rather than reading it themselves, to prevent excessive I/O.

There is exactly one ThunarxFileInfo per file, and it is kept around for as long as Thunar is interested in the file. Extensions can use this information to manage lifecycles of its own data - e.g. when the ThunarxFileInfo goes away, it is safe for the extension to forget any private data for that file.

### Names

Most objects created by the extensions need names, e.g. the GtkActions returned from the ThunarxMenuProviders. These names must be namespaced with the name of the extension. For example the main action returned from the OpenTerminal extension should be called `OpenTerminal::open-terminal`. The namespace must be global among the providers exported by a certain extension.

### Types

Thunar extensions are loaded as GTypeModules. This means that all GTypes created by the extension must be registered with the GTypeModule, using `g_type_module_register_type()` function rather than `g_type_register_static()`. All types exported by an extension must be registered in `thunar_extension_initialize()`.