class Gio::MenuItem
- Gio::MenuItem
- GObject::Object
- Reference
- Object
Overview
#GMenuItem is an opaque structure type. You must access it using the functions below.
Defined in:
lib/gi-crystal/src/auto/gio-2.0/menu_item.crConstructors
-
.new(label : String?, detailed_action : String?) : self
Creates a new #GMenuItem.
-
.new
Initialize a new
MenuItem
. -
.new_from_model(model : Gio::MenuModel, item_index : Int32) : self
Creates a #GMenuItem as an exact copy of an existing menu item in a #GMenuModel.
-
.new_section(label : String?, section : Gio::MenuModel) : self
Creates a new #GMenuItem representing a section.
-
.new_submenu(label : String?, submenu : Gio::MenuModel) : self
Creates a new #GMenuItem representing a submenu.
Class Method Summary
-
.g_type : UInt64
Returns the type id (GType) registered in GLib type system.
Instance Method Summary
-
#attribute_value(attribute : String, expected_type : GLib::VariantType?) : GLib::Variant?
Queries the named @attribute on @menu_item.
-
#detailed_action=(detailed_action : String) : Nil
Sets the "action" and possibly the "target" attribute of @menu_item.
-
#icon=(icon : Gio::Icon) : Nil
Sets (or unsets) the icon on @menu_item.
-
#label=(label : String?) : Nil
Sets or unsets the "label" attribute of @menu_item.
-
#link(link : String) : Gio::MenuModel?
Queries the named @link on @menu_item.
-
#section=(section : Gio::MenuModel?) : Nil
Sets or unsets the "section" link of @menu_item to @section.
-
#set_action_and_target_value(action : String?, target_value : _?) : Nil
Sets or unsets the "action" and "target" attributes of @menu_item.
-
#set_attribute_value(attribute : String, value : _?) : Nil
Sets or unsets an attribute on @menu_item.
-
#set_link(link : String, model : Gio::MenuModel?) : Nil
Creates a link from @menu_item to @model if non-
nil
, or unsets it. -
#submenu=(submenu : Gio::MenuModel?) : Nil
Sets or unsets the "submenu" link of @menu_item to @submenu.
Instance methods inherited from class GObject::Object
bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding
bind_property,
bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding
bind_property_full,
data(key : String) : Pointer(Void)?
data,
finalize
finalize,
freeze_notify : Nil
freeze_notify,
getv(names : Enumerable(String), values : Enumerable(_)) : Nil
getv,
notify(property_name : String) : Nil
notify,
notify_by_pspec(pspec : GObject::ParamSpec) : Nil
notify_by_pspec,
notify_signal
notify_signal,
property(property_name : String, value : _) : Nil
property,
qdata(quark : UInt32) : Pointer(Void)?
qdata,
ref_count : UInt32
ref_count,
run_dispose : Nil
run_dispose,
set_data(key : String, data : Pointer(Void)?) : Nil
set_data,
set_property(property_name : String, value : _) : Nil
set_property,
steal_data(key : String) : Pointer(Void)?
steal_data,
steal_qdata(quark : UInt32) : Pointer(Void)?
steal_qdata,
thaw_notify : Nil
thaw_notify,
to_unsafe : Pointer(Void)
to_unsafe,
watch_closure(closure : GObject::Closure) : Nil
watch_closure
Constructor methods inherited from class GObject::Object
cast(obj : GObject::Object) : self
cast,
cast?(obj : GObject::Object) : self?
cast?,
new(pointer : Pointer(Void), transfer : GICrystal::Transfer)new new, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv
Class methods inherited from class GObject::Object
compat_control(what : UInt64, data : Pointer(Void)?) : UInt64
compat_control,
g_type : UInt64
g_type,
interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec
interface_find_property,
interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec)
interface_list_properties
Constructor Detail
Creates a new #GMenuItem.
If @label is non-nil
it is used to set the "label" attribute of the
new item.
If @detailed_action is non-nil
it is used to set the "action" and
possibly the "target" attribute of the new item. See
g_menu_item_set_detailed_action() for more information.
Creates a #GMenuItem as an exact copy of an existing menu item in a #GMenuModel.
@item_index must be valid (ie: be sure to call g_menu_model_get_n_items() first).
Creates a new #GMenuItem representing a section.
This is a convenience API around g_menu_item_new() and g_menu_item_set_section().
The effect of having one menu appear as a section of another is exactly as it sounds: the items from @section become a direct part of the menu that @menu_item is added to.
Visual separation is typically displayed between two non-empty
sections. If @label is non-nil
then it will be encorporated into
this visual indication. This allows for labeled subsections of a
menu.
As a simple example, consider a typical "Edit" menu from a simple program. It probably contains an "Undo" and "Redo" item, followed by a separator, followed by "Cut", "Copy" and "Paste".
This would be accomplished by creating three #GMenu instances. The first would be populated with the "Undo" and "Redo" items, and the second with the "Cut", "Copy" and "Paste" items. The first and second menus would then be added as submenus of the third. In XML format, this would look something like the following: |[
]|The following example is exactly equivalent. It is more illustrative of the exact relationship between the menus and items (keeping in mind that the 'link' element defines a new menu that is linked to the containing one). The style of the second example is more verbose and difficult to read (and therefore not recommended except for the purpose of understanding what is really going on). |[
]|Class Method Detail
Instance Method Detail
Queries the named @attribute on @menu_item.
If @expected_type is specified and the attribute does not have this
type, nil
is returned. nil
is also returned if the attribute
simply does not exist.
Sets the "action" and possibly the "target" attribute of @menu_item.
The format of @detailed_action is the same format parsed by g_action_parse_detailed_name().
See g_menu_item_set_action_and_target() or g_menu_item_set_action_and_target_value() for more flexible (but slightly less convenient) alternatives.
See also g_menu_item_set_action_and_target_value() for a description of the semantics of the action and target attributes.
Sets (or unsets) the icon on @menu_item.
This call is the same as calling g_icon_serialize() and using the result as the value to g_menu_item_set_attribute_value() for %G_MENU_ATTRIBUTE_ICON.
This API is only intended for use with "noun" menu items; things like bookmarks or applications in an "Open With" menu. Don't use it on menu items corresponding to verbs (eg: stock icons for 'Save' or 'Quit').
If @icon is nil
then the icon is unset.
Sets or unsets the "label" attribute of @menu_item.
If @label is non-nil
it is used as the label for the menu item. If
it is nil
then the label attribute is unset.
Sets or unsets the "section" link of @menu_item to @section.
The effect of having one menu appear as a section of another is exactly as it sounds: the items from @section become a direct part of the menu that @menu_item is added to. See g_menu_item_new_section() for more information about what it means for a menu item to be a section.
Sets or unsets the "action" and "target" attributes of @menu_item.
If @action is nil
then both the "action" and "target" attributes
are unset (and @target_value is ignored).
If @action is non-nil
then the "action" attribute is set. The
"target" attribute is then set to the value of @target_value if it is
non-nil
or unset otherwise.
Normal menu items (ie: not submenu, section or other custom item types) are expected to have the "action" attribute set to identify the action that they are associated with. The state type of the action help to determine the disposition of the menu item. See #GAction and #GActionGroup for an overview of actions.
In general, clicking on the menu item will result in activation of the named action with the "target" attribute given as the parameter to the action invocation. If the "target" attribute is not set then the action is invoked with no parameter.
If the action has no state then the menu item is usually drawn as a plain menu item (ie: with no additional decoration).
If the action has a boolean state then the menu item is usually drawn
as a toggle menu item (ie: with a checkmark or equivalent
indication). The item should be marked as 'toggled' or 'checked'
when the boolean state is true
.
If the action has a string state then the menu item is usually drawn as a radio menu item (ie: with a radio bullet or equivalent indication). The item should be marked as 'selected' when the string state is equal to the value of the @target property.
See g_menu_item_set_action_and_target() or g_menu_item_set_detailed_action() for two equivalent calls that are probably more convenient for most uses.
Sets or unsets an attribute on @menu_item.
The attribute to set or unset is specified by @attribute. This can be one of the standard attribute names %G_MENU_ATTRIBUTE_LABEL, %G_MENU_ATTRIBUTE_ACTION, %G_MENU_ATTRIBUTE_TARGET, or a custom attribute name. Attribute names are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes.
must consist only of lowercase ASCII characters, digits and '-'.
If @value is non-nil
then it is used as the new value for the
attribute. If @value is nil
then the attribute is unset. If
the @value #GVariant is floating, it is consumed.
See also g_menu_item_set_attribute() for a more convenient way to do the same.
Creates a link from @menu_item to @model if non-nil
, or unsets it.
Links are used to establish a relationship between a particular menu item and another menu. For example, %G_MENU_LINK_SUBMENU is used to associate a submenu with a particular menu item, and %G_MENU_LINK_SECTION is used to create a section. Other types of link can be used, but there is no guarantee that clients will be able to make sense of them. Link types are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes.