class Gio::Menu

Overview

#GMenu is a simple implementation of #GMenuModel. You populate a #GMenu by adding #GMenuItem instances to it.

There are some convenience functions to allow you to directly add items (avoiding #GMenuItem) for the common cases. To add a regular item, use g_menu_insert(). To add a section, use g_menu_insert_section(). To add a submenu, use g_menu_insert_submenu().

Defined in:

lib/gi-crystal/src/auto/gio-2.0/menu.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Gio::MenuModel

is_mutable : Bool is_mutable, item_attribute_value(item_index : Int32, attribute : String, expected_type : GLib::VariantType?) : GLib::Variant? item_attribute_value, item_link(item_index : Int32, link : String) : Gio::MenuModel? item_link, items_changed(position : Int32, removed : Int32, added : Int32) : Nil items_changed, items_changed_signal items_changed_signal, iterate_item_attributes(item_index : Int32) : Gio::MenuAttributeIter iterate_item_attributes, iterate_item_links(item_index : Int32) : Gio::MenuLinkIter iterate_item_links, n_items : Int32 n_items

Constructor methods inherited from class Gio::MenuModel

new new

Class methods inherited from class Gio::MenuModel

g_type : UInt64 g_type

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

def self.new : self #

Creates a new #GMenu.

The new menu has no items.


Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def append(label : String?, detailed_action : String?) : Nil #

Convenience function for appending a normal menu item to the end of @menu. Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.


def append_item(item : Gio::MenuItem) : Nil #

Appends @item to the end of @menu.

See g_menu_insert_item() for more information.


def append_section(label : String?, section : Gio::MenuModel) : Nil #

Convenience function for appending a section menu item to the end of @menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.


def append_submenu(label : String?, submenu : Gio::MenuModel) : Nil #

Convenience function for appending a submenu menu item to the end of @menu. Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.


def freeze : Nil #

Marks @menu as frozen.

After the menu is frozen, it is an error to attempt to make any changes to it. In effect this means that the #GMenu API must no longer be used.

This function causes g_menu_model_is_mutable() to begin returning false, which has some positive performance implications.


def insert(position : Int32, label : String?, detailed_action : String?) : Nil #

Convenience function for inserting a normal menu item into @menu. Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.


def insert_item(position : Int32, item : Gio::MenuItem) : Nil #

Inserts @item into @menu.

The "insertion" is actually done by copying all of the attribute and link values of @item and using them to form a new item within @menu. As such, @item itself is not really inserted, but rather, a menu item that is exactly the same as the one presently described by @item.

This means that @item is essentially useless after the insertion occurs. Any changes you make to it are ignored unless it is inserted again (at which point its updated values will be copied).

You should probably just free @item once you're done.

There are many convenience functions to take care of common cases. See g_menu_insert(), g_menu_insert_section() and g_menu_insert_submenu() as well as "prepend" and "append" variants of each of these functions.


def insert_section(position : Int32, label : String?, section : Gio::MenuModel) : Nil #

Convenience function for inserting a section menu item into @menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.


def insert_submenu(position : Int32, label : String?, submenu : Gio::MenuModel) : Nil #

Convenience function for inserting a submenu menu item into @menu. Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.


def prepend(label : String?, detailed_action : String?) : Nil #

Convenience function for prepending a normal menu item to the start of @menu. Combine g_menu_item_new() and g_menu_insert_item() for a more flexible alternative.


def prepend_item(item : Gio::MenuItem) : Nil #

Prepends @item to the start of @menu.

See g_menu_insert_item() for more information.


def prepend_section(label : String?, section : Gio::MenuModel) : Nil #

Convenience function for prepending a section menu item to the start of @menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a more flexible alternative.


def prepend_submenu(label : String?, submenu : Gio::MenuModel) : Nil #

Convenience function for prepending a submenu menu item to the start of @menu. Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more flexible alternative.


def remove(position : Int32) : Nil #

Removes an item from the menu.

@position gives the index of the item to remove.

It is an error if position is not in range the range from 0 to one less than the number of items in the menu.

It is not possible to remove items by identity since items are added to the menu simply by copying their links and attributes (ie: identity of the item itself is not preserved).


def remove_all : Nil #

Removes all items in the menu.