summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Rutka <prutka13@gmail.com>2018-02-13 20:26:04 +0100
committerpawelrutka <prutka13@gmail.com>2018-02-23 15:15:22 +0000
commit4aced20a214538a50aef98d763293595d4f6983e (patch)
tree7b99dc9c2407310a36a89445ba191ab96dfb1214
parent5ea157f0b85f3fec6c351d844cf2b35a12a80b07 (diff)
downloadqt-creator-4aced20a214538a50aef98d763293595d4f6983e.tar.gz
Implement support for project file open after AddFile action
Change-Id: I5f5372498a34760976cea5b7d6f5f49dd04558db Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp20
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectnodes.h2
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp25
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizard.h3
-rw-r--r--src/plugins/projectexplorer/projectnodes.h5
5 files changed, 48 insertions, 7 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp
index 2e99162ada..d471910d47 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp
@@ -104,11 +104,17 @@ bool CMakeListsNode::showInSimpleTree() const
return false;
}
-bool CMakeListsNode::supportsAction(ProjectExplorer::ProjectAction action, const ProjectExplorer::Node *node) const
+bool CMakeListsNode::supportsAction(ProjectExplorer::ProjectAction action, const ProjectExplorer::Node *) const
{
return action == ProjectExplorer::ProjectAction::AddNewFile;
}
+Utils::optional<Utils::FileName> CMakeListsNode::visibleAfterAddFileAction() const
+{
+ Utils::FileName projFile{filePath()};
+ return projFile.appendPath("CMakeLists.txt");
+}
+
CMakeProjectNode::CMakeProjectNode(const Utils::FileName &directory) :
ProjectExplorer::ProjectNode(directory)
{
@@ -127,7 +133,7 @@ QString CMakeProjectNode::tooltip() const
return QString();
}
-bool CMakeProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
+bool CMakeProjectNode::addFiles(const QStringList &filePaths, QStringList *)
{
noAutoAdditionNotify(filePaths, this);
return true; // Return always true as autoadd is not supported!
@@ -157,17 +163,23 @@ QString CMakeTargetNode::tooltip() const
}
bool CMakeTargetNode::supportsAction(ProjectExplorer::ProjectAction action,
- const ProjectExplorer::Node *node) const
+ const ProjectExplorer::Node *) const
{
return action == ProjectExplorer::ProjectAction::AddNewFile;
}
-bool CMakeTargetNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
+bool CMakeTargetNode::addFiles(const QStringList &filePaths, QStringList *)
{
noAutoAdditionNotify(filePaths, this);
return true; // Return always true as autoadd is not supported!
}
+Utils::optional<Utils::FileName> CMakeTargetNode::visibleAfterAddFileAction() const
+{
+ Utils::FileName projFile{filePath()};
+ return projFile.appendPath("CMakeLists.txt");
+}
+
void CMakeTargetNode::setTargetInformation(const QList<Utils::FileName> &artifacts,
const QString &type)
{
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h
index 35adee0bd9..c360b0c60a 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h
@@ -47,6 +47,7 @@ public:
bool showInSimpleTree() const final;
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
+ virtual Utils::optional<Utils::FileName> visibleAfterAddFileAction() const override;
};
class CMakeProjectNode : public ProjectExplorer::ProjectNode
@@ -74,6 +75,7 @@ public:
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
bool addFiles(const QStringList &filePaths, QStringList *notAdded) override;
+ virtual Utils::optional<Utils::FileName> visibleAfterAddFileAction() const override;
private:
QString m_tooltip;
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
index 2e509f1dd3..0686c0caee 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
@@ -30,7 +30,7 @@
#include "../project.h"
#include "../projectexplorer.h"
-
+#include "../projectexplorerconstants.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/messagemanager.h>
@@ -288,6 +288,9 @@ void JsonWizard::accept()
emit allDone(m_files);
openFiles(m_files);
+
+ auto node = static_cast<ProjectExplorer::Node*>(value(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE).value<void*>());
+ openProjectForNode(node);
}
void JsonWizard::reject()
@@ -382,6 +385,26 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
}
}
+void JsonWizard::openProjectForNode(Node *node)
+{
+ using namespace Utils;
+
+ QTC_ASSERT(node, return); // may happend when no project is opened
+
+ ProjectNode *projNode = node->asProjectNode() ? node->asProjectNode() : node->parentProjectNode();
+
+ QTC_ASSERT(projNode, return);
+
+ Utils::optional<FileName> projFilePath = projNode->visibleAfterAddFileAction();
+
+ if (projFilePath && !Core::EditorManager::openEditor(projFilePath.value().toString())) {
+ auto errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
+ "Failed to open an editor for \"%1\".")
+ .arg(QDir::toNativeSeparators(projFilePath.value().toString()));
+ QMessageBox::warning(nullptr, tr("Cannot Open Project"), errorMessage);
+ }
+}
+
QString JsonWizard::OptionDefinition::value(Utils::MacroExpander &expander) const
{
if (JsonWizard::boolFromVariant(m_evaluate, &expander))
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h
index d571f9cab7..89da484514 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h
@@ -26,6 +26,7 @@
#pragma once
#include "../projectexplorer_export.h"
+#include <projectexplorer/projectnodes.h>
#include <coreplugin/generatedfile.h>
@@ -108,7 +109,6 @@ signals:
void filesReady(const JsonWizard::GeneratorFiles &files); // emitted just after files are in final state on disk.
void filesPolished(const JsonWizard::GeneratorFiles &files); // emitted just after additional files (e.g. settings) not directly related to the project were created.
void allDone(const JsonWizard::GeneratorFiles &files); // emitted just after the wizard is done with the files. They are ready to be opened.
-
public slots:
void accept() override;
void reject() override;
@@ -120,6 +120,7 @@ private:
QString stringify(const QVariant &v) const override;
QString evaluate(const QVariant &v) const override ;
void openFiles(const GeneratorFiles &files);
+ void openProjectForNode(ProjectExplorer::Node *node);
QList<JsonWizardGenerator *> m_generators;
diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h
index 34ad086a18..2619b7e8a6 100644
--- a/src/plugins/projectexplorer/projectnodes.h
+++ b/src/plugins/projectexplorer/projectnodes.h
@@ -32,7 +32,7 @@
#include <QStringList>
#include <utils/fileutils.h>
-
+#include <utils/optional.h>
#include <functional>
namespace Utils { class MimeType; }
@@ -324,6 +324,9 @@ public:
virtual bool canAddSubProject(const QString &proFilePath) const;
virtual bool addSubProject(const QString &proFile);
virtual bool removeSubProject(const QString &proFilePath);
+ virtual Utils::optional<Utils::FileName> visibleAfterAddFileAction() const {
+ return Utils::nullopt;
+ }
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;