Trait gio::prelude::MenuModelExt

source ·
pub trait MenuModelExt: 'static {
    // Required methods
    fn item_attribute_value(
        &self,
        item_index: i32,
        attribute: &str,
        expected_type: Option<&VariantTy>
    ) -> Option<Variant>;
    fn item_link(&self, item_index: i32, link: &str) -> Option<MenuModel>;
    fn n_items(&self) -> i32;
    fn is_mutable(&self) -> bool;
    fn items_changed(&self, position: i32, removed: i32, added: i32);
    fn iterate_item_attributes(&self, item_index: i32) -> MenuAttributeIter;
    fn iterate_item_links(&self, item_index: i32) -> MenuLinkIter;
    fn connect_items_changed<F: Fn(&Self, i32, i32, i32) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
}
Expand description

Trait containing all MenuModel methods.

Implementors

DBusMenuModel, MenuModel, Menu

Required Methods§

source

fn item_attribute_value( &self, item_index: i32, attribute: &str, expected_type: Option<&VariantTy> ) -> Option<Variant>

Queries the item at position item_index in self for the attribute specified by attribute.

If expected_type is non-None then it specifies the expected type of the attribute. If it is None then any type will be accepted.

If the attribute exists and matches expected_type (or if the expected type is unspecified) then the value is returned.

If the attribute does not exist, or does not match the expected type then None is returned.

item_index

the index of the item

attribute

the attribute to query

expected_type

the expected type of the attribute, or None

Returns

the value of the attribute

Queries the item at position item_index in self for the link specified by link.

If the link exists, the linked MenuModel is returned. If the link does not exist, None is returned.

item_index

the index of the item

the link to query

Returns

the linked MenuModel, or None

source

fn n_items(&self) -> i32

Query the number of items in self.

Returns

the number of items

source

fn is_mutable(&self) -> bool

Queries if self is mutable.

An immutable MenuModel will never emit the items-changed signal. Consumers of the model may make optimisations accordingly.

Returns

true if the model is mutable (ie: “items-changed” may be emitted).

source

fn items_changed(&self, position: i32, removed: i32, added: i32)

Requests emission of the items-changed signal on self.

This function should never be called except by MenuModel subclasses. Any other calls to this function will very likely lead to a violation of the interface of the model.

The implementation should update its internal representation of the menu before emitting the signal. The implementation should further expect to receive queries about the new state of the menu (and particularly added menu items) while signal handlers are running.

The implementation must dispatch this call directly from a mainloop entry and not in response to calls – particularly those from the MenuModel API. Said another way: the menu must not change while user code is running without returning to the mainloop.

position

the position of the change

removed

the number of items removed

added

the number of items added

source

fn iterate_item_attributes(&self, item_index: i32) -> MenuAttributeIter

Creates a MenuAttributeIter to iterate over the attributes of the item at position item_index in self.

You must free the iterator with g_object_unref() when you are done.

item_index

the index of the item

Returns

a new MenuAttributeIter

Creates a MenuLinkIter to iterate over the links of the item at position item_index in self.

You must free the iterator with g_object_unref() when you are done.

item_index

the index of the item

Returns

a new MenuLinkIter

source

fn connect_items_changed<F: Fn(&Self, i32, i32, i32) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted when a change has occurred to the menu.

The only changes that can occur to a menu is that items are removed or added. Items may not change (except by being removed and added back in the same location). This signal is capable of describing both of those changes (at the same time).

The signal means that starting at the index position, removed items were removed and added items were added in their place. If removed is zero then only items were added. If added is zero then only items were removed.

As an example, if the menu contains items a, b, c, d (in that order) and the signal (2, 1, 3) occurs then the new composition of the menu will be a, b, _, _, _, d (with each _ representing some new item).

Signal handlers may query the model (particularly the added items) and expect to see the results of the modification that is being reported. The signal is emitted after the modification.

position

the position of the change

removed

the number of items removed

added

the number of items added

Implementors§