Implement support for project file open after AddFile action

Change-Id: I5f5372498a34760976cea5b7d6f5f49dd04558db
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Pawel Rutka
2018-02-13 20:26:04 +01:00
committed by pawelrutka
parent 5ea157f0b8
commit 4aced20a21
5 changed files with 48 additions and 7 deletions

View File

@@ -104,11 +104,17 @@ bool CMakeListsNode::showInSimpleTree() const
return false; 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; 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) : CMakeProjectNode::CMakeProjectNode(const Utils::FileName &directory) :
ProjectExplorer::ProjectNode(directory) ProjectExplorer::ProjectNode(directory)
{ {
@@ -127,7 +133,7 @@ QString CMakeProjectNode::tooltip() const
return QString(); return QString();
} }
bool CMakeProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded) bool CMakeProjectNode::addFiles(const QStringList &filePaths, QStringList *)
{ {
noAutoAdditionNotify(filePaths, this); noAutoAdditionNotify(filePaths, this);
return true; // Return always true as autoadd is not supported! return true; // Return always true as autoadd is not supported!
@@ -157,17 +163,23 @@ QString CMakeTargetNode::tooltip() const
} }
bool CMakeTargetNode::supportsAction(ProjectExplorer::ProjectAction action, bool CMakeTargetNode::supportsAction(ProjectExplorer::ProjectAction action,
const ProjectExplorer::Node *node) const const ProjectExplorer::Node *) const
{ {
return action == ProjectExplorer::ProjectAction::AddNewFile; return action == ProjectExplorer::ProjectAction::AddNewFile;
} }
bool CMakeTargetNode::addFiles(const QStringList &filePaths, QStringList *notAdded) bool CMakeTargetNode::addFiles(const QStringList &filePaths, QStringList *)
{ {
noAutoAdditionNotify(filePaths, this); noAutoAdditionNotify(filePaths, this);
return true; // Return always true as autoadd is not supported! 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, void CMakeTargetNode::setTargetInformation(const QList<Utils::FileName> &artifacts,
const QString &type) const QString &type)
{ {

View File

@@ -47,6 +47,7 @@ public:
bool showInSimpleTree() const final; bool showInSimpleTree() const final;
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override; bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
virtual Utils::optional<Utils::FileName> visibleAfterAddFileAction() const override;
}; };
class CMakeProjectNode : public ProjectExplorer::ProjectNode class CMakeProjectNode : public ProjectExplorer::ProjectNode
@@ -74,6 +75,7 @@ public:
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override; bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
bool addFiles(const QStringList &filePaths, QStringList *notAdded) override; bool addFiles(const QStringList &filePaths, QStringList *notAdded) override;
virtual Utils::optional<Utils::FileName> visibleAfterAddFileAction() const override;
private: private:
QString m_tooltip; QString m_tooltip;

View File

@@ -30,7 +30,7 @@
#include "../project.h" #include "../project.h"
#include "../projectexplorer.h" #include "../projectexplorer.h"
#include "../projectexplorerconstants.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
@@ -288,6 +288,9 @@ void JsonWizard::accept()
emit allDone(m_files); emit allDone(m_files);
openFiles(m_files); openFiles(m_files);
auto node = static_cast<ProjectExplorer::Node*>(value(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE).value<void*>());
openProjectForNode(node);
} }
void JsonWizard::reject() 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 QString JsonWizard::OptionDefinition::value(Utils::MacroExpander &expander) const
{ {
if (JsonWizard::boolFromVariant(m_evaluate, &expander)) if (JsonWizard::boolFromVariant(m_evaluate, &expander))

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include "../projectexplorer_export.h" #include "../projectexplorer_export.h"
#include <projectexplorer/projectnodes.h>
#include <coreplugin/generatedfile.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 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 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. void allDone(const JsonWizard::GeneratorFiles &files); // emitted just after the wizard is done with the files. They are ready to be opened.
public slots: public slots:
void accept() override; void accept() override;
void reject() override; void reject() override;
@@ -120,6 +120,7 @@ private:
QString stringify(const QVariant &v) const override; QString stringify(const QVariant &v) const override;
QString evaluate(const QVariant &v) const override ; QString evaluate(const QVariant &v) const override ;
void openFiles(const GeneratorFiles &files); void openFiles(const GeneratorFiles &files);
void openProjectForNode(ProjectExplorer::Node *node);
QList<JsonWizardGenerator *> m_generators; QList<JsonWizardGenerator *> m_generators;

View File

@@ -32,7 +32,7 @@
#include <QStringList> #include <QStringList>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/optional.h>
#include <functional> #include <functional>
namespace Utils { class MimeType; } namespace Utils { class MimeType; }
@@ -324,6 +324,9 @@ public:
virtual bool canAddSubProject(const QString &proFilePath) const; virtual bool canAddSubProject(const QString &proFilePath) const;
virtual bool addSubProject(const QString &proFile); virtual bool addSubProject(const QString &proFile);
virtual bool removeSubProject(const QString &proFilePath); 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 addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override; bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;