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