forked from qt-creator/qt-creator
Custom wizard: Add boolean 'enabled' attribute to <wizard>.
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
@@ -331,13 +331,18 @@ QList<CustomWizard*> CustomWizard::createWizards()
|
|||||||
if (dir.exists(configFile)) {
|
if (dir.exists(configFile)) {
|
||||||
CustomWizardParametersPtr parameters(new Internal::CustomWizardParameters);
|
CustomWizardParametersPtr parameters(new Internal::CustomWizardParameters);
|
||||||
Core::BaseFileWizardParameters baseFileParameters;
|
Core::BaseFileWizardParameters baseFileParameters;
|
||||||
if (parameters->parse(dir.absoluteFilePath(configFile), &baseFileParameters, &errorMessage)) {
|
switch (parameters->parse(dir.absoluteFilePath(configFile), &baseFileParameters, &errorMessage)) {
|
||||||
|
case Internal::CustomWizardParameters::ParseOk:
|
||||||
parameters->directory = dir.absolutePath();
|
parameters->directory = dir.absolutePath();
|
||||||
if (CustomWizardPrivate::verbose)
|
if (CustomWizardPrivate::verbose)
|
||||||
verboseLog += parameters->toString();
|
verboseLog += parameters->toString();
|
||||||
if (CustomWizard *w = createWizard(parameters, baseFileParameters))
|
if (CustomWizard *w = createWizard(parameters, baseFileParameters))
|
||||||
rc.push_back(w);
|
rc.push_back(w);
|
||||||
} else {
|
case Internal::CustomWizardParameters::ParseDisabled:
|
||||||
|
if (CustomWizardPrivate::verbose)
|
||||||
|
qWarning("Ignoring disabled wizard %s...", qPrintable(dir.absolutePath()));
|
||||||
|
break;
|
||||||
|
case Internal::CustomWizardParameters::ParseFailed:
|
||||||
qWarning("Failed to initialize custom project wizard in %s: %s",
|
qWarning("Failed to initialize custom project wizard in %s: %s",
|
||||||
qPrintable(dir.absolutePath()), qPrintable(errorMessage));
|
qPrintable(dir.absolutePath()), qPrintable(errorMessage));
|
||||||
}
|
}
|
||||||
|
@@ -48,6 +48,7 @@ static const char customWizardElementC[] = "wizard";
|
|||||||
static const char iconElementC[] = "icon";
|
static const char iconElementC[] = "icon";
|
||||||
static const char descriptionElementC[] = "description";
|
static const char descriptionElementC[] = "description";
|
||||||
static const char displayNameElementC[] = "displayname";
|
static const char displayNameElementC[] = "displayname";
|
||||||
|
static const char wizardEnabledAttributeC[] = "enabled";
|
||||||
static const char idAttributeC[] = "id";
|
static const char idAttributeC[] = "id";
|
||||||
static const char kindAttributeC[] = "kind";
|
static const char kindAttributeC[] = "kind";
|
||||||
static const char klassAttributeC[] = "class";
|
static const char klassAttributeC[] = "class";
|
||||||
@@ -329,9 +330,13 @@ static inline QString msgError(const QXmlStreamReader &reader,
|
|||||||
arg(fileName).arg(reader.lineNumber()).arg(reader.columnNumber()).arg(what);
|
arg(fileName).arg(reader.lineNumber()).arg(reader.columnNumber()).arg(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool booleanAttributeValue(const QXmlStreamReader &r, const char *name)
|
static inline bool booleanAttributeValue(const QXmlStreamReader &r, const char *nameC,
|
||||||
|
bool defaultValue)
|
||||||
{
|
{
|
||||||
return r.attributes().value(QLatin1String(name)) == QLatin1String("true");
|
const QStringRef attributeValue = r.attributes().value(QLatin1String(nameC));
|
||||||
|
if (attributeValue.isEmpty())
|
||||||
|
return defaultValue;
|
||||||
|
return attributeValue == QLatin1String("true");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int integerAttributeValue(const QXmlStreamReader &r, const char *name, int defaultValue)
|
static inline int integerAttributeValue(const QXmlStreamReader &r, const char *name, int defaultValue)
|
||||||
@@ -368,7 +373,8 @@ static inline QString localeLanguage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Main parsing routine
|
// Main parsing routine
|
||||||
bool CustomWizardParameters::parse(QIODevice &device,
|
CustomWizardParameters::ParseResult
|
||||||
|
CustomWizardParameters::parse(QIODevice &device,
|
||||||
const QString &configFileFullPath,
|
const QString &configFileFullPath,
|
||||||
Core::BaseFileWizardParameters *bp,
|
Core::BaseFileWizardParameters *bp,
|
||||||
QString *errorMessage)
|
QString *errorMessage)
|
||||||
@@ -386,7 +392,7 @@ bool CustomWizardParameters::parse(QIODevice &device,
|
|||||||
switch (token) {
|
switch (token) {
|
||||||
case QXmlStreamReader::Invalid:
|
case QXmlStreamReader::Invalid:
|
||||||
*errorMessage = msgError(reader, configFileFullPath, reader.errorString());
|
*errorMessage = msgError(reader, configFileFullPath, reader.errorString());
|
||||||
return false;
|
return ParseFailed;
|
||||||
case QXmlStreamReader::StartElement:
|
case QXmlStreamReader::StartElement:
|
||||||
do {
|
do {
|
||||||
// Read out subelements applicable to current state
|
// Read out subelements applicable to current state
|
||||||
@@ -401,8 +407,10 @@ bool CustomWizardParameters::parse(QIODevice &device,
|
|||||||
case ParseError:
|
case ParseError:
|
||||||
*errorMessage = msgError(reader, configFileFullPath,
|
*errorMessage = msgError(reader, configFileFullPath,
|
||||||
QString::fromLatin1("Unexpected start element %1").arg(reader.name().toString()));
|
QString::fromLatin1("Unexpected start element %1").arg(reader.name().toString()));
|
||||||
return false;
|
return ParseFailed;
|
||||||
case ParseWithinWizard:
|
case ParseWithinWizard:
|
||||||
|
if (!booleanAttributeValue(reader, wizardEnabledAttributeC, true))
|
||||||
|
return ParseDisabled;
|
||||||
bp->setId(attributeValue(reader, idAttributeC));
|
bp->setId(attributeValue(reader, idAttributeC));
|
||||||
bp->setCategory(attributeValue(reader, categoryAttributeC));
|
bp->setCategory(attributeValue(reader, categoryAttributeC));
|
||||||
bp->setKind(kindAttribute(reader));
|
bp->setKind(kindAttribute(reader));
|
||||||
@@ -411,14 +419,14 @@ bool CustomWizardParameters::parse(QIODevice &device,
|
|||||||
break;
|
break;
|
||||||
case ParseWithinField: // field attribute
|
case ParseWithinField: // field attribute
|
||||||
field.name = attributeValue(reader, fieldNameAttributeC);
|
field.name = attributeValue(reader, fieldNameAttributeC);
|
||||||
field.mandatory = booleanAttributeValue(reader, fieldMandatoryAttributeC);
|
field.mandatory = booleanAttributeValue(reader, fieldMandatoryAttributeC, false);
|
||||||
break;
|
break;
|
||||||
case ParseWithinFile: { // file attribute
|
case ParseWithinFile: { // file attribute
|
||||||
CustomWizardFile file;
|
CustomWizardFile file;
|
||||||
file.source = attributeValue(reader, fileNameSourceAttributeC);
|
file.source = attributeValue(reader, fileNameSourceAttributeC);
|
||||||
file.target = attributeValue(reader, fileNameTargetAttributeC);
|
file.target = attributeValue(reader, fileNameTargetAttributeC);
|
||||||
file.openEditor = booleanAttributeValue(reader, fileNameOpenEditorAttributeC);
|
file.openEditor = booleanAttributeValue(reader, fileNameOpenEditorAttributeC, false);
|
||||||
file.openProject = booleanAttributeValue(reader, fileNameOpenProjectAttributeC);
|
file.openProject = booleanAttributeValue(reader, fileNameOpenProjectAttributeC, false);
|
||||||
if (file.target.isEmpty())
|
if (file.target.isEmpty())
|
||||||
file.target = file.source;
|
file.target = file.source;
|
||||||
if (file.source.isEmpty()) {
|
if (file.source.isEmpty()) {
|
||||||
@@ -438,7 +446,7 @@ bool CustomWizardParameters::parse(QIODevice &device,
|
|||||||
if (state == ParseError) {
|
if (state == ParseError) {
|
||||||
*errorMessage = msgError(reader, configFileFullPath,
|
*errorMessage = msgError(reader, configFileFullPath,
|
||||||
QString::fromLatin1("Unexpected end element %1").arg(reader.name().toString()));
|
QString::fromLatin1("Unexpected end element %1").arg(reader.name().toString()));
|
||||||
return false;
|
return ParseFailed;
|
||||||
}
|
}
|
||||||
if (state == ParseWithinFields) { // Leaving a field element
|
if (state == ParseWithinFields) { // Leaving a field element
|
||||||
fields.push_back(field);
|
fields.push_back(field);
|
||||||
@@ -449,17 +457,18 @@ bool CustomWizardParameters::parse(QIODevice &device,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (token != QXmlStreamReader::EndDocument);
|
} while (token != QXmlStreamReader::EndDocument);
|
||||||
return true;
|
return ParseOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomWizardParameters::parse(const QString &configFileFullPath,
|
CustomWizardParameters::ParseResult
|
||||||
|
CustomWizardParameters::parse(const QString &configFileFullPath,
|
||||||
Core::BaseFileWizardParameters *bp,
|
Core::BaseFileWizardParameters *bp,
|
||||||
QString *errorMessage)
|
QString *errorMessage)
|
||||||
{
|
{
|
||||||
QFile configFile(configFileFullPath);
|
QFile configFile(configFileFullPath);
|
||||||
if (!configFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
if (!configFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
||||||
*errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(configFileFullPath, configFile.errorString());
|
*errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(configFileFullPath, configFile.errorString());
|
||||||
return false;
|
return ParseFailed;
|
||||||
}
|
}
|
||||||
return parse(configFile, configFileFullPath, bp, errorMessage);
|
return parse(configFile, configFileFullPath, bp, errorMessage);
|
||||||
}
|
}
|
||||||
|
@@ -67,11 +67,13 @@ struct CustomWizardFile {
|
|||||||
struct CustomWizardParameters
|
struct CustomWizardParameters
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum ParseResult { ParseOk, ParseDisabled, ParseFailed };
|
||||||
|
|
||||||
CustomWizardParameters();
|
CustomWizardParameters();
|
||||||
void clear();
|
void clear();
|
||||||
bool parse(QIODevice &device, const QString &configFileFullPath,
|
ParseResult parse(QIODevice &device, const QString &configFileFullPath,
|
||||||
Core::BaseFileWizardParameters *bp, QString *errorMessage);
|
Core::BaseFileWizardParameters *bp, QString *errorMessage);
|
||||||
bool parse(const QString &configFileFullPath,
|
ParseResult parse(const QString &configFileFullPath,
|
||||||
Core::BaseFileWizardParameters *bp, QString *errorMessage);
|
Core::BaseFileWizardParameters *bp, QString *errorMessage);
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user