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

@@ -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))