forked from qt-creator/qt-creator
Custom wizards: Add option -customwizard-verbose.
This commit is contained in:
@@ -3,3 +3,6 @@ Qt Creator custom wizard are located in this directory.
|
|||||||
The subdirectories 'helloworld' and 'listmodel' are provided as examples.
|
The subdirectories 'helloworld' and 'listmodel' are provided as examples.
|
||||||
To see how they work in Qt Creator, rename the 'wizard_sample.xml' files
|
To see how they work in Qt Creator, rename the 'wizard_sample.xml' files
|
||||||
to 'wizard.xml'.
|
to 'wizard.xml'.
|
||||||
|
|
||||||
|
The command line option -customwizard-verbose can be used to obtain
|
||||||
|
verbose information while loading the custom wizards.
|
||||||
|
|||||||
@@ -19,4 +19,7 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General
|
|||||||
<dependency name="Locator" version="1.3.82"/>
|
<dependency name="Locator" version="1.3.82"/>
|
||||||
<dependency name="TextEditor" version="1.3.82"/>
|
<dependency name="TextEditor" version="1.3.82"/>
|
||||||
</dependencyList>
|
</dependencyList>
|
||||||
|
<argumentList>
|
||||||
|
<argument name="-customwizard-verbose">Verbose loading of custom wizards</argument>
|
||||||
|
</argumentList>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -44,8 +44,6 @@
|
|||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
|
|
||||||
enum { debug = 0 };
|
|
||||||
|
|
||||||
static const char templatePathC[] = "templates/wizards";
|
static const char templatePathC[] = "templates/wizards";
|
||||||
static const char configFileC[] = "wizard.xml";
|
static const char configFileC[] = "wizard.xml";
|
||||||
|
|
||||||
@@ -53,8 +51,11 @@ namespace ProjectExplorer {
|
|||||||
|
|
||||||
struct CustomWizardPrivate {
|
struct CustomWizardPrivate {
|
||||||
QSharedPointer<Internal::CustomWizardParameters> m_parameters;
|
QSharedPointer<Internal::CustomWizardParameters> m_parameters;
|
||||||
|
static int verbose;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int CustomWizardPrivate::verbose = 0;
|
||||||
|
|
||||||
CustomWizard::CustomWizard(const Core::BaseFileWizardParameters& baseFileParameters,
|
CustomWizard::CustomWizard(const Core::BaseFileWizardParameters& baseFileParameters,
|
||||||
QObject *parent) :
|
QObject *parent) :
|
||||||
Core::BaseFileWizard(baseFileParameters, parent),
|
Core::BaseFileWizard(baseFileParameters, parent),
|
||||||
@@ -67,6 +68,16 @@ CustomWizard::~CustomWizard()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CustomWizard::setVerbose(int v)
|
||||||
|
{
|
||||||
|
CustomWizardPrivate::verbose = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CustomWizard::verbose()
|
||||||
|
{
|
||||||
|
return CustomWizardPrivate::verbose;
|
||||||
|
}
|
||||||
|
|
||||||
void CustomWizard::setParameters(const CustomWizardParametersPtr &p)
|
void CustomWizard::setParameters(const CustomWizardParametersPtr &p)
|
||||||
{
|
{
|
||||||
d->m_parameters = p;
|
d->m_parameters = p;
|
||||||
@@ -100,7 +111,7 @@ void CustomWizard::initWizardDialog(QWizard *wizard, const QString &defaultPath,
|
|||||||
foreach(QWizardPage *ep, extensionPages)
|
foreach(QWizardPage *ep, extensionPages)
|
||||||
wizard->addPage(ep);
|
wizard->addPage(ep);
|
||||||
Core::BaseFileWizard::setupWizard(wizard);
|
Core::BaseFileWizard::setupWizard(wizard);
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qDebug() << "initWizardDialog" << wizard << wizard->pageIds();
|
qDebug() << "initWizardDialog" << wizard << wizard->pageIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +188,7 @@ static inline bool createFile(Internal::CustomWizardFile cwFile,
|
|||||||
const QString sourcePath = sourceDirectory + slash + cwFile.source;
|
const QString sourcePath = sourceDirectory + slash + cwFile.source;
|
||||||
replaceFields(fm, &cwFile.target);
|
replaceFields(fm, &cwFile.target);
|
||||||
const QString targetPath = QDir::toNativeSeparators(targetDirectory + slash + cwFile.target);
|
const QString targetPath = QDir::toNativeSeparators(targetDirectory + slash + cwFile.target);
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qDebug() << "generating " << targetPath << sourcePath << fm;
|
qDebug() << "generating " << targetPath << sourcePath << fm;
|
||||||
QFile file(sourcePath);
|
QFile file(sourcePath);
|
||||||
if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
||||||
@@ -211,7 +222,7 @@ Core::GeneratedFiles CustomWizard::generateFiles(const QWizard *dialog, QString
|
|||||||
QTC_ASSERT(cwp, return Core::GeneratedFiles())
|
QTC_ASSERT(cwp, return Core::GeneratedFiles())
|
||||||
QString path = cwp->path();
|
QString path = cwp->path();
|
||||||
const FieldReplacementMap fieldMap = defaultReplacementMap(dialog);
|
const FieldReplacementMap fieldMap = defaultReplacementMap(dialog);
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qDebug() << "CustomWizard::generateFiles" << dialog << path << fieldMap;
|
qDebug() << "CustomWizard::generateFiles" << dialog << path << fieldMap;
|
||||||
return generateWizardFiles(path, fieldMap, errorMessage);
|
return generateWizardFiles(path, fieldMap, errorMessage);
|
||||||
}
|
}
|
||||||
@@ -220,7 +231,7 @@ Core::GeneratedFiles CustomWizard::generateWizardFiles(const QString &targetPath
|
|||||||
const FieldReplacementMap &fieldReplacementMap,
|
const FieldReplacementMap &fieldReplacementMap,
|
||||||
QString *errorMessage) const
|
QString *errorMessage) const
|
||||||
{
|
{
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qDebug() << "Replacements" << fieldReplacementMap;
|
qDebug() << "Replacements" << fieldReplacementMap;
|
||||||
// Create files
|
// Create files
|
||||||
Core::GeneratedFiles rc;
|
Core::GeneratedFiles rc;
|
||||||
@@ -299,7 +310,7 @@ QList<CustomWizard*> CustomWizard::createWizards()
|
|||||||
QLatin1Char('/') + QLatin1String(templatePathC);
|
QLatin1Char('/') + QLatin1String(templatePathC);
|
||||||
const QDir templateDir(templateDirName);
|
const QDir templateDir(templateDirName);
|
||||||
if (!templateDir.exists()) {
|
if (!templateDir.exists()) {
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qWarning("Custom project template path %s does not exist.", qPrintable(templateDir.absolutePath()));
|
qWarning("Custom project template path %s does not exist.", qPrintable(templateDir.absolutePath()));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -311,19 +322,24 @@ QList<CustomWizard*> CustomWizard::createWizards()
|
|||||||
|
|
||||||
foreach(const QFileInfo &dirFi, dirs) {
|
foreach(const QFileInfo &dirFi, dirs) {
|
||||||
const QDir dir(dirFi.absoluteFilePath());
|
const QDir dir(dirFi.absoluteFilePath());
|
||||||
|
if (CustomWizardPrivate::verbose)
|
||||||
|
qDebug("CustomWizard: Scanning %s", qPrintable(dirFi.absoluteFilePath()));
|
||||||
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)) {
|
if (parameters->parse(dir.absoluteFilePath(configFile), &baseFileParameters, &errorMessage)) {
|
||||||
parameters->directory = dir.absolutePath();
|
parameters->directory = dir.absolutePath();
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qDebug() << (*parameters);
|
qDebug("%s\n", qPrintable(parameters->toString()));
|
||||||
if (CustomWizard *w = createWizard(parameters, baseFileParameters))
|
if (CustomWizard *w = createWizard(parameters, baseFileParameters))
|
||||||
rc.push_back(w);
|
rc.push_back(w);
|
||||||
} else {
|
} else {
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (CustomWizardPrivate::verbose)
|
||||||
|
qDebug("CustomWizard: '%s' not found\n", qPrintable(configFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
@@ -362,7 +378,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w,
|
|||||||
w->addPage(ep);
|
w->addPage(ep);
|
||||||
w->setPath(defaultPath);
|
w->setPath(defaultPath);
|
||||||
w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath));
|
w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath));
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qDebug() << "initProjectWizardDialog" << w << w->pageIds();
|
qDebug() << "initProjectWizardDialog" << w << w->pageIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +390,7 @@ Core::GeneratedFiles CustomProjectWizard::generateFiles(const QWizard *w, QStrin
|
|||||||
// Add project name as macro.
|
// Add project name as macro.
|
||||||
FieldReplacementMap fieldReplacementMap = defaultReplacementMap(dialog);
|
FieldReplacementMap fieldReplacementMap = defaultReplacementMap(dialog);
|
||||||
fieldReplacementMap.insert(QLatin1String("ProjectName"), dialog->projectName());
|
fieldReplacementMap.insert(QLatin1String("ProjectName"), dialog->projectName());
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qDebug() << "CustomProjectWizard::generateFiles" << dialog << targetPath << fieldReplacementMap;
|
qDebug() << "CustomProjectWizard::generateFiles" << dialog << targetPath << fieldReplacementMap;
|
||||||
return generateWizardFiles(targetPath, fieldReplacementMap, errorMessage);
|
return generateWizardFiles(targetPath, fieldReplacementMap, errorMessage);
|
||||||
}
|
}
|
||||||
@@ -384,7 +400,7 @@ bool CustomProjectWizard::postGenerateFiles(const QWizard *, const Core::Generat
|
|||||||
// Post-Generate: Open the project
|
// Post-Generate: Open the project
|
||||||
const QString proFileName = l.back().path();
|
const QString proFileName = l.back().path();
|
||||||
const bool opened = ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName);
|
const bool opened = ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName);
|
||||||
if (debug)
|
if (CustomWizardPrivate::verbose)
|
||||||
qDebug() << "CustomProjectWizard::postGenerateFiles: opened " << proFileName << opened;
|
qDebug() << "CustomProjectWizard::postGenerateFiles: opened " << proFileName << opened;
|
||||||
if (opened) {
|
if (opened) {
|
||||||
*errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
|
*errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ public:
|
|||||||
// classes, call it in extensionsInitialized().
|
// classes, call it in extensionsInitialized().
|
||||||
static QList<CustomWizard*> createWizards();
|
static QList<CustomWizard*> createWizards();
|
||||||
|
|
||||||
|
static void setVerbose(int);
|
||||||
|
static int verbose();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef QSharedPointer<Internal::CustomWizardParameters> CustomWizardParametersPtr;
|
typedef QSharedPointer<Internal::CustomWizardParameters> CustomWizardParametersPtr;
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ CustomWizardFieldPage::CustomWizardFieldPage(const FieldList &fields,
|
|||||||
m_formLayout(new QFormLayout)
|
m_formLayout(new QFormLayout)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << Q_FUNC_INFO << fields;
|
qDebug() << Q_FUNC_INFO << fields.size();
|
||||||
foreach(const CustomWizardField &f, fields)
|
foreach(const CustomWizardField &f, fields)
|
||||||
addField(f);
|
addField(f);
|
||||||
setLayout(m_formLayout);
|
setLayout(m_formLayout);
|
||||||
|
|||||||
@@ -442,30 +442,29 @@ bool CustomWizardParameters::parse(const QString &configFileFullPath,
|
|||||||
return parse(configFile, configFileFullPath, bp, errorMessage);
|
return parse(configFile, configFileFullPath, bp, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDebug operator<<(QDebug d, const CustomWizardField &m)
|
QString CustomWizardParameters::toString() const
|
||||||
{
|
{
|
||||||
QDebug nsp = d.nospace();
|
QString rc;
|
||||||
nsp << "Name: " << m.name;
|
QTextStream str(&rc);
|
||||||
if (m.mandatory)
|
str << "Directory: " << directory << " Klass: '" << klass << "'\n";
|
||||||
nsp << '*';
|
foreach(const CustomWizardFile &f, files) {
|
||||||
nsp << " Desc: " << m.description << " Control: " << m.controlAttributes;
|
str << " File source: " << f.source << " Target: " << f.target << '\n';
|
||||||
return d;
|
}
|
||||||
}
|
foreach(const CustomWizardField &f, fields) {
|
||||||
|
str << " Field name: " << f.name;
|
||||||
QDebug operator<<(QDebug d, const CustomWizardFile &f)
|
if (f.mandatory)
|
||||||
{
|
str << '*';
|
||||||
d.nospace() << "source: " << f.source << " target: " << f.target;
|
str << " Description: '" << f.description << '\'';
|
||||||
return d;
|
if (!f.controlAttributes.isEmpty()) {
|
||||||
}
|
typedef CustomWizardField::ControlAttributeMap::const_iterator AttrMapConstIt;
|
||||||
|
str << " Control: ";
|
||||||
QDebug operator<<(QDebug d, const CustomWizardParameters &p)
|
const AttrMapConstIt cend = f.controlAttributes.constEnd();
|
||||||
{
|
for (AttrMapConstIt it = f.controlAttributes.constBegin(); it != cend; ++it)
|
||||||
QDebug nsp = d.nospace();
|
str << '\'' << it.key() << "' -> '" << it.value() << "' ";
|
||||||
nsp << "Dir: " << p.directory << " klass:" << p.klass << " Files: " << p.files;
|
}
|
||||||
if (!p.fields.isEmpty())
|
str << '\n';
|
||||||
nsp << " Fields: " << p.fields;
|
}
|
||||||
nsp << "First page: " << p.firstPageId;
|
return rc;
|
||||||
return d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public:
|
|||||||
Core::BaseFileWizardParameters *bp, QString *errorMessage);
|
Core::BaseFileWizardParameters *bp, QString *errorMessage);
|
||||||
bool parse(const QString &configFileFullPath,
|
bool parse(const QString &configFileFullPath,
|
||||||
Core::BaseFileWizardParameters *bp, QString *errorMessage);
|
Core::BaseFileWizardParameters *bp, QString *errorMessage);
|
||||||
|
QString toString() const;
|
||||||
|
|
||||||
QString directory;
|
QString directory;
|
||||||
QString klass;
|
QString klass;
|
||||||
@@ -78,10 +79,6 @@ public:
|
|||||||
int firstPageId;
|
int firstPageId;
|
||||||
};
|
};
|
||||||
|
|
||||||
QDebug operator<<(QDebug d, const CustomWizardField &);
|
|
||||||
QDebug operator<<(QDebug d, const CustomWizardFile &);
|
|
||||||
QDebug operator<<(QDebug d, const CustomWizardParameters &);
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
|
|||||||
@@ -226,10 +226,16 @@ ProjectExplorerPlugin *ProjectExplorerPlugin::instance()
|
|||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProjectExplorerPlugin::parseArguments(const QStringList &arguments, QString * /* error */)
|
||||||
|
{
|
||||||
|
CustomWizard::setVerbose(arguments.count(QLatin1String("-customwizard-verbose")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
|
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
|
||||||
{
|
{
|
||||||
Q_UNUSED(arguments)
|
if (!parseArguments(arguments, error))
|
||||||
Q_UNUSED(error)
|
return false;
|
||||||
|
|
||||||
Core::ICore *core = Core::ICore::instance();
|
Core::ICore *core = Core::ICore::instance();
|
||||||
Core::ActionManager *am = core->actionManager();
|
Core::ActionManager *am = core->actionManager();
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ private slots:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool parseArguments(const QStringList &arguments, QString *error);
|
||||||
void runProjectImpl(Project *pro, QString mode);
|
void runProjectImpl(Project *pro, QString mode);
|
||||||
void executeRunConfiguration(RunConfiguration *, const QString &mode);
|
void executeRunConfiguration(RunConfiguration *, const QString &mode);
|
||||||
bool showBuildConfigDialog();
|
bool showBuildConfigDialog();
|
||||||
|
|||||||
Reference in New Issue
Block a user