Home Home > 2009 > 03 > 06 > YaST Qt UI with Context Menus
Sign up | Login

Deprecation notice: openSUSE Lizards user blog platform is deprecated, and will remain read only for the time being. Learn more...

YaST Qt UI with Context Menus

March 6th, 2009 by

Context menus are supported by almost all UI frameworks and most people got used to them. Therefore it’s high time to provide context menus in the YaST Qt UI as well. yast2-qt-2.18.6 offers this feature, packages are available in my build service repository.

contextmenu

In four simple steps YCP programmers can benefit from this new feature:

Step 1:
Create a widget and tell via `opt(`contextMenu) that a ContextMenuActivated Event should be emitted when the user right clicks the widget:

`SelectionBox( `id(`sport), `opt(`notify,`immediate, `contextMenu),
"Open a context menu:",
[
"Item1",
"Item2",
"Item3"
] );

Step 2:
Wait and analyze events:
event = UI::WaitForEvent( ... );
...
if ( event["EventReason"]:"" == "ContextMenuActivated" )
...

Step 3:
Open a context menu. The argument of OpenContextMenu() describes the menu structure:

UI::OpenContextMenu( `menu(
[ `item(`id(`folder), "&Folder"  ),
`menu( "&Document",
[ `item(`id(`text),
"&Text File" ),
`item(`id(`image),
"&Image"     ) ]) ]  ));

Step 4:
Analyze the returned `id and trigger an action. An example called ContextMenu.ycp is included in the package yast2-ycp-ui-bindings.

Usability
A Context menu provides shortcuts to actions for a certain widget or item. This features improves usability when it’s used properly. Application programmers should avoid making certain features only using context menus because users might not find them.
Please keep in mind that YaST ncurses doesn’t provide context menus. Each operation that is only available via a context menu is useless in YaST ncurses because the user cannot select it.

Both comments and pings are currently closed.

4 Responses to “YaST Qt UI with Context Menus”

  1. Anonymous

    Cool. Can the menus be accessed by keyboard?

    • Lukas Ocilka

      I don’t think there is a reason for that. The same functionality “must” be available using the buttons below (ncurses doesn’t support context menu).

  2. J. Daniel Schmidt

    As I can see it, the `opt(`contextMenu) flag behaves like `opt(`notify) with just the difference that it reacts on the other mouse button. So if this is the only difference and the mechanism is the same as for notify why not give it a similar name? I’d suggest to call it `opt(`notifyContextMenu) or `opt(`contextNotify). By this even the naming indicates similar behaviour …. just an idea.
    And btw. you could even add an `opt(`notifyScrollWheel) e.g. for Integer-Input fields with consistent naming.

    • Thomas Goettlicher

      Thanks you Daniel. I changed `opt(`contextMenu) to `opt(`notifyContextMenu) for more consistent nomenclature.