Wizards: Open a relevant file in editor after the wizard run

Remove all hacks/conventions of considering the last generated
file as project file, etc. and instead add attributes flags to
Core::GeneratedFile, giving fine-grained control of what to do
with the file. Implement static utility functions in wizards
that handle it. Add boolean XML-attributes "openeditor"/"openproject"
to the file elements used by the CustomWizard XML-specification.
Manually set the attributes in all wizards.

Task-number: QTCREATORBUG-1166
This commit is contained in:
Friedemann Kleint
2010-04-16 15:55:32 +02:00
parent 854309267d
commit 0a643a1994
26 changed files with 144 additions and 70 deletions

View File

@@ -42,8 +42,8 @@ leave room for the Qt 4 target page.
<displayname>Hello World</displayname>; <displayname>Hello World</displayname>;
<displaycategory>Custom Projects</displaycategory> <displaycategory>Custom Projects</displaycategory>
<files> <files>
<file source="main.cpp"/> <file source="main.cpp" openeditor="true"/>
<file source="project.pro" target="%ProjectName%.pro"/> <file source="project.pro" target="%ProjectName%.pro" openproject="true"/>
</files> </files>
<!-- Create a 2nd wizard page with parameters --> <!-- Create a 2nd wizard page with parameters -->
<fieldpagetitle>Hello World Parameters</fieldpagetitle> <fieldpagetitle>Hello World Parameters</fieldpagetitle>

View File

@@ -38,8 +38,8 @@ Custom class wizard example configuration file. -->
<displaycategory>Custom Classes</displaycategory> <displaycategory>Custom Classes</displaycategory>
<displaycategory xml:lang="de">Benutzerdefinierte Klassen</displaycategory> <displaycategory xml:lang="de">Benutzerdefinierte Klassen</displaycategory>
<files> <files>
<file source="listmodel.cpp" target="%ClassName:l%.%CppSourceSuffix%"/> <file source="listmodel.cpp" target="%ClassName:l%.%CppSourceSuffix%" openeditor="true"/>
<file source="listmodel.h" target="%ClassName:l%.%CppHeaderSuffix%"/> <file source="listmodel.h" target="%ClassName:l%.%CppHeaderSuffix%" openeditor="true"/>
</files> </files>
<!-- Create parameter wizard page --> <!-- Create parameter wizard page -->
<fieldpagetitle>ListModel parameters</fieldpagetitle> <fieldpagetitle>ListModel parameters</fieldpagetitle>

View File

@@ -45,8 +45,8 @@ leave room for the Qt 4 target page.
<file source="plugin.h" target="%ProjectName%.h"/> <file source="plugin.h" target="%ProjectName%.h"/>
<file source="plugin.cpp" target="%ProjectName%.cpp"/> <file source="plugin.cpp" target="%ProjectName%.cpp"/>
<file source="object.h" target="%ObjectName%.h"/> <file source="object.h" target="%ObjectName%.h"/>
<file source="object.cpp" target="%ObjectName%.cpp"/> <file source="object.cpp" target="%ObjectName%.cpp" openeditor="true"/>
<file source="project.pro" target="%ProjectName%.pro"/> <file source="project.pro" target="%ProjectName%.pro" openproject="true"/>
</files> </files>
<!-- Create a 2nd wizard page with parameters --> <!-- Create a 2nd wizard page with parameters -->
<fieldpagetitle>QML Runtime Plug-in Parameters</fieldpagetitle> <fieldpagetitle>QML Runtime Plug-in Parameters</fieldpagetitle>

View File

@@ -66,11 +66,13 @@ public:
QByteArray contents; QByteArray contents;
QString editorId; QString editorId;
bool binary; bool binary;
GeneratedFile::Attributes attributes;
}; };
GeneratedFilePrivate::GeneratedFilePrivate(const QString &p) : GeneratedFilePrivate::GeneratedFilePrivate(const QString &p) :
path(p), path(p),
binary(false) binary(false),
attributes(0)
{ {
} }
@@ -180,6 +182,15 @@ bool GeneratedFile::write(QString *errorMessage) const
return true; return true;
} }
GeneratedFile::Attributes GeneratedFile::attributes() const
{
return m_d->attributes;
}
void GeneratedFile::setAttributes(Attributes a)
{
m_d->attributes = a;
}
// ------------ BaseFileWizardParameterData // ------------ BaseFileWizardParameterData
class BaseFileWizardParameterData : public QSharedData class BaseFileWizardParameterData : public QSharedData
@@ -584,18 +595,23 @@ void BaseFileWizard::applyExtensionPageShortTitle(Utils::Wizard *wizard, int pag
item->setTitle(shortTitle); item->setTitle(shortTitle);
} }
bool BaseFileWizard::postGenerateFiles(const QWizard *w, const GeneratedFiles &l, QString *errorMessage) bool BaseFileWizard::postGenerateFiles(const QWizard *, const GeneratedFiles &l, QString *errorMessage)
{
return BaseFileWizard::postGenerateOpenEditors(l, errorMessage);
}
bool BaseFileWizard::postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage)
{ {
Q_UNUSED(w);
// File mode: open the editors in file mode and ensure editor pane
const Core::GeneratedFiles::const_iterator cend = l.constEnd();
Core::EditorManager *em = Core::EditorManager::instance(); Core::EditorManager *em = Core::EditorManager::instance();
for (Core::GeneratedFiles::const_iterator it = l.constBegin(); it != cend; ++it) { foreach(const Core::GeneratedFile &file, l) {
if (!em->openEditor(it->path(), it->editorId())) { if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) {
*errorMessage = tr("Failed to open an editor for '%1'.").arg(it->path()); if (!em->openEditor(file.path(), file.editorId())) {
if (errorMessage)
*errorMessage = tr("Failed to open an editor for '%1'.").arg(file.path());
return false; return false;
} }
} }
}
return true; return true;
} }

View File

@@ -65,6 +65,9 @@ class GeneratedFilePrivate;
class CORE_EXPORT GeneratedFile class CORE_EXPORT GeneratedFile
{ {
public: public:
enum Attribute { OpenEditorAttribute = 0x01, OpenProjectAttribute = 0x02 };
Q_DECLARE_FLAGS(Attributes, Attribute)
GeneratedFile(); GeneratedFile();
explicit GeneratedFile(const QString &path); explicit GeneratedFile(const QString &path);
GeneratedFile(const GeneratedFile &); GeneratedFile(const GeneratedFile &);
@@ -92,6 +95,9 @@ public:
bool write(QString *errorMessage) const; bool write(QString *errorMessage) const;
Attributes attributes() const;
void setAttributes(Attributes a);
private: private:
QSharedDataPointer<GeneratedFilePrivate> m_d; QSharedDataPointer<GeneratedFilePrivate> m_d;
}; };
@@ -207,6 +213,10 @@ protected:
OverwriteResult promptOverwrite(const QString &location, OverwriteResult promptOverwrite(const QString &location,
const QStringList &files, const QStringList &files,
QString *errorMessage) const; QString *errorMessage) const;
// Utility to open the editors for the files whose attribute is set accordingly.
static bool postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage = 0);
private: private:
BaseFileWizardPrivate *m_d; BaseFileWizardPrivate *m_d;
}; };
@@ -239,4 +249,6 @@ protected:
} // namespace Core } // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::GeneratedFile::Attributes)
#endif // BASEFILEWIZARD_H #endif // BASEFILEWIZARD_H

View File

@@ -209,7 +209,10 @@ Core::GeneratedFiles CppClassWizard::generateFiles(const QWizard *w, QString *er
return Core::GeneratedFiles(); return Core::GeneratedFiles();
} }
headerFile.setContents(header); headerFile.setContents(header);
headerFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
sourceFile.setContents(source); sourceFile.setContents(source);
sourceFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << headerFile << sourceFile; return Core::GeneratedFiles() << headerFile << sourceFile;
} }

View File

@@ -62,7 +62,7 @@ Core::GeneratedFiles CppFileWizard::generateFilesFromPath(const QString &path,
Core::GeneratedFile file(fileName); Core::GeneratedFile file(fileName);
file.setEditorId(QLatin1String(Constants::CPPEDITOR_ID)); file.setEditorId(QLatin1String(Constants::CPPEDITOR_ID));
file.setContents(fileContents(m_type, fileName)); file.setContents(fileContents(m_type, fileName));
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << file; return Core::GeneratedFiles() << file;
} }

View File

@@ -88,15 +88,18 @@ Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *e
Core::GeneratedFile headerFile(headerFileName); Core::GeneratedFile headerFile(headerFileName);
headerFile.setEditorId(QLatin1String(CppEditor::Constants::CPPEDITOR_ID)); headerFile.setEditorId(QLatin1String(CppEditor::Constants::CPPEDITOR_ID));
headerFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
// Source // Source
Core::GeneratedFile sourceFile(sourceFileName); Core::GeneratedFile sourceFile(sourceFileName);
sourceFile.setEditorId(QLatin1String(CppEditor::Constants::CPPEDITOR_ID)); sourceFile.setEditorId(QLatin1String(CppEditor::Constants::CPPEDITOR_ID));
sourceFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
// UI // UI
Core::GeneratedFile uiFile(formFileName); Core::GeneratedFile uiFile(formFileName);
uiFile.setContents(params.uiTemplate()); uiFile.setContents(params.uiTemplate());
uiFile.setEditorId(QLatin1String(Constants::DESIGNER_XML_EDITOR_ID)); uiFile.setEditorId(QLatin1String(Constants::DESIGNER_XML_EDITOR_ID));
uiFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
QString source, header; QString source, header;
Designer::FormClassWizardGenerationParameters generationParameters; Designer::FormClassWizardGenerationParameters generationParameters;

View File

@@ -67,5 +67,6 @@ Core::GeneratedFiles FormWizard::generateFiles(const QWizard *w,
Core::GeneratedFile file(fileName); Core::GeneratedFile file(fileName);
file.setContents(formTemplate); file.setContents(formTemplate);
file.setEditorId(QLatin1String(Constants::DESIGNER_XML_EDITOR_ID)); file.setEditorId(QLatin1String(Constants::DESIGNER_XML_EDITOR_ID));
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << file; return Core::GeneratedFiles() << file;
} }

View File

@@ -31,8 +31,8 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/customwizard/customwizard.h>
#include <utils/filewizardpage.h> #include <utils/filewizardpage.h>
@@ -198,6 +198,7 @@ Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w,
Core::GeneratedFile generatedCreatorFile(creatorFileName); Core::GeneratedFile generatedCreatorFile(creatorFileName);
generatedCreatorFile.setContents(QLatin1String("[General]\n")); generatedCreatorFile.setContents(QLatin1String("[General]\n"));
generatedCreatorFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
Core::GeneratedFile generatedFilesFile(filesFileName); Core::GeneratedFile generatedFilesFile(filesFileName);
generatedFilesFile.setContents(sources.join(QLatin1String("\n"))); generatedFilesFile.setContents(sources.join(QLatin1String("\n")));
@@ -220,12 +221,5 @@ Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w,
bool GenericProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage) bool GenericProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
{ {
Q_UNUSED(w); Q_UNUSED(w);
// Post-Generate: Open the project return ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
const QString proFileName = l.back().path();
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName)) {
*errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
return false;
} }
return true;
}

View File

@@ -161,6 +161,12 @@ static inline bool createFile(Internal::CustomWizardFile cwFile,
Core::GeneratedFile generatedFile; Core::GeneratedFile generatedFile;
generatedFile.setContents(contents); generatedFile.setContents(contents);
generatedFile.setPath(targetPath); generatedFile.setPath(targetPath);
Core::GeneratedFile::Attributes attributes = 0;
if (cwFile.openEditor)
attributes |= Core::GeneratedFile::OpenEditorAttribute;
if (cwFile.openProject)
attributes |= Core::GeneratedFile::OpenProjectAttribute;
generatedFile.setAttributes(attributes);
files->push_back(generatedFile); files->push_back(generatedFile);
return true; return true;
} }
@@ -410,18 +416,26 @@ Core::GeneratedFiles CustomProjectWizard::generateFiles(const QWizard *w, QStrin
return generateWizardFiles(targetPath, fieldReplacementMap, errorMessage); return generateWizardFiles(targetPath, fieldReplacementMap, errorMessage);
} }
bool CustomProjectWizard::postGenerateFiles(const QWizard *, const Core::GeneratedFiles &l, QString *errorMessage) bool CustomProjectWizard::postGenerateOpen(const Core::GeneratedFiles &l, QString *errorMessage)
{ {
// Post-Generate: Open the project // Post-Generate: Open the project and the editors as desired
const QString proFileName = l.back().path(); foreach(const Core::GeneratedFile &file, l) {
const bool opened = ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName); if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
if (CustomWizardPrivate::verbose) if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(file.path())) {
qDebug() << "CustomProjectWizard::postGenerateFiles: opened " << proFileName << opened; if (errorMessage)
if (opened) { *errorMessage = tr("The project %1 could not be opened.").arg(file.path());
*errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
return false; return false;
} }
return true; }
}
return BaseFileWizard::postGenerateOpenEditors(l, errorMessage);
}
bool CustomProjectWizard::postGenerateFiles(const QWizard *, const Core::GeneratedFiles &l, QString *errorMessage)
{
if (CustomWizardPrivate::verbose)
qDebug() << "CustomProjectWizard::postGenerateFiles()";
return CustomProjectWizard::postGenerateOpen(l, errorMessage);
} }
void CustomProjectWizard::introPageLeft(const QString &project, const QString & /* path */) void CustomProjectWizard::introPageLeft(const QString &project, const QString & /* path */)

View File

@@ -154,6 +154,10 @@ public:
virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
// Utility to open the projects and editors for the files that have
// the respective attributes set.
static bool postGenerateOpen(const Core::GeneratedFiles &l, QString *errorMessage = 0);
protected: protected:
virtual bool postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage); virtual bool postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage);

View File

@@ -68,6 +68,9 @@ static const char filesElementC[] = "files";
static const char fileElementC[] = "file"; static const char fileElementC[] = "file";
static const char fileNameSourceAttributeC[] = "source"; static const char fileNameSourceAttributeC[] = "source";
static const char fileNameTargetAttributeC[] = "target"; static const char fileNameTargetAttributeC[] = "target";
static const char fileNameOpenEditorAttributeC[] = "openeditor";
static const char fileNameOpenProjectAttributeC[] = "openproject";
enum ParseState { enum ParseState {
ParseBeginning, ParseBeginning,
@@ -95,6 +98,11 @@ void CustomWizardField::clear()
controlAttributes.clear(); controlAttributes.clear();
} }
CustomWizardFile::CustomWizardFile() :
openEditor(false), openProject(false)
{
}
CustomWizardParameters::CustomWizardParameters() : CustomWizardParameters::CustomWizardParameters() :
firstPageId(-1) firstPageId(-1)
{ {
@@ -409,6 +417,8 @@ bool CustomWizardParameters::parse(QIODevice &device,
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.openProject = booleanAttributeValue(reader, fileNameOpenProjectAttributeC);
if (file.target.isEmpty()) if (file.target.isEmpty())
file.target = file.source; file.target = file.source;
if (file.source.isEmpty()) { if (file.source.isEmpty()) {
@@ -460,7 +470,12 @@ QString CustomWizardParameters::toString() const
QTextStream str(&rc); QTextStream str(&rc);
str << "Directory: " << directory << " Klass: '" << klass << "'\n"; str << "Directory: " << directory << " Klass: '" << klass << "'\n";
foreach(const CustomWizardFile &f, files) { foreach(const CustomWizardFile &f, files) {
str << " File source: " << f.source << " Target: " << f.target << '\n'; str << " File source: " << f.source << " Target: " << f.target;
if (f.openEditor)
str << " [editor]";
if (f.openProject)
str << " [project]";
str << '\n';
} }
foreach(const CustomWizardField &f, fields) { foreach(const CustomWizardField &f, fields) {
str << " Field name: " << f.name; str << " Field name: " << f.name;

View File

@@ -56,8 +56,12 @@ struct CustomWizardField {
}; };
struct CustomWizardFile { struct CustomWizardFile {
CustomWizardFile();
QString source; QString source;
QString target; QString target;
bool openEditor;
bool openProject;
}; };
struct CustomWizardParameters struct CustomWizardParameters

View File

@@ -52,7 +52,7 @@ Core::GeneratedFiles QmlFileWizard::generateFilesFromPath(const QString &path,
Core::GeneratedFile file(fileName); Core::GeneratedFile file(fileName);
file.setEditorId(QLatin1String(Constants::C_QMLJSEDITOR_ID)); file.setEditorId(QLatin1String(Constants::C_QMLJSEDITOR_ID));
file.setContents(fileContents(fileName)); file.setContents(fileContents(fileName));
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << file; return Core::GeneratedFiles() << file;
} }

View File

@@ -31,8 +31,7 @@
#include "qmlprojectconstants.h" #include "qmlprojectconstants.h"
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/customwizard/customwizard.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <QtGui/QIcon> #include <QtGui/QIcon>
@@ -120,6 +119,7 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w
} }
Core::GeneratedFile generatedMainFile(mainFileName); Core::GeneratedFile generatedMainFile(mainFileName);
generatedMainFile.setContents(contents); generatedMainFile.setContents(contents);
generatedMainFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
QString projectContents; QString projectContents;
{ {
@@ -150,6 +150,7 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w
} }
Core::GeneratedFile generatedCreatorFile(creatorFileName); Core::GeneratedFile generatedCreatorFile(creatorFileName);
generatedCreatorFile.setContents(projectContents); generatedCreatorFile.setContents(projectContents);
generatedCreatorFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
Core::GeneratedFiles files; Core::GeneratedFiles files;
files.append(generatedMainFile); files.append(generatedMainFile);
@@ -158,16 +159,10 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w
return files; return files;
} }
bool QmlProjectApplicationWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage) bool QmlProjectApplicationWizard::postGenerateFiles(const QWizard *, const Core::GeneratedFiles &l, QString *errorMessage)
{ {
Q_UNUSED(w); return ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
// Post-Generate: Open the project
const QString proFileName = l.back().path();
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName)) {
*errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
return false;
}
return true;
} }
} // namespace Internal } // namespace Internal

View File

@@ -33,8 +33,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/customwizard/customwizard.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/filenamevalidatinglineedit.h> #include <utils/filenamevalidatinglineedit.h>
#include <utils/filewizardpage.h> #include <utils/filewizardpage.h>
@@ -166,6 +165,7 @@ Core::GeneratedFiles QmlProjectImportWizard::generateFiles(const QWizard *w,
} }
Core::GeneratedFile generatedCreatorFile(creatorFileName); Core::GeneratedFile generatedCreatorFile(creatorFileName);
generatedCreatorFile.setContents(projectContents); generatedCreatorFile.setContents(projectContents);
generatedCreatorFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
Core::GeneratedFiles files; Core::GeneratedFiles files;
files.append(generatedCreatorFile); files.append(generatedCreatorFile);
@@ -173,16 +173,9 @@ Core::GeneratedFiles QmlProjectImportWizard::generateFiles(const QWizard *w,
return files; return files;
} }
bool QmlProjectImportWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage) bool QmlProjectImportWizard::postGenerateFiles(const QWizard *, const Core::GeneratedFiles &l, QString *errorMessage)
{ {
Q_UNUSED(w); return ProjectExplorer::CustomProjectWizard::postGenerateOpen(l ,errorMessage);
// Post-Generate: Open the project
const QString proFileName = l.back().path();
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName)) {
*errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
return false;
}
return true;
} }
} // namespace Internal } // namespace Internal

View File

@@ -93,7 +93,9 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
// First create the widget wrappers (plugins) and - if requested - skeletons // First create the widget wrappers (plugins) and - if requested - skeletons
// for the widgets. // for the widgets.
foreach (const PluginOptions::WidgetOptions &wo, options.widgetOptions) { const int widgetCount = options.widgetOptions.size();
for (int i = 0; i < widgetCount; i++) {
const PluginOptions::WidgetOptions &wo = options.widgetOptions.at(i);
sm.clear(); sm.clear();
sm.insert(QLatin1String("SINGLE_INCLUDE_GUARD"), headerGuard(wo.pluginHeaderFile)); sm.insert(QLatin1String("SINGLE_INCLUDE_GUARD"), headerGuard(wo.pluginHeaderFile));
sm.insert(QLatin1String("PLUGIN_CLASS"), wo.pluginClassName); sm.insert(QLatin1String("PLUGIN_CLASS"), wo.pluginClassName);
@@ -133,6 +135,8 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile pluginSource(baseDir + wo.pluginSourceFile); Core::GeneratedFile pluginSource(baseDir + wo.pluginSourceFile);
pluginSource.setContents(p.license + pluginSourceContents); pluginSource.setContents(p.license + pluginSourceContents);
if (i == 0 && widgetCount == 1) // Open first widget unless collection
pluginSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
rc.push_back(pluginSource); rc.push_back(pluginSource);
if (wo.sourceType == PluginOptions::WidgetOptions::LinkLibrary) if (wo.sourceType == PluginOptions::WidgetOptions::LinkLibrary)
@@ -209,7 +213,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
} }
// Create the sources for the collection if necessary. // Create the sources for the collection if necessary.
if (options.widgetOptions.count() > 1) { if (widgetCount > 1) {
sm.clear(); sm.clear();
sm.insert(QLatin1String("COLLECTION_INCLUDE_GUARD"), headerGuard(options.collectionHeaderFile)); sm.insert(QLatin1String("COLLECTION_INCLUDE_GUARD"), headerGuard(options.collectionHeaderFile));
sm.insert(QLatin1String("COLLECTION_PLUGIN_CLASS"), options.collectionClassName); sm.insert(QLatin1String("COLLECTION_PLUGIN_CLASS"), options.collectionClassName);
@@ -238,6 +242,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile collectionSource(baseDir + options.collectionSourceFile); Core::GeneratedFile collectionSource(baseDir + options.collectionSourceFile);
collectionSource.setContents(p.license + collectionSourceFileContents); collectionSource.setContents(p.license + collectionSourceFileContents);
collectionSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
rc.push_back(collectionSource); rc.push_back(collectionSource);
pluginHeaders += blank + options.collectionHeaderFile; pluginHeaders += blank + options.collectionHeaderFile;
@@ -282,6 +287,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile proFile(baseDir + p.fileName + QLatin1String(".pro")); Core::GeneratedFile proFile(baseDir + p.fileName + QLatin1String(".pro"));
proFile.setContents(proFileContents); proFile.setContents(proFileContents);
proFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
rc.push_back(proFile); rc.push_back(proFile);
return rc; return rc;
} }

View File

@@ -87,10 +87,12 @@ Core::GeneratedFiles
const QString sourceFileName = Core::BaseFileWizard::buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix()); const QString sourceFileName = Core::BaseFileWizard::buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix());
Core::GeneratedFile source(sourceFileName); Core::GeneratedFile source(sourceFileName);
source.setContents(license + QLatin1String(mainCppC)); source.setContents(license + QLatin1String(mainCppC));
source.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
// Create files: Profile // Create files: Profile
const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix()); const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix());
Core::GeneratedFile profile(profileName); Core::GeneratedFile profile(profileName);
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
QString contents; QString contents;
{ {
QTextStream proStr(&contents); QTextStream proStr(&contents);

View File

@@ -69,6 +69,7 @@ Core::GeneratedFiles
const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix()); const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix());
Core::GeneratedFile profile(profileName); Core::GeneratedFile profile(profileName);
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
return Core::GeneratedFiles() << profile; return Core::GeneratedFiles() << profile;
} }

View File

@@ -175,6 +175,7 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
// Create files: form // Create files: form
const QString formName = buildFileName(projectPath, params.formFileName, formSuffix()); const QString formName = buildFileName(projectPath, params.formFileName, formSuffix());
form = QSharedPointer<Core::GeneratedFile>(new Core::GeneratedFile(formName)); form = QSharedPointer<Core::GeneratedFile>(new Core::GeneratedFile(formName));
form->setAttributes(Core::GeneratedFile::OpenEditorAttribute);
if (!parametrizeTemplate(templatePath, QLatin1String("widget.ui"), params, &contents, errorMessage)) if (!parametrizeTemplate(templatePath, QLatin1String("widget.ui"), params, &contents, errorMessage))
return Core::GeneratedFiles(); return Core::GeneratedFiles();
form->setContents(contents); form->setContents(contents);
@@ -185,6 +186,7 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage)) if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage))
return Core::GeneratedFiles(); return Core::GeneratedFiles();
formSource.setContents(license + contents); formSource.setContents(license + contents);
formSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
// Create files: form header // Create files: form header
const QString formHeaderTemplate = QLatin1String("mywidget.h"); const QString formHeaderTemplate = QLatin1String("mywidget.h");
if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage)) if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage))
@@ -194,6 +196,7 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w,
// Create files: profile // Create files: profile
const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix()); const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix());
Core::GeneratedFile profile(profileName); Core::GeneratedFile profile(profileName);
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
contents.clear(); contents.clear();
{ {
QTextStream proStr(&contents); QTextStream proStr(&contents);

View File

@@ -88,6 +88,7 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
// Class header + source // Class header + source
const QString sourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix()); const QString sourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix());
Core::GeneratedFile source(sourceFileName); Core::GeneratedFile source(sourceFileName);
source.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
const QString headerFileFullName = buildFileName(projectPath, params.headerFileName, headerSuffix()); const QString headerFileFullName = buildFileName(projectPath, params.headerFileName, headerSuffix());
const QString headerFileName = QFileInfo(headerFileFullName).fileName(); const QString headerFileName = QFileInfo(headerFileFullName).fileName();
@@ -116,6 +117,7 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
// Create files: profile // Create files: profile
const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix()); const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix());
Core::GeneratedFile profile(profileName); Core::GeneratedFile profile(profileName);
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
QString profileContents; QString profileContents;
{ {
QTextStream proStr(&profileContents); QTextStream proStr(&profileContents);

View File

@@ -37,6 +37,7 @@
#include "targetsetuppage.h" #include "targetsetuppage.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
@@ -108,20 +109,21 @@ bool QtWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l
return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage); return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage);
} }
bool QtWizard::qt4ProjectPostGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage) bool QtWizard::qt4ProjectPostGenerateFiles(const QWizard *w,
const Core::GeneratedFiles &generatedFiles,
QString *errorMessage)
{ {
const QString proFileName = l.back().path();
const BaseQt4ProjectWizardDialog *dialog = qobject_cast<const BaseQt4ProjectWizardDialog *>(w); const BaseQt4ProjectWizardDialog *dialog = qobject_cast<const BaseQt4ProjectWizardDialog *>(w);
// Generate user settings: // Generate user settings
dialog->writeUserFile(proFileName); foreach (const Core::GeneratedFile &file, generatedFiles)
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
// Post-Generate: Open the project dialog->writeUserFile(file.path());
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName)) { break;
*errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
return false;
} }
return true;
// Post-Generate: Open the projects/editors
return ProjectExplorer::CustomProjectWizard::postGenerateOpen(generatedFiles ,errorMessage);
} }
QString QtWizard::templateDir() QString QtWizard::templateDir()

View File

@@ -162,11 +162,13 @@ Core::GeneratedFiles TestWizard::generateFiles(const QWizard *w, QString *errorM
const QFileInfo sourceFileInfo(sourceFilePath); const QFileInfo sourceFileInfo(sourceFilePath);
Core::GeneratedFile source(sourceFilePath); Core::GeneratedFile source(sourceFilePath);
source.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
source.setContents(generateTestCode(testParams, sourceFileInfo.baseName())); source.setContents(generateTestCode(testParams, sourceFileInfo.baseName()));
// Create profile with define for base dir to find test data // Create profile with define for base dir to find test data
const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, projectParams.fileName, profileSuffix()); const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, projectParams.fileName, profileSuffix());
Core::GeneratedFile profile(profileName); Core::GeneratedFile profile(profileName);
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
QString contents; QString contents;
{ {
QTextStream proStr(&contents); QTextStream proStr(&contents);

View File

@@ -50,5 +50,6 @@ ResourceWizard::generateFilesFromPath(const QString &path,
Core::GeneratedFile file(fileName); Core::GeneratedFile file(fileName);
file.setContents(QLatin1String("<RCC/>")); file.setContents(QLatin1String("<RCC/>"));
file.setEditorId(QLatin1String(Constants::RESOURCEEDITOR_ID)); file.setEditorId(QLatin1String(Constants::RESOURCEEDITOR_ID));
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << file; return Core::GeneratedFiles() << file;
} }

View File

@@ -54,5 +54,6 @@ Core::GeneratedFiles
const QString fileName = Core::BaseFileWizard::buildFileName(path, name, suffix); const QString fileName = Core::BaseFileWizard::buildFileName(path, name, suffix);
Core::GeneratedFile file(fileName); Core::GeneratedFile file(fileName);
file.setEditorId(m_editorId); file.setEditorId(m_editorId);
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << file; return Core::GeneratedFiles() << file;
} }