Core: Replace new "Action" by an "ActionBuilder"

This needs not be stored somewhere but does its work latest
at destruction automatically.

Change-Id: If929f5a5ccc15b085f110d8d9db8f72ff2a5fac5
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2023-11-09 10:51:53 +01:00
committed by Eike Ziller
parent 09f43e79cf
commit ab8ba7f264
5 changed files with 352 additions and 351 deletions

View File

@@ -71,175 +71,164 @@ void PresentationModeHandler::showShortcutPopup(const QString &shortcut)
namespace Core { namespace Core {
class ActionPrivate class ActionBuilderPrivate
{ {
public: public:
void ensureCommand() ActionBuilderPrivate(QObject *contextActionParent, const Id actionId)
: action(new QAction(contextActionParent))
, actionId(actionId)
{ {
if (!command) { command = ActionManager::createCommand(actionId);
QTC_ASSERT(actionId.isValid(), return);
command = ActionManager::registerAction(&action, actionId, context);
}
} }
QAction action; void registerAction()
{
QTC_ASSERT(actionId.isValid(), return);
ActionManager::registerAction(action, actionId, context);
}
QAction *action = nullptr;
Command *command = nullptr;
Id actionId; Id actionId;
Context context{Constants::C_GLOBAL}; Context context{Constants::C_GLOBAL};
Command *command = nullptr;
}; };
Action::Action() ActionBuilder::ActionBuilder(QObject *contextActionParent, const Id actionId)
: d(new ActionPrivate) : d(new ActionBuilderPrivate(contextActionParent, actionId))
{ {
} }
Action::~Action() ActionBuilder::~ActionBuilder()
{ {
delete d; d->registerAction();
} }
void Action::setText(const QString &text) void ActionBuilder::setText(const QString &text)
{ {
d->action.setText(text); d->action->setText(text);
if (d->command)
d->command->action()->setText(text);
} }
void Action::setCommandAttribute(Command::CommandAttribute attr) void ActionBuilder::setCommandAttribute(Command::CommandAttribute attr)
{ {
d->ensureCommand();
QTC_ASSERT(d->command, return);
d->command->setAttribute(attr); d->command->setAttribute(attr);
} }
void Action::setContainer(Utils::Id containerId, Utils::Id groupId) void ActionBuilder::setCommandDescription(const QString &desc)
{ {
d->ensureCommand(); d->command->setDescription(desc);
QTC_ASSERT(d->command, return); }
if (containerId.isValid()) {
void ActionBuilder::setContainer(Id containerId, Id groupId)
{
QTC_ASSERT(containerId.isValid(), return);
ActionContainer *container = ActionManager::actionContainer(containerId); ActionContainer *container = ActionManager::actionContainer(containerId);
QTC_ASSERT(container, return);
container->addAction(d->command, groupId); container->addAction(d->command, groupId);
} }
void ActionBuilder::setOnTriggered(const std::function<void ()> &func)
{
QObject::connect(d->action, &QAction::triggered, d->action, func);
} }
void Action::setOnTriggered(const std::function<void ()> &func) void ActionBuilder::setOnTriggered(QObject *guard, const std::function<void()> &func)
{ {
QObject::connect(&d->action, &QAction::triggered, &d->action, func); QObject::connect(d->action, &QAction::triggered, guard, func);
} }
void Action::setOnTriggered(QObject *guard, const std::function<void()> &func) void ActionBuilder::setOnTriggered(QObject *guard, const std::function<void(bool)> &func)
{ {
QObject::connect(&d->action, &QAction::triggered, guard, func); QObject::connect(d->action, &QAction::triggered, guard, func);
} }
void Action::setOnTriggered(QObject *guard, const std::function<void(bool)> &func) void ActionBuilder::setDefaultKeySequence(const QKeySequence &seq)
{ {
QObject::connect(&d->action, &QAction::triggered, guard, func);
}
void Action::setDefaultKeySequence(const QKeySequence &seq)
{
d->ensureCommand();
QTC_ASSERT(d->command, return);
d->command->setDefaultKeySequence(seq); d->command->setDefaultKeySequence(seq);
} }
void Action::setDefaultKeySequence(const QString &mac, const QString &nonMac) void ActionBuilder::setDefaultKeySequences(const QList<QKeySequence> &seqs)
{
d->command->setDefaultKeySequences(seqs);
}
void ActionBuilder::setDefaultKeySequence(const QString &mac, const QString &nonMac)
{ {
d->ensureCommand();
QTC_ASSERT(d->command, return);
d->command->setDefaultKeySequence(QKeySequence(useMacShortcuts ? mac : nonMac)); d->command->setDefaultKeySequence(QKeySequence(useMacShortcuts ? mac : nonMac));
} }
void Action::setIcon(const QIcon &icon) void ActionBuilder::setIcon(const QIcon &icon)
{ {
d->action.setIcon(icon); d->action->setIcon(icon);
if (d->command)
d->command->action()->setIcon(icon);
} }
void Action::setIconVisibleInMenu(bool on) void ActionBuilder::setIconVisibleInMenu(bool on)
{ {
d->action.setIconVisibleInMenu(on); d->action->setIconVisibleInMenu(on);
if (d->command)
d->command->action()->setIconVisibleInMenu(on);
} }
void Action::setTouchBarIcon(const QIcon &icon) void ActionBuilder::setTouchBarIcon(const QIcon &icon)
{ {
d->ensureCommand();
QTC_ASSERT(d->command, return);
d->command->setTouchBarIcon(icon); d->command->setTouchBarIcon(icon);
} }
void Action::setEnabled(bool on) void ActionBuilder::setEnabled(bool on)
{ {
d->action.setEnabled(on); d->action->setEnabled(on);
// Explicitly not needed, done via context update:
// if (d->command)
// d->command->action()->...
} }
void Action::setChecked(bool on) void ActionBuilder::setChecked(bool on)
{ {
d->action.setChecked(on); d->action->setChecked(on);
// Explicitly not needed, done via context update:
// if (d->command)
// d->command->action()->...
} }
void Action::setVisible(bool on) void ActionBuilder::setVisible(bool on)
{ {
d->action.setVisible(on); d->action->setVisible(on);
// Explicitly not needed, done via context update:
// if (d->command)
// d->command->action()->....
} }
void Action::setCheckable(bool on) void ActionBuilder::setCheckable(bool on)
{ {
d->action.setCheckable(on); d->action->setCheckable(on);
if (d->command)
d->command->action()->setCheckable(on);
} }
void Action::setMenuRole(QAction::MenuRole role) void ActionBuilder::setMenuRole(QAction::MenuRole role)
{ {
d->action.setMenuRole(role); d->action->setMenuRole(role);
if (d->command)
d->command->action()->setMenuRole(role);
} }
Command *Action::command() const Command *ActionBuilder::command() const
{ {
d->ensureCommand();
QTC_CHECK(d->command);
return d->command; return d->command;
} }
QAction *Action::commandAction() const QAction *ActionBuilder::commandAction() const
{ {
d->ensureCommand();
QTC_ASSERT(d->command, return nullptr);
return d->command->action(); return d->command->action();
} }
QAction *Action::contextAction() const QAction *ActionBuilder::contextAction() const
{ {
return &d->action; return d->action;
} }
void Action::setId(Id id) void ActionBuilder::bindContextAction(QAction **dest)
{
QTC_ASSERT(dest, return);
*dest = d->action;
}
void ActionBuilder::setId(Id id)
{ {
d->actionId = id; d->actionId = id;
} }
void Action::setContext(Id id) void ActionBuilder::setContext(Id id)
{ {
d->context = Context(id); d->context = Context(id);
} }
void Action::setContext(const Context &context) void ActionBuilder::setContext(const Context &context)
{ {
QTC_ASSERT(!context.isEmpty(), return); QTC_ASSERT(!context.isEmpty(), return);
d->context = context; d->context = context;
@@ -484,6 +473,21 @@ Command *ActionManager::registerAction(QAction *action, Id id, const Context &co
return cmd; return cmd;
} }
/*!
Creates a Command or returns an existing Command with the specified \a id.
The created command doesn't have any actions associated with it yet, so
it cannot actually be triggered.
But the system is aware of it, it appears in the keyboard shortcut
settings, and QActions can later be registered for it.
If you already have a QAction, ID and Context that you want to register,
there is no need to call this. Just directly call registerAction().
*/
Command *ActionManager::createCommand(Utils::Id id)
{
return d->overridableAction(id);
}
/*! /*!
Returns the Command instance that has been created with registerAction() Returns the Command instance that has been created with registerAction()
for the specified \a id. for the specified \a id.

View File

@@ -26,22 +26,24 @@ class ICorePrivate;
class MainWindow; class MainWindow;
} // Internal } // Internal
class CORE_EXPORT Action class CORE_EXPORT ActionBuilder
{ {
public: public:
Action(); ActionBuilder(QObject *contextActionParent, const Utils::Id actionId = {});
~Action(); ~ActionBuilder();
void setId(Utils::Id id); void setId(Utils::Id id);
void setContext(const Utils::Id id); void setContext(const Utils::Id id);
void setContext(const Core::Context &context); void setContext(const Core::Context &context);
void setText(const QString &text); void setText(const QString &text);
void setCommandAttribute(Core::Command::CommandAttribute attr); void setCommandAttribute(Core::Command::CommandAttribute attr);
void setCommandDescription(const QString &desc);
void setContainer(Utils::Id containerId, Utils::Id groupId = {}); void setContainer(Utils::Id containerId, Utils::Id groupId = {});
void setOnTriggered(const std::function<void()> &func); void setOnTriggered(const std::function<void()> &func);
void setOnTriggered(QObject *guard, const std::function<void()> &func); void setOnTriggered(QObject *guard, const std::function<void()> &func);
void setOnTriggered(QObject *guard, const std::function<void(bool)> &func); void setOnTriggered(QObject *guard, const std::function<void(bool)> &func);
void setDefaultKeySequence(const QKeySequence &seq); void setDefaultKeySequence(const QKeySequence &seq);
void setDefaultKeySequences(const QList<QKeySequence> &seqs);
void setDefaultKeySequence(const QString &mac, const QString &nonMac); void setDefaultKeySequence(const QString &mac, const QString &nonMac);
void setIcon(const QIcon &icon); void setIcon(const QIcon &icon);
void setIconVisibleInMenu(bool on); void setIconVisibleInMenu(bool on);
@@ -55,9 +57,10 @@ public:
Command *command() const; Command *command() const;
QAction *commandAction() const; QAction *commandAction() const;
QAction *contextAction() const; QAction *contextAction() const;
void bindContextAction(QAction **dest);
private: private:
class ActionPrivate *d = nullptr; class ActionBuilderPrivate *d = nullptr;
}; };
class CORE_EXPORT Menu class CORE_EXPORT Menu
@@ -96,6 +99,7 @@ public:
const Context &context = Context(Constants::C_GLOBAL), const Context &context = Context(Constants::C_GLOBAL),
bool scriptable = false); bool scriptable = false);
static Command *createCommand(Utils::Id id);
static Command *command(Utils::Id id); static Command *command(Utils::Id id);
static ActionContainer *actionContainer(Utils::Id id); static ActionContainer *actionContainer(Utils::Id id);

View File

@@ -321,15 +321,7 @@ public:
SystemEditor *m_systemEditor = nullptr; SystemEditor *m_systemEditor = nullptr;
// actions // actions
QAction *m_focusToEditor = nullptr;
QAction *m_newAction = nullptr;
QAction *m_openAction = nullptr;
QAction *m_openWithAction = nullptr;
QAction *m_openFromDeviceAction = nullptr;
QAction *m_saveAllAction = nullptr; QAction *m_saveAllAction = nullptr;
QAction *m_exitAction = nullptr;
QAction *m_optionsAction = nullptr;
QAction *m_loggerAction = nullptr;
QAction *m_toggleLeftSideBarAction = nullptr; QAction *m_toggleLeftSideBarAction = nullptr;
QAction *m_toggleRightSideBarAction = nullptr; QAction *m_toggleRightSideBarAction = nullptr;
QAction *m_toggleMenubarAction = nullptr; QAction *m_toggleMenubarAction = nullptr;
@@ -338,11 +330,6 @@ public:
QAction *m_setModeSelectorStyleHiddenAction = nullptr; QAction *m_setModeSelectorStyleHiddenAction = nullptr;
QAction *m_setModeSelectorStyleIconsOnlyAction = nullptr; QAction *m_setModeSelectorStyleIconsOnlyAction = nullptr;
Action m_aboutIdeAction;
Action m_aboutPluginsAction;
Action m_changeLogAction;
Action m_contactAction;
QToolButton *m_toggleLeftSideBarButton = nullptr; QToolButton *m_toggleLeftSideBarButton = nullptr;
QToolButton *m_toggleRightSideBarButton = nullptr; QToolButton *m_toggleRightSideBarButton = nullptr;
QList<std::function<bool()>> m_preCloseListeners; QList<std::function<bool()>> m_preCloseListeners;
@@ -1569,19 +1556,18 @@ void ICorePrivate::registerDefaultActions()
// Return to editor shortcut: Note this requires Qt to fix up // Return to editor shortcut: Note this requires Qt to fix up
// handling of shortcut overrides in menus, item views, combos.... // handling of shortcut overrides in menus, item views, combos....
m_focusToEditor = new QAction(Tr::tr("Return to Editor"), this); ActionBuilder focusToEditor(this, Constants::S_RETURNTOEDITOR);
Command *cmd = ActionManager::registerAction(m_focusToEditor, Constants::S_RETURNTOEDITOR); focusToEditor.setText(Tr::tr("Return to Editor"));
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_Escape)); focusToEditor.setDefaultKeySequence(QKeySequence(Qt::Key_Escape));
connect(m_focusToEditor, &QAction::triggered, this, &ICorePrivate::setFocusToEditor); focusToEditor.setOnTriggered(this, [] { setFocusToEditor(); });
// New File Action // New Project Action
QIcon icon = Icon::fromTheme("document-new"); ActionBuilder newProjectAction(this, Constants::NEW);
newProjectAction.setText(Tr::tr("&New Project..."));
m_newAction = new QAction(icon, Tr::tr("&New Project..."), this); newProjectAction.setIcon(Icon::fromTheme("document-new"));
cmd = ActionManager::registerAction(m_newAction, Constants::NEW); newProjectAction.setDefaultKeySequence(QKeySequence("Ctrl+Shift+N"));
cmd->setDefaultKeySequence(QKeySequence("Ctrl+Shift+N")); newProjectAction.setContainer(Constants::M_FILE, Constants::G_FILE_NEW);
mfile->addAction(cmd, Constants::G_FILE_NEW); newProjectAction.setOnTriggered(this, [] {
connect(m_newAction, &QAction::triggered, this, [] {
if (!ICore::isNewItemDialogRunning()) { if (!ICore::isNewItemDialogRunning()) {
ICore::showNewItemDialog( ICore::showNewItemDialog(
Tr::tr("New Project", "Title of dialog"), Tr::tr("New Project", "Title of dialog"),
@@ -1594,13 +1580,16 @@ void ICorePrivate::registerDefaultActions()
} }
}); });
auto action = new QAction(icon, Tr::tr("New File..."), this); // New File Action
cmd = ActionManager::registerAction(action, Constants::NEW_FILE); ActionBuilder newFileAction(this, Constants::NEW_FILE);
cmd->setDefaultKeySequence(QKeySequence::New); newFileAction.setText(Tr::tr("New File..."));
mfile->addAction(cmd, Constants::G_FILE_NEW); newFileAction.setIcon(Icon::fromTheme("document-new"));
connect(action, &QAction::triggered, this, [] { newFileAction.setDefaultKeySequence(QKeySequence::New);
newFileAction.setContainer(Constants::M_FILE, Constants::G_FILE_NEW);
newFileAction.setOnTriggered(this, [] {
if (!ICore::isNewItemDialogRunning()) { if (!ICore::isNewItemDialogRunning()) {
ICore::showNewItemDialog(Tr::tr("New File", "Title of dialog"), ICore::showNewItemDialog(
Tr::tr("New File", "Title of dialog"),
Utils::filtered(Core::IWizardFactory::allWizardFactories(), Utils::filtered(Core::IWizardFactory::allWizardFactories(),
Utils::equal(&Core::IWizardFactory::kind, Utils::equal(&Core::IWizardFactory::kind,
Core::IWizardFactory::FileWizard)), Core::IWizardFactory::FileWizard)),
@@ -1611,25 +1600,25 @@ void ICorePrivate::registerDefaultActions()
}); });
// Open Action // Open Action
icon = Icon::fromTheme("document-open"); ActionBuilder openAction(this, Constants::OPEN);
m_openAction = new QAction(icon, Tr::tr("&Open File or Project..."), this); openAction.setText(Tr::tr("&Open File or Project..."));
cmd = ActionManager::registerAction(m_openAction, Constants::OPEN); openAction.setIcon(Icon::fromTheme("document-open"));
cmd->setDefaultKeySequence(QKeySequence::Open); openAction.setDefaultKeySequence(QKeySequence::Open);
mfile->addAction(cmd, Constants::G_FILE_OPEN); openAction.setContainer(Constants::M_FILE, Constants::G_FILE_OPEN);
connect(m_openAction, &QAction::triggered, this, &ICorePrivate::openFile); openAction.setOnTriggered(this, [] { openFile(); });
// Open With Action // Open With Action
m_openWithAction = new QAction(Tr::tr("Open File &With..."), this); ActionBuilder openWithAction(this, Constants::OPEN_WITH);
cmd = ActionManager::registerAction(m_openWithAction, Constants::OPEN_WITH); openWithAction.setText(Tr::tr("Open File &With..."));
mfile->addAction(cmd, Constants::G_FILE_OPEN); openWithAction.setContainer(Constants::M_FILE, Constants::G_FILE_OPEN);
connect(m_openWithAction, &QAction::triggered, m_core, &ICore::openFileWith); openWithAction.setOnTriggered(this, &ICore::openFileWith);
if (FSEngine::isAvailable()) { if (FSEngine::isAvailable()) {
// Open From Device Action // Open From Device Action
m_openFromDeviceAction = new QAction(Tr::tr("Open From Device..."), this); ActionBuilder openFromDeviceAction(this, Constants::OPEN_FROM_DEVICE);
cmd = ActionManager::registerAction(m_openFromDeviceAction, Constants::OPEN_FROM_DEVICE); openFromDeviceAction.setText(Tr::tr("Open From Device..."));
mfile->addAction(cmd, Constants::G_FILE_OPEN); openFromDeviceAction.setContainer(Constants::M_FILE, Constants::G_FILE_OPEN);
connect(m_openFromDeviceAction, &QAction::triggered, this, &ICorePrivate::openFileFromDevice); openFromDeviceAction.setOnTriggered(this, [this] { openFileFromDevice(); });
} }
// File->Recent Files Menu // File->Recent Files Menu
@@ -1639,128 +1628,128 @@ void ICorePrivate::registerDefaultActions()
ac->setOnAllDisabledBehavior(ActionContainer::Show); ac->setOnAllDisabledBehavior(ActionContainer::Show);
// Save Action // Save Action
icon = Icon::fromTheme("document-save"); ActionBuilder saveAction(this, Constants::SAVE);
QAction *tmpaction = new QAction(icon, Tr::tr("&Save"), this); saveAction.setText(Tr::tr("&Save"));
tmpaction->setEnabled(false); saveAction.setIcon(Icon::fromTheme("document-save"));
cmd = ActionManager::registerAction(tmpaction, Constants::SAVE); saveAction.setEnabled(false);
cmd->setDefaultKeySequence(QKeySequence::Save); saveAction.setDefaultKeySequence(QKeySequence::Save);
cmd->setAttribute(Command::CA_UpdateText); saveAction.setCommandAttribute(Command::CA_UpdateText);
cmd->setDescription(Tr::tr("Save")); saveAction.setCommandDescription(Tr::tr("Save"));
mfile->addAction(cmd, Constants::G_FILE_SAVE); saveAction.setContainer(Constants::M_FILE, Constants::G_FILE_SAVE);
// Save As Action // Save As Action
icon = Icon::fromTheme("document-save-as"); ActionBuilder saveAsAction(this, Constants::SAVEAS);
tmpaction = new QAction(icon, Tr::tr("Save &As..."), this); saveAsAction.setText(Tr::tr("Save &As..."));
tmpaction->setEnabled(false); saveAsAction.setIcon(Icon::fromTheme("document-save-as"));
cmd = ActionManager::registerAction(tmpaction, Constants::SAVEAS); saveAsAction.setEnabled(false);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Shift+S") : QString())); saveAsAction.setDefaultKeySequence(Tr::tr("Ctrl+Shift+S"), QString());
cmd->setAttribute(Command::CA_UpdateText); saveAsAction.setCommandAttribute(Command::CA_UpdateText);
cmd->setDescription(Tr::tr("Save As...")); saveAsAction.setCommandDescription(Tr::tr("Save As..."));
mfile->addAction(cmd, Constants::G_FILE_SAVE); saveAsAction.setContainer(Constants::M_FILE, Constants::G_FILE_SAVE);
// SaveAll Action // SaveAll Action
DocumentManager::registerSaveAllAction(); DocumentManager::registerSaveAllAction();
// Print Action // Print Action
icon = Icon::fromTheme("document-print"); ActionBuilder printAction(this, Constants::PRINT);
tmpaction = new QAction(icon, Tr::tr("&Print..."), this); printAction.setText(Tr::tr("&Print..."));
tmpaction->setEnabled(false); printAction.setIcon(Icon::fromTheme("document-print"));
cmd = ActionManager::registerAction(tmpaction, Constants::PRINT); printAction.setEnabled(false);
cmd->setDefaultKeySequence(QKeySequence::Print); printAction.setDefaultKeySequence(QKeySequence::Print);
mfile->addAction(cmd, Constants::G_FILE_PRINT); printAction.setContainer(Constants::M_FILE, Constants::G_FILE_PRINT);
// Exit Action // Exit Action
icon = Icon::fromTheme("application-exit"); ActionBuilder exitAction(this, Constants::EXIT);
m_exitAction = new QAction(icon, Tr::tr("E&xit"), this); exitAction.setText(Tr::tr("E&xit"));
m_exitAction->setMenuRole(QAction::QuitRole); exitAction.setIcon(Icon::fromTheme("application-exit"));
cmd = ActionManager::registerAction(m_exitAction, Constants::EXIT); exitAction.setMenuRole(QAction::QuitRole);
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Q"))); exitAction.setDefaultKeySequence(Tr::tr("Ctrl+Q"));
mfile->addAction(cmd, Constants::G_FILE_OTHER); exitAction.setContainer(Constants::M_FILE, Constants::G_FILE_OTHER);
connect(m_exitAction, &QAction::triggered, m_core, &ICore::exit); exitAction.setOnTriggered(this, &ICore::exit);
// Undo Action // Undo Action
icon = Icon::fromTheme("edit-undo"); ActionBuilder undoAction(this, Constants::UNDO);
tmpaction = new QAction(icon, Tr::tr("&Undo"), this); undoAction.setText(Tr::tr("&Undo"));
cmd = ActionManager::registerAction(tmpaction, Constants::UNDO); undoAction.setIcon(Icon::fromTheme("edit-undo"));
cmd->setDefaultKeySequence(QKeySequence::Undo); undoAction.setDefaultKeySequence(QKeySequence::Undo);
cmd->setAttribute(Command::CA_UpdateText); undoAction.setCommandAttribute(Command::CA_UpdateText);
cmd->setDescription(Tr::tr("Undo")); undoAction.setCommandDescription(Tr::tr("Undo"));
medit->addAction(cmd, Constants::G_EDIT_UNDOREDO); undoAction.setContainer(Constants::M_EDIT, Constants::G_EDIT_UNDOREDO);
tmpaction->setEnabled(false); undoAction.setEnabled(false);
// Redo Action // Redo Action
icon = Icon::fromTheme("edit-redo"); ActionBuilder redoAction(this, Constants::REDO);
tmpaction = new QAction(icon, Tr::tr("&Redo"), this); redoAction.setIcon(Icon::fromTheme("edit-redo"));
cmd = ActionManager::registerAction(tmpaction, Constants::REDO); redoAction.setText(Tr::tr("&Redo"));
cmd->setDefaultKeySequence(QKeySequence::Redo); redoAction.setDefaultKeySequence(QKeySequence::Redo);
cmd->setAttribute(Command::CA_UpdateText); redoAction.setCommandAttribute(Command::CA_UpdateText);
cmd->setDescription(Tr::tr("Redo")); redoAction.setCommandDescription(Tr::tr("Redo"));
medit->addAction(cmd, Constants::G_EDIT_UNDOREDO); redoAction.setContainer(Constants::M_EDIT, Constants::G_EDIT_UNDOREDO);
tmpaction->setEnabled(false); redoAction.setEnabled(false);
// Cut Action // Cut Action
icon = Icon::fromTheme("edit-cut"); ActionBuilder cutAction(this, Constants::CUT);
tmpaction = new QAction(icon, Tr::tr("Cu&t"), this); cutAction.setText(Tr::tr("Cu&t"));
cmd = ActionManager::registerAction(tmpaction, Constants::CUT); cutAction.setIcon(Icon::fromTheme("edit-cut"));
cmd->setDefaultKeySequence(QKeySequence::Cut); cutAction.setDefaultKeySequence(QKeySequence::Cut);
medit->addAction(cmd, Constants::G_EDIT_COPYPASTE); cutAction.setContainer(Constants::M_EDIT, Constants::G_EDIT_COPYPASTE);
tmpaction->setEnabled(false); cutAction.setEnabled(false);
// Copy Action // Copy Action
icon = Icon::fromTheme("edit-copy"); ActionBuilder copyAction(this, Constants::COPY);
tmpaction = new QAction(icon, Tr::tr("&Copy"), this); copyAction.setText(Tr::tr("&Copy"));
cmd = ActionManager::registerAction(tmpaction, Constants::COPY); copyAction.setIcon(Icon::fromTheme("edit-copy"));
cmd->setDefaultKeySequence(QKeySequence::Copy); copyAction.setDefaultKeySequence(QKeySequence::Copy);
medit->addAction(cmd, Constants::G_EDIT_COPYPASTE); copyAction.setContainer(Constants::M_EDIT, Constants::G_EDIT_COPYPASTE);
tmpaction->setEnabled(false); copyAction.setEnabled(false);
// Paste Action // Paste Action
icon = Icon::fromTheme("edit-paste"); ActionBuilder pasteAction(this, Constants::PASTE);
tmpaction = new QAction(icon, Tr::tr("&Paste"), this); pasteAction.setText(Tr::tr("&Paste"));
cmd = ActionManager::registerAction(tmpaction, Constants::PASTE); pasteAction.setIcon(Icon::fromTheme("edit-paste"));
cmd->setDefaultKeySequence(QKeySequence::Paste); pasteAction.setDefaultKeySequence(QKeySequence::Paste);
medit->addAction(cmd, Constants::G_EDIT_COPYPASTE); pasteAction.setContainer(Constants::M_EDIT, Constants::G_EDIT_COPYPASTE);
tmpaction->setEnabled(false); pasteAction.setEnabled(false);
// Select All // Select All
icon = Icon::fromTheme("edit-select-all"); ActionBuilder selectAllAction(this, Constants::SELECTALL);
tmpaction = new QAction(icon, Tr::tr("Select &All"), this); selectAllAction.setText(Tr::tr("Select &All"));
cmd = ActionManager::registerAction(tmpaction, Constants::SELECTALL); selectAllAction.setIcon(Icon::fromTheme("edit-select-all"));
cmd->setDefaultKeySequence(QKeySequence::SelectAll); selectAllAction.setDefaultKeySequence(QKeySequence::SelectAll);
medit->addAction(cmd, Constants::G_EDIT_SELECTALL); selectAllAction.setContainer(Constants::M_EDIT, Constants::G_EDIT_SELECTALL);
tmpaction->setEnabled(false); selectAllAction.setEnabled(false);
// Goto Action // Goto Action
icon = Icon::fromTheme("go-jump"); ActionBuilder gotoLineAction(this, Constants::GOTO);
tmpaction = new QAction(icon, Tr::tr("&Go to Line..."), this); gotoLineAction.setText(Tr::tr("&Go to Line..."));
cmd = ActionManager::registerAction(tmpaction, Constants::GOTO); gotoLineAction.setIcon(Icon::fromTheme("go-jump"));
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+L"))); gotoLineAction.setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+L")));
medit->addAction(cmd, Constants::G_EDIT_OTHER); gotoLineAction.setContainer(Constants::M_EDIT, Constants::G_EDIT_OTHER);
tmpaction->setEnabled(false); gotoLineAction.setEnabled(false);
// Zoom In Action // Zoom In Action
icon = Icon::fromTheme("zoom-in"); ActionBuilder zoomInAction(this, Constants::ZOOM_IN);
tmpaction = new QAction(icon, Tr::tr("Zoom In"), this); zoomInAction.setText(Tr::tr("Zoom In"));
cmd = ActionManager::registerAction(tmpaction, Constants::ZOOM_IN); zoomInAction.setIcon(Icon::fromTheme("zoom-in"));
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl++"))); zoomInAction.setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl++")));
tmpaction->setEnabled(false); zoomInAction.setEnabled(false);
// Zoom Out Action // Zoom Out Action
icon = Icon::fromTheme("zoom-out"); ActionBuilder zoomOutAction(this, Constants::ZOOM_OUT);
tmpaction = new QAction(icon, Tr::tr("Zoom Out"), this); zoomOutAction.setText(Tr::tr("Zoom Out"));
cmd = ActionManager::registerAction(tmpaction, Constants::ZOOM_OUT); zoomOutAction.setIcon(Icon::fromTheme("zoom-out"));
if (useMacShortcuts) if (useMacShortcuts)
cmd->setDefaultKeySequences({QKeySequence(Tr::tr("Ctrl+-")), QKeySequence(Tr::tr("Ctrl+Shift+-"))}); zoomOutAction.setDefaultKeySequences({QKeySequence(Tr::tr("Ctrl+-")), QKeySequence(Tr::tr("Ctrl+Shift+-"))});
else else
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+-"))); zoomOutAction.setDefaultKeySequence(Tr::tr("Ctrl+-"));
tmpaction->setEnabled(false); zoomOutAction.setEnabled(false);
// Zoom Reset Action // Zoom Reset Action
icon = Icon::fromTheme("zoom-original"); ActionBuilder zoomOriginalAction(this, Constants::ZOOM_RESET);
tmpaction = new QAction(icon, Tr::tr("Original Size"), this); zoomOriginalAction.setText(Tr::tr("Original Size"));
cmd = ActionManager::registerAction(tmpaction, Constants::ZOOM_RESET); zoomOriginalAction.setIcon(Icon::fromTheme("zoom-original"));
cmd->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+0") : Tr::tr("Ctrl+0"))); zoomOriginalAction.setDefaultKeySequence(Tr::tr("Meta+0"), Tr::tr("Ctrl+0"));
tmpaction->setEnabled(false); zoomOriginalAction.setEnabled(false);
// Debug Qt Creator menu // Debug Qt Creator menu
mtools->appendGroup(Constants::G_TOOLS_DEBUG); mtools->appendGroup(Constants::G_TOOLS_DEBUG);
@@ -1768,21 +1757,21 @@ void ICorePrivate::registerDefaultActions()
mtoolsdebug->menu()->setTitle(Tr::tr("Debug %1").arg(QGuiApplication::applicationDisplayName())); mtoolsdebug->menu()->setTitle(Tr::tr("Debug %1").arg(QGuiApplication::applicationDisplayName()));
mtools->addMenu(mtoolsdebug, Constants::G_TOOLS_DEBUG); mtools->addMenu(mtoolsdebug, Constants::G_TOOLS_DEBUG);
m_loggerAction = new QAction(Tr::tr("Show Logs..."), this); ActionBuilder loggerAction(this, Constants::LOGGER);
cmd = ActionManager::registerAction(m_loggerAction, Constants::LOGGER); loggerAction.setText(Tr::tr("Show Logs..."));
mtoolsdebug->addAction(cmd); loggerAction.setContainer(Constants::M_TOOLS_DEBUG);
connect(m_loggerAction, &QAction::triggered, this, [] { LoggingViewer::showLoggingView(); }); loggerAction.setOnTriggered(this, &LoggingViewer::showLoggingView);
// Options Action // Options Action
medit->appendGroup(Constants::G_EDIT_PREFERENCES); medit->appendGroup(Constants::G_EDIT_PREFERENCES);
medit->addSeparator(Constants::G_EDIT_PREFERENCES); medit->addSeparator(Constants::G_EDIT_PREFERENCES);
m_optionsAction = new QAction(Tr::tr("Pr&eferences..."), this); ActionBuilder optionsAction(this, Constants::OPTIONS);
m_optionsAction->setMenuRole(QAction::PreferencesRole); optionsAction.setText(Tr::tr("Pr&eferences..."));
cmd = ActionManager::registerAction(m_optionsAction, Constants::OPTIONS); optionsAction.setMenuRole(QAction::PreferencesRole);
cmd->setDefaultKeySequence(QKeySequence::Preferences); optionsAction.setDefaultKeySequence(QKeySequence::Preferences);
medit->addAction(cmd, Constants::G_EDIT_PREFERENCES); optionsAction.setContainer(Constants::M_EDIT, Constants::G_EDIT_PREFERENCES);
connect(m_optionsAction, &QAction::triggered, this, [] { ICore::showOptionsDialog(Id()); }); optionsAction.setOnTriggered(this, [] { ICore::showOptionsDialog(Id()); });
mwindow->addSeparator(Constants::G_WINDOW_LIST); mwindow->addSeparator(Constants::G_WINDOW_LIST);
@@ -1790,7 +1779,7 @@ void ICorePrivate::registerDefaultActions()
// Minimize Action // Minimize Action
QAction *minimizeAction = new QAction(Tr::tr("Minimize"), this); QAction *minimizeAction = new QAction(Tr::tr("Minimize"), this);
minimizeAction->setEnabled(false); // actual implementation in WindowSupport minimizeAction->setEnabled(false); // actual implementation in WindowSupport
cmd = ActionManager::registerAction(minimizeAction, Constants::MINIMIZE_WINDOW); Command *cmd = ActionManager::registerAction(minimizeAction, Constants::MINIMIZE_WINDOW);
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+M"))); cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+M")));
mwindow->addAction(cmd, Constants::G_WINDOW_SIZE); mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
@@ -1805,7 +1794,7 @@ void ICorePrivate::registerDefaultActions()
QAction *toggleFullScreenAction = new QAction(Tr::tr("Full Screen"), this); QAction *toggleFullScreenAction = new QAction(Tr::tr("Full Screen"), this);
toggleFullScreenAction->setCheckable(!HostOsInfo::isMacHost()); toggleFullScreenAction->setCheckable(!HostOsInfo::isMacHost());
toggleFullScreenAction->setEnabled(false); // actual implementation in WindowSupport toggleFullScreenAction->setEnabled(false); // actual implementation in WindowSupport
cmd = ActionManager::registerAction(toggleFullScreenAction, Constants::TOGGLE_FULLSCREEN); Command *cmd = ActionManager::registerAction(toggleFullScreenAction, Constants::TOGGLE_FULLSCREEN);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Meta+F") : Tr::tr("Ctrl+Shift+F11"))); cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Meta+F") : Tr::tr("Ctrl+Shift+F11")));
if (HostOsInfo::isMacHost()) if (HostOsInfo::isMacHost())
cmd->setAttribute(Command::CA_UpdateText); cmd->setAttribute(Command::CA_UpdateText);
@@ -1824,36 +1813,36 @@ void ICorePrivate::registerDefaultActions()
} }
// Show Left Sidebar Action // Show Left Sidebar Action
m_toggleLeftSideBarAction = new QAction(Utils::Icons::TOGGLE_LEFT_SIDEBAR.icon(), ActionBuilder toggleLeftSideBarAction(this, Constants::TOGGLE_LEFT_SIDEBAR);
Tr::tr(Constants::TR_SHOW_LEFT_SIDEBAR), toggleLeftSideBarAction.setIcon(Utils::Icons::TOGGLE_LEFT_SIDEBAR.icon());
this); toggleLeftSideBarAction.setText(Tr::tr(Constants::TR_SHOW_LEFT_SIDEBAR));
m_toggleLeftSideBarAction->setCheckable(true); toggleLeftSideBarAction.setCheckable(true);
cmd = ActionManager::registerAction(m_toggleLeftSideBarAction, Constants::TOGGLE_LEFT_SIDEBAR); toggleLeftSideBarAction.setCommandAttribute(Command::CA_UpdateText);
cmd->setAttribute(Command::CA_UpdateText); toggleLeftSideBarAction.setDefaultKeySequence(Tr::tr("Ctrl+0"), Tr::tr("Alt+0"));
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+0") : Tr::tr("Alt+0"))); toggleLeftSideBarAction.setContainer(Constants::M_VIEW, Constants::G_VIEW_VIEWS);
connect(m_toggleLeftSideBarAction, &QAction::triggered, toggleLeftSideBarAction.setOnTriggered(this,
this, [this](bool visible) { setSidebarVisible(visible, Side::Left); }); [this](bool visible) { setSidebarVisible(visible, Side::Left); });
ProxyAction *toggleLeftSideBarProxyAction =
ProxyAction::proxyActionWithIcon(cmd->action(), Utils::Icons::TOGGLE_LEFT_SIDEBAR_TOOLBAR.icon()); m_toggleLeftSideBarAction = toggleLeftSideBarAction.contextAction();
m_toggleLeftSideBarButton->setDefaultAction(toggleLeftSideBarProxyAction); m_toggleLeftSideBarButton->setDefaultAction(ProxyAction::proxyActionWithIcon(
mview->addAction(cmd, Constants::G_VIEW_VIEWS); toggleLeftSideBarAction.commandAction(), Utils::Icons::TOGGLE_LEFT_SIDEBAR_TOOLBAR.icon()));
m_toggleLeftSideBarAction->setEnabled(false); m_toggleLeftSideBarButton->setEnabled(false);
// Show Right Sidebar Action // Show Right Sidebar Action
m_toggleRightSideBarAction = new QAction(Utils::Icons::TOGGLE_RIGHT_SIDEBAR.icon(), ActionBuilder toggleRightSideBarAction(this, Constants::TOGGLE_RIGHT_SIDEBAR);
Tr::tr(Constants::TR_SHOW_RIGHT_SIDEBAR), toggleRightSideBarAction.setIcon(Utils::Icons::TOGGLE_RIGHT_SIDEBAR.icon());
this); toggleRightSideBarAction.setText(Tr::tr(Constants::TR_SHOW_RIGHT_SIDEBAR));
m_toggleRightSideBarAction->setCheckable(true); toggleRightSideBarAction.setCheckable(true);
cmd = ActionManager::registerAction(m_toggleRightSideBarAction, Constants::TOGGLE_RIGHT_SIDEBAR); toggleRightSideBarAction.setCommandAttribute(Command::CA_UpdateText);
cmd->setAttribute(Command::CA_UpdateText); toggleRightSideBarAction.setDefaultKeySequence(Tr::tr("Ctrl+Shift+0"), Tr::tr("Alt+Shift+0"));
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Shift+0") : Tr::tr("Alt+Shift+0"))); toggleRightSideBarAction.setContainer(Constants::M_VIEW, Constants::G_VIEW_VIEWS);
connect(m_toggleRightSideBarAction, &QAction::triggered, toggleRightSideBarAction.setEnabled(false);
this, [this](bool visible) { setSidebarVisible(visible, Side::Right); }); toggleRightSideBarAction.setOnTriggered(this,
ProxyAction *toggleRightSideBarProxyAction = [this](bool visible) { setSidebarVisible(visible, Side::Right); });
ProxyAction::proxyActionWithIcon(cmd->action(), Utils::Icons::TOGGLE_RIGHT_SIDEBAR_TOOLBAR.icon());
m_toggleRightSideBarButton->setDefaultAction(toggleRightSideBarProxyAction); m_toggleRightSideBarAction = toggleRightSideBarAction.contextAction();
mview->addAction(cmd, Constants::G_VIEW_VIEWS); m_toggleRightSideBarButton->setDefaultAction(ProxyAction::proxyActionWithIcon(
m_toggleRightSideBarButton->setEnabled(false); toggleRightSideBarAction.commandAction(), Utils::Icons::TOGGLE_RIGHT_SIDEBAR_TOOLBAR.icon()));
// Show Menubar Action // Show Menubar Action
if (globalMenuBar() && !globalMenuBar()->isNativeMenuBar()) { if (globalMenuBar() && !globalMenuBar()->isNativeMenuBar()) {
@@ -1889,49 +1878,49 @@ void ICorePrivate::registerDefaultActions()
mhelp->addSeparator(Constants::G_HELP_ABOUT); mhelp->addSeparator(Constants::G_HELP_ABOUT);
// About IDE Action // About IDE Action
m_aboutIdeAction.setId(Constants::ABOUT_QTCREATOR); ActionBuilder aboutIdeAction(this, Constants::ABOUT_QTCREATOR);
m_aboutIdeAction.setIcon(Icon::fromTheme("help-about")); aboutIdeAction.setIcon(Icon::fromTheme("help-about"));
m_aboutIdeAction.setText( aboutIdeAction.setText(
(HostOsInfo::isMacHost() ? Tr::tr("About &%1") : Tr::tr("About &%1...")) (HostOsInfo::isMacHost() ? Tr::tr("About &%1") : Tr::tr("About &%1..."))
.arg(QGuiApplication::applicationDisplayName())); .arg(QGuiApplication::applicationDisplayName()));
m_aboutIdeAction.setMenuRole(QAction::AboutRole); aboutIdeAction.setMenuRole(QAction::AboutRole);
m_aboutIdeAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT); aboutIdeAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT);
m_aboutIdeAction.setEnabled(true); aboutIdeAction.setEnabled(true);
m_aboutIdeAction.setOnTriggered(this, [this] { aboutQtCreator(); }); aboutIdeAction.setOnTriggered(this, [this] { aboutQtCreator(); });
// About Plugins Action // About Plugins Action
m_aboutPluginsAction.setId(Constants::ABOUT_PLUGINS); ActionBuilder aboutPluginsAction(this, Constants::ABOUT_PLUGINS);
m_aboutPluginsAction.setText(Tr::tr("About &Plugins...")); aboutPluginsAction.setText(Tr::tr("About &Plugins..."));
m_aboutPluginsAction.setMenuRole(QAction::ApplicationSpecificRole); aboutPluginsAction.setMenuRole(QAction::ApplicationSpecificRole);
m_aboutPluginsAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT); aboutPluginsAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT);
m_aboutPluginsAction.setEnabled(true); aboutPluginsAction.setEnabled(true);
m_aboutPluginsAction.setOnTriggered(this, [this] { aboutPlugins(); }); aboutPluginsAction.setOnTriggered(this, [this] { aboutPlugins(); });
// About Qt Action // About Qt Action
// aboutQtAction.setId(Constants:: ABOUT_QT); // ActionBuilder aboutQtAction(this, Constants:: ABOUT_QT);
// aboutQtAction.setText(Tr::tr("About &Qt..."), this); // aboutQtAction.setText(Tr::tr("About &Qt..."), this);
// aboutQtAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT); // aboutQtAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT);
// aboutQtAction.setEnabled(true); // aboutQtAction.setEnabled(true);
// aboutQtAction.setOnTriggered(this, &QApplication::aboutQt); // aboutQtAction.setOnTriggered(this, &QApplication::aboutQt);
// Change Log Action // Change Log Action
m_changeLogAction.setId(Constants::CHANGE_LOG); ActionBuilder changeLogAction(this, Constants::CHANGE_LOG);
m_changeLogAction.setText(Tr::tr("Change Log...")); changeLogAction.setText(Tr::tr("Change Log..."));
m_changeLogAction.setMenuRole(QAction::ApplicationSpecificRole); changeLogAction.setMenuRole(QAction::ApplicationSpecificRole);
m_changeLogAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT); changeLogAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT);
m_changeLogAction.setEnabled(true); changeLogAction.setEnabled(true);
m_changeLogAction.setOnTriggered(this, [this] { changeLog(); }); changeLogAction.setOnTriggered(this, [this] { changeLog(); });
// Contact // Contact
m_contactAction.setId("QtCreator.Contact"); ActionBuilder contactAction(this, "QtCreator.Contact");
m_contactAction.setText(Tr::tr("Contact...")); contactAction.setText(Tr::tr("Contact..."));
m_contactAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT); contactAction.setContainer(Constants::M_HELP, Constants::G_HELP_ABOUT);
m_contactAction.setEnabled(true); contactAction.setEnabled(true);
m_contactAction.setOnTriggered(this, [this] { contact(); }); contactAction.setOnTriggered(this, [this] { contact(); });
// About sep // About sep
if (!HostOsInfo::isMacHost()) { // doesn't have the "About" actions in the Help menu if (!HostOsInfo::isMacHost()) { // doesn't have the "About" actions in the Help menu
tmpaction = new QAction(this); auto tmpaction = new QAction(this);
tmpaction->setSeparator(true); tmpaction->setSeparator(true);
cmd = ActionManager::registerAction(tmpaction, "QtCreator.Help.Sep.About"); cmd = ActionManager::registerAction(tmpaction, "QtCreator.Help.Sep.About");
mhelp->addAction(cmd, Constants::G_HELP_ABOUT); mhelp->addAction(cmd, Constants::G_HELP_ABOUT);

View File

@@ -39,8 +39,6 @@ public:
ProjectFilesFactory projectFilesFactory; ProjectFilesFactory projectFilesFactory;
GenericMakeStepFactory makeStepFactory; GenericMakeStepFactory makeStepFactory;
GenericBuildConfigurationFactory buildConfigFactory; GenericBuildConfigurationFactory buildConfigFactory;
Action editAction;
Action removeDirAction;
}; };
GenericProjectPlugin::~GenericProjectPlugin() GenericProjectPlugin::~GenericProjectPlugin()
@@ -59,7 +57,7 @@ GenericProjectPluginPrivate::GenericProjectPluginPrivate()
IWizardFactory::registerFactoryCreator([] { return new GenericProjectWizard; }); IWizardFactory::registerFactoryCreator([] { return new GenericProjectWizard; });
editAction.setId("GenericProjectManager.EditFiles"); ActionBuilder editAction(this, "GenericProjectManager.EditFiles");
editAction.setContext(Constants::GENERICPROJECT_ID); editAction.setContext(Constants::GENERICPROJECT_ID);
editAction.setText(Tr::tr("Edit Files...")); editAction.setText(Tr::tr("Edit Files..."));
editAction.setCommandAttribute(Command::CA_Hide); editAction.setCommandAttribute(Command::CA_Hide);
@@ -69,7 +67,7 @@ GenericProjectPluginPrivate::GenericProjectPluginPrivate()
genericProject->editFilesTriggered(); genericProject->editFilesTriggered();
}); });
removeDirAction.setId("GenericProject.RemoveDir"); ActionBuilder removeDirAction(this, "GenericProject.RemoveDir");
removeDirAction.setContext(PEC::C_PROJECT_TREE); removeDirAction.setContext(PEC::C_PROJECT_TREE);
removeDirAction.setText(Tr::tr("Remove Directory")); removeDirAction.setText(Tr::tr("Remove Directory"));
removeDirAction.setContainer(PEC::M_FOLDERCONTEXT, PEC::G_FOLDER_OTHER); removeDirAction.setContainer(PEC::M_FOLDERCONTEXT, PEC::G_FOLDER_OTHER);

View File

@@ -87,12 +87,12 @@ public:
BookmarkViewFactory m_bookmarkViewFactory{&m_bookmarkManager}; BookmarkViewFactory m_bookmarkViewFactory{&m_bookmarkManager};
Menu m_bookmarkMenu; Menu m_bookmarkMenu;
Action m_toggleAction; QAction *m_toggleAction = nullptr;
Action m_editAction; QAction *m_editAction = nullptr;
Action m_prevAction; QAction *m_prevAction = nullptr;
Action m_nextAction; QAction *m_nextAction = nullptr;
Action m_docPrevAction; QAction *m_docPrevAction = nullptr;
Action m_docNextAction; QAction *m_docNextAction = nullptr;
QAction m_editBookmarkAction{Tr::tr("Edit Bookmark")}; QAction m_editBookmarkAction{Tr::tr("Edit Bookmark")};
QAction m_bookmarkMarginAction{Tr::tr("Toggle Bookmark")}; QAction m_bookmarkMarginAction{Tr::tr("Toggle Bookmark")};
@@ -122,25 +122,27 @@ TextEditorPluginPrivate::TextEditorPluginPrivate()
m_bookmarkMenu.setTitle(Tr::tr("&Bookmarks")); m_bookmarkMenu.setTitle(Tr::tr("&Bookmarks"));
m_bookmarkMenu.setContainer(Core::Constants::M_TOOLS); m_bookmarkMenu.setContainer(Core::Constants::M_TOOLS);
m_toggleAction.setId("Bookmarks.Toggle"); ActionBuilder toggleAction(this, "Bookmarks.Toggle");
m_toggleAction.setContext(editorManagerContext); toggleAction.setContext(editorManagerContext);
m_toggleAction.setText(Tr::tr("Toggle Bookmark")); toggleAction.setText(Tr::tr("Toggle Bookmark"));
m_toggleAction.setDefaultKeySequence(Tr::tr("Meta+M"), Tr::tr("Ctrl+M")); toggleAction.setDefaultKeySequence(Tr::tr("Meta+M"), Tr::tr("Ctrl+M"));
m_toggleAction.setTouchBarIcon(Icons::MACOS_TOUCHBAR_BOOKMARK.icon()); toggleAction.setTouchBarIcon(Icons::MACOS_TOUCHBAR_BOOKMARK.icon());
m_toggleAction.setContainer(bookmarkMenuId); toggleAction.setContainer(bookmarkMenuId);
m_toggleAction.setOnTriggered(this, [this] { toggleAction.bindContextAction(&m_toggleAction);
toggleAction.setOnTriggered(this, [this] {
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
auto widget = TextEditorWidget::fromEditor(editor); auto widget = TextEditorWidget::fromEditor(editor);
if (widget && editor && !editor->document()->isTemporary()) if (widget && editor && !editor->document()->isTemporary())
m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine()); m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine());
}); });
m_editAction.setId("Bookmarks.Edit"); ActionBuilder editAction(this, "Bookmarks.Edit");
m_editAction.setContext(editorManagerContext); editAction.setContext(editorManagerContext);
m_editAction.setText(Tr::tr("Edit Bookmark")); editAction.setText(Tr::tr("Edit Bookmark"));
m_editAction.setDefaultKeySequence(Tr::tr("Meta+Shift+M"), Tr::tr("Ctrl+Shift+M")); editAction.setDefaultKeySequence(Tr::tr("Meta+Shift+M"), Tr::tr("Ctrl+Shift+M"));
m_editAction.setContainer(bookmarkMenuId); editAction.setContainer(bookmarkMenuId);
m_editAction.setOnTriggered(this, [this] { editAction.bindContextAction(&m_editAction);
editAction.setOnTriggered(this, [this] {
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
auto widget = TextEditorWidget::fromEditor(editor); auto widget = TextEditorWidget::fromEditor(editor);
if (widget && editor && !editor->document()->isTemporary()) { if (widget && editor && !editor->document()->isTemporary()) {
@@ -154,37 +156,41 @@ TextEditorPluginPrivate::TextEditorPluginPrivate()
m_bookmarkMenu.addSeparator(); m_bookmarkMenu.addSeparator();
m_prevAction.setId(BOOKMARKS_PREV_ACTION); ActionBuilder prevAction(this, BOOKMARKS_PREV_ACTION);
m_prevAction.setContext(editorManagerContext); prevAction.setContext(editorManagerContext);
m_prevAction.setText(Tr::tr("Previous Bookmark")); prevAction.setText(Tr::tr("Previous Bookmark"));
m_prevAction.setDefaultKeySequence(Tr::tr("Meta+,"), Tr::tr("Ctrl+,")); prevAction.setDefaultKeySequence(Tr::tr("Meta+,"), Tr::tr("Ctrl+,"));
m_prevAction.setContainer(bookmarkMenuId); prevAction.setContainer(bookmarkMenuId);
m_prevAction.setIcon(Icons::PREV_TOOLBAR.icon()); prevAction.setIcon(Icons::PREV_TOOLBAR.icon());
m_prevAction.setIconVisibleInMenu(false); prevAction.setIconVisibleInMenu(false);
m_prevAction.setOnTriggered(this, [this] { m_bookmarkManager.prev(); }); prevAction.bindContextAction(&m_prevAction);
prevAction.setOnTriggered(this, [this] { m_bookmarkManager.prev(); });
m_nextAction.setId(BOOKMARKS_NEXT_ACTION); ActionBuilder nextAction(this, BOOKMARKS_NEXT_ACTION);
m_nextAction.setContext(editorManagerContext); nextAction.setContext(editorManagerContext);
m_nextAction.setText(Tr::tr("Next Bookmark")); nextAction.setText(Tr::tr("Next Bookmark"));
m_nextAction.setIcon(Icons::NEXT_TOOLBAR.icon()); nextAction.setIcon(Icons::NEXT_TOOLBAR.icon());
m_nextAction.setIconVisibleInMenu(false); nextAction.setIconVisibleInMenu(false);
m_nextAction.setDefaultKeySequence(Tr::tr("Meta+."), Tr::tr("Ctrl+.")); nextAction.setDefaultKeySequence(Tr::tr("Meta+."), Tr::tr("Ctrl+."));
m_nextAction.setContainer(bookmarkMenuId); nextAction.setContainer(bookmarkMenuId);
m_nextAction.setOnTriggered(this, [this] { m_bookmarkManager.next(); }); nextAction.bindContextAction(&m_nextAction);
nextAction.setOnTriggered(this, [this] { m_bookmarkManager.next(); });
m_bookmarkMenu.addSeparator(); m_bookmarkMenu.addSeparator();
m_docPrevAction.setId("Bookmarks.PreviousDocument"); ActionBuilder docPrevAction(this, "Bookmarks.PreviousDocument");
m_docPrevAction.setContext(editorManagerContext); docPrevAction.setContext(editorManagerContext);
m_docPrevAction.setText(Tr::tr("Previous Bookmark in Document")); docPrevAction.setText(Tr::tr("Previous Bookmark in Document"));
m_docPrevAction.setContainer(bookmarkMenuId); docPrevAction.setContainer(bookmarkMenuId);
m_docPrevAction.setOnTriggered(this, [this] { m_bookmarkManager.prevInDocument(); }); docPrevAction.bindContextAction(&m_docPrevAction);
docPrevAction.setOnTriggered(this, [this] { m_bookmarkManager.prevInDocument(); });
m_docNextAction.setId("Bookmarks.NextDocument"); ActionBuilder docNextAction(this, "Bookmarks.NextDocument");
m_docNextAction.setContext(Core::Constants::C_EDITORMANAGER); docNextAction.setContext(Core::Constants::C_EDITORMANAGER);
m_docNextAction.setText(Tr::tr("Next Bookmark in Document")); docNextAction.setText(Tr::tr("Next Bookmark in Document"));
m_docNextAction.setContainer(bookmarkMenuId); docNextAction.setContainer(bookmarkMenuId);
m_docNextAction.setOnTriggered(this, [this] { m_bookmarkManager.nextInDocument(); }); docNextAction.bindContextAction(&m_docNextAction);
docNextAction.setOnTriggered(this, [this] { m_bookmarkManager.nextInDocument(); });
connect(&m_editBookmarkAction, &QAction::triggered, this, [this] { connect(&m_editBookmarkAction, &QAction::triggered, this, [this] {
m_bookmarkManager.editByFileAndLine(m_marginActionFileName, m_marginActionLineNumber); m_bookmarkManager.editByFileAndLine(m_marginActionFileName, m_marginActionLineNumber);
@@ -199,7 +205,7 @@ TextEditorPluginPrivate::TextEditorPluginPrivate()
}); });
ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR); ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR);
touchBar->addAction(m_toggleAction.command(), Core::Constants::G_TOUCHBAR_EDITOR); touchBar->addAction(toggleAction.command(), Core::Constants::G_TOUCHBAR_EDITOR);
// EditorManager // EditorManager
connect(EditorManager::instance(), &EditorManager::editorAboutToClose, connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
@@ -213,12 +219,12 @@ void TextEditorPluginPrivate::updateActions(bool enableToggle, int state)
const bool hasbm = state >= BookmarkManager::HasBookMarks; const bool hasbm = state >= BookmarkManager::HasBookMarks;
const bool hasdocbm = state == BookmarkManager::HasBookmarksInDocument; const bool hasdocbm = state == BookmarkManager::HasBookmarksInDocument;
m_toggleAction.setEnabled(enableToggle); m_toggleAction->setEnabled(enableToggle);
m_editAction.setEnabled(enableToggle); m_editAction->setEnabled(enableToggle);
m_prevAction.setEnabled(hasbm); m_prevAction->setEnabled(hasbm);
m_nextAction.setEnabled(hasbm); m_nextAction->setEnabled(hasbm);
m_docPrevAction.setEnabled(hasdocbm); m_docPrevAction->setEnabled(hasdocbm);
m_docNextAction.setEnabled(hasdocbm); m_docNextAction->setEnabled(hasdocbm);
} }
void TextEditorPluginPrivate::editorOpened(IEditor *editor) void TextEditorPluginPrivate::editorOpened(IEditor *editor)