forked from qt-creator/qt-creator
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:
@@ -21,7 +21,8 @@
|
||||
"source": "file.txt",
|
||||
"target": "%{TargetPath}",
|
||||
"overwrite": true,
|
||||
"openInEditor": true
|
||||
"openInEditor": true,
|
||||
"temporary": true
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@@ -36,17 +36,19 @@ class GeneratedFilePrivate;
|
||||
class CORE_EXPORT GeneratedFile
|
||||
{
|
||||
public:
|
||||
enum Attribute { // Open this file in editor
|
||||
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() */
|
||||
// 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 */
|
||||
// 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
|
||||
// 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)
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -55,6 +55,7 @@ private:
|
||||
QVariant overwrite = false;
|
||||
QVariant openInEditor = false;
|
||||
QVariant openAsProject = false;
|
||||
QVariant isTemporary = false;
|
||||
|
||||
QList<JsonWizard::OptionDefinition> options;
|
||||
};
|
||||
|
Reference in New Issue
Block a user