Commit f7ca05e4 authored by Eike Ziller's avatar Eike Ziller Committed by hjk

Let Command construct its description (former defaultText) itself.

Instead of doing it duplicated in the general and the fakevim shortcut
settings.

Change-Id: Id4b0e5b0630f1e94c825528f1c038776dc205aa3
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent de26dad9
......@@ -239,14 +239,25 @@ void CommandPrivate::setKeySequence(const QKeySequence &key)
m_isKeyInitialized = true;
}
void CommandPrivate::setDefaultText(const QString &text)
void CommandPrivate::setDescription(const QString &text)
{
m_defaultText = text;
}
QString CommandPrivate::defaultText() const
QString CommandPrivate::description() const
{
return m_defaultText;
if (!m_defaultText.isEmpty())
return m_defaultText;
if (action()) {
QString text = action()->text();
text.remove(QRegExp(QLatin1String("&(?!&)")));
if (!text.isEmpty())
return text;
} else if (shortcut()) {
if (!shortcut()->whatsThis().isEmpty())
return shortcut()->whatsThis();
}
return id().toString();
}
Id CommandPrivate::id() const
......@@ -332,16 +343,6 @@ QKeySequence Shortcut::keySequence() const
return m_shortcut->key();
}
void Shortcut::setDefaultText(const QString &text)
{
m_defaultText = text;
}
QString Shortcut::defaultText() const
{
return m_defaultText;
}
void Shortcut::setCurrentContext(const Core::Context &context)
{
foreach (int ctxt, m_context) {
......
......@@ -64,8 +64,12 @@ public:
virtual void setDefaultKeySequence(const QKeySequence &key) = 0;
virtual QKeySequence defaultKeySequence() const = 0;
virtual QKeySequence keySequence() const = 0;
virtual void setDefaultText(const QString &text) = 0;
virtual QString defaultText() const = 0;
// explicitly set the description (used e.g. in shortcut settings)
// default is to use the action text for actions, or the whatsThis for shortcuts,
// or, as a last fall back if these are empty, the command ID string
// override the default e.g. if the text is context dependent and contains file names etc
virtual void setDescription(const QString &text) = 0;
virtual QString description() const = 0;
virtual Id id() const = 0;
......
......@@ -61,8 +61,8 @@ public:
void setKeySequence(const QKeySequence &key);
void setDefaultText(const QString &text);
QString defaultText() const;
void setDescription(const QString &text);
QString description() const;
Id id() const;
......@@ -97,9 +97,6 @@ public:
void setKeySequence(const QKeySequence &key);
QKeySequence keySequence() const;
virtual void setDefaultText(const QString &key);
virtual QString defaultText() const;
void setShortcut(QShortcut *shortcut);
QShortcut *shortcut() const;
......@@ -115,7 +112,6 @@ public:
private:
QShortcut *m_shortcut;
QString m_defaultText;
bool m_scriptable;
};
......
......@@ -322,17 +322,7 @@ void ShortcutSettings::initialize()
sections[section]->addChild(item);
item->setText(0, subId);
if (c->action()) {
QString text = c->hasAttribute(Command::CA_UpdateText) && !c->defaultText().isNull() ? c->defaultText() : c->action()->text();
text.remove(QRegExp(QLatin1String("&(?!&)")));
s->m_key = c->action()->shortcut();
item->setText(1, text);
} else {
s->m_key = c->shortcut()->key();
item->setText(1, c->shortcut()->whatsThis());
}
item->setText(1, c->description());
item->setText(2, s->m_key);
if (s->m_cmd->defaultKeySequence() != s->m_key)
setModified(item, true);
......
......@@ -307,7 +307,7 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
Command *cmd = am->registerAction(d->m_revertToSavedAction,
Constants::REVERTTOSAVED, editManagerContext);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDefaultText(tr("Revert File to Saved"));
cmd->setDescription(tr("Revert File to Saved"));
mfile->addAction(cmd, Constants::G_FILE_SAVE);
connect(d->m_revertToSavedAction, SIGNAL(triggered()), this, SLOT(revertToSaved()));
......@@ -337,7 +337,7 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
cmd = am->registerAction(d->m_closeCurrentEditorAction, Constants::CLOSE, editManagerContext, true);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+W")));
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_closeCurrentEditorAction->text());
cmd->setDescription(d->m_closeCurrentEditorAction->text());
mfile->addAction(cmd, Constants::G_FILE_CLOSE);
connect(d->m_closeCurrentEditorAction, SIGNAL(triggered()), this, SLOT(closeEditor()));
......
......@@ -624,7 +624,7 @@ void MainWindow::registerDefaultActions()
cmd = am->registerAction(tmpaction, Constants::SAVE, globalContext);
cmd->setDefaultKeySequence(QKeySequence::Save);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDefaultText(tr("&Save"));
cmd->setDescription(tr("Save"));
mfile->addAction(cmd, Constants::G_FILE_SAVE);
// Save As Action
......@@ -636,7 +636,7 @@ void MainWindow::registerDefaultActions()
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+S")));
#endif
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDefaultText(tr("Save &As..."));
cmd->setDescription(tr("Save As..."));
mfile->addAction(cmd, Constants::G_FILE_SAVE);
// SaveAll Action
......@@ -670,7 +670,7 @@ void MainWindow::registerDefaultActions()
cmd = am->registerAction(tmpaction, Constants::UNDO, globalContext);
cmd->setDefaultKeySequence(QKeySequence::Undo);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDefaultText(tr("&Undo"));
cmd->setDescription(tr("Undo"));
medit->addAction(cmd, Constants::G_EDIT_UNDOREDO);
tmpaction->setEnabled(false);
......@@ -680,7 +680,7 @@ void MainWindow::registerDefaultActions()
cmd = am->registerAction(tmpaction, Constants::REDO, globalContext);
cmd->setDefaultKeySequence(QKeySequence::Redo);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDefaultText(tr("&Redo"));
cmd->setDescription(tr("Redo"));
medit->addAction(cmd, Constants::G_EDIT_UNDOREDO);
tmpaction->setEnabled(false);
......
......@@ -3112,7 +3112,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
ActionContainer *mstart = am->actionContainer(PE::M_DEBUG_STARTDEBUGGING);
cmd = am->registerAction(m_startAction, Constants::DEBUG, globalcontext);
cmd->setDefaultText(tr("Start Debugging"));
cmd->setDescription(tr("Start Debugging"));
cmd->setDefaultKeySequence(QKeySequence(QLatin1String(Constants::DEBUG_KEY)));
cmd->setAttribute(Command::CA_UpdateText);
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
......@@ -3165,12 +3165,12 @@ void DebuggerPluginPrivate::extensionsInitialized()
cmd = am->registerAction(m_startRemoteServerAction,
"Debugger.StartRemoteServer", globalcontext);
cmd->setDefaultText(tr("Start Gdbserver"));
cmd->setDescription(tr("Start Gdbserver"));
mstart->addAction(cmd, Constants::G_MANUAL_REMOTE);
cmd = am->registerAction(m_attachToRemoteProcessAction,
"Debugger.AttachToRemoteProcess", globalcontext);
cmd->setDefaultText(tr("Attach to Remote Process"));
cmd->setDescription(tr("Attach to Remote Process"));
mstart->addAction(cmd, Debugger::Constants::G_AUTOMATIC_REMOTE);
#ifdef WITH_LLDB
......@@ -3205,7 +3205,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
cmd = am->registerAction(m_interruptAction,
Constants::INTERRUPT, globalcontext);
cmd->setDefaultText(tr("Interrupt Debugger"));
cmd->setDescription(tr("Interrupt Debugger"));
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_continueAction,
......@@ -3215,7 +3215,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
cmd = am->registerAction(m_exitAction,
Constants::STOP, globalcontext);
cmd->setDefaultText(tr("Stop Debugger"));
cmd->setDescription(tr("Stop Debugger"));
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
m_hiddenStopAction = new Utils::ProxyAction(this);
......@@ -3230,7 +3230,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
cmd = am->registerAction(m_abortAction,
Constants::ABORT, globalcontext);
//cmd->setDefaultKeySequence(QKeySequence(QLatin1String(Constants::RESET_KEY)));
cmd->setDefaultText(tr("Reset Debugger"));
cmd->setDescription(tr("Reset Debugger"));
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
sep = new QAction(this);
......
......@@ -408,16 +408,7 @@ void FakeVimExCommandsPage::initialize()
sections[section]->addChild(item);
item->setText(0, subId);
if (c->action()) {
QString text = c->hasAttribute(Command::CA_UpdateText)
&& !c->defaultText().isNull()
? c->defaultText() : c->action()->text();
text.remove(QRegExp("&(?!&)"));
item->setText(1, text);
} else {
item->setText(1, c->shortcut()->whatsThis());
}
item->setText(1, c->description());
QString regex;
if (exCommandMap().contains(name))
......
......@@ -279,7 +279,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
m_diffFileAction = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = am->registerAction(m_diffFileAction, CMD_ID_DIFF_CURRENT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultText(tr("Diff Current File"));
command->setDescription(tr("Diff Current File"));
connect(m_diffFileAction, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
mperforce->addAction(command);
m_commandLocator->appendCommand(command);
......@@ -287,7 +287,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
m_annotateCurrentAction = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = am->registerAction(m_annotateCurrentAction, CMD_ID_ANNOTATE_CURRENT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultText(tr("Annotate Current File"));
command->setDescription(tr("Annotate Current File"));
connect(m_annotateCurrentAction, SIGNAL(triggered()), this, SLOT(annotateCurrentFile()));
mperforce->addAction(command);
m_commandLocator->appendCommand(command);
......@@ -296,7 +296,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
command = am->registerAction(m_filelogCurrentAction, CMD_ID_FILELOG_CURRENT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+F")));
command->setDefaultText(tr("Filelog Current File"));
command->setDescription(tr("Filelog Current File"));
connect(m_filelogCurrentAction, SIGNAL(triggered()), this, SLOT(filelogCurrentFile()));
mperforce->addAction(command);
m_commandLocator->appendCommand(command);
......@@ -307,7 +307,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
command = am->registerAction(m_editAction, CMD_ID_EDIT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+E")));
command->setDefaultText(tr("Edit File"));
command->setDescription(tr("Edit File"));
connect(m_editAction, SIGNAL(triggered()), this, SLOT(openCurrentFile()));
mperforce->addAction(command);
m_commandLocator->appendCommand(command);
......@@ -316,7 +316,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
command = am->registerAction(m_addAction, CMD_ID_ADD, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+A")));
command->setDefaultText(tr("Add File"));
command->setDescription(tr("Add File"));
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
mperforce->addAction(command);
m_commandLocator->appendCommand(command);
......@@ -324,7 +324,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = am->registerAction(m_deleteAction, CMD_ID_DELETE_FILE, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultText(tr("Delete File"));
command->setDescription(tr("Delete File"));
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
mperforce->addAction(command);
m_commandLocator->appendCommand(command);
......@@ -333,7 +333,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
command = am->registerAction(m_revertFileAction, CMD_ID_REVERT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+R")));
command->setDefaultText(tr("Revert File"));
command->setDescription(tr("Revert File"));
connect(m_revertFileAction, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
mperforce->addAction(command);
m_commandLocator->appendCommand(command);
......@@ -345,7 +345,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
command = am->registerAction(m_diffProjectAction, CMD_ID_DIFF_PROJECT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+D")));
command->setDefaultText(diffProjectDefaultText);
command->setDescription(diffProjectDefaultText);
connect(m_diffProjectAction, SIGNAL(triggered()), this, SLOT(diffCurrentProject()));
mperforce->addAction(command);
m_commandLocator->appendCommand(command);
......@@ -368,7 +368,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
const QString updateProjectDefaultText = tr("Update Current Project");
m_updateProjectAction = new Utils::ParameterAction(updateProjectDefaultText, tr("Update Project \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
command = am->registerAction(m_updateProjectAction, CMD_ID_UPDATE_PROJECT, globalcontext);
command->setDefaultText(updateProjectDefaultText);
command->setDescription(updateProjectDefaultText);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_updateProjectAction, SIGNAL(triggered()), this, SLOT(updateCurrentProject()));
mperforce->addAction(command);
......
......@@ -640,7 +640,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::EnabledWithParameter, this);
cmd = am->registerAction(d->m_unloadAction, Constants::UNLOAD, globalcontext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_unloadAction->text());
cmd->setDescription(d->m_unloadAction->text());
mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
// unload session action
......@@ -686,7 +686,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
d->m_buildAction->setIcon(buildIcon);
cmd = am->registerAction(d->m_buildAction, Constants::BUILD, globalcontext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_buildAction->text());
cmd->setDescription(d->m_buildAction->text());
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+B")));
mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
......@@ -698,7 +698,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::AlwaysEnabled, this);
cmd = am->registerAction(d->m_rebuildAction, Constants::REBUILD, globalcontext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_rebuildAction->text());
cmd->setDescription(d->m_rebuildAction->text());
mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
// deploy action
......@@ -706,7 +706,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::AlwaysEnabled, this);
cmd = am->registerAction(d->m_deployAction, Constants::DEPLOY, globalcontext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_deployAction->text());
cmd->setDescription(d->m_deployAction->text());
mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
// Publish action
......@@ -714,7 +714,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::AlwaysEnabled, this);
cmd = am->registerAction(d->m_publishAction, Constants::PUBLISH, globalcontext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_publishAction->text());
cmd->setDescription(d->m_publishAction->text());
mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
// clean action
......@@ -722,7 +722,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::AlwaysEnabled, this);
cmd = am->registerAction(d->m_cleanAction, Constants::CLEAN, globalcontext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_cleanAction->text());
cmd->setDescription(d->m_cleanAction->text());
mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
// build action (context menu)
......@@ -730,7 +730,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::AlwaysEnabled, this);
cmd = am->registerAction(d->m_buildActionContextMenu, Constants::BUILDCM, projecTreeContext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_buildActionContextMenu->text());
cmd->setDescription(d->m_buildActionContextMenu->text());
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_BUILD);
// rebuild action (context menu)
......@@ -738,7 +738,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::AlwaysEnabled, this);
cmd = am->registerAction(d->m_rebuildActionContextMenu, Constants::REBUILDCM, projecTreeContext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_rebuildActionContextMenu->text());
cmd->setDescription(d->m_rebuildActionContextMenu->text());
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_BUILD);
// deploy action (context menu)
......@@ -746,7 +746,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::AlwaysEnabled, this);
cmd = am->registerAction(d->m_deployActionContextMenu, Constants::DEPLOYCM, projecTreeContext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_deployActionContextMenu->text());
cmd->setDescription(d->m_deployActionContextMenu->text());
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_BUILD);
// clean action (context menu)
......@@ -754,7 +754,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
Utils::ParameterAction::AlwaysEnabled, this);
cmd = am->registerAction(d->m_cleanActionContextMenu, Constants::CLEANCM, projecTreeContext);
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(d->m_cleanActionContextMenu->text());
cmd->setDescription(d->m_cleanActionContextMenu->text());
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_BUILD);
// build without dependencies action
......
Markdown is supported
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