Commit 4321e01e authored by con's avatar con
Browse files

Some API beautification in action container.

Done-with: Daniel Molkentin
parent 83e82de6
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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));
......
......@@ -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"));
......
......@@ -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()),
......
......@@ -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"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment