ProjectExplorer: Set temporary flag on scratch buffer document

Task-number: QTCREATORBUG-23509
Change-Id: Ieb3922030cb1dd4984b91ac24d0396bb19a4a711
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2020-03-24 09:44:38 +01:00
parent 6989c9bbea
commit 398930d3cf
5 changed files with 25 additions and 14 deletions

View File

@@ -21,7 +21,8 @@
"source": "file.txt",
"target": "%{TargetPath}",
"overwrite": true,
"openInEditor": true
"openInEditor": true,
"temporary": true
}
}
]

View File

@@ -36,18 +36,20 @@ class GeneratedFilePrivate;
class CORE_EXPORT GeneratedFile
{
public:
enum Attribute { // Open this file in editor
OpenEditorAttribute = 0x01,
// Open project
OpenProjectAttribute = 0x02,
/* File is generated by external scripts, do not write out,
* see BaseFileWizard::writeFiles() */
CustomGeneratorAttribute = 0x4,
/* File exists and the user indicated that he wants to keep it */
KeepExistingFileAttribute = 0x8,
/* Force overwriting of a file without asking the user to keep it */
ForceOverwrite = 0x10
};
enum Attribute {
// Open this file in editor
OpenEditorAttribute = 0x01,
// Open project
OpenProjectAttribute = 0x02,
// File is generated by external scripts, do not write out, see BaseFileWizard::writeFiles()
CustomGeneratorAttribute = 0x4,
// File exists and the user indicated that he wants to keep it
KeepExistingFileAttribute = 0x8,
// Force overwriting of a file without asking the user to keep it
ForceOverwrite = 0x10,
// Mark the document temporary after opening the file
TemporaryFile = 0x20
};
Q_DECLARE_FLAGS(Attributes, Attribute)
GeneratedFile();

View File

@@ -33,6 +33,7 @@
#include "../projectexplorerconstants.h"
#include "../projecttree.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/messagemanager.h>
#include <utils/algorithm.h>
@@ -465,11 +466,14 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
openedSomething = true;
}
if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) {
if (!Core::EditorManager::openEditor(file.path(), file.editorId())) {
Core::IEditor *editor = Core::EditorManager::openEditor(file.path(), file.editorId());
if (!editor) {
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"Failed to open an editor for \"%1\".")
.arg(QDir::toNativeSeparators(file.path()));
break;
} else if (file.attributes() & Core::GeneratedFile::TemporaryFile) {
editor->document()->setTemporary(true);
}
openedSomething = true;
}

View File

@@ -69,6 +69,7 @@ bool JsonWizardFileGenerator::setup(const QVariant &data, QString *errorMessage)
f.isBinary = tmp.value(QLatin1String("isBinary"), false);
f.overwrite = tmp.value(QLatin1String("overwrite"), false);
f.openInEditor = tmp.value(QLatin1String("openInEditor"), false);
f.isTemporary = tmp.value(QLatin1String("temporary"), false);
f.openAsProject = tmp.value(QLatin1String("openAsProject"), false);
f.options = JsonWizard::parseOptions(tmp.value(QLatin1String("options")), errorMessage);
@@ -148,6 +149,8 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
attributes |= Core::GeneratedFile::OpenProjectAttribute;
if (JsonWizard::boolFromVariant(file.overwrite, expander))
attributes |= Core::GeneratedFile::ForceOverwrite;
if (JsonWizard::boolFromVariant(file.isTemporary, expander))
attributes |= Core::GeneratedFile::TemporaryFile;
if (file.keepExisting)
attributes |= Core::GeneratedFile::KeepExistingFileAttribute;

View File

@@ -55,6 +55,7 @@ private:
QVariant overwrite = false;
QVariant openInEditor = false;
QVariant openAsProject = false;
QVariant isTemporary = false;
QList<JsonWizard::OptionDefinition> options;
};