Commit a43f162d authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Mercurial: Disable hidden menu entries



To avoid shortcut ambiguity

Task-number: QTCREATORBUG-13364
Change-Id: Ibce1701be72376845624856b5de097332aaaccae
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 895e0d84
......@@ -307,6 +307,18 @@ Command *ActionContainerPrivate::addSeparator(const Context &context, Id group,
return cmd;
}
void ActionContainerPrivate::setEnabled(bool enabled)
{
foreach (const Group &group, m_groups) {
foreach (QObject *item, group.items) {
if (Command *command = qobject_cast<Command *>(item))
command->action()->setEnabled(enabled);
else if (ActionContainer *container = qobject_cast<ActionContainer *>(item))
container->setEnabled(enabled);
}
}
}
void ActionContainerPrivate::clear()
{
QMutableListIterator<Group> it(m_groups);
......
......@@ -72,6 +72,7 @@ public:
virtual void addMenu(ActionContainer *menu, Id group = Id()) = 0;
virtual void addMenu(ActionContainer *before, ActionContainer *menu, Id group = Id()) = 0;
virtual Command *addSeparator(const Context &context, Id group = Id(), QAction **outSeparator = 0) = 0;
virtual void setEnabled(bool enabled) = 0;
// This clears this menu and submenus from all actions and submenus.
// It does not destroy the submenus and commands, just removes them from their parents.
......
......@@ -64,6 +64,7 @@ public:
void addMenu(ActionContainer *menu, Id group = Id());
void addMenu(ActionContainer *before, ActionContainer *menu, Id group = Id());
Command *addSeparator(const Context &context, Id group = Id(), QAction **outSeparator = 0);
void setEnabled(bool enabled);
virtual void clear();
Id id() const;
......
......@@ -191,22 +191,22 @@ void MercurialPlugin::createMenu()
Core::Context context(Core::Constants::C_GLOBAL);
// Create menu item for Mercurial
mercurialContainer = Core::ActionManager::createMenu("Mercurial.MercurialMenu");
QMenu *menu = mercurialContainer->menu();
m_mercurialContainer = Core::ActionManager::createMenu("Mercurial.MercurialMenu");
QMenu *menu = m_mercurialContainer->menu();
menu->setTitle(tr("Me&rcurial"));
createFileActions(context);
mercurialContainer->addSeparator(context);
m_mercurialContainer->addSeparator(context);
createDirectoryActions(context);
mercurialContainer->addSeparator(context);
m_mercurialContainer->addSeparator(context);
createRepositoryActions(context);
mercurialContainer->addSeparator(context);
m_mercurialContainer->addSeparator(context);
createRepositoryManagementActions(context);
// Request the Tools menu and add the Mercurial menu to it
Core::ActionContainer *toolsMenu = Core::ActionManager::actionContainer(Core::Id(Core::Constants::M_TOOLS));
toolsMenu->addMenu(mercurialContainer);
m_menuAction = mercurialContainer->menu()->menuAction();
toolsMenu->addMenu(m_mercurialContainer);
m_menuAction = m_mercurialContainer->menu()->menuAction();
}
void MercurialPlugin::createFileActions(const Core::Context &context)
......@@ -217,7 +217,7 @@ void MercurialPlugin::createFileActions(const Core::Context &context)
command = Core::ActionManager::registerAction(annotateFile, Core::Id(Constants::ANNOTATE), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(annotateFile, SIGNAL(triggered()), this, SLOT(annotateCurrentFile()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
diffFile = new ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), ParameterAction::EnabledWithParameter, this);
......@@ -225,7 +225,7 @@ void MercurialPlugin::createFileActions(const Core::Context &context)
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+H,Meta+D") : tr("Alt+G,Alt+D")));
connect(diffFile, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
logFile = new ParameterAction(tr("Log Current File"), tr("Log \"%1\""), ParameterAction::EnabledWithParameter, this);
......@@ -233,7 +233,7 @@ void MercurialPlugin::createFileActions(const Core::Context &context)
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+H,Meta+L") : tr("Alt+G,Alt+L")));
connect(logFile, SIGNAL(triggered()), this, SLOT(logCurrentFile()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
statusFile = new ParameterAction(tr("Status Current File"), tr("Status \"%1\""), ParameterAction::EnabledWithParameter, this);
......@@ -241,30 +241,30 @@ void MercurialPlugin::createFileActions(const Core::Context &context)
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+H,Meta+S") : tr("Alt+G,Alt+S")));
connect(statusFile, SIGNAL(triggered()), this, SLOT(statusCurrentFile()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
mercurialContainer->addSeparator(context);
m_mercurialContainer->addSeparator(context);
m_addAction = new ParameterAction(tr("Add"), tr("Add \"%1\""), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_addAction, Core::Id(Constants::ADD), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
m_deleteAction = new ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_deleteAction, Core::Id(Constants::DELETE), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
revertFile = new ParameterAction(tr("Revert Current File..."), tr("Revert \"%1\"..."), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(revertFile, Core::Id(Constants::REVERT), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(revertFile, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
}
......@@ -327,28 +327,28 @@ void MercurialPlugin::createDirectoryActions(const Core::Context &context)
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::DIFFMULTI), context);
connect(action, SIGNAL(triggered()), this, SLOT(diffRepository()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Log"), this);
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::LOGMULTI), context);
connect(action, SIGNAL(triggered()), this, SLOT(logRepository()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Revert..."), this);
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::REVERTMULTI), context);
connect(action, SIGNAL(triggered()), this, SLOT(revertMulti()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Status"), this);
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::STATUSMULTI), context);
connect(action, SIGNAL(triggered()), this, SLOT(statusMulti()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
}
......@@ -391,42 +391,42 @@ void MercurialPlugin::createRepositoryActions(const Core::Context &context)
m_repositoryActionList.append(action);
Core::Command *command = Core::ActionManager::registerAction(action, Core::Id(Constants::PULL), context);
connect(action, SIGNAL(triggered()), this, SLOT(pull()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Push..."), this);
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::PUSH), context);
connect(action, SIGNAL(triggered()), this, SLOT(push()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Update..."), this);
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::UPDATE), context);
connect(action, SIGNAL(triggered()), this, SLOT(update()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Import..."), this);
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::IMPORT), context);
connect(action, SIGNAL(triggered()), this, SLOT(import()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Incoming..."), this);
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::INCOMING), context);
connect(action, SIGNAL(triggered()), this, SLOT(incoming()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Outgoing..."), this);
m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::OUTGOING), context);
connect(action, SIGNAL(triggered()), this, SLOT(outgoing()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
action = new QAction(tr("Commit..."), this);
......@@ -434,13 +434,13 @@ void MercurialPlugin::createRepositoryActions(const Core::Context &context)
command = Core::ActionManager::registerAction(action, Core::Id(Constants::COMMIT), context);
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+H,Meta+C") : tr("Alt+G,Alt+C")));
connect(action, SIGNAL(triggered()), this, SLOT(commit()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
m_commandLocator->appendCommand(command);
m_createRepositoryAction = new QAction(tr("Create Repository..."), this);
command = Core::ActionManager::registerAction(m_createRepositoryAction, Core::Id(Constants::CREATE_REPOSITORY), context);
connect(m_createRepositoryAction, SIGNAL(triggered()), this, SLOT(createRepository()));
mercurialContainer->addAction(command);
m_mercurialContainer->addAction(command);
}
void MercurialPlugin::pull()
......@@ -653,17 +653,19 @@ void MercurialPlugin::createRepositoryManagementActions(const Core::Context &con
// actionList.append(action);
// Core::Command *command = Core::ActionManager::registerAction(action, Constants::BRANCH, context);
// // connect(action, SIGNAL(triggered()), this, SLOT(branch()));
// mercurialContainer->addAction(command);
// m_mercurialContainer->addAction(command);
}
void MercurialPlugin::updateActions(VcsBasePlugin::ActionState as)
{
if (!enableMenuAction(as, m_menuAction)) {
m_mercurialContainer->setEnabled(false);
m_commandLocator->setEnabled(false);
return;
}
const QString filename = currentState().currentFileName();
const bool repoEnabled = currentState().hasTopLevel();
m_mercurialContainer->setEnabled(repoEnabled);
m_commandLocator->setEnabled(repoEnabled);
annotateFile->setParameter(filename);
......
......@@ -144,7 +144,7 @@ private:
Core::ICore *core;
Core::CommandLocator *m_commandLocator;
Core::ActionContainer *mercurialContainer;
Core::ActionContainer *m_mercurialContainer;
QList<QAction *> m_repositoryActionList;
......
Supports Markdown
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