Next: Executing external tools, Previous: Defining default command line, Up: Adding support for new tools
The user has to be able to specify which switches to use with the tool. If the tool is simply called through custom menus, you might want to hard code some or all of the switches. However, in the general case it is better to use the project properties editor, so that project-specific switches can be specified.
This is what GPS does by default for Ada, C and C++. You can find in the GPS installation directory how the switches for these languages are defined in an XML file. These provide extended examples of the use of customization files.
The switches editor in the project properties editor provides a powerful interface to the command line, where the user can edit the command line both as text and through GUI widgets.
The switches are declared through the <switches>
tag in the
customization file, which must be a child of a <tool>
tag as described
above.
This <switches>
tag accepts the following attributes:
lines (default value is 1)
columns (default value is 1)
separator (default value is "")
" "
rather than " "
,
since XML parser must normalize the latter to the empty string when reading
the XML file.
use_scrolled_window (Default value is false)
show_command_line (Default value is true)
switch_char (Default value is "-")
sections (Default value is empty)
This <switches>
tag can have any number of child tag, among the
following. They can be repeated multiple times if you need several check boxes.
For consistency, most of these child tags accept attributes among the
following:
line (default value is 1)
lines
above.
column (default value is 1)
columns
above.
label (mandatory)
switch (mandatory)
combo
and spin
below.
This switch shouldn't contain any space.
switch-off (default value is empty)
<check>
tags, and indicates the switch
used for deactivating the concerned feature. This is useful for features that
are on by default on certain occasions, but can be individually deactivated.
section (default value is empty)
tip (default value is empty)
<tip>
whose value will contain the text to be displayed. The
advantage of the latter is that the text formatting is then kept.
before (default value is "false")
min (default value is 1)
<spin>
tags, and indicates the minimum
value authorized for that switch.
max (default value is 1)
<spin>
tags, and indicates the maximum
value authorized for that switch.
default (default value is 1)
<check>
and <spin>
tags. See the
description below.
noswitch (default is empty)
<combo>
tags, and described below.
nodigit (default is empty)
<combo>
tags, and described below.
value (mandatory)
<combo-entry>
tags.
separator (default is the value given to <switches>
<switches>
.
Here are the valid children for <switches>
:
<title>
line
and column
attributes, is used
to give a name to a specific frame.
The value of the tag is the title itself. You do not have to specify
a name, and this can be left to an empty value.
Extra attributes for <title>
are:
line-span (default value is 1)
column-span (default value is 1)
<check>
line
, column
, label
, switch
,
switch-off
, section
, default
, before
and tip
attributes.
This tag doesn't have any value. An optional <tip>
child can be present.
It creates a toggle button. When the latter is active, the text defined in the
switch attribute is added as is to the command line. The switch can be also
activated by default (default
attribute is "on" or "true"). In this
case, deactivating the switch will add switch-off
to the command line.
<spin>
line
, column
, label
, switch
,
section
, tip
, min
, max
, separator
and
default
attributes.
This tag doesn't have any value. An optional <tip>
child can be present.
This switch will add the contents of the switch
attribute followed by
the current numeric value of the widget to the command line. This is typically
used to indicate indentation length for instance.
If the current value of the widget is equal to the default
attribute,
then nothing is added to the command line.
<radio>
line
and column
attributes. It groups any
number of children, each of which is associated with its own switch. However,
only one of the children can be selected at any given time.
The children must have the tag radio-entry
. This tag accepts the
attributes label
, switch
, section
, before
and
tip
. As a special case, the switch attribute can have an empty value
("") to indicate this is the default switch to use in this group of radio
buttons.
This tag doesn't have any value. An optional <tip>
child can also be
present.
<field>
line
, column
, label
, switch
,
section
, separator
, before
and tip
attributes.
This tag doesn't have any value. An optional <tip>
child can be present.
This tag describes a text edition field, which can
contain any text the user types. This text will be prefixed by the value of
the switch
attribute, and the separator (by default nothing). If no text
is entered in the field
by the user, nothing is put on the command line.
This tag accepts two extra attributes:
as-directory (optional)
as-file (optional)
as-directory
, but opens a dialog to
select a file instead of a directory. If both attributes are set to "true",
the user will select a file.
<combo>
line
, column
, label
, switch
,
section
, before
, tip
, noswitch
, separator
and nodigit
attributes.
The tag <combo>
accepts any number of combo-entry
children tags,
each of which accepts the label
and value
attribute. An optional
<tip>
child can also be present.
The text inserted in the command line is the text from the switch
attribute, concatenated with the text of the value
attribute for the
currently selected entry. If the value of the current entry is the same
as that of the nodigit
attribute, then only the text of the
switch
attribute is put on the command line. This is in fact necessary
to interpret the gcc switch "-O" as "-O1".
If the value of the current entry is that of the noswitch
attribute,
then nothing is put in the command line.
<popup>
line
, column
, label
, lines
and columns
attributes. This displays a simply button that, when
clicked, displays a dialog with some extra switches. This dialog, just as the
switches editor itself, is organizes into lines and columns of frames, the
number of which is provided by the lines
and columns
attributes.
This tag accepts any number of children, which are the same as the
<switches>
attribute itself.
<dependency>
It has its own set of attributes:
master-page master-switch master-section
<check>
or <field>
. If it is part of a section, then 'master-section' needs
to be defined. If the check button is selected, it forces the
selection of the slave check button. Likewise, if the field is set to
any value, it forces the selection of the slave.
slave-page slave-switch slave-section
<check>
.
master-status slave-status
<default-value-dependency>
It has its own set of attributes:
master-switch
master-switch
is
present in the command line, then the switch's default status of
slave-switch
is modified accordingly.
slave-switch
master-switch
. This
needs to be a switch already defined in a <switch>
tag. It can match
its 'switch' or 'switch-off' attributes. In the latter case, the
slave-switch default value is deactivated if master-switch is present.
<expansion>
It is easier to explain it through an example. Specifying the GNAT switch "-gnatyy" is equivalent to specifying "-gnaty3abcefhiklmnprst". This is in fact a style check switch, with a number of default values. But it is also equivalent to decomposing it into several switches, as in "-gnatya", "-gnatyb", ...; With this information, GPS will try to keep the command line length as short as possible, to keep it readable.
Both these aspects are defined in a unique <expansion>
tag, which
accepts two attributes: switch
is mandatory, and alias
is
optional. Alias contains the text "-gnatyabcefhiklmnprst" in our example.
There are two possible uses for this tag:
The same "switch" attribute can be used in two expansion nodes if you want to combine the behavior.
For historical reasons, this tag accepts <entry>
children, but these
are no longer used.