API reference - Class AbstractMenu

Notation used in Ruby API documentation

Module: lay

Description: An abstraction for the application menus

The abstract menu is a class that stores a main menu and several popup menus in a generic form such that they can be manipulated and converted into GUI objects.

Each item can be associated with a Action, which delivers a title, enabled/disable state etc. The Action is either provided when new entries are inserted or created upon initialisation.

The abstract menu class provides methods to manipulate the menu structure (the state of the menu items, their title and shortcut key is provided and manipulated through the Action object).

Menu items and submenus are referred to by a "path". The path is a string with this interpretation:

"" is the root
"[<path>.]<name>" is an element of the submenu given by <path>. If <path> is omitted, this refers to an element in the root
"[<path>.]end" refers to the item past the last item of the submenu given by <path> or root
"[<path>.]begin" refers to the first item of the submenu given by <path> or root
"[<path>.]#<n>" refers to the nth item of the submenu given by <path> or root (n is an integer number)

Menu items can be put into groups. The path strings of each group can be obtained with the "group" method. An item is put into a group by appending ":<group-name>" to the item's name. This specification can be used several times.

Detached menus (i.e. for use in context menus) can be created as virtual top-level submenus with a name of the form "@<name>". A special detached menu is "@toolbar" which represents the tool bar of the main window. Menus are closely related to the Action class. Actions are used to represent selectable items inside menus, provide the title and other configuration settings. Actions also link the menu items with code. See the Action class description for further details.

Public methods

void_createEnsures the C++ object is created
void_destroyExplicitly destroys the object
[const]bool_destroyed?Returns a value indicating whether the object was already destroyed
[const]bool_is_const_object?Returns a value indicating whether the reference is a const reference
void_manageMarks the object as managed by the script side.
void_unmanageMarks the object as no longer owned by the script side.
Action ptraction(string path)Gets the reference to a Action object associated with the given path
voiddelete_item(string path)Deletes the item given by the path
[const]string[]group(string group)Gets the group members
voidinsert_item(string path,
string name,
const Action ptr action)
Inserts a new item before the one given by the path
voidinsert_menu(string path,
string name,
string title)
Inserts a new submenu before the item given by the path
voidinsert_separator(string path,
string name)
Inserts a new separator before the item given by the path
[const]boolis_menu?(string path)Returns true if the item is a menu
[const]boolis_separator?(string path)Returns true if the item is a separator
[const]boolis_valid?(string path)Returns true if the path is a valid one
[const]string[]items(string path)Gets the subitems for a given submenu

Public static methods and constants

stringpack_key_binding(map<string,string> path_to_keys)Serializes a key binding definition into a single string
stringpack_menu_items_hidden(map<string,bool> path_to_visibility)Serializes a menu item visibility definition into a single string
map<string,string>unpack_key_binding(string s)Deserializes a key binding definition
map<string,bool>unpack_menu_items_hidden(string s)Deserializes a menu item visibility definition

Deprecated methods (protected, public, static, non-static and constructors)

voidcreateUse of this method is deprecated. Use _create instead
voiddestroyUse of this method is deprecated. Use _destroy instead
[const]booldestroyed?Use of this method is deprecated. Use _destroyed? instead
[const]boolis_const_object?Use of this method is deprecated. Use _is_const_object? instead

Detailed description

_create

Signature: void _create

Description: Ensures the C++ object is created

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

_destroy

Signature: void _destroy

Description: Explicitly destroys the object

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

_destroyed?

Signature: [const] bool _destroyed?

Description: Returns a value indicating whether the object was already destroyed

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

_is_const_object?

Signature: [const] bool _is_const_object?

Description: Returns a value indicating whether the reference is a const reference

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

_manage

Signature: void _manage

Description: Marks the object as managed by the script side.

After calling this method on an object, the script side will be responsible for the management of the object. This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. If necessary, the script side may delete the object if the script's reference is no longer required.

Usually it's not required to call this method. It has been introduced in version 0.24.

_unmanage

Signature: void _unmanage

Description: Marks the object as no longer owned by the script side.

Calling this method will make this object no longer owned by the script's memory management. Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. Technically speaking, this method will turn the script's reference into a weak reference. After the script engine decides to delete the reference, the object itself will still exist. If the object is not managed otherwise, memory leaks will occur.

Usually it's not required to call this method. It has been introduced in version 0.24.

action

Signature: Action ptr action (string path)

Description: Gets the reference to a Action object associated with the given path

path:The path to the item.
Returns:A reference to a Action object associated with this path or nil if the path is not valid

create

Signature: void create

Description: Ensures the C++ object is created

Use of this method is deprecated. Use _create instead

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

delete_item

Signature: void delete_item (string path)

Description: Deletes the item given by the path

path:The path to the item to delete

destroy

Signature: void destroy

Description: Explicitly destroys the object

Use of this method is deprecated. Use _destroy instead

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

destroyed?

Signature: [const] bool destroyed?

Description: Returns a value indicating whether the object was already destroyed

Use of this method is deprecated. Use _destroyed? instead

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

group

Signature: [const] string[] group (string group)

Description: Gets the group members

group:The group name
A:vector of all members (by path) of the group

insert_item

Signature: void insert_item (string path, string name, const Action ptr action)

Description: Inserts a new item before the one given by the path

path:The path to the item before which to insert the new item
name:The name of the item to insert
action:The Action object to insert

The Action object passed as the third parameter references the handler which both implements the action to perform and the menu item's appearance such as title, icon and keyboard shortcut.

insert_menu

Signature: void insert_menu (string path, string name, string title)

Description: Inserts a new submenu before the item given by the path

path:The path to the item before which to insert the submenu
name:The name of the submenu to insert
title:The title of the submenu to insert

The title string optionally encodes the key shortcut and icon resource in the form <text>["("<shortcut>")"]["<"<icon-resource>">"].

insert_separator

Signature: void insert_separator (string path, string name)

Description: Inserts a new separator before the item given by the path

path:The path to the item before which to insert the separator
name:The name of the separator to insert

is_const_object?

Signature: [const] bool is_const_object?

Description: Returns a value indicating whether the reference is a const reference

Use of this method is deprecated. Use _is_const_object? instead

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

is_menu?

Signature: [const] bool is_menu? (string path)

Description: Returns true if the item is a menu

path:The path to the item
Returns:false if the path is not valid or is not a menu

is_separator?

Signature: [const] bool is_separator? (string path)

Description: Returns true if the item is a separator

path:The path to the item
Returns:false if the path is not valid or is not a separator

This method has been introduced in version 0.19.

is_valid?

Signature: [const] bool is_valid? (string path)

Description: Returns true if the path is a valid one

path:The path to check
Returns:false if the path is not a valid path to an item

items

Signature: [const] string[] items (string path)

Description: Gets the subitems for a given submenu

path:The path to the submenu
Returns:A vector or path strings for the child items or an empty vector if the path is not valid or the item does not have children

pack_key_binding

Signature: [static] string pack_key_binding (map<string,string> path_to_keys)

Description: Serializes a key binding definition into a single string

The serialized format is used by the 'key-bindings' config key. This method will take an array of path/key definitions (including the Action#NoKeyBound option) and convert it to a single string suitable for assigning to the config key.

This method has been introduced in version 0.26.

pack_menu_items_hidden

Signature: [static] string pack_menu_items_hidden (map<string,bool> path_to_visibility)

Description: Serializes a menu item visibility definition into a single string

The serialized format is used by the 'menu-items-hidden' config key. This method will take an array of path/visibility flag definitions and convert it to a single string suitable for assigning to the config key.

This method has been introduced in version 0.26.

unpack_key_binding

Signature: [static] map<string,string> unpack_key_binding (string s)

Description: Deserializes a key binding definition

This method is the reverse of pack_key_binding.

This method has been introduced in version 0.26.

unpack_menu_items_hidden

Signature: [static] map<string,bool> unpack_menu_items_hidden (string s)

Description: Deserializes a menu item visibility definition

This method is the reverse of pack_menu_items_hidden.

This method has been introduced in version 0.26.