Skip to main content

MenuShellExt

Trait MenuShellExt 

Source
pub trait MenuShellExt: IsA<MenuShell> + 'static {
Show 27 methods // Provided methods fn activate_item( &self, menu_item: &impl IsA<Widget>, force_deactivate: bool, ) { ... } fn append(&self, child: &impl IsA<MenuItem>) { ... } fn bind_model( &self, model: Option<&impl IsA<MenuModel>>, action_namespace: Option<&str>, with_separators: bool, ) { ... } fn cancel(&self) { ... } fn deactivate(&self) { ... } fn deselect(&self) { ... } fn parent_shell(&self) -> Option<Widget> { ... } fn selected_item(&self) -> Option<Widget> { ... } fn takes_focus(&self) -> bool { ... } fn insert(&self, child: &impl IsA<Widget>, position: i32) { ... } fn prepend(&self, child: &impl IsA<Widget>) { ... } fn select_first(&self, search_sensitive: bool) { ... } fn select_item(&self, menu_item: &impl IsA<Widget>) { ... } fn set_take_focus(&self, take_focus: bool) { ... } fn connect_activate_current<F: Fn(&Self, bool) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn emit_activate_current(&self, force_hide: bool) { ... } fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { ... } fn emit_cancel(&self) { ... } fn connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn emit_cycle_focus(&self, direction: DirectionType) { ... } fn connect_deactivate<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_insert<F: Fn(&Self, &Widget, i32) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn emit_move_current(&self, direction: MenuDirectionType) { ... } fn connect_move_selected<F: Fn(&Self, i32) -> Propagation + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_selection_done<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_take_focus_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all MenuShell methods.

§Implementors

MenuBar, MenuShell, Menu

Provided Methods§

Source

fn activate_item(&self, menu_item: &impl IsA<Widget>, force_deactivate: bool)

Activates the menu item within the menu shell.

the MenuItem to activate

§force_deactivate

if true, force the deactivation of the menu shell after the menu item is activated

Source

fn append(&self, child: &impl IsA<MenuItem>)

Adds a new MenuItem to the end of the menu shell’s item list.

§child

The MenuItem to add

Source

fn bind_model( &self, model: Option<&impl IsA<MenuModel>>, action_namespace: Option<&str>, with_separators: bool, )

Establishes a binding between a MenuShell and a gio::MenuModel.

The contents of shell are removed and then refilled with menu items according to model. When model changes, shell is updated. Calling this function twice on shell with different model will cause the first binding to be replaced with a binding to the new model. If model is None then any previous binding is undone and all children are removed.

with_separators determines if toplevel items (eg: sections) have separators inserted between them. This is typically desired for menus but doesn’t make sense for menubars.

If action_namespace is non-None then the effect is as if all actions mentioned in the model have their names prefixed with the namespace, plus a dot. For example, if the action “quit” is mentioned and action_namespace is “app” then the effective action name is “app.quit”.

This function uses Actionable to define the action name and target values on the created menu items. If you want to use an action group other than “app” and “win”, or if you want to use a MenuShell outside of a ApplicationWindow, then you will need to attach your own action group to the widget hierarchy using WidgetExt::insert_action_group(). As an example, if you created a group with a “quit” action and inserted it with the name “mygroup” then you would use the action name “mygroup.quit” in your gio::MenuModel.

For most cases you are probably better off using Menu::from_model() or MenuBar::from_model() or just directly passing the gio::MenuModel to GtkApplicationExt::set_app_menu() or GtkApplicationExt::set_menubar().

§model

the gio::MenuModel to bind to or None to remove binding

§action_namespace

the namespace for actions in model

§with_separators

true if toplevel items in shell should have separators between them

Source

fn cancel(&self)

Cancels the selection within the menu shell.

Source

fn deactivate(&self)

Deactivates the menu shell.

Typically this results in the menu shell being erased from the screen.

Source

fn deselect(&self)

Deselects the currently selected item from the menu shell, if any.

Source

fn parent_shell(&self) -> Option<Widget>

Gets the parent menu shell.

The parent menu shell of a submenu is the Menu or MenuBar from which it was opened up.

§Returns

the parent MenuShell

Source

fn selected_item(&self) -> Option<Widget>

Gets the currently selected item.

§Returns

the currently selected item

Source

fn takes_focus(&self) -> bool

Returns true if the menu shell will take the keyboard focus on popup.

§Returns

true if the menu shell will take the keyboard focus on popup.

Source

fn insert(&self, child: &impl IsA<Widget>, position: i32)

Adds a new MenuItem to the menu shell’s item list at the position indicated by position.

§child

The MenuItem to add

§position

The position in the item list where child is added. Positions are numbered from 0 to n-1

Source

fn prepend(&self, child: &impl IsA<Widget>)

Adds a new MenuItem to the beginning of the menu shell’s item list.

§child

The MenuItem to add

Source

fn select_first(&self, search_sensitive: bool)

Select the first visible or selectable child of the menu shell; don’t select tearoff items unless the only item is a tearoff item.

§search_sensitive

if true, search for the first selectable menu item, otherwise select nothing if the first item isn’t sensitive. This should be false if the menu is being popped up initially.

Source

fn select_item(&self, menu_item: &impl IsA<Widget>)

Selects the menu item from the menu shell.

The MenuItem to select

Source

fn set_take_focus(&self, take_focus: bool)

If take_focus is true (the default) the menu shell will take the keyboard focus so that it will receive all keyboard events which is needed to enable keyboard navigation in menus.

Setting take_focus to false is useful only for special applications like virtual keyboard implementations which should not take keyboard focus.

The take_focus state of a menu or menu bar is automatically propagated to submenus whenever a submenu is popped up, so you don’t have to worry about recursively setting it for your entire menu hierarchy. Only when programmatically picking a submenu and popping it up manually, the take_focus property of the submenu needs to be set explicitly.

Note that setting it to false has side-effects:

If the focus is in some other app, it keeps the focus and keynav in the menu doesn’t work. Consequently, keynav on the menu will only work if the focus is on some toplevel owned by the onscreen keyboard.

To avoid confusing the user, menus with take_focus set to false should not display mnemonics or accelerators, since it cannot be guaranteed that they will work.

See also gdk_keyboard_grab()

§take_focus

true if the menu shell should take the keyboard focus on popup

Source

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

An action signal that activates the current menu item within the menu shell.

§force_hide

if true, hide the menu after activating the menu item

Source

fn emit_activate_current(&self, force_hide: bool)

Source

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

An action signal which cancels the selection within the menu shell. Causes the selection-done signal to be emitted.

Source

fn emit_cancel(&self)

Source

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

A keybinding signal which moves the focus in the given direction.

§direction

the direction to cycle in

Source

fn emit_cycle_focus(&self, direction: DirectionType)

Source

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

This signal is emitted when a menu shell is deactivated.

Source

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

The ::insert signal is emitted when a new MenuItem is added to a MenuShell. A separate signal is used instead of GtkContainer::add because of the need for an additional position parameter.

The inverse of this signal is the GtkContainer::removed signal.

§child

the MenuItem that is being inserted

§position

the position at which the insert occurs

Source

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

An keybinding signal which moves the current menu item in the direction specified by direction.

§direction

the direction to move

Source

fn emit_move_current(&self, direction: MenuDirectionType)

Source

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

The ::move-selected signal is emitted to move the selection to another item.

§distance

+1 to move to the next item, -1 to move to the previous

§Returns

true to stop the signal emission, false to continue

Source

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

This signal is emitted when a selection has been completed within a menu shell.

Source

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§