convert utf-8 encoded path name to escaped unicode when saving document with Python
This commit is contained in:
parent
a12ecd49bd
commit
05a25967bd
|
@ -83,11 +83,14 @@ PyObject* DocumentPy::save(PyObject * args)
|
|||
PyObject* DocumentPy::saveAs(PyObject * args)
|
||||
{
|
||||
char* fn;
|
||||
if (!PyArg_ParseTuple(args, "s", &fn)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "et", "utf-8", &fn))
|
||||
return NULL;
|
||||
|
||||
std::string utf8Name = fn;
|
||||
PyMem_Free(fn);
|
||||
|
||||
try {
|
||||
if (!getDocumentPtr()->saveAs(fn)) {
|
||||
if (!getDocumentPtr()->saveAs(utf8Name.c_str())) {
|
||||
PyErr_SetString(PyExc_ValueError, "Object attribute 'FileName' is not set");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -101,9 +104,9 @@ PyObject* DocumentPy::saveAs(PyObject * args)
|
|||
return 0;
|
||||
}
|
||||
|
||||
Base::FileInfo fi(fn);
|
||||
Base::FileInfo fi(utf8Name);
|
||||
if (!fi.isReadable()) {
|
||||
PyErr_Format(PyExc_IOError, "No such file or directory: '%s'", fn);
|
||||
PyErr_Format(PyExc_IOError, "No such file or directory: '%s'", utf8Name.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include <Base/Matrix.h>
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Writer.h>
|
||||
#include <Base/Tools.h>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
|
@ -670,8 +671,9 @@ bool Document::saveAs(void)
|
|||
// save as new file name
|
||||
try {
|
||||
Gui::WaitCursor wc;
|
||||
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").saveAs(\"%s\")"
|
||||
, DocName, (const char*)fn.toUtf8());
|
||||
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(fn.toUtf8());
|
||||
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").saveAs(u\"%s\")"
|
||||
, DocName, escapedstr.c_str());
|
||||
setModified(false);
|
||||
getMainWindow()->appendRecentFile(fi.filePath());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user