forked from qt-creator/qt-creator
Some API beautification in action container.
Done-with: Daniel Molkentin
This commit is contained in:
@@ -65,26 +65,37 @@ using namespace Core::Internal;
|
|||||||
|
|
||||||
You can define if the menu represented by this action container should automatically disable
|
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
|
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.
|
Defines what happens when the represented menu is empty or contains only disabled/invisible items.
|
||||||
\omitvalue EA_Mask
|
\value Disable
|
||||||
\value EA_None
|
|
||||||
The menu will still be visible and active.
|
|
||||||
\value EA_Disable
|
|
||||||
The menu will be visible but disabled.
|
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.
|
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::setEmptyAction(EmptyAction disableOrHide)
|
\fn ActionContainer::setOnAllDisabledBehavior(OnAllDisabledBehavior behavior)
|
||||||
Defines if the menu represented by this action container should automatically \a disableOrHide
|
Defines the \a behavior of the menu represented by this action container for the case
|
||||||
whenever it only contains disabled items and submenus.
|
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::onAllDisabledBehavior()
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\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.
|
||||||
|
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)
|
ActionContainerPrivate::ActionContainerPrivate(int id)
|
||||||
: m_data(0), m_id(id), m_updateRequested(false)
|
: m_onAllDisabledBehavior(Disable), m_id(id), m_updateRequested(false)
|
||||||
{
|
{
|
||||||
scheduleUpdate();
|
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)
|
void ActionContainerPrivate::appendGroup(const QString &group)
|
||||||
@@ -343,7 +354,7 @@ void ActionContainerPrivate::update()
|
|||||||
MenuActionContainer::MenuActionContainer(int id)
|
MenuActionContainer::MenuActionContainer(int id)
|
||||||
: ActionContainerPrivate(id), m_menu(0)
|
: ActionContainerPrivate(id), m_menu(0)
|
||||||
{
|
{
|
||||||
setEmptyAction(EA_Disable);
|
setOnAllDisabledBehavior(Disable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuActionContainer::setMenu(QMenu *menu)
|
void MenuActionContainer::setMenu(QMenu *menu)
|
||||||
@@ -383,7 +394,7 @@ CommandLocation MenuActionContainer::location() const
|
|||||||
|
|
||||||
bool MenuActionContainer::updateInternal()
|
bool MenuActionContainer::updateInternal()
|
||||||
{
|
{
|
||||||
if (hasEmptyAction(EA_None))
|
if (onAllDisabledBehavior() == Show)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool hasitems = false;
|
bool hasitems = false;
|
||||||
@@ -419,9 +430,9 @@ bool MenuActionContainer::updateInternal()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasEmptyAction(EA_Hide))
|
if (onAllDisabledBehavior() == Hide)
|
||||||
m_menu->menuAction()->setVisible(hasitems);
|
m_menu->menuAction()->setVisible(hasitems);
|
||||||
else if (hasEmptyAction(EA_Disable))
|
else if (onAllDisabledBehavior() == Disable)
|
||||||
m_menu->menuAction()->setEnabled(hasitems);
|
m_menu->menuAction()->setEnabled(hasitems);
|
||||||
|
|
||||||
return hasitems;
|
return hasitems;
|
||||||
@@ -443,7 +454,7 @@ bool MenuActionContainer::canBeAddedToMenu() const
|
|||||||
MenuBarActionContainer::MenuBarActionContainer(int id)
|
MenuBarActionContainer::MenuBarActionContainer(int id)
|
||||||
: ActionContainerPrivate(id), m_menuBar(0)
|
: ActionContainerPrivate(id), m_menuBar(0)
|
||||||
{
|
{
|
||||||
setEmptyAction(EA_None);
|
setOnAllDisabledBehavior(Show);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuBarActionContainer::setMenuBar(QMenuBar *menuBar)
|
void MenuBarActionContainer::setMenuBar(QMenuBar *menuBar)
|
||||||
@@ -468,7 +479,7 @@ void MenuBarActionContainer::insertMenu(QAction *before, QMenu *menu)
|
|||||||
|
|
||||||
bool MenuBarActionContainer::updateInternal()
|
bool MenuBarActionContainer::updateInternal()
|
||||||
{
|
{
|
||||||
if (hasEmptyAction(EA_None))
|
if (onAllDisabledBehavior() == Show)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool hasitems = false;
|
bool hasitems = false;
|
||||||
@@ -480,9 +491,9 @@ bool MenuBarActionContainer::updateInternal()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasEmptyAction(EA_Hide))
|
if (onAllDisabledBehavior() == Hide)
|
||||||
m_menuBar->setVisible(hasitems);
|
m_menuBar->setVisible(hasitems);
|
||||||
else if (hasEmptyAction(EA_Disable))
|
else if (onAllDisabledBehavior() == Disable)
|
||||||
m_menuBar->setEnabled(hasitems);
|
m_menuBar->setEnabled(hasitems);
|
||||||
|
|
||||||
return hasitems;
|
return hasitems;
|
||||||
|
|||||||
@@ -47,14 +47,14 @@ class ActionContainer : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum EmptyAction {
|
enum OnAllDisabledBehavior {
|
||||||
EA_Mask = 0xFF00,
|
Disable,
|
||||||
EA_None = 0x0100,
|
Hide,
|
||||||
EA_Hide = 0x0200,
|
Show
|
||||||
EA_Disable = 0x0300
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void setEmptyAction(EmptyAction ea) = 0;
|
virtual void setOnAllDisabledBehavior(OnAllDisabledBehavior behavior) = 0;
|
||||||
|
virtual ActionContainer::OnAllDisabledBehavior onAllDisabledBehavior() const = 0;
|
||||||
|
|
||||||
virtual int id() const = 0;
|
virtual int id() const = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ public:
|
|||||||
ActionContainerPrivate(int id);
|
ActionContainerPrivate(int id);
|
||||||
virtual ~ActionContainerPrivate() {}
|
virtual ~ActionContainerPrivate() {}
|
||||||
|
|
||||||
void setEmptyAction(EmptyAction ea);
|
void setOnAllDisabledBehavior(OnAllDisabledBehavior behavior);
|
||||||
bool hasEmptyAction(EmptyAction ea) const;
|
ActionContainer::OnAllDisabledBehavior onAllDisabledBehavior() const;
|
||||||
|
|
||||||
QAction *insertLocation(const QString &group) const;
|
QAction *insertLocation(const QString &group) const;
|
||||||
void appendGroup(const QString &group);
|
void appendGroup(const QString &group);
|
||||||
@@ -84,7 +84,7 @@ private:
|
|||||||
int calcPosition(int pos, int prevKey) const;
|
int calcPosition(int pos, int prevKey) const;
|
||||||
|
|
||||||
QList<int> m_groups;
|
QList<int> m_groups;
|
||||||
int m_data;
|
OnAllDisabledBehavior m_onAllDisabledBehavior;
|
||||||
int m_id;
|
int m_id;
|
||||||
QMap<int, int> m_posmap;
|
QMap<int, int> m_posmap;
|
||||||
QList<ActionContainer *> m_subContainers;
|
QList<ActionContainer *> m_subContainers;
|
||||||
|
|||||||
@@ -590,7 +590,7 @@ void MainWindow::registerDefaultActions()
|
|||||||
ActionContainer *ac = am->createMenu(Constants::M_FILE_RECENTFILES);
|
ActionContainer *ac = am->createMenu(Constants::M_FILE_RECENTFILES);
|
||||||
mfile->addMenu(ac, Constants::G_FILE_OPEN);
|
mfile->addMenu(ac, Constants::G_FILE_OPEN);
|
||||||
ac->menu()->setTitle(tr("Recent &Files"));
|
ac->menu()->setTitle(tr("Recent &Files"));
|
||||||
ac->setEmptyAction(ActionContainer::EA_None);
|
ac->setOnAllDisabledBehavior(ActionContainer::Show);
|
||||||
|
|
||||||
// Save Action
|
// Save Action
|
||||||
icon = QIcon::fromTheme(QLatin1String("document-save"), QIcon(Constants::ICON_SAVEFILE));
|
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::ActionManager *am = core->actionManager();
|
||||||
Core::ActionContainer *contextMenu = am->createMenu(GLSLEditor::Constants::M_CONTEXT);
|
Core::ActionContainer *contextMenu = am->createMenu(GLSLEditor::Constants::M_CONTEXT);
|
||||||
Core::ActionContainer *glslToolsMenu = am->createMenu(Core::Id(Constants::M_TOOLS_GLSL));
|
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();
|
QMenu *menu = glslToolsMenu->menu();
|
||||||
//: GLSL sub-menu in the Tools menu
|
//: GLSL sub-menu in the Tools menu
|
||||||
menu->setTitle(tr("GLSL"));
|
menu->setTitle(tr("GLSL"));
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
// "open with" submenu
|
// "open with" submenu
|
||||||
Core::ActionContainer * const openWith =
|
Core::ActionContainer * const openWith =
|
||||||
am->createMenu(ProjectExplorer::Constants::M_OPENFILEWITHCONTEXT);
|
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 = openWith->menu();
|
||||||
d->m_openWithMenu->setTitle(tr("Open With"));
|
d->m_openWithMenu->setTitle(tr("Open With"));
|
||||||
|
|
||||||
@@ -540,7 +540,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
Core::ActionContainer *mrecent =
|
Core::ActionContainer *mrecent =
|
||||||
am->createMenu(Constants::M_RECENTPROJECTS);
|
am->createMenu(Constants::M_RECENTPROJECTS);
|
||||||
mrecent->menu()->setTitle(tr("Recent P&rojects"));
|
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);
|
mfile->addMenu(mrecent, Core::Constants::G_FILE_OPEN);
|
||||||
connect(mfile->menu(), SIGNAL(aboutToShow()),
|
connect(mfile->menu(), SIGNAL(aboutToShow()),
|
||||||
this, SLOT(updateRecentProjectMenu()));
|
this, SLOT(updateRecentProjectMenu()));
|
||||||
@@ -563,7 +563,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
// session menu
|
// session menu
|
||||||
Core::ActionContainer *msession = am->createMenu(Constants::M_SESSION);
|
Core::ActionContainer *msession = am->createMenu(Constants::M_SESSION);
|
||||||
msession->menu()->setTitle(tr("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);
|
mfile->addMenu(msession, Core::Constants::G_FILE_PROJECT);
|
||||||
d->m_sessionMenu = msession->menu();
|
d->m_sessionMenu = msession->menu();
|
||||||
connect(mfile->menu(), SIGNAL(aboutToShow()),
|
connect(mfile->menu(), SIGNAL(aboutToShow()),
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
Core::ActionManager *am = core->actionManager();
|
Core::ActionManager *am = core->actionManager();
|
||||||
Core::ActionContainer *contextMenu = am->createMenu(QmlJSEditor::Constants::M_CONTEXT);
|
Core::ActionContainer *contextMenu = am->createMenu(QmlJSEditor::Constants::M_CONTEXT);
|
||||||
Core::ActionContainer *qmlToolsMenu = am->createMenu(Core::Id(Constants::M_TOOLS_QML));
|
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();
|
QMenu *menu = qmlToolsMenu->menu();
|
||||||
//: QML sub-menu in the Tools menu
|
//: QML sub-menu in the Tools menu
|
||||||
menu->setTitle(tr("QML"));
|
menu->setTitle(tr("QML"));
|
||||||
|
|||||||
Reference in New Issue
Block a user