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",
|
"source": "file.txt",
|
||||||
"target": "%{TargetPath}",
|
"target": "%{TargetPath}",
|
||||||
"overwrite": true,
|
"overwrite": true,
|
||||||
"openInEditor": true
|
"openInEditor": true,
|
||||||
|
"temporary": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@@ -36,18 +36,20 @@ class GeneratedFilePrivate;
|
|||||||
class CORE_EXPORT GeneratedFile
|
class CORE_EXPORT GeneratedFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Attribute { // Open this file in editor
|
enum Attribute {
|
||||||
OpenEditorAttribute = 0x01,
|
// Open this file in editor
|
||||||
// Open project
|
OpenEditorAttribute = 0x01,
|
||||||
OpenProjectAttribute = 0x02,
|
// Open project
|
||||||
/* File is generated by external scripts, do not write out,
|
OpenProjectAttribute = 0x02,
|
||||||
* see BaseFileWizard::writeFiles() */
|
// File is generated by external scripts, do not write out, see BaseFileWizard::writeFiles()
|
||||||
CustomGeneratorAttribute = 0x4,
|
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,
|
KeepExistingFileAttribute = 0x8,
|
||||||
/* Force overwriting of a file without asking the user to keep it */
|
// Force overwriting of a file without asking the user to keep it
|
||||||
ForceOverwrite = 0x10
|
ForceOverwrite = 0x10,
|
||||||
};
|
// Mark the document temporary after opening the file
|
||||||
|
TemporaryFile = 0x20
|
||||||
|
};
|
||||||
Q_DECLARE_FLAGS(Attributes, Attribute)
|
Q_DECLARE_FLAGS(Attributes, Attribute)
|
||||||
|
|
||||||
GeneratedFile();
|
GeneratedFile();
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include "../projectexplorerconstants.h"
|
#include "../projectexplorerconstants.h"
|
||||||
#include "../projecttree.h"
|
#include "../projecttree.h"
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
@@ -465,11 +466,14 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
|
|||||||
openedSomething = true;
|
openedSomething = true;
|
||||||
}
|
}
|
||||||
if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) {
|
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",
|
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
|
||||||
"Failed to open an editor for \"%1\".")
|
"Failed to open an editor for \"%1\".")
|
||||||
.arg(QDir::toNativeSeparators(file.path()));
|
.arg(QDir::toNativeSeparators(file.path()));
|
||||||
break;
|
break;
|
||||||
|
} else if (file.attributes() & Core::GeneratedFile::TemporaryFile) {
|
||||||
|
editor->document()->setTemporary(true);
|
||||||
}
|
}
|
||||||
openedSomething = true;
|
openedSomething = true;
|
||||||
}
|
}
|
||||||
|
@@ -69,6 +69,7 @@ bool JsonWizardFileGenerator::setup(const QVariant &data, QString *errorMessage)
|
|||||||
f.isBinary = tmp.value(QLatin1String("isBinary"), false);
|
f.isBinary = tmp.value(QLatin1String("isBinary"), false);
|
||||||
f.overwrite = tmp.value(QLatin1String("overwrite"), false);
|
f.overwrite = tmp.value(QLatin1String("overwrite"), false);
|
||||||
f.openInEditor = tmp.value(QLatin1String("openInEditor"), false);
|
f.openInEditor = tmp.value(QLatin1String("openInEditor"), false);
|
||||||
|
f.isTemporary = tmp.value(QLatin1String("temporary"), false);
|
||||||
f.openAsProject = tmp.value(QLatin1String("openAsProject"), false);
|
f.openAsProject = tmp.value(QLatin1String("openAsProject"), false);
|
||||||
|
|
||||||
f.options = JsonWizard::parseOptions(tmp.value(QLatin1String("options")), errorMessage);
|
f.options = JsonWizard::parseOptions(tmp.value(QLatin1String("options")), errorMessage);
|
||||||
@@ -148,6 +149,8 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
|
|||||||
attributes |= Core::GeneratedFile::OpenProjectAttribute;
|
attributes |= Core::GeneratedFile::OpenProjectAttribute;
|
||||||
if (JsonWizard::boolFromVariant(file.overwrite, expander))
|
if (JsonWizard::boolFromVariant(file.overwrite, expander))
|
||||||
attributes |= Core::GeneratedFile::ForceOverwrite;
|
attributes |= Core::GeneratedFile::ForceOverwrite;
|
||||||
|
if (JsonWizard::boolFromVariant(file.isTemporary, expander))
|
||||||
|
attributes |= Core::GeneratedFile::TemporaryFile;
|
||||||
|
|
||||||
if (file.keepExisting)
|
if (file.keepExisting)
|
||||||
attributes |= Core::GeneratedFile::KeepExistingFileAttribute;
|
attributes |= Core::GeneratedFile::KeepExistingFileAttribute;
|
||||||
|
@@ -55,6 +55,7 @@ private:
|
|||||||
QVariant overwrite = false;
|
QVariant overwrite = false;
|
||||||
QVariant openInEditor = false;
|
QVariant openInEditor = false;
|
||||||
QVariant openAsProject = false;
|
QVariant openAsProject = false;
|
||||||
|
QVariant isTemporary = false;
|
||||||
|
|
||||||
QList<JsonWizard::OptionDefinition> options;
|
QList<JsonWizard::OptionDefinition> options;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user