BaseExtensions can be used to show or hide elements in ribbon (even though they are connected to other Alloy Plugins). Using this, we can filter events or hide buttons in ribbon if, for instance, a shape or a document property is not present. To filter events and show/hide buttons, the newest BaseExtensions and Alloy plugins are required.
Visible vs. enable
We support both visible
and enable
. If you use visible
when filtering, the button will be either shown or hidden. In contrast, when enable
is used to filter, the button will be either enabled or disabled. Thus, the button will always be visible in ribbon when using enable
, but depending on what is defined in the filter, the user will either be able to click at the button or the button will be gray and not clickable.
Document property example illustrating the syntax:
visible-1-type="documentprop"
(type of element - see supported elements here)
visible-1-key-1="document property key"
(name of document property)
visible-1-value-1="document property value"
(value of document property)
The value field is optional. If it is not present, any value for the document property will be accepted (empty included).
Here is an example:
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="documentprop"
visible-1-key-1="test"
visible-1-value-1="1234"
visible-1-value-2="5678"
>
Style controlled button
This button will only be visible if the style "wdStyleNormal" is present.
<Button label="Body Text"
visible="BaseExtensions:any"
visible-1-type="styles"
visible-1-key="wdStyleNormal"
>
Document property controlled button
In the example below, the button will be visible in ribbon if the document property "TemplafyLanguageCode" with "de-DE" as value exists,
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="documentprop"
visible-1-key="TemplafyLanguageCode"
visible-1-value-1="de-DE"
>
Example with "contains"-logic
We support evaluating multiple document properties by adding Contains.
before the name of the document property in the visible-X-key
parameter. For instance, if the visibility should depend on the presence of any property containing the prefix "Omni_":
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="documentprop"
visible-1-key="Contains.Omni_"
>
Example with built-in document property
We support referring to a built-in document property by adding BuiltIn.
before the name of the document property in the visible-X-key
parameter. For instance, if the visibility should be depended on the built in document property called Title, the configuration should look like this:
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="documentprop"
visible-1-key="BuiltIn.Title"
visible-1-value-1="My doc title"
>
Document property controlled event
This logic can also be used in events. Here is an example:
<event type="BaseExtensions:any"
visible="BaseExtensions:any"
visible-1-type="documentprop"
visible-1-key="WordColor"
>
This event will only be executed if the document property "WordColor" is present in the opened document.
Multiple control elements
It is possible to utilize multiple control elements in one element:
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="styles"
visible-1-key="wdStyleNormal"
visible-2-type="documentprop"
visible-2-key="SD,SD2"
>
This will only show if the wdStyleNormal and the SD and SD2 document properties are present.
Also, both visible
and enable
can be used at the same time in a button or an event. Here is an example:
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="lang"
visible-1-key-1="wdNorwegianBokmol"
enable="BaseExtensions:any"
enable-1-type="documentprop"
enable-1-key-1="SettInnRad"
>
Here, the button will only be visible and enabled if the language is set to Norwegian (Bokmål) and a document property called SettInnRad is present.
Office version controlled button
We are able to control the visibility based on the version of Office. The example below illustrates that the button will only be visible if the installed Office version is greater or equal to 15.
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="OfficeVersion"
visible-1-value-1="gt15">
</Button>
The value determines which version of Office that are accepted in order to make the button visible. There are various options to set as value for this type of visibility, which is shown below. The # refers to the number.
gt##
(greater than given version number)gte##
(greater than or equal given version number)lt##
(less than given version number)lte##
(less than or equal given version number)eq##
(equal given version number)
This feature looks at the name of the used Office version. To find the version of the version, open a Office program and go to Files -> Account -> About, and then an interface will prompt:
Document compatibility controlled button (W)
Using below we are able to control visibility based the document compatibility version rather than the installed Office version as described above.
visible="BaseExtensions:any"
visible-1-type="compatibilitymode"
visible-1-key-1="xx"
Click here to view compatibility options.
Language controlled button
Also, we are able to control whether modules in ribbon should be shown or hidden based on document language and inverse document language. Here, the visible-N-type
must be either lang
or !lang
, while the visible-1-key
can be multiple and should contain a Word langauge ID from this list. The language is checked on "Normal"-style in Word, and not in the bottom left corner.
In this example, the button will be visible if the language is set to "English (United States)" in the "Normal"-style:
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="lang"
visible-1-key-1="wdEnglishUS"
>
If another language is set in the "Normal"-style, the button will be hidden.
In the example below, the button will be hidden if the language is set to "Danish" or "English (United States) in the "Normal"-style:
<Button label="Blah"
visible="BaseExtensions:any"
visible-1-type="!lang"
visible-1-key-1="wdDanish"
visible-1-key-2="wdEnglishUS"
>
If any language than those in the visible-N-key
is set in the "Normal"-style, the button will be visible.
Layout controlled button (P)
It is possible to control a module's visibility based on whether a specific layout is used in a presentation. In the example below, the button will only show if the custom layout "Agenda Layout" is present in the presentation, meaning that the particular layout must be included in the active presentation. In this way, it will also hide the button even though the layout is in the slide master and not used in the presentation.
<Button label="Insert Agenda"
visible="BaseExtensions:any"
visible-1-type="customlayout"
visible-1-key="Agenda Layout">
>
Here, the visible-N-type
must be either customlayout
or !customlayout
where the last mentioned controls the visibility to not show if the specified layout is present.
Docpropmap
With the extended Document property filter, we are able to introduce a lot more versatility to the filtering. Here's an example:
visible="BaseExtensions:any"
visible-1-type="docpropmap" visible-1-key-1="DocType" visible-1-value-1="-;+Letter;+Memo" visible-1-key-2="ReportFilter" visible-1-value-2="+;-True"
key
is the title of the document property - same as regular docprop filtering.
value
can now include multiple values as well as control the default behaviour.
The first character of the input controls the default behavior and can be either -
(omit) or +
(incude). The following inputs will provide exceptions to the default. Each exception is separated by ;
.
In above example the default for "DocType" is to omit. The two exceptions are values "Letter" and "Memo". Additionally, a second filter, "ReportFilter", default is include as indicated by the +
, will omit if value is "True".
HKCU Registry
With the extended Document property filter, we are able to introduce a lot more versatility to the filtering. Here's an example:
visible="BaseExtensions:any"
visible-1-type="Registry" visible-1-key-1="RegistryPath" visible-1-key-2="RegistryName" visible-1-value-2="RegistryValue"
Example
In below example we filter based on the registry setting "Language" as set by HKCU_Global.reg
. If English is the language, the module will show.
This is the module:
visible="BaseExtensions:any"
visible-1-type="Registry" visible-1-key-1="Software\SkabelonDesign\Global" visible-1-key-2="Language" visible-1-value-2="en-GB"
This is where the values are pulled from:
Custom XML
Control by value
Ribbon visibility can be controlled by the value of a custom XML part. The configuration of this is a bit different from other types of visibility as we need to include the name of the custom XML part in the type parameter.
The key(s) is then the child node name and the value for each key is the text inside the child node.
Example
As an example, we want to control the visibility with a custom XML part called VisibilityPart that has a child node called test that contains the value true:
<VisibilityPart>
<test>true</test>
</VisibilityPart>
This is how the module should look:
visible="BaseExtensions:any"
visible-1-type="CustomXml.VisibilityPart"
visible-1-key-1="test"
visible-1-value-1="true"
Check if part exists
It is also possible to just check if the Custom XML part exists in Ribbon Visibility. If the Custom XML part exists it will show or hide the button dependent on whether the type is CustomXml
or !CustomXml
.
For checking if the Custom XML part exists only type
is used. Here it is important to define the partname inside two "$" so the code knows that we are checking for existence and not values.
Example
visible="BaseExtensions:any"
visible-1-type="CustomXml.$VisibilityPart$"
Comments
0 comments
Article is closed for comments.