Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
MenuModel
represents the contents of a menu -- an ordered list of
menu items. The items are associated with actions, which can be
activated through them. Items can be grouped in sections, and may
have submenus associated with them. Both items and sections usually
have some representation data, such as labels or icons. The type of
the associated action (ie whether it is stateful, and what kind of
state it has) can influence the representation of the item.
The conceptual model of menus in MenuModel
is hierarchical:
sections and submenus are again represented by GMenuModels
.
Menus themselves do not define their own roles. Rather, the role
of a particular MenuModel
is defined by the item that references
it (or, in the case of the 'root' menu, is defined by the context
in which it is used).
As an example, consider the visible portions of this menu:
There are 8 "menus" visible in the screenshot: one menubar, two submenus and 5 sections:
- the toplevel menubar (containing 4 items)
- the View submenu (containing 3 sections)
- the first section of the View submenu (containing 2 items)
- the second section of the View submenu (containing 1 item)
- the final section of the View submenu (containing 1 item)
- the Highlight Mode submenu (containing 2 sections)
- the Sources section (containing 2 items)
- the Markup section (containing 2 items)
The [example][menu-model] illustrates the conceptual connection between these 8 menus. Each large block in the figure represents a menu and the smaller blocks within the large block represent items in that menu. Some items contain references to other menus.
Notice that the separators visible in the [example][menu-example] appear nowhere in the [menu model][menu-model]. This is because separators are not explicitly represented in the menu model. Instead, a separator is inserted between any two non-empty sections of a menu. Section items can have labels just like any other item. In that case, a display system may show a section header instead of a separator.
The motivation for this abstract model of application controls is
that modern user interfaces tend to make these controls available
outside the application. Examples include global menus, jumplists,
dash boards, etc. To support such uses, it is necessary to 'export'
information about actions and their representation in menus, which
is exactly what the [GActionGroup exporter][gio-GActionGroup-exporter]
and the [GMenuModel exporter][gio-GMenuModel-exporter] do for
ActionGroup
and MenuModel
. The client-side counterparts to
make use of the exported information are DBusActionGroup
and
DBusMenuModel
.
The API of MenuModel
is very generic, with iterators for the
attributes and links of an item, see menuModelIterateItemAttributes
and menuModelIterateItemLinks
. The 'standard' attributes and
link types have predefined names: MENU_ATTRIBUTE_LABEL
,
MENU_ATTRIBUTE_ACTION
, MENU_ATTRIBUTE_TARGET
, MENU_LINK_SECTION
and MENU_LINK_SUBMENU
.
Items in a MenuModel
represent active controls if they refer to
an action that can get activated when the user interacts with the
menu item. The reference to the action is encoded by the string id
in the MENU_ATTRIBUTE_ACTION
attribute. An action id uniquely
identifies an action in an action group. Which action group(s) provide
actions depends on the context in which the menu model is used.
E.g. when the model is exported as the application menu of a
GtkApplication
, actions can be application-wide or window-specific
(and thus come from two different action groups). By convention, the
application-wide actions have names that start with "app.", while the
names of window-specific actions start with "win.".
While a wide variety of stateful actions is possible, the following is the minimum that is expected to be supported by all users of exported menu information:
- an action with no parameter type and no state
- an action with no parameter type and boolean state
- an action with string parameter type and string state
Stateless
A stateless action typically corresponds to an ordinary menu item.
Selecting such a menu item will activate the action (with no parameter).
Boolean State
An action with a boolean state will most typically be used with a "toggle" or "switch" menu item. The state can be set directly, but activating the action (with no parameter) results in the state being toggled.
Selecting a toggle menu item will activate the action. The menu item should be rendered as "checked" when the state is true.
String Parameter and State
Actions with string parameters and state will most typically be used to represent an enumerated choice over the items available for a group of radio menu items. Activating the action with a string parameter is equivalent to setting that parameter as the state.
Radio menu items, in addition to being associated with the action, will have a target value. Selecting that menu item will result in activation of the action with the target value as the parameter. The menu item should be rendered as "selected" when the state of the action is equal to the target value of the menu item.
Since: 2.32
Synopsis
- newtype MenuModel = MenuModel (ManagedPtr MenuModel)
- class GObject o => IsMenuModel o
- toMenuModel :: (MonadIO m, IsMenuModel o) => o -> m MenuModel
- noMenuModel :: Maybe MenuModel
- menuModelGetItemAttributeValue :: (HasCallStack, MonadIO m, IsMenuModel a) => a -> Int32 -> Text -> Maybe VariantType -> m GVariant
- menuModelGetItemLink :: (HasCallStack, MonadIO m, IsMenuModel a) => a -> Int32 -> Text -> m MenuModel
- menuModelGetNItems :: (HasCallStack, MonadIO m, IsMenuModel a) => a -> m Int32
- menuModelIsMutable :: (HasCallStack, MonadIO m, IsMenuModel a) => a -> m Bool
- menuModelItemsChanged :: (HasCallStack, MonadIO m, IsMenuModel a) => a -> Int32 -> Int32 -> Int32 -> m ()
- menuModelIterateItemAttributes :: (HasCallStack, MonadIO m, IsMenuModel a) => a -> Int32 -> m MenuAttributeIter
- menuModelIterateItemLinks :: (HasCallStack, MonadIO m, IsMenuModel a) => a -> Int32 -> m MenuLinkIter
- type C_MenuModelItemsChangedCallback = Ptr () -> Int32 -> Int32 -> Int32 -> Ptr () -> IO ()
- type MenuModelItemsChangedCallback = Int32 -> Int32 -> Int32 -> IO ()
- afterMenuModelItemsChanged :: (IsMenuModel a, MonadIO m) => a -> MenuModelItemsChangedCallback -> m SignalHandlerId
- genClosure_MenuModelItemsChanged :: MenuModelItemsChangedCallback -> IO Closure
- mk_MenuModelItemsChangedCallback :: C_MenuModelItemsChangedCallback -> IO (FunPtr C_MenuModelItemsChangedCallback)
- noMenuModelItemsChangedCallback :: Maybe MenuModelItemsChangedCallback
- onMenuModelItemsChanged :: (IsMenuModel a, MonadIO m) => a -> MenuModelItemsChangedCallback -> m SignalHandlerId
- wrap_MenuModelItemsChangedCallback :: MenuModelItemsChangedCallback -> C_MenuModelItemsChangedCallback
Exported types
Memory-managed wrapper type.
Instances
GObject MenuModel Source # | |
Defined in GI.Gio.Objects.MenuModel gobjectType :: MenuModel -> IO GType # | |
IsObject MenuModel Source # | |
Defined in GI.Gio.Objects.MenuModel | |
IsMenuModel MenuModel Source # | |
Defined in GI.Gio.Objects.MenuModel |
class GObject o => IsMenuModel o Source #
Type class for types which can be safely cast to MenuModel
, for instance with toMenuModel
.
Instances
(GObject a, (UnknownAncestorError MenuModel a :: Constraint)) => IsMenuModel a Source # | |
Defined in GI.Gio.Objects.MenuModel | |
IsMenuModel MenuModel Source # | |
Defined in GI.Gio.Objects.MenuModel | |
IsMenuModel Menu Source # | |
Defined in GI.Gio.Objects.Menu | |
IsMenuModel DBusMenuModel Source # | |
Defined in GI.Gio.Objects.DBusMenuModel |
toMenuModel :: (MonadIO m, IsMenuModel o) => o -> m MenuModel Source #
Methods
getItemAttributeValue
menuModelGetItemAttributeValue Source #
:: (HasCallStack, MonadIO m, IsMenuModel a) | |
=> a |
|
-> Int32 |
|
-> Text |
|
-> Maybe VariantType |
|
-> m GVariant | Returns: the value of the attribute |
Queries the item at position itemIndex
in model
for the attribute
specified by attribute
.
If expectedType
is non-Nothing
then it specifies the expected type of
the attribute. If it is Nothing
then any type will be accepted.
If the attribute exists and matches expectedType
(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 Nothing
is returned.
Since: 2.32
getItemLink
:: (HasCallStack, MonadIO m, IsMenuModel a) | |
=> a |
|
-> Int32 |
|
-> Text |
|
-> m MenuModel |
getNItems
:: (HasCallStack, MonadIO m, IsMenuModel a) | |
=> a |
|
-> m Int32 | Returns: the number of items |
Query the number of items in model
.
Since: 2.32
isMutable
:: (HasCallStack, MonadIO m, IsMenuModel a) | |
=> a |
|
-> m Bool | Returns: |
itemsChanged
menuModelItemsChanged Source #
:: (HasCallStack, MonadIO m, IsMenuModel a) | |
=> a |
|
-> Int32 |
|
-> Int32 |
|
-> Int32 |
|
-> m () |
Requests emission of the MenuModel
::items-changed
signal on model
.
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.
Since: 2.32
iterateItemAttributes
menuModelIterateItemAttributes Source #
:: (HasCallStack, MonadIO m, IsMenuModel a) | |
=> a |
|
-> Int32 |
|
-> m MenuAttributeIter | Returns: a new |
Creates a MenuAttributeIter
to iterate over the attributes of
the item at position itemIndex
in model
.
You must free the iterator with objectUnref
when you are done.
Since: 2.32
iterateItemLinks
menuModelIterateItemLinks Source #
:: (HasCallStack, MonadIO m, IsMenuModel a) | |
=> a |
|
-> Int32 |
|
-> m MenuLinkIter | Returns: a new |
Creates a MenuLinkIter
to iterate over the links of the item at
position itemIndex
in model
.
You must free the iterator with objectUnref
when you are done.
Since: 2.32
Signals
itemsChanged
type C_MenuModelItemsChangedCallback = Ptr () -> Int32 -> Int32 -> Int32 -> Ptr () -> IO () Source #
Type for the callback on the (unwrapped) C side.
type MenuModelItemsChangedCallback Source #
= Int32 |
|
-> Int32 |
|
-> Int32 |
|
-> IO () |
Emitted when a change has occured 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.
afterMenuModelItemsChanged :: (IsMenuModel a, MonadIO m) => a -> MenuModelItemsChangedCallback -> m SignalHandlerId Source #
Connect a signal handler for the “items-changed
” signal, to be run after the default handler.
When overloading is enabled, this is equivalent to
after
menuModel #itemsChanged callback
genClosure_MenuModelItemsChanged :: MenuModelItemsChangedCallback -> IO Closure Source #
Wrap the callback into a Closure
.
mk_MenuModelItemsChangedCallback :: C_MenuModelItemsChangedCallback -> IO (FunPtr C_MenuModelItemsChangedCallback) Source #
Generate a function pointer callable from C code, from a C_MenuModelItemsChangedCallback
.
noMenuModelItemsChangedCallback :: Maybe MenuModelItemsChangedCallback Source #
A convenience synonym for
.Nothing
:: Maybe
MenuModelItemsChangedCallback
onMenuModelItemsChanged :: (IsMenuModel a, MonadIO m) => a -> MenuModelItemsChangedCallback -> m SignalHandlerId Source #
Connect a signal handler for the “items-changed
” signal, to be run before the default handler.
When overloading is enabled, this is equivalent to
on
menuModel #itemsChanged callback