36 #include <QtCore/QDebug>
37 #include <QtCore/QSettings>
44 enum { warnAboutFindFailures = 0 };
207 using namespace Core;
208 using namespace Core::Internal;
231 qDeleteAll(m_idCmdMap.values());
232 qDeleteAll(m_idContainerMap.values());
242 return m_defaultGroups;
247 return m_idCmdMap.values();
252 return m_idContainerMap.values();
257 return m_context.contains(context);
266 const IdCmdMap::const_iterator cmdcend = m_idCmdMap.constEnd();
267 for (IdCmdMap::const_iterator it = m_idCmdMap.constBegin(); it != cmdcend; ++it)
268 it.value()->setCurrentContext(m_context);
270 const IdContainerMap::const_iterator acend = m_idContainerMap.constEnd();
271 for (IdContainerMap::const_iterator it = m_idContainerMap.constBegin(); it != acend; ++it)
272 it.value()->update();
277 for (
int i = 0;
i < m_context.count(); ++
i) {
278 if (context.contains(m_context.at(
i)))
287 const IdContainerMap::const_iterator it = m_idContainerMap.constFind(uid);
288 if (it != m_idContainerMap.constEnd())
291 QMenu *
m =
new QMenu(m_mainWnd);
292 m->setObjectName(
id);
297 m_idContainerMap.insert(uid, mc);
305 const IdContainerMap::const_iterator it = m_idContainerMap.constFind(uid);
306 if (it != m_idContainerMap.constEnd())
309 QMenuBar *mb =
new QMenuBar;
310 mb->setObjectName(
id);
315 m_idContainerMap.insert(uid, mbc);
324 Command *c = registerOverridableAction(action,
id,
false);
331 Command *ActionManagerPrivate::registerOverridableAction(QAction *action,
const QString &
id,
339 qWarning() <<
"registerAction: id" <<
id
340 <<
"is registered with a different command type.";
345 m_idCmdMap.insert(uid, a);
349 QAction *baseAction =
new QAction(m_mainWnd);
350 baseAction->setObjectName(
id);
351 baseAction->setCheckable(action->isCheckable());
352 baseAction->setIcon(action->icon());
353 baseAction->setIconText(action->iconText());
354 baseAction->setText(action->text());
355 baseAction->setToolTip(action->toolTip());
356 baseAction->setStatusTip(action->statusTip());
357 baseAction->setWhatsThis(action->whatsThis());
358 baseAction->setChecked(action->isChecked());
359 baseAction->setSeparator(action->isSeparator());
360 baseAction->setShortcutContext(Qt::ApplicationShortcut);
361 baseAction->setEnabled(
false);
362 baseAction->setParent(m_mainWnd);
364 baseAction->setIconVisibleInMenu(
false);
367 m_mainWnd->addAction(baseAction);
370 }
else if (checkUnique) {
371 qWarning() <<
"registerOverridableAction: id" <<
id <<
"is already registered.";
385 qWarning() <<
"registerShortcut: id" <<
id
386 <<
"is registered with a different command type.";
391 m_idCmdMap.insert(uid, sc);
395 qWarning() <<
"registerShortcut: action already registered (id" <<
id <<
".";
400 shortcut->setEnabled(
false);
401 shortcut->setObjectName(
id);
402 shortcut->setParent(m_mainWnd);
405 if (context.isEmpty())
419 const IdCmdMap::const_iterator it = m_idCmdMap.constFind(uid);
420 if (it == m_idCmdMap.constEnd()) {
421 if (warnAboutFindFailures)
422 qWarning() <<
"ActionManagerPrivate::command(): failed to find :" <<
id <<
'/' << uid;
431 const IdContainerMap::const_iterator it = m_idContainerMap.constFind(uid);
432 if (it == m_idContainerMap.constEnd()) {
433 if (warnAboutFindFailures)
434 qWarning() <<
"ActionManagerPrivate::actionContainer(): failed to find :" <<
id <<
'/'
443 const IdCmdMap::const_iterator it = m_idCmdMap.constFind(uid);
444 if (it == m_idCmdMap.constEnd()) {
445 if (warnAboutFindFailures)
446 qWarning() <<
"ActionManagerPrivate::command(): failed to find :"
455 const IdContainerMap::const_iterator it = m_idContainerMap.constFind(uid);
456 if (it == m_idContainerMap.constEnd()) {
457 if (warnAboutFindFailures)
458 qWarning() <<
"ActionManagerPrivate::actionContainer(): failed to find :"
465 static const char *settingsGroup =
"KeyBindings";
466 static const char *idKey =
"ID";
467 static const char *sequenceKey =
"Keysequence";
471 const int shortcuts = settings->beginReadArray(QLatin1String(settingsGroup));
472 for (
int i = 0;
i < shortcuts; ++
i) {
473 settings->setArrayIndex(
i);
474 const QString sid = settings->value(QLatin1String(idKey)).toString();
475 const QKeySequence key(settings->value(QLatin1String(sequenceKey)).toString());
482 settings->endArray();
487 settings->beginWriteArray(QLatin1String(settingsGroup));
490 const IdCmdMap::const_iterator cmdcend = m_idCmdMap.constEnd();
491 for (IdCmdMap::const_iterator j = m_idCmdMap.constBegin(); j != cmdcend; ++j) {
492 const int id = j.key();
497 settings->setArrayIndex(count);
498 settings->setValue(QLatin1String(idKey), sid);
499 settings->setValue(QLatin1String(sequenceKey), key.toString());
504 settings->endArray();
static UniqueIDManager * instance()
int uniqueIdentifier(const QString &id)
void setMenuBar(QMenuBar *menuBar)
void addOverrideAction(QAction *action, const QList< int > &context)
void setKeySequence(const QKeySequence &key)
Command * registerShortcut(QShortcut *shortcut, const QString &id, const QList< int > &context)
Makes a shortcut known to the system under the specified string id.
ActionContainer * createMenuBar(const QString &id)
Creates a new menu bar with the given string id.
bool hasContext(int context) const
QKeySequence keySequence() const
Command * command(int uid) const
void setMenu(QMenu *menu)
virtual QKeySequence keySequence() const =0
void setAction(QAction *action)
void setKeySequence(const QKeySequence &key)
void setContext(const QList< int > &context)
void setDefaultKeySequence(const QKeySequence &key)
void readSettings(QSettings *settings)
static ActionManagerPrivate * instance()
QList< ActionContainerPrivate * > containers() const
QShortcut * shortcut() const
void saveSettings(QSettings *settings)
Command * registerAction(QAction *action, const QString &id, const QList< int > &context)
Makes an action known to the system under the specified string id.
void setDefaultKeySequence(const QKeySequence &key)
void setContext(const QList< int > &context)
virtual void setKeySequence(const QKeySequence &key)=0
QString stringForUniqueIdentifier(int uid)
ActionContainer * createMenu(const QString &id)
Creates a new menu with the given string id.
QKeySequence defaultKeySequence() const
The action manager is responsible for registration of menus and menu items and keyboard shortcuts...
const char *const G_DEFAULT_ONE
ActionContainer * actionContainer(int uid) const
ActionManagerPrivate(MainWindow *mainWnd)
const char *const G_DEFAULT_TWO
QList< CommandPrivate * > commands() const
QList< int > defaultGroups() const
The class Command represents an action like a menu item, tool button, or shortcut. You don't create Command objects directly, instead use {ActionManager::registerAction()} to register an action and retrieve a Command. The Command object represents the user visible action and its properties. If multiple actions are registered with the same ID (but different contexts) the returned Command is the shared one between these actions.
void setShortcut(QShortcut *shortcut)
const char *const G_DEFAULT_THREE