YShortcutManager Class Reference

Helper class to manage keyboard shortcuts within one dialog and resolve keyboard shortcut conflicts. More...

#include <YShortcutManager.h>

List of all members.

Public Member Functions

 YShortcutManager (YDialog *dialog)
virtual ~YShortcutManager ()
void checkShortcuts (bool autoResolve=true)
int conflictCount ()
void resolveAllConflicts ()
YDialogdialog ()

Protected Member Functions

void clearShortcutList ()
void findShortcutWidgets ()
void resolveConflict (YShortcut *shortcut)

Protected Attributes

YDialog_dialog
YShortcutList _shortcutList
int _wanted [sizeof(char)<< 8]
bool _used [sizeof(char)<< 8]
int _conflictCount

Private Attributes

bool _did_check


Detailed Description

Helper class to manage keyboard shortcuts within one dialog and resolve keyboard shortcut conflicts.


Constructor & Destructor Documentation

YShortcutManager::YShortcutManager ( YDialog dialog  ) 

Constructor

YShortcutManager::~YShortcutManager (  )  [virtual]

Destructor


Member Function Documentation

void YShortcutManager::checkShortcuts ( bool  autoResolve = true  ) 

Checks the keyboard shortcuts of all children of this dialog ( not for sub-dialogs! ).

Runs resolveAllConflicts() if 'autoResolve' is 'true'.

int YShortcutManager::conflictCount (  ) 

Returns the number of shortcut conflicts. Valid only after checkShortcuts() or resolveAllConflicts().

void YShortcutManager::resolveAllConflicts (  ) 

Resolve shortcut conflicts. Requires checkShortcuts() to be called first.

Note: This may or may not work. There is no general solution to that problem. This method tries its best, but you may end up with widgets that don't have any ( more ) shortcut.

Why? Just picture the following ( admittedly pathologic ) situation:

[& OK] [& OK] [& OK]

This will result in something like this:

[& OK] [O& K] [OK]

I.e. the first OK button will retain its preferred shortcut ( 'O' ), the second OK button's shortcut will be reassigned to 'K' and the third won't get any - there are simply not enough eligible shortcut characters.

This may even fail in much less pathological situations. This example is only supposed to give you a general idea why not to blindly rely on automatic shortcut resolving.

It's always best to resolve conflicts manually. This will generally result in much better shortcuts: Easier to memorize, less chance of picking characters that cannot really do a good job showing their shortcut like very narrow characters ( .e.g., 'i' ) or descender characters ( e.g., 'g', 'p', 'q' - imagine those underlined! ).

Pick a conflict widget to resolve. Use the widget with the least number of eligible shortcut characters first to maximize chances for success.

YDialog* YShortcutManager::dialog (  )  [inline]

Returns the dialog this shortcut manager works on.

void YShortcutManager::clearShortcutList (  )  [protected]

Delete all members of the internal shortcut list, then empty the list.

void YShortcutManager::findShortcutWidgets (  )  [protected]

Search all children of _dialog ( not those of any sub-dialogs! ) for child widgets that could accept a keyboard shortcut and add these to _shortcutList.

void YShortcutManager::resolveConflict ( YShortcut shortcut  )  [protected]

Pick a new shortcut character for 'shortcut' - one that isn't marked as used in the '_used' array. Unset the conflict marker if that succeeded.


Member Data Documentation

YDialog* YShortcutManager::_dialog [protected]

The dialog this shortcut manager works on.

YShortcutList YShortcutManager::_shortcutList [protected]

List of all the shortcuts in this dialog.

int YShortcutManager::_wanted[sizeof(char)<< 8] [protected]

Counters for wanted shortcut characters.

bool YShortcutManager::_used[sizeof(char)<< 8] [protected]

Flags for used shortcut characters.

int YShortcutManager::_conflictCount [protected]

Counter for shortcut conflicts

bool YShortcutManager::_did_check [private]


The documentation for this class was generated from the following files:
Generated on Tue Nov 6 01:20:23 2007 for yast2-core by  doxygen 1.5.0