diff options
author | con <[email protected]> | 2010-12-16 11:49:47 +0100 |
---|---|---|
committer | con <[email protected]> | 2010-12-17 16:05:47 +0100 |
commit | 4321e01efbe7cbe2f360809e4fc170aff8c896a4 (patch) | |
tree | dfe9949f5d6a06de8c6202acaac84072267ba497 /src | |
parent | 83e82de6fd4ff8421eaccb14a4deac99212e187a (diff) |
Some API beautification in action container.
Done-with: Daniel Molkentin
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/coreplugin/actionmanager/actioncontainer.cpp | 57 | ||||
-rw-r--r-- | src/plugins/coreplugin/actionmanager/actioncontainer.h | 12 | ||||
-rw-r--r-- | src/plugins/coreplugin/actionmanager/actioncontainer_p.h | 6 | ||||
-rw-r--r-- | src/plugins/coreplugin/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/plugins/glsleditor/glsleditorplugin.cpp | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectexplorer.cpp | 6 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditorplugin.cpp | 2 |
7 files changed, 49 insertions, 38 deletions
diff --git a/src/plugins/coreplugin/actionmanager/actioncontainer.cpp b/src/plugins/coreplugin/actionmanager/actioncontainer.cpp index 68e73a197c5..22b7060966d 100644 --- a/src/plugins/coreplugin/actionmanager/actioncontainer.cpp +++ b/src/plugins/coreplugin/actionmanager/actioncontainer.cpp @@ -65,26 +65,37 @@ using namespace Core::Internal; You can define if the menu represented by this action container should automatically disable or hide whenever it only contains disabled items and submenus by setting the corresponding - \l{ActionContainer::setEmptyAction()}{EmptyAction}. + \l{ActionContainer::setOnAllDisabledBehavior()}{OnAllDisabledBehavior}. The default is + ActionContainer::Disable for menus, and ActionContainer::Show for menu bars. */ /*! - \enum ActionContainer::EmptyAction + \enum ActionContainer::OnAllDisabledBehavior Defines what happens when the represented menu is empty or contains only disabled/invisible items. - \omitvalue EA_Mask - \value EA_None - The menu will still be visible and active. - \value EA_Disable + \value Disable The menu will be visible but disabled. - \value EA_Hide + \value Hide The menu will not be visible until the state of the subitems change. + \value Show + The menu will still be visible and active. +*/ + +/*! + \fn ActionContainer::setOnAllDisabledBehavior(OnAllDisabledBehavior behavior) + Defines the \a behavior of the menu represented by this action container for the case + whenever it only contains disabled items and submenus. + The default is ActionContainer::Disable for menus, and ActionContainer::Show for menu bars. + \sa ActionContainer::OnAllDisabledBehavior + \sa ActionContainer::onAllDisabledBehavior() */ /*! - \fn ActionContainer::setEmptyAction(EmptyAction disableOrHide) - Defines if the menu represented by this action container should automatically \a disableOrHide + \fn ActionContainer::onAllDisabledBehavior() const + Returns the \a behavior of the menu represented by this action container for the case whenever it only contains disabled items and submenus. - \sa ActionContainer::EmptyAction + The default is ActionContainer::Disable for menus, and ActionContainer::Show for menu bars. + \sa ActionContainer::OnAllDisabledBehavior + \sa ActionContainer::setOnAllDisabledBehavior() */ /*! @@ -148,19 +159,19 @@ using namespace Core::Internal; */ ActionContainerPrivate::ActionContainerPrivate(int id) - : m_data(0), m_id(id), m_updateRequested(false) + : m_onAllDisabledBehavior(Disable), m_id(id), m_updateRequested(false) { scheduleUpdate(); } -void ActionContainerPrivate::setEmptyAction(EmptyAction ea) +void ActionContainerPrivate::setOnAllDisabledBehavior(OnAllDisabledBehavior behavior) { - m_data = ((m_data & ~EA_Mask) | ea); + m_onAllDisabledBehavior = behavior; } -bool ActionContainerPrivate::hasEmptyAction(EmptyAction ea) const +ActionContainer::OnAllDisabledBehavior ActionContainerPrivate::onAllDisabledBehavior() const { - return (m_data & EA_Mask) == ea; + return m_onAllDisabledBehavior; } void ActionContainerPrivate::appendGroup(const QString &group) @@ -343,7 +354,7 @@ void ActionContainerPrivate::update() MenuActionContainer::MenuActionContainer(int id) : ActionContainerPrivate(id), m_menu(0) { - setEmptyAction(EA_Disable); + setOnAllDisabledBehavior(Disable); } void MenuActionContainer::setMenu(QMenu *menu) @@ -383,7 +394,7 @@ CommandLocation MenuActionContainer::location() const bool MenuActionContainer::updateInternal() { - if (hasEmptyAction(EA_None)) + if (onAllDisabledBehavior() == Show) return true; bool hasitems = false; @@ -419,9 +430,9 @@ bool MenuActionContainer::updateInternal() } } - if (hasEmptyAction(EA_Hide)) + if (onAllDisabledBehavior() == Hide) m_menu->menuAction()->setVisible(hasitems); - else if (hasEmptyAction(EA_Disable)) + else if (onAllDisabledBehavior() == Disable) m_menu->menuAction()->setEnabled(hasitems); return hasitems; @@ -443,7 +454,7 @@ bool MenuActionContainer::canBeAddedToMenu() const MenuBarActionContainer::MenuBarActionContainer(int id) : ActionContainerPrivate(id), m_menuBar(0) { - setEmptyAction(EA_None); + setOnAllDisabledBehavior(Show); } void MenuBarActionContainer::setMenuBar(QMenuBar *menuBar) @@ -468,7 +479,7 @@ void MenuBarActionContainer::insertMenu(QAction *before, QMenu *menu) bool MenuBarActionContainer::updateInternal() { - if (hasEmptyAction(EA_None)) + if (onAllDisabledBehavior() == Show) return true; bool hasitems = false; @@ -480,9 +491,9 @@ bool MenuBarActionContainer::updateInternal() } } - if (hasEmptyAction(EA_Hide)) + if (onAllDisabledBehavior() == Hide) m_menuBar->setVisible(hasitems); - else if (hasEmptyAction(EA_Disable)) + else if (onAllDisabledBehavior() == Disable) m_menuBar->setEnabled(hasitems); return hasitems; diff --git a/src/plugins/coreplugin/actionmanager/actioncontainer.h b/src/plugins/coreplugin/actionmanager/actioncontainer.h index 042921df65b..708f7df5d30 100644 --- a/src/plugins/coreplugin/actionmanager/actioncontainer.h +++ b/src/plugins/coreplugin/actionmanager/actioncontainer.h @@ -47,14 +47,14 @@ class ActionContainer : public QObject Q_OBJECT public: - enum EmptyAction { - EA_Mask = 0xFF00, - EA_None = 0x0100, - EA_Hide = 0x0200, - EA_Disable = 0x0300 + enum OnAllDisabledBehavior { + Disable, + Hide, + Show }; - virtual void setEmptyAction(EmptyAction ea) = 0; + virtual void setOnAllDisabledBehavior(OnAllDisabledBehavior behavior) = 0; + virtual ActionContainer::OnAllDisabledBehavior onAllDisabledBehavior() const = 0; virtual int id() const = 0; diff --git a/src/plugins/coreplugin/actionmanager/actioncontainer_p.h b/src/plugins/coreplugin/actionmanager/actioncontainer_p.h index 226fcc35acf..39be99c30c4 100644 --- a/src/plugins/coreplugin/actionmanager/actioncontainer_p.h +++ b/src/plugins/coreplugin/actionmanager/actioncontainer_p.h @@ -46,8 +46,8 @@ public: ActionContainerPrivate(int id); virtual ~ActionContainerPrivate() {} - void setEmptyAction(EmptyAction ea); - bool hasEmptyAction(EmptyAction ea) const; + void setOnAllDisabledBehavior(OnAllDisabledBehavior behavior); + ActionContainer::OnAllDisabledBehavior onAllDisabledBehavior() const; QAction *insertLocation(const QString &group) const; void appendGroup(const QString &group); @@ -84,7 +84,7 @@ private: int calcPosition(int pos, int prevKey) const; QList<int> m_groups; - int m_data; + OnAllDisabledBehavior m_onAllDisabledBehavior; int m_id; QMap<int, int> m_posmap; QList<ActionContainer *> m_subContainers; diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 898ec1a6b4b..178999f3fd4 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -590,7 +590,7 @@ void MainWindow::registerDefaultActions() ActionContainer *ac = am->createMenu(Constants::M_FILE_RECENTFILES); mfile->addMenu(ac, Constants::G_FILE_OPEN); ac->menu()->setTitle(tr("Recent &Files")); - ac->setEmptyAction(ActionContainer::EA_None); + ac->setOnAllDisabledBehavior(ActionContainer::Show); // Save Action icon = QIcon::fromTheme(QLatin1String("document-save"), QIcon(Constants::ICON_SAVEFILE)); diff --git a/src/plugins/glsleditor/glsleditorplugin.cpp b/src/plugins/glsleditor/glsleditorplugin.cpp index fe66604d464..62fbc9c8bfd 100644 --- a/src/plugins/glsleditor/glsleditorplugin.cpp +++ b/src/plugins/glsleditor/glsleditorplugin.cpp @@ -141,7 +141,7 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er Core::ActionManager *am = core->actionManager(); Core::ActionContainer *contextMenu = am->createMenu(GLSLEditor::Constants::M_CONTEXT); Core::ActionContainer *glslToolsMenu = am->createMenu(Core::Id(Constants::M_TOOLS_GLSL)); - glslToolsMenu->setEmptyAction(Core::ActionContainer::EA_Hide); + glslToolsMenu->setOnAllDisabledBehavior(Core::ActionContainer::Hide); QMenu *menu = glslToolsMenu->menu(); //: GLSL sub-menu in the Tools menu menu->setTitle(tr("GLSL")); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 41113dca7cf..5c966f101d4 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -435,7 +435,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er // "open with" submenu Core::ActionContainer * const openWith = am->createMenu(ProjectExplorer::Constants::M_OPENFILEWITHCONTEXT); - openWith->setEmptyAction(Core::ActionContainer::EA_None); + openWith->setOnAllDisabledBehavior(Core::ActionContainer::Show); d->m_openWithMenu = openWith->menu(); d->m_openWithMenu->setTitle(tr("Open With")); @@ -540,7 +540,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er Core::ActionContainer *mrecent = am->createMenu(Constants::M_RECENTPROJECTS); mrecent->menu()->setTitle(tr("Recent P&rojects")); - mrecent->setEmptyAction(Core::ActionContainer::EA_None); + mrecent->setOnAllDisabledBehavior(Core::ActionContainer::Show); mfile->addMenu(mrecent, Core::Constants::G_FILE_OPEN); connect(mfile->menu(), SIGNAL(aboutToShow()), this, SLOT(updateRecentProjectMenu())); @@ -563,7 +563,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er // session menu Core::ActionContainer *msession = am->createMenu(Constants::M_SESSION); msession->menu()->setTitle(tr("Session")); - msession->setEmptyAction(Core::ActionContainer::EA_None); + msession->setOnAllDisabledBehavior(Core::ActionContainer::Show); mfile->addMenu(msession, Core::Constants::G_FILE_PROJECT); d->m_sessionMenu = msession->menu(); connect(mfile->menu(), SIGNAL(aboutToShow()), diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 31385027cdd..183634c6d0e 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -161,7 +161,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e Core::ActionManager *am = core->actionManager(); Core::ActionContainer *contextMenu = am->createMenu(QmlJSEditor::Constants::M_CONTEXT); Core::ActionContainer *qmlToolsMenu = am->createMenu(Core::Id(Constants::M_TOOLS_QML)); - qmlToolsMenu->setEmptyAction(Core::ActionContainer::EA_Hide); + qmlToolsMenu->setOnAllDisabledBehavior(Core::ActionContainer::Hide); QMenu *menu = qmlToolsMenu->menu(); //: QML sub-menu in the Tools menu menu->setTitle(tr("QML")); |