Thunarx.Renamer

Thunarx.Renamer — Thunarx.Renamer Reference

Synopsis

 Thunarx.Renamer extends, GObject.GObject {
  get_help_name();
  set_help_url(help_url);
  get_name();
  set_name(name);
  do_process(file,
             text,
             index);

  do_load(settings);
  do_save(settings);
  do_get_menu_items(window,
                    files);

  do_changed();
}

Ancestry

+-- GObject.GObject
    +-- Thunarx.Renamer

Description

The abstract base class Thunarx.Renamer is implemented by extensions which provide additional bulk renamers that should be used in the bulk rename dialog.

Derived classes must override the do_process() method, which is called by the bulk rename dialog for every file to generate a new name. For example, the ThunarSbrReplaceRenamer class included in the thunar-sbr plugin (which is part of the Thunar distribution) provides a bulk renamer, named Search & Replace, which allows the user to rename multiple files by searching for a pattern in each file name and, if the pattern is found, replacing it with the specified replacement text.

Properties

"help-url" The URL to the documentation of this ThunarxRenamer. Derived classes can set this property to point to the documentation for the specific renamer. The documentation of the specific renamer in turn should contain a link to the general Thunar renamer documentation. May also be unset, in which case the general Thunar renamer documentation will be shown when the user clicks the "Help" button. Default value: NULL Read-Write
"name" The user visible name of the renamer, that is displayed in the bulk rename dialog of the file manager. Derived classes should set a useful name. Default value: NULL Read-Write

Signals

"changed"

callback();

Passive Methods

Thunarx.Renamer.do_process

do_process(file,
           text,
           index);

file :

the Thunarx.FileInfo for the file whose new name - according to renamer - should be determined.

text :

the part of the filename to which the renamer should be applied.

index :

the index of the file in the list, used for renamers that work on numbering.

Returns :

the string with which to replace text.

Determines the replacement for text (which is the relevant part of the full file name, i.e. either the suffix, the name or the name and the suffix).


Thunarx.Renamer.do_load

do_load(settings);

settings :

a dictionary which contains the previously saved settings for renamer as key/value pairs of strings.

Tells renamer to load its internal settings from the specified settings. The settings hash table contains previously saved settings, see Thunarx.Renamer.do_save(), as key/value pairs of strings. That is, both the keys and the values are strings.

Implementations of Thunarx.Renamer may decide to override this method to perform custom loading of settings. If you do not override this method, the default method of Thunarx.Renamer will be used, which simply loads all GObject properties provided by renamers class (excluding the ones provided by the parent classes) from the settings. The GObject properties must be transformable to strings and from strings.

If you decide to override this method for your Thunarx.Renamer implementation, you should also override Thunarx.Renamer.do_save().


Thunarx.Renamer.do_save

do_save(settings);

settings :

a dictionary to which the current settings of renamer should be stored as key/value pairs of strings.

Thunarx.Renamer.do_get_menu_items

do_get_menu_items(window,
                  files);

window :

a Gtk.Window

files :

a list of Thunarx.FileInfo objects

Returns :

the list of ThunarxMenuItems provided by renamer for the given list of files

Returns the list of Thunarx.MenuItem objects provided by renamer for the given list of files. By default, this method returns NULL (the empty list), but derived classes may override this method to provide additional actions for files in the bulk renamer dialog list.

The returned Thunarx.MenuItem objects will be displayed in the file's context menu of the bulk renamer dialog, when this renamer is active. For example, an ID3-Tag based renamer may add an action "Edit Tags" to the context menus of supported media files and, when activated, display a dialog (which should be transient and modal for window, if not NULL), which allows the users to edit media file tags on-the-fly.

Derived classes that override this method should always check first if all the Thunarx.FileInfo objects in the list of files are supported, and only return actions that can be performed on this specific list of files. For example, the ID3-Tag renamer mentioned above, should first check whether all items in files are actually audio files. The Thunarx.FileInfo.has_mime_type() of the Thunarx.FileInfo interface can be used to easily test whether a file in the files list is of a certain MIME type.

Some actions may only work properly if only a single file ist selected (for example, the ID3-Tag renamer will probably only supporting editing one file at a time). In this case you have basicly two options: Either you can return NULL here if files does not contain exactly one item, or you can return the actions as usual, but make them insensitive, using: action.set_sensitive(False)

The latter has the advantage that the user will still notice the existance of the action and probably realize that it can only be applied to a single item at once.

The Thunarx.MenuItem objects returned from this method must be namespaced with the module to avoid collision with internal file manager actions and actions provided by other extensions. For example, the menu action provided by the ID3-Tag renamer mentioned above, should be named TagRenamer::edit-tags (if TagRenamer is the class name). For additional information about the way ThunarxMenuItems should be returned from extensions and the way they are used, read the description of the Thunarx.MenuProvider interface or read the introduction provided with this reference manual.


Thunarx.Renamer.do_changed

do_changed();

Returns :

This method should be used by derived classes to emit the "changed" signal for renamer. See the documentation of the "changed" signal for details.

Active Methods

Thunarx.Renamer.get_help_url

get_help_url();

Returns :

the URL of the documentation for renamer.

Returns the URL of the documentation for renamer or NULL if no specific documentation is available for renamer and the general documentation of the Thunar renamers should be displayed instead.


Thunarx.Renamer.set_help_url

set_help_url(help_url);

Returns :

the new URL for the documentation for renamer.

The URL to the documentation of this Thunarx.Renamer. Derived classes can set this property to point to the documentation for the specific renamer. The documentation of the specific renamer in turn should contain a link to the general Thunar renamer documentation.

May also be unset, in which case the general Thunar renamer documentation will be shown when the user clicks the "Help" button.


Thunarx.Renamer.get_name

get_name();

Returns :

the user visible name for renamer.

Returns the user visible name for renamer, previously set with Thunarx.Renamer.set_name().


Thunarx.Renamer.set_name

set_name();

name :

the new user visible name for renamer.

Returns :

the new user visible name for renamer.

Sets the user visible name for renamer to name.

Signal Details

The "changed" Thunarx.Renamer Signal

Derived classes should emit this signal using the Thunarx.Renamer.do_changed() method whenever the user changed a setting in the renamer GUI.

The file manager will then invoke Thunarx.Renamer.do_process() for all files that should be renamed and update the preview.