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

@@ -119,11 +119,12 @@ PyMethodDef Application::Methods[] = {
// "saveDocument(string) -- Save the document to a file."},
// {"saveDocumentAs", (PyCFunction) Application::sSaveDocumentAs, METH_VARARGS},
{"newDocument", reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) (void)>( Application::sNewDocument )), METH_VARARGS|METH_KEYWORDS,
"newDocument(name, label=None, hidden=False) -> object\n"
"newDocument(name, label=None, hidden=False, tmp=False) -> object\n"
"Create a new document with a given name.\n\n"
"name: unique document name which is checked automatically.\n"
"label: optional user changeable label for the document.\n"
"hidden: whether to hide document 3D view."},
"hidden: whether to hide document 3D view.\n"
"temp: mark the document as temporary so that it will not be saved"},
{"closeDocument", (PyCFunction) Application::sCloseDocument, METH_VARARGS,
"closeDocument(string) -> None\n\n"
"Close the document with a given name."},
@@ -269,13 +270,16 @@ PyObject* Application::sNewDocument(PyObject * /*self*/, PyObject *args, PyObjec
char *docName = 0;
char *usrName = 0;
PyObject *hidden = Py_False;
static char *kwlist[] = {"name","label","hidden",0};
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|etetO", kwlist,
PyObject *temp = Py_False;
static char *kwlist[] = {"name","label","hidden","temp",0};
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|etetOO", kwlist,
"utf-8", &docName, "utf-8", &usrName, &hidden))
return NULL;
PY_TRY {
App::Document* doc = GetApplication().newDocument(docName, usrName,!PyObject_IsTrue(hidden));
App::Document* doc = GetApplication().newDocument(docName, usrName,
!PyObject_IsTrue(hidden),
PyObject_IsTrue(temp));
PyMem_Free(docName);
PyMem_Free(usrName);
return doc->getPyObject();