forked from qt-creator/qt-creator
Core: Let ActionBuilder build a ParameterAction
Simpler overall interface with only slight overhead when not used. Change-Id: I4846df70df0d442a264d81ac5f351407b2d5e40f Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -9,11 +9,11 @@
|
|||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fadingindicator.h>
|
#include <utils/fadingindicator.h>
|
||||||
|
#include <utils/parameteraction.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <nanotrace/nanotrace.h>
|
#include <nanotrace/nanotrace.h>
|
||||||
|
|
||||||
#include <QAction>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
@@ -75,7 +75,7 @@ class ActionBuilderPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ActionBuilderPrivate(QObject *contextActionParent, const Id actionId)
|
ActionBuilderPrivate(QObject *contextActionParent, const Id actionId)
|
||||||
: action(new QAction(contextActionParent))
|
: action(new ParameterAction({}, {}, ParameterAction::AlwaysEnabled, contextActionParent))
|
||||||
, actionId(actionId)
|
, actionId(actionId)
|
||||||
{
|
{
|
||||||
command = ActionManager::createCommand(actionId);
|
command = ActionManager::createCommand(actionId);
|
||||||
@@ -87,7 +87,7 @@ public:
|
|||||||
ActionManager::registerAction(action, actionId, context);
|
ActionManager::registerAction(action, actionId, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction *action = nullptr;
|
ParameterAction *action = nullptr;
|
||||||
Command *command = nullptr;
|
Command *command = nullptr;
|
||||||
|
|
||||||
Id actionId;
|
Id actionId;
|
||||||
@@ -213,6 +213,20 @@ void ActionBuilder::setMenuRole(QAction::MenuRole role)
|
|||||||
d->action->setMenuRole(role);
|
d->action->setMenuRole(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActionBuilder::setParameterText(const QString ¶meterText,
|
||||||
|
const QString &emptyText,
|
||||||
|
EnablingMode mode)
|
||||||
|
{
|
||||||
|
QTC_CHECK(parameterText.contains("%1"));
|
||||||
|
QTC_CHECK(!emptyText.contains("%1"));
|
||||||
|
|
||||||
|
d->action->setEmptyText(emptyText);
|
||||||
|
d->action->setParameterText(parameterText);
|
||||||
|
d->action->setEnablingMode(mode == AlwaysEnabled
|
||||||
|
? ParameterAction::AlwaysEnabled
|
||||||
|
: ParameterAction::EnabledWithParameter);
|
||||||
|
}
|
||||||
|
|
||||||
Command *ActionBuilder::command() const
|
Command *ActionBuilder::command() const
|
||||||
{
|
{
|
||||||
return d->command;
|
return d->command;
|
||||||
@@ -228,6 +242,11 @@ QAction *ActionBuilder::contextAction() const
|
|||||||
return d->action;
|
return d->action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ParameterAction *ActionBuilder::contextParameterAction() const
|
||||||
|
{
|
||||||
|
return d->action;
|
||||||
|
}
|
||||||
|
|
||||||
void ActionBuilder::bindContextAction(QAction **dest)
|
void ActionBuilder::bindContextAction(QAction **dest)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(dest, return);
|
QTC_ASSERT(dest, return);
|
||||||
|
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
namespace Utils { class ParameterAction; }
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class ActionContainer;
|
class ActionContainer;
|
||||||
@@ -57,10 +59,18 @@ public:
|
|||||||
void setCheckable(bool on);
|
void setCheckable(bool on);
|
||||||
void setMenuRole(QAction::MenuRole role);
|
void setMenuRole(QAction::MenuRole role);
|
||||||
|
|
||||||
|
enum EnablingMode { AlwaysEnabled, EnabledWithParameter };
|
||||||
|
void setParameterText(const QString ¶metrizedText,
|
||||||
|
const QString &emptyText,
|
||||||
|
EnablingMode mode = EnabledWithParameter);
|
||||||
|
|
||||||
|
|
||||||
Command *command() const;
|
Command *command() const;
|
||||||
QAction *commandAction() const;
|
QAction *commandAction() const;
|
||||||
QAction *contextAction() const;
|
QAction *contextAction() const;
|
||||||
|
Utils::ParameterAction *contextParameterAction() const;
|
||||||
void bindContextAction(QAction **dest);
|
void bindContextAction(QAction **dest);
|
||||||
|
void bindContextAction(Utils::ParameterAction **dest);
|
||||||
void augmentActionWithShortcutToolTip();
|
void augmentActionWithShortcutToolTip();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user