Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Unified Engineering

Editing Bars and Menus

  • Last UpdatedOct 30, 2024
  • 5 minute read

The contents of menu bars and menus can be modified at any time using the members and methods of the bar menu gadget object and the menu object.

Inserting Menus into a Bar

You can insert new fields into a menu bar using the InsertBefore() and InsertAfter() methods, which insert the new fields relative to existing named menus. The methods use named menus to determine the point where you should insert the new menu.

The general syntax is:

InsertBefore(<TargetMenuName>, <Dtext>, <MenuName>)

InsertAfter(<TargetMenuName>, <Dtext>, <MenuName>)

Where the fields have the following meanings:

Field

Description

<TargetMenuName>

is the name of the menu immediately before or after where you want the new menu to go.

<Dtext>

is the display-text for the menu.

<FieldName>

is the unique name for the menu within the bar.

For example:

layout form !!MyForm Dialog size 30 5

bar

-- adds a pulldown for menu1 labelled with <dtext>

!this.bar.Add( ‘<dtext>’, ‘menu1’ )

-- adds a window pulldown labelled with <dtext>

!this.bar.Add( ‘<dtext>’, ‘Window’ )

-- adds a help pulldown labelled with <dtext>

!bar.InsertAfter( ‘Window’, ‘<dtext>’, ‘Help’ )

...

exit

If you use the identifier ‘Window’ or ‘Help’ as the name of the menu, the system will interpret them as system Window and Help menus, although they will still be displayed with the string given in <dtext>.If you use the identifier ‘Window’ or ‘Help’ as the name of the menu, the system will interpret them as system Window and Help menus, although they will still be displayed with the string given in <dtext>.

Named menus and the methods that create them are discussed in more detail in the rest of this section.

Inserting New Menu Fields

You can insert new fields into a menu using the InsertBefore() and InsertAfter() methods, which insert the new fields relative to existing named menu fields.

The methods use named menu fields to determine the point where they should insert the new field.

The general syntax is:

InsertBefore(<TargetFieldName>,<FieldType>,<Dtext>,<Rtext>,{<FieldName>})

InsertBefore(‘SEPARATOR’,{<FieldName>})

InsertAfter(<TargetFieldName>,<FieldType>,<Dtext>,<Rtext>,{<FieldName>})

InsertAfter(‘SEPARATOR’,{<FieldName>})

Where the fields have the following meanings:

Field

Description

<TargetFieldName>

is the name of the field immediately before or after where you want the new field to go.

<FieldType>

has allowable values: ‘CALLBACK’, ‘TOGGLE’, ‘MENU’, and ‘FORM’.

<Dtext>

is the display-text for the field (cannot be null or blank). May contain multi-byte characters.

<Rtext>

is the replacement-text for the field. A null string indicates no replacement-text. The allowable values for RTEXT for the different field types are:

‘CALLBACK’ - callback string

'TOGGLE’ - callback string

‘MENU’ - menu name string (without preceding ‘.’). It cannot be blank.

‘FORM’ - form name string (without preceding ‘!!’). It cannot be blank.

<FieldName>

is an optional argument, which, if present, is the unique field name within the menu.

Changing the State of Menufields

There are two methods you can use to set and read the status of menu- and menu-field properties.

Setting Menu-Options’ Status

You can de-activate a menufield on a menu bar and a field in a menu with the SetFieldProperty() so that it cannot be selected. Similarly, you can make them invisible so you cannot see them.

You can also use SetFieldProperty() to hide a menu field and to select or unselect toggle-type fields.

The general syntax is:

!menu.SetFieldProperty (<FieldName>, <PropertyName>, Boolean)

Where the fields have the following meanings:

Field

Description

<FieldName>

The name of the field you want to change.

<PropertyName>

The name of the property you want to change in the named field. The allowed values are:

ACTIVE’ - greyed in or out

VISIBLE’ ‑ visible or invisible

SELECTED’ - selected or unselected (toggle type fields, only. Specifically, this value cannot be used with bars).

Boolean

The value, TRUE or FALSE, for the property.

Note:
The property names may optionally be truncated to the first three characters ‘ACT’, ‘VIS’, and ‘SEL’.

For example:

!bar = !!MyForm.bar

!menu = !!MyForm.Menu1

sets local variables !bar and !menu to be references to the bar gadget and Menu1 of form !!MyForm

Then

!bar.SetFieldProperty( 'Foo', ‘ACTive’, false)

will grey-out the menufield on bar that has the field-name “Foo”. And

!menu.SetFieldProperty ( 'Bar', ‘ACTive’, true)

will activate the menufield on Menu1 that has the field-name “Bar”.

You can use the same method to change the selected status of a toggle menu field.

Reading the Status of Menus and Menus’ Fields

To read the status of a menu or of a menu-field property, you can use the FieldProperty() method.

The general syntax is:

Boolean = !menu.FieldProperty (<FieldName>, <PropertyName>)

Where the fields have the following meanings:

Field

Description

<FieldName>

is the name of the field you want to change.

<PropertyName>

is the name of the property you want to change in the named field. The allowed values are:

‘ACTIVE’ - greyed in or out

‘VISIBLE’ ‑ visible or invisible

‘SELECTED’ - selected or unselected (toggle type fields, only. Specifically, this value cannot be used with bars)

Note:
The property names may optionally be truncated to the first three characters ‘ACT’, ‘VIS’, and ‘SEL’.

For example:

!bar = !!MyForm.bar

sets local variable !bar to be a reference to the bar gadget of form !!MyForm.

Then

!isSet = !bar.FieldProperty( 'Foo', ‘ACT’)

will get the greyed-out status of the menufield on bar that has the field-name “Foo”.

You can use the same method to change the selected status of a toggle menu field.

Implied Menu-field Groups

A separator field and all following fields up to but not including the next separator field implies a menu-field group. You can modify the ACTIVE and VISIBLE properties of all fields in the group, by reference to its separator name.

For example, for the menu:

!menu = !this.newmenu( 'file', 'Main' )

!menu.add( 'MENU', 'Send to', 'SendList', 'SendTo' )

!menu.add( 'SEPARATOR', 'SaveGroup' )

!menu.add( 'CALLBACK', 'Save', '!this.SaveFile()', 'Save' )

menu.add( 'FORM', 'Save as...', 'SaveFile', 'SaveAs' )

!menu.add( 'SEPARATOR', 'explGroup' )

!menu.add( 'FORM', 'Explorer...', 'ExplFile', 'Expl' )

Executing the method

!menu.SetField( 'saveGroup', 'visible', false )

will make the all the fields invisible for the group currently implied by the separator field ‘SaveGroup’, i.e. the fields SaveGroup, Save and SaveAs.

The combination of named SEPARATOR fields, insertion and field group visibility will be useful for managing the sharing of menus between co-operating sub-applications. This facility should be used with great care.

Creating Menus Dynamically

You can create new menus from within their appware dynamically using the form method NewMenu().

For example, you could equip your form with the methods popupCreate() and popupAction() which would allow you to create and service a popup menu from an array of strings.

Executing !this.popupCreate(‘NewPopup’, !fieldArray) will create a new popup menu and assign it to the form.

define method .popupCreate( !name is STRING, !fields is ARRAY )

--!fields is an array of field name strings

!menu = !this.newmenu( !name, ‘popup’ )

--add all the fields with same open callback

do !n from 1 to !fields.size()

!menu.add( 'Callback', !fields[!n], '!this.menuAction(' )

enddo

-- assign the new menu as the form’s popup menu

!this.setpopup( !menu )

endmethod

define method .popupAction( !menu is MENU, !action is STRING )

-- General popup menu action routine

if ( !action eq ‘SELECT’ ) then

!name = !menu.fullname()

!field = !menu.pickedField

-- execute application actions according to the field selected

$P selected field $!field of menu $!name

...

else

-- execute applications for unselected field (toggle)

...

endif

endmethod

Related Links
TitleResults for “How to create a CRG?”Also Available in