diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2009-05-15 15:41:00 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2009-05-15 15:41:00 +0200 |
commit | 81d69641abd750de877f96ba348eb0aa550a752e (patch) | |
tree | 289d6a51b80ceeaa665f8cb26a19f457f3c8c31a /src/plugins/perforce | |
parent | 9106c7211676b3495c42c4457ce81d6792006bf0 (diff) |
Added ParameterAction class for QActions acting on files.
Reduce inconsistencies in tr()-Strings provided for
QActions that act on a current <something> (mostly files) by
introducing a ParameterAction class that takes the tr()-Strings
at construction time and provides a setParameter(QString) slot,
allows for setting that parameter or an empty string, which
will cause the displayed text to be updated.
Diffstat (limited to 'src/plugins/perforce')
-rw-r--r-- | src/plugins/perforce/perforceplugin.cpp | 61 | ||||
-rw-r--r-- | src/plugins/perforce/perforceplugin.h | 19 |
2 files changed, 33 insertions, 47 deletions
diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index 1cb25746d2..4c4c319075 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -48,6 +48,7 @@ #include <coreplugin/uniqueidmanager.h> #include <utils/qtcassert.h> #include <utils/synchronousprocess.h> +#include <utils/parameteraction.h> #include <vcsbase/basevcseditorfactory.h> #include <vcsbase/basevcssubmiteditorfactory.h> #include <vcsbase/vcsbaseeditor.h> @@ -263,7 +264,7 @@ bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMess Core::Command *command; QAction *tmpaction; - m_editAction = new QAction(tr("Edit"), this); + m_editAction = new Core::Utils::ParameterAction(tr("Edit"), tr("Edit \"%1\""), Core::Utils::ParameterAction::EnabledWithParameter, this); command = am->registerAction(m_editAction, PerforcePlugin::EDIT, globalcontext); command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+E"))); @@ -271,7 +272,7 @@ bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMess connect(m_editAction, SIGNAL(triggered()), this, SLOT(openCurrentFile())); mperforce->addAction(command); - m_addAction = new QAction(tr("Add"), this); + m_addAction = new Core::Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Core::Utils::ParameterAction::EnabledWithParameter, this); command = am->registerAction(m_addAction, PerforcePlugin::ADD, globalcontext); command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+A"))); @@ -279,14 +280,14 @@ bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMess connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile())); mperforce->addAction(command); - m_deleteAction = new QAction(tr("Delete"), this); + m_deleteAction = new Core::Utils::ParameterAction(tr("Delete"), tr("Delete \"%1\""), Core::Utils::ParameterAction::EnabledWithParameter, this); command = am->registerAction(m_deleteAction, PerforcePlugin::DELETE_FILE, globalcontext); command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultText(tr("Delete File")); connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteCurrentFile())); mperforce->addAction(command); - m_revertAction = new QAction(tr("Revert"), this); + m_revertAction = new Core::Utils::ParameterAction(tr("Revert"), tr("Revert \"%1\""), Core::Utils::ParameterAction::EnabledWithParameter, this); command = am->registerAction(m_revertAction, PerforcePlugin::REVERT, globalcontext); command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+R"))); @@ -299,14 +300,14 @@ bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMess command = am->registerAction(tmpaction, QLatin1String("Perforce.Sep.Edit"), globalcontext); mperforce->addAction(command); - m_diffCurrentAction = new QAction(tr("Diff Current File"), this); + m_diffCurrentAction = new Core::Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Core::Utils::ParameterAction::EnabledWithParameter, this); command = am->registerAction(m_diffCurrentAction, PerforcePlugin::DIFF_CURRENT, globalcontext); command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultText(tr("Diff Current File")); connect(m_diffCurrentAction, SIGNAL(triggered()), this, SLOT(diffCurrentFile())); mperforce->addAction(command); - m_diffProjectAction = new QAction(tr("Diff Current Project/Session"), this); + m_diffProjectAction = new Core::Utils::ParameterAction(tr("Diff Current Project/Session"), tr("Diff Project \"%1\""), Core::Utils::ParameterAction::EnabledWithParameter, this); command = am->registerAction(m_diffProjectAction, PerforcePlugin::DIFF_PROJECT, globalcontext); command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+D"))); @@ -351,7 +352,7 @@ bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMess connect(m_describeAction, SIGNAL(triggered()), this, SLOT(describeChange())); mperforce->addAction(command); - m_annotateCurrentAction = new QAction(tr("Annotate Current File"), this); + m_annotateCurrentAction = new Core::Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Core::Utils::ParameterAction::EnabledWithParameter, this); command = am->registerAction(m_annotateCurrentAction, PerforcePlugin::ANNOTATE_CURRENT, globalcontext); command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultText(tr("Annotate Current File")); @@ -363,7 +364,7 @@ bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMess connect(m_annotateAction, SIGNAL(triggered()), this, SLOT(annotate())); mperforce->addAction(command); - m_filelogCurrentAction = new QAction(tr("Filelog Current File"), this); + m_filelogCurrentAction = new Core::Utils::ParameterAction(tr("Filelog Current File"), tr("Filelog \"%1\""), Core::Utils::ParameterAction::EnabledWithParameter, this); command = am->registerAction(m_filelogCurrentAction, PerforcePlugin::FILELOG_CURRENT, globalcontext); command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultKeySequence(QKeySequence(tr("Alt+P,Alt+F"))); @@ -628,40 +629,22 @@ void PerforcePlugin::filelog(const QString &fileName) void PerforcePlugin::updateActions() { - QString fileName = currentFileName(); - QString baseName = QFileInfo(fileName).fileName(); - const bool hasFile = !currentFileName().isEmpty(); - m_editAction->setEnabled(hasFile); - m_addAction->setEnabled(hasFile); - m_deleteAction->setEnabled(hasFile); - m_revertAction->setEnabled(hasFile); - m_diffCurrentAction->setEnabled(hasFile); - m_annotateCurrentAction->setEnabled(hasFile); - m_filelogCurrentAction->setEnabled(hasFile); - if (hasFile) { - m_editAction->setText(tr("Edit %1").arg(baseName)); - m_addAction->setText(tr("Add %1").arg(baseName)); - m_deleteAction->setText(tr("Delete %1").arg(baseName)); - m_revertAction->setText(tr("Revert %1").arg(baseName)); - m_diffCurrentAction->setText(tr("Diff %1").arg(baseName)); - m_annotateCurrentAction->setText(tr("Annotate %1").arg(baseName)); - m_filelogCurrentAction->setText(tr("Filelog %1").arg(baseName)); - } else { - m_editAction->setText(tr("Edit")); - m_addAction->setText(tr("Add")); - m_deleteAction->setText(tr("Delete")); - m_revertAction->setText(tr("Revert")); - m_diffCurrentAction->setText(tr("Diff")); - m_annotateCurrentAction->setText(tr("Annotate Current File")); - m_filelogCurrentAction->setText(tr("Filelog Current File")); - } + const QString fileName = currentFileName(); + const QString baseName = fileName.isEmpty() ? fileName : QFileInfo(fileName).fileName(); + + m_editAction->setParameter(baseName); + m_addAction->setParameter(baseName); + m_deleteAction->setParameter(baseName); + m_revertAction->setParameter(baseName); + m_diffCurrentAction->setParameter(baseName); + m_annotateCurrentAction->setParameter(baseName); + m_filelogCurrentAction->setParameter(baseName); + if (m_projectExplorer && m_projectExplorer->currentProject()) { - m_diffProjectAction->setEnabled(true); - m_diffProjectAction->setText(tr("Diff Project %1").arg(m_projectExplorer->currentProject()->name())); + m_diffProjectAction->setParameter(m_projectExplorer->currentProject()->name()); m_submitAction->setEnabled(true); } else { - m_diffProjectAction->setEnabled(false); - m_diffProjectAction->setText(tr("Diff Current Project/Solution")); + m_diffProjectAction->setParameter(QString()); m_submitAction->setEnabled(false); } m_diffAllAction->setEnabled(true); diff --git a/src/plugins/perforce/perforceplugin.h b/src/plugins/perforce/perforceplugin.h index 733b514dd2..042736a2dd 100644 --- a/src/plugins/perforce/perforceplugin.h +++ b/src/plugins/perforce/perforceplugin.h @@ -51,6 +51,9 @@ QT_END_NAMESPACE namespace Core { class IEditorFactory; + namespace Utils { + class ParameterAction; + } } namespace Perforce { @@ -170,21 +173,21 @@ private: SettingsPage *m_settingsPage; QList<Core::IEditorFactory*> m_editorFactories; - QAction *m_editAction; - QAction *m_addAction; - QAction *m_deleteAction; + Core::Utils::ParameterAction *m_editAction; + Core::Utils::ParameterAction *m_addAction; + Core::Utils::ParameterAction *m_deleteAction; QAction *m_openedAction; - QAction *m_revertAction; - QAction *m_diffCurrentAction; - QAction *m_diffProjectAction; + Core::Utils::ParameterAction *m_revertAction; + Core::Utils::ParameterAction *m_diffCurrentAction; + Core::Utils::ParameterAction *m_diffProjectAction; QAction *m_diffAllAction; QAction *m_resolveAction; QAction *m_submitAction; QAction *m_pendingAction; QAction *m_describeAction; - QAction *m_annotateCurrentAction; + Core::Utils::ParameterAction *m_annotateCurrentAction; QAction *m_annotateAction; - QAction *m_filelogCurrentAction; + Core::Utils::ParameterAction *m_filelogCurrentAction; QAction *m_filelogAction; QAction *m_submitCurrentLogAction; bool m_submitActionTriggered; |