26 #define YUILogComponent "ui-shortcuts"
29 #include "YShortcutManager.h"
40 #define MIN_VALID_PERCENT 50
43 #define DIM( ARRAY ) ( (int) ( sizeof( ARRAY)/( sizeof( ARRAY[0] ) ) ) )
64 yuiDebug() <<
"Checking keyboard shortcuts" << endl;
80 if ( validPercent < MIN_VALID_PERCENT )
87 yuiWarning() <<
"Not enough widgets with valid shortcut characters - no check" << endl;
88 yuiDebug() <<
"Found " << validCount <<
" widgets with valid shortcut characters" << endl;
94 for (
int i=0; i < DIM(
_wanted ); i++ )
98 for (
int i=0; i < DIM(
_wanted ); i++ )
121 yuiDebug() <<
"Shortcut conflict: '" << shortcut->
preferred()
122 <<
"' used for " << shortcut->
widget()
135 yuiDebug() <<
"No valid shortcut for " << shortcut->
widget() << endl;
157 yuiDebug() <<
"No shortcut conflicts" << endl;
165 yuiDebug() <<
"Resolving shortcut conflicts" << endl;
169 yuiError() <<
"Call checkShortcuts() first!" << endl;
176 YShortcutList conflictList;
183 if ( ( *it )->conflict() )
185 conflictList.push_back( *it );
193 while ( ! conflictList.empty() )
208 YShortcut * shortcut = conflictList[ prioIndex ];
213 yuiWarning() <<
"Couldn't resolve shortcut conflict for " << shortcut->
widget() << endl;
219 conflictList.erase( conflictList.begin() + prioIndex );
224 yuiDebug() <<
_conflictCount <<
" shortcut conflict(s) left" << endl;
238 ||
_used[ (
int) candidate ] )
243 for ( string::size_type pos = 0; pos < str.length(); pos++ )
265 if ( candidate != shortcut->
preferred() )
269 yuiDebug() <<
"Automatically assigning shortcut '" << candidate
270 <<
"' to " << shortcut->
widgetClass() <<
"(`opt(`autoShortcut ), \""
276 yuiDebug() <<
"Reassigning shortcut '" << candidate
277 <<
"' to " << shortcut->
widget()
284 yuiDebug() <<
"Keeping preferred shortcut '" << candidate
285 <<
"' for " << shortcut->
widget()
289 _used[ (int) candidate ] =
true;
294 yuiWarning() <<
"Couldn't resolve shortcut conflict for "
296 <<
" - assigning no shortcut"
311 int shortestIndex = -1;
312 int shortestLen = -1;
314 for (
unsigned i=1; i < conflictList.size(); i++ )
316 if ( conflictList[i]->isWizardButton() )
318 if ( shortestLen < 0 ||
319 conflictList[i]->distinctShortcutChars() < shortestLen )
322 shortestLen = conflictList[i]->distinctShortcutChars();
328 return shortestIndex;
336 unsigned shortestIndex = 0;
337 int shortestLen = conflictList[ shortestIndex ]->distinctShortcutChars();
339 for (
unsigned i=1; i < conflictList.size(); i++ )
341 int currentLen = conflictList[i]->distinctShortcutChars();
343 if ( currentLen < shortestLen )
348 shortestLen = currentLen;
350 else if ( currentLen == shortestLen )
352 if ( conflictList[i]->isButton() &&
353 ! conflictList[ shortestIndex ]->isButton() )
358 shortestLen = currentLen;
363 return shortestIndex;
382 YWidgetListConstIterator end )
384 for ( YWidgetListConstIterator it = begin; it != end; ++it )
void resolveAllConflicts()
Resolve shortcut conflicts.
void checkShortcuts(bool autoResolve=true)
Check the keyboard shortcuts of all children of this dialog (not for sub-dialogs!).
YDialog * _dialog
The dialog this shortcut manager works on.
YShortcutList _shortcutList
List of all the shortcuts in this dialog.
int findShortestWizardButton(const YShortcutList &conflictList)
Find the shortest wizard button in 'conflictList', if there is any.
bool conflict()
Query the internal 'conflict' marker.
const char * widgetClass() const
Returns the textual representation of the widget class of the widget this shortcut data belongs to.
bool _used[sizeof(char)<< 8]
Flags for used shortcut characters.
Special case for widgets that can have multiple shortcuts based on items (like YDumbTab)
YWidget * widget() const
Returns the YWidget this shortcut data belong to.
virtual void setShortcut(char newShortcut)
Set (override) the shortcut character.
static char normalized(char c)
Return the normalized version of shortcut character 'c', i.e.
Helper class for shortcut management: This class holds data about the shortcut for one single widget.
YShortcutManager(YDialog *dialog)
Constructor.
void resolveConflict(YShortcut *shortcut)
Pick a new shortcut character for 'shortcut' - one that isn't marked as used in the '_used' array.
int _conflictCount
Counter for shortcut conflicts.
int _wanted[sizeof(char)<< 8]
Counters for wanted shortcut characters.
void clearShortcut()
Clear the shortcut: Override the shortcut character with nothing.
static bool isValid(char c)
Returns 'true' if 'c' is a valid shortcut character, i.e.
DumbTab: A very simple tab widget that can display and switch between a number of tabs,...
void setConflict(bool newConflictState=true)
Set or unset the internal 'conflict' marker.
void findShortcutWidgets(YWidgetListConstIterator begin, YWidgetListConstIterator end)
Recursively search all widgets between iterators 'begin' and 'end' (not those of any sub-dialogs!...
void clearShortcutList()
Delete all members of the internal shortcut list, then empty the list.
char preferred()
The preferred shortcut character, i.e.
std::string cleanShortcutString()
Returns the shortcut string ( from the widget's shortcut property ) without any "&" markers.
YItemCollection::const_iterator YItemConstIterator
Const iterator over YItemCollection.
A window in the desktop environment.
virtual ~YShortcutManager()
Destructor.
unsigned findShortestWidget(const YShortcutList &conflictList)
Find the shortest widget in 'conflictList'.