diff options
author | Daniel Teske <daniel.teske@nokia.com> | 2012-04-02 14:55:56 +0200 |
---|---|---|
committer | Daniel Teske <daniel.teske@nokia.com> | 2012-04-03 14:11:47 +0200 |
commit | 633468482404d70c280bc93c51ecfc62b588aea8 (patch) | |
tree | 164b9cb35fbdd833ce995c8bd33cb81a5763c6c3 | |
parent | 8d5d1f2f66f8bfd5f1cc7953aa8e80b1f72163a3 (diff) | |
download | qt-creator-633468482404d70c280bc93c51ecfc62b588aea8.tar.gz |
New File Dialog: Choose right default project for adding
So far we used a heuristic that prefers .pro files in the same directory
as the new files. That fails if there are multiple .pro files in the
same directory. So instead introduce a mechanism to pass extra data
through the wizard.
Task-number: QTCREATORBUG-7157
Change-Id: I615f7292e16a0a6cb1e84f090016879f1038409f
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
-rw-r--r-- | src/plugins/coreplugin/basefilewizard.cpp | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/basefilewizard.h | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/dialogs/iwizard.h | 3 | ||||
-rw-r--r-- | src/plugins/coreplugin/icore.cpp | 5 | ||||
-rw-r--r-- | src/plugins/coreplugin/icore.h | 3 | ||||
-rw-r--r-- | src/plugins/coreplugin/ifilewizardextension.h | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/mainwindow.cpp | 5 | ||||
-rw-r--r-- | src/plugins/coreplugin/mainwindow.h | 3 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectexplorer.cpp | 8 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectexplorerconstants.h | 3 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectfilewizardextension.cpp | 18 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectfilewizardextension.h | 2 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp | 8 | ||||
-rw-r--r-- | src/plugins/vcsbase/basecheckoutwizard.cpp | 3 | ||||
-rw-r--r-- | src/plugins/vcsbase/basecheckoutwizard.h | 2 |
15 files changed, 52 insertions, 21 deletions
diff --git a/src/plugins/coreplugin/basefilewizard.cpp b/src/plugins/coreplugin/basefilewizard.cpp index b47ff946c6..2e19226150 100644 --- a/src/plugins/coreplugin/basefilewizard.cpp +++ b/src/plugins/coreplugin/basefilewizard.cpp @@ -434,7 +434,7 @@ QString BaseFileWizard::descriptionImage() const return d->m_parameters.descriptionImage(); } -void BaseFileWizard::runWizard(const QString &path, QWidget *parent, const QString &platform) +void BaseFileWizard::runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &extraValues) { QTC_ASSERT(!path.isEmpty(), return); @@ -493,7 +493,7 @@ void BaseFileWizard::runWizard(const QString &path, QWidget *parent, const QStri } if (firstExtensionPageHit) foreach (IFileWizardExtension *ex, extensions) - ex->firstExtensionPageShown(files); + ex->firstExtensionPageShown(files, extraValues); if (accepted) break; } diff --git a/src/plugins/coreplugin/basefilewizard.h b/src/plugins/coreplugin/basefilewizard.h index 9701857fd1..6f4fc76baa 100644 --- a/src/plugins/coreplugin/basefilewizard.h +++ b/src/plugins/coreplugin/basefilewizard.h @@ -158,7 +158,7 @@ public: virtual QString descriptionImage() const; - virtual void runWizard(const QString &path, QWidget *parent, const QString &platform); + virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &extraValues); virtual Core::FeatureSet requiredFeatures() const; virtual WizardFlags flags() const; diff --git a/src/plugins/coreplugin/dialogs/iwizard.h b/src/plugins/coreplugin/dialogs/iwizard.h index 50383da148..8347cd0252 100644 --- a/src/plugins/coreplugin/dialogs/iwizard.h +++ b/src/plugins/coreplugin/dialogs/iwizard.h @@ -37,6 +37,7 @@ #include <coreplugin/featureprovider.h> #include <QObject> +#include <QVariantMap> QT_BEGIN_NAMESPACE class QIcon; @@ -77,7 +78,7 @@ public: virtual FeatureSet requiredFeatures() const = 0; virtual WizardFlags flags() const = 0; - virtual void runWizard(const QString &path, QWidget *parent, const QString &platform) = 0; + virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &variables) = 0; bool isAvailable(const QString &platformName) const; QStringList supportedPlatforms() const; diff --git a/src/plugins/coreplugin/icore.cpp b/src/plugins/coreplugin/icore.cpp index ff9f8619fe..185ed4868e 100644 --- a/src/plugins/coreplugin/icore.cpp +++ b/src/plugins/coreplugin/icore.cpp @@ -385,9 +385,10 @@ ICore::~ICore() void ICore::showNewItemDialog(const QString &title, const QList<IWizard *> &wizards, - const QString &defaultLocation) + const QString &defaultLocation, + const QVariantMap &extraVariables) { - m_mainwindow->showNewItemDialog(title, wizards, defaultLocation); + m_mainwindow->showNewItemDialog(title, wizards, defaultLocation, extraVariables); } bool ICore::showOptionsDialog(const QString &group, const QString &page, QWidget *parent) diff --git a/src/plugins/coreplugin/icore.h b/src/plugins/coreplugin/icore.h index 5b06c7fbf6..169fd0d4f0 100644 --- a/src/plugins/coreplugin/icore.h +++ b/src/plugins/coreplugin/icore.h @@ -81,7 +81,8 @@ public: static void showNewItemDialog(const QString &title, const QList<IWizard *> &wizards, - const QString &defaultLocation = QString()); + const QString &defaultLocation = QString(), + const QVariantMap &extraVariables = QVariantMap()); static bool showOptionsDialog(const QString &group = QString(), const QString &page = QString(), diff --git a/src/plugins/coreplugin/ifilewizardextension.h b/src/plugins/coreplugin/ifilewizardextension.h index 0d0cf5cfc1..cadb2b4495 100644 --- a/src/plugins/coreplugin/ifilewizardextension.h +++ b/src/plugins/coreplugin/ifilewizardextension.h @@ -37,6 +37,7 @@ #include <QObject> #include <QList> +#include <QVariantMap> QT_BEGIN_NAMESPACE class QWizardPage; @@ -71,8 +72,9 @@ public: public slots: /* Notification about the first extension page being shown. */ - virtual void firstExtensionPageShown(const QList<GeneratedFile> &files) { + virtual void firstExtensionPageShown(const QList<GeneratedFile> &files, const QVariantMap &extraValues) { Q_UNUSED(files) + Q_UNUSED(extraValues) } }; diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index baa881d204..4397688d7b 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -937,7 +937,8 @@ void MainWindow::setFocusToEditor() void MainWindow::showNewItemDialog(const QString &title, const QList<IWizard *> &wizards, - const QString &defaultLocation) + const QString &defaultLocation, + const QVariantMap &extraVariables) { // Scan for wizards matching the filter and pick one. Don't show // dialog if there is only one. @@ -978,7 +979,7 @@ void MainWindow::showNewItemDialog(const QString &title, break; } } - wizard->runWizard(path, this, selectedPlatform); + wizard->runWizard(path, this, selectedPlatform, extraVariables); } bool MainWindow::showOptionsDialog(const QString &category, diff --git a/src/plugins/coreplugin/mainwindow.h b/src/plugins/coreplugin/mainwindow.h index ed60198476..86d77f7800 100644 --- a/src/plugins/coreplugin/mainwindow.h +++ b/src/plugins/coreplugin/mainwindow.h @@ -137,7 +137,8 @@ public slots: void showNewItemDialog(const QString &title, const QList<IWizard *> &wizards, - const QString &defaultLocation = QString()); + const QString &defaultLocation = QString(), + const QVariantMap &extraVariables = QVariantMap()); bool showOptionsDialog(const QString &category = QString(), const QString &page = QString(), diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index ceb45cafe1..016644bdfd 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -2569,10 +2569,12 @@ void ProjectExplorerPlugin::addNewFile() QTC_ASSERT(d->m_currentNode, return) QString location = directoryFor(d->m_currentNode); + QVariantMap map; + map.insert(QLatin1String(Constants::PREFERED_PROJECT_NODE), d->m_currentNode->projectNode()->path()); Core::ICore::showNewItemDialog(tr("New File", "Title of dialog"), Core::IWizard::wizardsOfKind(Core::IWizard::FileWizard) + Core::IWizard::wizardsOfKind(Core::IWizard::ClassWizard), - location); + location, map); } void ProjectExplorerPlugin::addNewSubproject() @@ -2583,9 +2585,11 @@ void ProjectExplorerPlugin::addNewSubproject() if (d->m_currentNode->nodeType() == ProjectNodeType && d->m_currentNode->projectNode()->supportedActions( d->m_currentNode->projectNode()).contains(ProjectNode::AddSubProject)) { + QVariantMap map; + map.insert(QLatin1String(Constants::PREFERED_PROJECT_NODE), d->m_currentNode->projectNode()->path()); Core::ICore::showNewItemDialog(tr("New Subproject", "Title of dialog"), Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard), - location); + location, map); } } diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index 3d1be9a915..5c6c18cdf0 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -205,6 +205,9 @@ const char PROJECT_WIZARD_CATEGORY_DISPLAY[] = QT_TRANSLATE_NOOP("ProjectExplore const char IMPORT_WIZARD_CATEGORY[] = "T.Import"; const char IMPORT_WIZARD_CATEGORY_DISPLAY[] = QT_TRANSLATE_NOOP("ProjectExplorer", "Import Project"); +// Wizard extra values +const char PREFERED_PROJECT_NODE[] = "ProjectExplorer.PreferedProjectNode"; + // Build step lists ids: const char BUILDSTEPS_CLEAN[] = "ProjectExplorer.BuildSteps.Clean"; const char BUILDSTEPS_BUILD[] = "ProjectExplorer.BuildSteps.Build"; diff --git a/src/plugins/projectexplorer/projectfilewizardextension.cpp b/src/plugins/projectexplorer/projectfilewizardextension.cpp index 828948d44b..2386645d07 100644 --- a/src/plugins/projectexplorer/projectfilewizardextension.cpp +++ b/src/plugins/projectexplorer/projectfilewizardextension.cpp @@ -231,15 +231,23 @@ static QList<ProjectEntry> findDeployProject(const QList<ProjectEntry> &projects // the longest matching path (list containing"/project/subproject1" matching // common path "/project/subproject1/newuserpath"). static int findMatchingProject(const QList<ProjectEntry> &projects, - const QString &commonPath) + const QString &commonPath, + const QString &preferedProjectNode) { if (projects.isEmpty() || commonPath.isEmpty()) return -1; + const int count = projects.size(); + if (!preferedProjectNode.isEmpty()) { + for (int p = 0; p < count; ++p) { + if (projects.at(p).node->path() == preferedProjectNode) + return p; + } + } + int bestMatch = -1; int bestMatchLength = 0; bool bestMatchIsProFile = false; - const int count = projects.size(); for (int p = 0; p < count; p++) { // Direct match or better match? (note that the wizards' files are native). const ProjectEntry &entry = projects.at(p); @@ -268,7 +276,8 @@ static QString generatedProjectFilePath(const QList<Core::GeneratedFile> &files) } void ProjectFileWizardExtension::firstExtensionPageShown( - const QList<Core::GeneratedFile> &files) + const QList<Core::GeneratedFile> &files, + const QVariantMap &extraValues) { initProjectChoices(generatedProjectFilePath(files)); @@ -302,7 +311,8 @@ void ProjectFileWizardExtension::firstExtensionPageShown( m_context->page->setAdditionalInfo(text); bestProjectIndex = -1; } else { - bestProjectIndex = findMatchingProject(m_context->projects, m_context->commonDirectory); + bestProjectIndex = findMatchingProject(m_context->projects, m_context->commonDirectory, + extraValues.value(QLatin1String(Constants::PREFERED_PROJECT_NODE)).toString()); m_context->page->setNoneLabel(tr("<None>")); } diff --git a/src/plugins/projectexplorer/projectfilewizardextension.h b/src/plugins/projectexplorer/projectfilewizardextension.h index f413c4fd4c..c8e3167595 100644 --- a/src/plugins/projectexplorer/projectfilewizardextension.h +++ b/src/plugins/projectexplorer/projectfilewizardextension.h @@ -54,7 +54,7 @@ public: void applyCodeStyle(Core::GeneratedFile *file) const; public slots: - void firstExtensionPageShown(const QList<Core::GeneratedFile> &files); + void firstExtensionPageShown(const QList<Core::GeneratedFile> &files, const QVariantMap &extraValues); void initializeVersionControlChoices(); private: diff --git a/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp index 0c58f4a45b..fb603ca124 100644 --- a/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp @@ -83,9 +83,15 @@ bool SubdirsProjectWizard::postGenerateFiles(const QWizard *w, const Core::Gener { const SubdirsProjectWizardDialog *wizard = qobject_cast< const SubdirsProjectWizardDialog *>(w); if (QtWizard::qt4ProjectPostGenerateFiles(wizard, files, errorMessage)) { + const QtProjectParameters params = wizard->parameters(); + const QString projectPath = params.projectPath(); + const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix()); + QVariantMap map; + map.insert(QLatin1String(ProjectExplorer::Constants::PREFERED_PROJECT_NODE), profileName); Core::ICore::showNewItemDialog(tr("New Subproject", "Title of dialog"), Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard), - wizard->parameters().projectPath()); + wizard->parameters().projectPath(), + map); } else { return false; } diff --git a/src/plugins/vcsbase/basecheckoutwizard.cpp b/src/plugins/vcsbase/basecheckoutwizard.cpp index b19c281c1e..6b0892ceea 100644 --- a/src/plugins/vcsbase/basecheckoutwizard.cpp +++ b/src/plugins/vcsbase/basecheckoutwizard.cpp @@ -129,8 +129,9 @@ void BaseCheckoutWizard::setId(const QString &id) d->id = id; } -void BaseCheckoutWizard::runWizard(const QString &path, QWidget *parent, const QString & /*platform*/) +void BaseCheckoutWizard::runWizard(const QString &path, QWidget *parent, const QString & /*platform*/, const QVariantMap &extraValues) { + Q_UNUSED(extraValues) // Create dialog and launch d->parameterPages = createParameterPages(path); Internal::CheckoutWizardDialog dialog(d->parameterPages, parent); diff --git a/src/plugins/vcsbase/basecheckoutwizard.h b/src/plugins/vcsbase/basecheckoutwizard.h index 0a46d1811b..1148b73cb7 100644 --- a/src/plugins/vcsbase/basecheckoutwizard.h +++ b/src/plugins/vcsbase/basecheckoutwizard.h @@ -66,7 +66,7 @@ public: virtual QString descriptionImage() const; - virtual void runWizard(const QString &path, QWidget *parent, const QString &platform); + virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &extraValues); virtual Core::FeatureSet requiredFeatures() const; |