forked from qt-creator/qt-creator
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.
This commit is contained in:
61
src/libs/utils/parameteraction.cpp
Normal file
61
src/libs/utils/parameteraction.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "parameteraction.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Utils {
|
||||
|
||||
ParameterAction::ParameterAction(const QString &emptyText,
|
||||
const QString ¶meterText,
|
||||
EnablingMode mode,
|
||||
QObject* parent) :
|
||||
QAction(emptyText, parent),
|
||||
m_emptyText(emptyText),
|
||||
m_parameterText(parameterText),
|
||||
m_enablingMode(mode)
|
||||
{
|
||||
}
|
||||
|
||||
QString ParameterAction::emptyText() const
|
||||
{
|
||||
return m_emptyText;
|
||||
}
|
||||
|
||||
void ParameterAction::setEmptyText(const QString &t)
|
||||
{
|
||||
m_emptyText = t;
|
||||
}
|
||||
|
||||
QString ParameterAction::parameterText() const
|
||||
{
|
||||
return m_parameterText;
|
||||
}
|
||||
|
||||
void ParameterAction::setParameterText(const QString &t)
|
||||
{
|
||||
m_parameterText = t;
|
||||
}
|
||||
|
||||
ParameterAction::EnablingMode ParameterAction::enablingMode() const
|
||||
{
|
||||
return m_enablingMode;
|
||||
}
|
||||
|
||||
void ParameterAction::setEnablingMode(EnablingMode m)
|
||||
{
|
||||
m_enablingMode = m;
|
||||
}
|
||||
|
||||
void ParameterAction::setParameter(const QString &p)
|
||||
{
|
||||
const bool enabled = !p.isEmpty();
|
||||
if (enabled) {
|
||||
setText(m_parameterText.arg(p));
|
||||
} else {
|
||||
setText(m_emptyText);
|
||||
}
|
||||
if (m_enablingMode == EnabledWithParameter)
|
||||
setEnabled(enabled);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user