forked from qt-creator/qt-creator
ActionManager: Centralize ActionContainer update
Each ActionContainer used to schedule an invokeMethod on the event loop when it changes, which creates an unnecessary amount of individual events, especially during startup. Instead schedule that update through the ActionManager, which then can schedule a single event that handles all updates up to that time. Change-Id: Ia193606adc4cfda88df8e45f2027662ca16f2ad3 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -172,8 +172,11 @@ namespace Internal {
|
||||
\internal
|
||||
*/
|
||||
|
||||
ActionContainerPrivate::ActionContainerPrivate(Id id)
|
||||
: m_onAllDisabledBehavior(Disable), m_id(id), m_updateRequested(false)
|
||||
ActionContainerPrivate::ActionContainerPrivate(Id id, ActionManagerPrivate *actionManagerPrivate)
|
||||
: m_onAllDisabledBehavior(Disable)
|
||||
, m_id(id)
|
||||
, m_actionManagerPrivate(actionManagerPrivate)
|
||||
, m_updateRequested(false)
|
||||
{
|
||||
appendGroup(Constants::G_DEFAULT_ONE);
|
||||
appendGroup(Constants::G_DEFAULT_TWO);
|
||||
@@ -382,16 +385,7 @@ bool ActionContainerPrivate::canAddAction(Command *action)
|
||||
|
||||
void ActionContainerPrivate::scheduleUpdate()
|
||||
{
|
||||
if (m_updateRequested)
|
||||
return;
|
||||
m_updateRequested = true;
|
||||
QMetaObject::invokeMethod(this, &ActionContainerPrivate::update, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void ActionContainerPrivate::update()
|
||||
{
|
||||
updateInternal();
|
||||
m_updateRequested = false;
|
||||
m_actionManagerPrivate->scheduleContainerUpdate(this);
|
||||
}
|
||||
|
||||
// ---------- MenuActionContainer ------------
|
||||
@@ -401,9 +395,9 @@ void ActionContainerPrivate::update()
|
||||
\internal
|
||||
*/
|
||||
|
||||
MenuActionContainer::MenuActionContainer(Id id)
|
||||
: ActionContainerPrivate(id),
|
||||
m_menu(new QMenu)
|
||||
MenuActionContainer::MenuActionContainer(Id id, ActionManagerPrivate *actionManagerPrivate)
|
||||
: ActionContainerPrivate(id, actionManagerPrivate)
|
||||
, m_menu(new QMenu)
|
||||
{
|
||||
m_menu->setObjectName(id.toString());
|
||||
m_menu->menuAction()->setMenuRole(QAction::NoRole);
|
||||
@@ -450,7 +444,7 @@ void MenuActionContainer::removeMenu(ActionContainer *container)
|
||||
m_menu->removeAction(menu->menuAction());
|
||||
}
|
||||
|
||||
bool MenuActionContainer::updateInternal()
|
||||
bool MenuActionContainer::update()
|
||||
{
|
||||
if (onAllDisabledBehavior() == Show)
|
||||
return true;
|
||||
@@ -470,7 +464,7 @@ bool MenuActionContainer::updateInternal()
|
||||
qWarning("%s", warning.constData());
|
||||
continue;
|
||||
}
|
||||
if (container->updateInternal()) {
|
||||
if (container->update()) {
|
||||
hasitems = true;
|
||||
break;
|
||||
}
|
||||
@@ -520,8 +514,9 @@ bool MenuActionContainer::canBeAddedToContainer(ActionContainerPrivate *containe
|
||||
\internal
|
||||
*/
|
||||
|
||||
MenuBarActionContainer::MenuBarActionContainer(Id id)
|
||||
: ActionContainerPrivate(id), m_menuBar(nullptr)
|
||||
MenuBarActionContainer::MenuBarActionContainer(Id id, ActionManagerPrivate *actionManagerPrivate)
|
||||
: ActionContainerPrivate(id, actionManagerPrivate)
|
||||
, m_menuBar(nullptr)
|
||||
{
|
||||
setOnAllDisabledBehavior(Show);
|
||||
}
|
||||
@@ -566,7 +561,7 @@ void MenuBarActionContainer::removeMenu(ActionContainer *container)
|
||||
m_menuBar->removeAction(menu->menuAction());
|
||||
}
|
||||
|
||||
bool MenuBarActionContainer::updateInternal()
|
||||
bool MenuBarActionContainer::update()
|
||||
{
|
||||
if (onAllDisabledBehavior() == Show)
|
||||
return true;
|
||||
@@ -597,9 +592,12 @@ bool MenuBarActionContainer::canBeAddedToContainer(ActionContainerPrivate *) con
|
||||
|
||||
const char ID_PREFIX[] = "io.qt.qtcreator.";
|
||||
|
||||
TouchBarActionContainer::TouchBarActionContainer(Id id, const QIcon &icon, const QString &text)
|
||||
: ActionContainerPrivate(id),
|
||||
m_touchBar(std::make_unique<TouchBar>(id.withPrefix(ID_PREFIX).name(), icon, text))
|
||||
TouchBarActionContainer::TouchBarActionContainer(Id id,
|
||||
ActionManagerPrivate *actionManagerPrivate,
|
||||
const QIcon &icon,
|
||||
const QString &text)
|
||||
: ActionContainerPrivate(id, actionManagerPrivate)
|
||||
, m_touchBar(std::make_unique<TouchBar>(id.withPrefix(ID_PREFIX).name(), icon, text))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -653,7 +651,7 @@ bool TouchBarActionContainer::canBeAddedToContainer(ActionContainerPrivate *cont
|
||||
return qobject_cast<TouchBarActionContainer *>(container);
|
||||
}
|
||||
|
||||
bool TouchBarActionContainer::updateInternal()
|
||||
bool TouchBarActionContainer::update()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user