26 #define YUILogComponent "ui-shortcuts"
29 #include "YShortcutManager.h"
32 #include "YItemSelector.h"
42 #define MIN_VALID_PERCENT 50
45 #define DIM( ARRAY ) ( (int) ( sizeof( ARRAY)/( sizeof( ARRAY[0] ) ) ) )
66 yuiDebug() <<
"Checking keyboard shortcuts" << endl;
82 if ( validPercent < MIN_VALID_PERCENT )
89 yuiWarning() <<
"Not enough widgets with valid shortcut characters - no check" << endl;
90 yuiDebug() <<
"Found " << validCount <<
" widgets with valid shortcut characters" << endl;
96 for (
int i=0; i < DIM(
_wanted ); i++ )
100 for (
int i=0; i < DIM(
_wanted ); i++ )
123 yuiDebug() <<
"Shortcut conflict: '" << shortcut->
preferred()
124 <<
"' used for " << shortcut->
widget()
137 yuiDebug() <<
"No valid shortcut for " << shortcut->
widget() << endl;
159 yuiDebug() <<
"No shortcut conflicts" << endl;
167 yuiDebug() <<
"Resolving shortcut conflicts" << endl;
171 yuiError() <<
"Call checkShortcuts() first!" << endl;
178 YShortcutList conflictList;
185 if ( ( *it )->conflict() )
187 conflictList.push_back( *it );
195 while ( ! conflictList.empty() )
210 YShortcut * shortcut = conflictList[ prioIndex ];
215 yuiWarning() <<
"Couldn't resolve shortcut conflict for " << shortcut->
widget() << endl;
221 conflictList.erase( conflictList.begin() + prioIndex );
226 yuiDebug() <<
_conflictCount <<
" shortcut conflict(s) left" << endl;
240 ||
_used[ (
int) candidate ] )
245 for ( string::size_type pos = 0; pos < str.length(); pos++ )
267 if ( candidate != shortcut->
preferred() )
271 yuiDebug() <<
"Automatically assigning shortcut '" << candidate
272 <<
"' to " << shortcut->
widgetClass() <<
"(`opt(`autoShortcut ), \""
278 yuiDebug() <<
"Reassigning shortcut '" << candidate
279 <<
"' to " << shortcut->
widget()
286 yuiDebug() <<
"Keeping preferred shortcut '" << candidate
287 <<
"' for " << shortcut->
widget()
291 _used[ (int) candidate ] =
true;
296 yuiWarning() <<
"Couldn't resolve shortcut conflict for "
298 <<
" - assigning no shortcut"
313 int shortestIndex = -1;
314 int shortestLen = -1;
316 for (
unsigned i=1; i < conflictList.size(); i++ )
318 if ( conflictList[i]->isWizardButton() )
320 if ( shortestLen < 0 ||
321 conflictList[i]->distinctShortcutChars() < shortestLen )
324 shortestLen = conflictList[i]->distinctShortcutChars();
330 return shortestIndex;
338 unsigned shortestIndex = 0;
339 int shortestLen = conflictList[ shortestIndex ]->distinctShortcutChars();
341 for (
unsigned i=1; i < conflictList.size(); i++ )
343 int currentLen = conflictList[i]->distinctShortcutChars();
345 if ( currentLen < shortestLen )
350 shortestLen = currentLen;
352 else if ( currentLen == shortestLen )
354 if ( conflictList[i]->isButton() &&
355 ! conflictList[ shortestIndex ]->isButton() )
360 shortestLen = currentLen;
365 return shortestIndex;
390 if ( ! selectionWidget )
393 if ( ! selectionWidget )
394 selectionWidget =
dynamic_cast<YMenuBar *
> (widget);
396 return selectionWidget;
402 YWidgetListConstIterator end )
404 for ( YWidgetListConstIterator it = begin; it != end; ++it )
410 if ( selectionWidget )
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 (owning) 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.
Scrollable item selector widget with not only a label for each item, but also a (possible multi-line)...
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'.