Struct gio::MenuItem [−][src]
pub struct MenuItem(_);
Expand description
MenuItem
is an opaque structure type. You must access it using the
functions below.
Implements
Implementations
Creates a new MenuItem
.
If label
is non-None
it is used to set the “label” attribute of the
new item.
If detailed_action
is non-None
it is used to set the “action” and
possibly the “target” attribute of the new item. See
set_detailed_action()
for more information.
label
the section label, or None
detailed_action
the detailed action string, or None
Returns
a new MenuItem
Creates a MenuItem
as an exact copy of an existing menu item in a
MenuModel
.
item_index
must be valid (ie: be sure to call
MenuModelExt::n_items()
first).
model
item_index
the index of an item in model
Returns
a new MenuItem
.
Creates a new MenuItem
representing a section.
This is a convenience API around new()
and
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-None
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 Menu
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:
<menu id='edit-menu'>
<section>
<item label='Undo'/>
<item label='Redo'/>
</section>
<section>
<item label='Cut'/>
<item label='Copy'/>
<item label='Paste'/>
</section>
</menu>
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).
<menu id='edit-menu'>
<item>
<link name='section'>
<item label='Undo'/>
<item label='Redo'/>
</link>
</item>
<item>
<link name='section'>
<item label='Cut'/>
<item label='Copy'/>
<item label='Paste'/>
</link>
</item>
</menu>
label
the section label, or None
section
a MenuModel
with the items of the section
Returns
a new MenuItem
Queries the named attribute
on self
.
If expected_type
is specified and the attribute does not have this
type, None
is returned. None
is also returned if the attribute
simply does not exist.
attribute
the attribute name to query
expected_type
the expected type of the attribute
Returns
the attribute value, or None
Sets or unsets the “action” and “target” attributes of self
.
If action
is None
then both the “action” and “target” attributes
are unset (and target_value
is ignored).
If action
is non-None
then the “action” attribute is set. The
“target” attribute is then set to the value of target_value
if it is
non-None
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
Action
and ActionGroup
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
set_detailed_action()
for two equivalent calls that are
probably more convenient for most uses.
action
the name of the action for this item
target_value
a glib::Variant
to use as the action target
Sets or unsets an attribute on self
.
The attribute to set or unset is specified by attribute
. This
can be one of the standard attribute names MENU_ATTRIBUTE_LABEL
,
MENU_ATTRIBUTE_ACTION
, 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-None
then it is used as the new value for the
attribute. If value
is None
then the attribute is unset. If
the value
glib::Variant
is floating, it is consumed.
See also g_menu_item_set_attribute()
for a more convenient way to do
the same.
attribute
the attribute to set
value
a glib::Variant
to use as the value, or None
Sets the “action” and possibly the “target” attribute of self
.
The format of detailed_action
is the same format parsed by
Action::parse_detailed_name()
.
See g_menu_item_set_action_and_target()
or
set_action_and_target_value()
for more flexible (but
slightly less convenient) alternatives.
See also set_action_and_target_value()
for a description of
the semantics of the action and target attributes.
detailed_action
the “detailed” action string
Sets (or unsets) the icon on self
.
This call is the same as calling IconExt::serialize()
and using the
result as the value to set_attribute_value()
for
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 None
then the icon is unset.
icon
Creates a link from self
to model
if non-None
, or unsets it.
Links are used to establish a relationship between a particular menu
item and another menu. For example, MENU_LINK_SUBMENU
is used to
associate a submenu with a particular menu item, and 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.
link
type of link to establish or unset
model
Sets or unsets the “section” link of self
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 self
is added to. See new_section()
for more information about what it means for a menu item to be a
section.
section
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for MenuItem
impl UnwindSafe for MenuItem
Blanket Implementations
Mutably borrows from an owned value. Read more
Upcasts an object to a superclass or interface T
. Read more
Upcasts an object to a reference of its superclass or interface T
. Read more
Tries to downcast to a subclass or interface implementor T
. Read more
Tries to downcast to a reference of its subclass or interface implementor T
. Read more
Tries to cast to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Tries to cast to reference to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Casts to T
unconditionally. Read more
Casts to &T
unconditionally. Read more
Returns true
if the object is an instance of (can be cast to) T
.
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
V: ToValue,
N: Into<&'a str>,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,
N: Into<&'a str>,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value> + 'static,
N: Into<&'a str>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value>,
N: Into<&'a str>,
Same as connect_unsafe
but takes a SignalId
instead of a signal name.
Emit signal by signal id.
Emit signal with details by signal id.
Emit signal by it’s name.
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>,
Same as emit
but takes Value
for the arguments.
Same as emit_by_name
but takes Value
for the arguments.
Returns a SendValue
clone of self
.
impl<'a, T, C> FromValueOptional<'a> for T where
C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError>,
T: FromValue<'a, Checker = C>,