26 #define YUILogComponent "ui-shortcuts" 29 #include "YShortcutManager.h" 38 #define MIN_VALID_PERCENT 50 41 #define DIM( ARRAY ) ( (int) ( sizeof( ARRAY)/( sizeof( ARRAY[0] ) ) ) ) 62 yuiDebug() <<
"Checking keyboard shortcuts" << std::endl;
78 if ( validPercent < MIN_VALID_PERCENT )
85 yuiWarning() <<
"Not enough widgets with valid shortcut characters - no check" << std::endl;
86 yuiDebug() <<
"Found " << validCount <<
" widgets with valid shortcut characters" << std::endl;
92 for (
int i=0; i < DIM(
_wanted ); i++ )
96 for (
int i=0; i < DIM(
_wanted ); i++ )
119 yuiDebug() <<
"Shortcut conflict: '" << shortcut->
preferred()
120 <<
"' used for " << shortcut->
widget()
133 yuiDebug() <<
"No valid shortcut for " << shortcut->
widget() << std::endl;
155 yuiDebug() <<
"No shortcut conflicts" << std::endl;
163 yuiDebug() <<
"Resolving shortcut conflicts" << std::endl;
167 yuiError() <<
"Call checkShortcuts() first!" << std::endl;
174 YShortcutList conflictList;
181 if ( ( *it )->conflict() )
183 conflictList.push_back( *it );
191 while ( ! conflictList.empty() )
206 YShortcut * shortcut = conflictList[ prioIndex ];
211 yuiWarning() <<
"Couldn't resolve shortcut conflict for " << shortcut->
widget() << std::endl;
217 conflictList.erase( conflictList.begin() + prioIndex );
222 yuiDebug() <<
_conflictCount <<
" shortcut conflict(s) left" << std::endl;
236 ||
_used[ (
int) candidate ] )
241 for ( std::string::size_type pos = 0; pos < str.length(); pos++ )
263 if ( candidate != shortcut->
preferred() )
267 yuiDebug() <<
"Automatically assigning shortcut '" << candidate
268 <<
"' to " << shortcut->
widgetClass() <<
"(`opt(`autoShortcut ), \"" 274 yuiDebug() <<
"Reassigning shortcut '" << candidate
275 <<
"' to " << shortcut->
widget()
282 yuiDebug() <<
"Keeping preferred shortcut '" << candidate
283 <<
"' for " << shortcut->
widget()
287 _used[ (int) candidate ] =
true;
292 yuiWarning() <<
"Couldn't resolve shortcut conflict for " 294 <<
" - assigning no shortcut" 309 int shortestIndex = -1;
310 int shortestLen = -1;
312 for (
unsigned i=1; i < conflictList.size(); i++ )
314 if ( conflictList[i]->isWizardButton() )
316 if ( shortestLen < 0 ||
317 conflictList[i]->distinctShortcutChars() < shortestLen )
320 shortestLen = conflictList[i]->distinctShortcutChars();
326 return shortestIndex;
334 unsigned shortestIndex = 0;
335 int shortestLen = conflictList[ shortestIndex ]->distinctShortcutChars();
337 for (
unsigned i=1; i < conflictList.size(); i++ )
339 int currentLen = conflictList[i]->distinctShortcutChars();
341 if ( currentLen < shortestLen )
346 shortestLen = currentLen;
348 else if ( currentLen == shortestLen )
350 if ( conflictList[i]->isButton() &&
351 ! conflictList[ shortestIndex ]->isButton() )
356 shortestLen = currentLen;
361 return shortestIndex;
380 YWidgetListConstIterator end )
382 for ( YWidgetListConstIterator it = begin; it != end; ++it )
bool _used[sizeof(char)<< 8]
Flags for used shortcut characters.
int _conflictCount
Counter for shortcut conflicts.
virtual ~YShortcutManager()
Destructor.
DumbTab: A very simple tab widget that can display and switch between a number of tabs...
void clearShortcutList()
Delete all members of the internal shortcut list, then empty the list.
char preferred()
The preferred shortcut character, i.e.
void resolveAllConflicts()
Resolve shortcut conflicts.
const char * widgetClass() const
Returns the textual representation of the widget class of the widget this shortcut data belongs to...
Helper class for shortcut management: This class holds data about the shortcut for one single widget...
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.
void setConflict(bool newConflictState=true)
Set or unset the internal 'conflict' marker.
std::string cleanShortcutString()
Returns the shortcut string ( from the widget's shortcut property ) without any "&" markers...
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.
Special case for widgets that can have multiple shortcuts based on items (like YDumbTab) ...
void checkShortcuts(bool autoResolve=true)
Check the keyboard shortcuts of all children of this dialog (not for sub-dialogs!).
unsigned findShortestWidget(const YShortcutList &conflictList)
Find the shortest widget in 'conflictList'.
bool conflict()
Query the internal 'conflict' marker.
YItemCollection::const_iterator YItemConstIterator
Const iterator over YItemCollection.
int _wanted[sizeof(char)<< 8]
Counters for wanted shortcut characters.
void clearShortcut()
Clear the shortcut: Override the shortcut character with nothing.
YDialog * _dialog
The dialog this shortcut manager works on.
A window in the desktop environment.
YWidget * widget() const
Returns the YWidget this shortcut data belong to.
void findShortcutWidgets(YWidgetListConstIterator begin, YWidgetListConstIterator end)
Recursively search all widgets between iterators 'begin' and 'end' (not those of any sub-dialogs!) fo...
YShortcutManager(YDialog *dialog)
Constructor.
static bool isValid(char c)
Returns 'true' if 'c' is a valid shortcut character, i.e.
void resolveConflict(YShortcut *shortcut)
Pick a new shortcut character for 'shortcut' - one that isn't marked as used in the '_used' array...