Next: Creating themes, Previous: Binding actions to keys, Up: Customizing through XML and Python files
GPS has a number of predefined preferences to configure its behavior and its appearance. They are all customizable through the Edit->Preferences menu.
However, you might wish to add your own kind of preferences for your extension modules. This can easily be done through the usual GPS customization files. Preferences are different from project attributes (see Defining project attributes), in that the latter will vary depending on which project is loaded by the user, whereas preferences are always set to the same value no matter what project is loaded.
Such preferences are created with the <preference>
tag, which takes
a number of attributes.
name (mandatory)
GPS.Preference
class in the
GPS shell or python. There are a few limitation to the form of these names:
they cannot contain space or underscore characters. You should replace the
latter with minus signs for instance.
page (optional, default is "General")
Subpages are references by separating pages name with colons (':').
default (optional, default depends on the type of the preference)
tip (optional, default is "")
label (mandatory)
type (mandatory)
The preference can be True or False.
The preference is an integer. Two optional attributes can be specified for
<preference>
, "minimum" and "maximum", which define the range of
valid values for that integer. Default values are 0 and 10 respectively.
The preference is a string, which might contain any value
The preference is a color name, in the format of a named color such as "yellow", or a string similar to "#RRGGBB", where RR is the red component, GG is the green component, and BB is the blue component
The preference is a font
The preference is a string, whose value is chosen among a static list of
possible values. Each possible value is defined in a <choice>
child
of the <preference>
node.
Here is an example that defines a few new preferences:
<?xml version="1.0"?> <custom> <preference name="my-int" page="Editor" label="My Integer" default="30" minimum="20" maximum="35" page="Manu" type="integer" /> <preference name="my-enum" page="Editor:Fonts & Colors" label="My Enum" default="1" type="choices" > <choice>Choice1</choice> <choice>Choice2</choice> <!-- The default choice --> <choice>Choice3</choice> </preference> </custom>
The values of the above preferences can be queries in the scripting languages:
Preference "my-enum" Preference.get %1
val = GPS.Preference ("my-enum").get () val2 = GPS.Preference ("my-int").get ()
You can force specific default values for the preferences in the customization
files through the <pref>
tag. This is the same tag that is used by
GPS itself when it saves the preferences edited through the preferences
dialog.
This tag requires on attribute:
name
It accepts no child tag, but the value of the <pref>
tag defines the
default value of the preference, which will be used unless the user has
overridden it in his own preferences file.
Any setting that you have defined in the customization files will be overridden by the user's preferences file itself, unless the user was still using the default value of that preference.
This <pref>
tag is mostly intended for use through the themes
(see Creating themes).