forked from qt-creator/qt-creator
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:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user