App/Gui: introduce temporary document

Add new argument to Application::newDocument() to create a temporary
    document. Also exposed to Python API App.newDocument() with a named
    argument 'temp'.

    The temporary document is marked with status bit 'TempDoc'. The user
    will not be prompt for saving when closing. The undo/redo is disabled.
    The AutoSaver skips it. And the tree view will not show it.
    PropertyXLink allows linking to/from object within a temporary document
    without saving.
This commit is contained in:
Zheng, Lei
2020-01-03 20:36:54 +08:00
committed by wmayer
parent 20cb8e2480
commit 36d046d489
13 changed files with 119 additions and 46 deletions

View File

@@ -2894,6 +2894,12 @@ const char* Document::getProgramVersion() const
return d->programVersion.c_str();
}
const char* Document::getFileName() const
{
return testStatus(TempDoc) ? TransientDir.getValue()
: FileName.getValue();
}
/// Remove all modifications. After this call The document becomes valid again.
void Document::purgeTouched()
{
@@ -4241,7 +4247,7 @@ void Document::breakDependency(DocumentObject* pcObject, bool clear)
}
std::vector<DocumentObject*> Document::copyObject(
const std::vector<DocumentObject*> &objs, bool recursive)
const std::vector<DocumentObject*> &objs, bool recursive, bool returnAll)
{
std::vector<DocumentObject*> deps;
if(!recursive)
@@ -4249,10 +4255,11 @@ std::vector<DocumentObject*> Document::copyObject(
else
deps = getDependencyList(objs,DepNoXLinked|DepSort);
if(!isSaved() && PropertyXLink::hasXLink(deps))
if (!testStatus(TempDoc) && !isSaved() && PropertyXLink::hasXLink(deps)) {
throw Base::RuntimeError(
"Document must be saved at least once before link to external objects");
}
MergeDocuments md(this);
// if not copying recursively then suppress possible warnings
md.setVerbose(recursive);
@@ -4291,7 +4298,7 @@ std::vector<DocumentObject*> Document::copyObject(
imported = md.importObjects(istr);
}
if(imported.size()!=deps.size())
if (returnAll || imported.size()!=deps.size())
return imported;
std::unordered_map<App::DocumentObject*,size_t> indices;