Added SaveCopy command
This command saves a copy of the current document under a new name, without modifying the document itself. Available in menu File -> Save a Copy or from python with FreeCAD.ActiveDocument.saveCopy(filename)
This commit is contained in:
parent
0d9dc9414d
commit
da2c497671
|
@ -1001,6 +1001,24 @@ bool Document::saveAs(const char* file)
|
|||
return save();
|
||||
}
|
||||
|
||||
bool Document::saveCopy(const char* file)
|
||||
{
|
||||
std::string originalFileName = this->FileName.getStrValue();
|
||||
std::string originalLabel = this->Label.getStrValue();
|
||||
Base::FileInfo fi(file);
|
||||
if (this->FileName.getStrValue() != file) {
|
||||
this->FileName.setValue(file);
|
||||
this->Label.setValue(fi.fileNamePure());
|
||||
this->Uid.touch(); // this forces a rename of the transient directory
|
||||
bool result = save();
|
||||
this->FileName.setValue(originalFileName);
|
||||
this->Label.setValue(originalLabel);
|
||||
this->Uid.touch();
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the document under the name it has been opened
|
||||
bool Document::save (void)
|
||||
{
|
||||
|
|
|
@ -139,6 +139,7 @@ public:
|
|||
/// Save the document to the file in Property Path
|
||||
bool save (void);
|
||||
bool saveAs(const char* file);
|
||||
bool saveCopy(const char* file);
|
||||
/// Restore the document from the file in Property Path
|
||||
void restore (void);
|
||||
void exportObjects(const std::vector<App::DocumentObject*>&, std::ostream&);
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
<UserDocu>Save the document under a new name to disk</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="saveCopy">
|
||||
<Documentation>
|
||||
<UserDocu>Save a copy of the document under a new name to disk</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="load">
|
||||
<Documentation>
|
||||
<UserDocu>Load the document from the given path</UserDocu>
|
||||
|
|
|
@ -88,6 +88,25 @@ PyObject* DocumentPy::saveAs(PyObject * args)
|
|||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::saveCopy(PyObject * args)
|
||||
{
|
||||
char* fn;
|
||||
if (!PyArg_ParseTuple(args, "s", &fn)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!getDocumentPtr()->saveCopy(fn)) {
|
||||
PyErr_Format(PyExc_ValueError, "Object attribute 'FileName' is not set");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Base::FileInfo fi(fn);
|
||||
if (!fi.isReadable()) {
|
||||
PyErr_Format(PyExc_IOError, "No such file or directory: '%s'", fn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::load(PyObject * args)
|
||||
{
|
||||
char* filename=0;
|
||||
|
|
|
@ -476,6 +476,38 @@ bool StdCmdSaveAs::isActive(void)
|
|||
return getGuiApplication()->sendHasMsgToActiveView("SaveAs");
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Std_SaveCopy
|
||||
//===========================================================================
|
||||
DEF_STD_CMD_A(StdCmdSaveCopy);
|
||||
|
||||
StdCmdSaveCopy::StdCmdSaveCopy()
|
||||
:Command("Std_SaveCopy")
|
||||
{
|
||||
sGroup = QT_TR_NOOP("File");
|
||||
sMenuText = QT_TR_NOOP("Save a &Copy...");
|
||||
sToolTipText = QT_TR_NOOP("Save a copy of the active document under a new file name");
|
||||
sWhatsThis = "Std_SaveCopy";
|
||||
sStatusTip = QT_TR_NOOP("Save a copy of the active document under a new file name");
|
||||
//sPixmap = "document-save-as";
|
||||
}
|
||||
|
||||
void StdCmdSaveCopy::activated(int iMsg)
|
||||
{
|
||||
#if 0
|
||||
Gui::Document* pActiveDoc = getActiveGuiDocument();
|
||||
if ( pActiveDoc )
|
||||
pActiveDoc->saveCopy();
|
||||
else
|
||||
#endif
|
||||
doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"SaveCopy\")");
|
||||
}
|
||||
|
||||
bool StdCmdSaveCopy::isActive(void)
|
||||
{
|
||||
return ( getActiveGuiDocument() ? true : false );
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Std_Revert
|
||||
//===========================================================================
|
||||
|
@ -1327,6 +1359,7 @@ void CreateDocCommands(void)
|
|||
|
||||
rcCmdMgr.addCommand(new StdCmdSave());
|
||||
rcCmdMgr.addCommand(new StdCmdSaveAs());
|
||||
rcCmdMgr.addCommand(new StdCmdSaveCopy());
|
||||
rcCmdMgr.addCommand(new StdCmdRevert());
|
||||
rcCmdMgr.addCommand(new StdCmdProjectInfo());
|
||||
rcCmdMgr.addCommand(new StdCmdProjectUtil());
|
||||
|
|
|
@ -644,6 +644,33 @@ bool Document::saveAs(void)
|
|||
}
|
||||
}
|
||||
|
||||
/// Save a copy of the document under a new file name
|
||||
bool Document::saveCopy(void)
|
||||
{
|
||||
getMainWindow()->showMessage(QObject::tr("Save a copy of the document under new filename..."));
|
||||
|
||||
QString exe = qApp->applicationName();
|
||||
QString fn = FileDialog::getSaveFileName(getMainWindow(), QObject::tr("Save %1 Document").arg(exe),
|
||||
QString(), QObject::tr("%1 document (*.FCStd)").arg(exe));
|
||||
if (!fn.isEmpty()) {
|
||||
QFileInfo fi;
|
||||
fi.setFile(fn);
|
||||
|
||||
const char * DocName = App::GetApplication().getDocumentName(getDocument());
|
||||
|
||||
// save as new file name
|
||||
Gui::WaitCursor wc;
|
||||
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").saveCopy(\"%s\")"
|
||||
, DocName, (const char*)fn.toUtf8());
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
getMainWindow()->showMessage(QObject::tr("Saving aborted"), 2000);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Document::getMemSize (void) const
|
||||
{
|
||||
unsigned int size = 0;
|
||||
|
|
|
@ -120,6 +120,8 @@ public:
|
|||
bool save(void);
|
||||
/// Save the document under a new file name
|
||||
bool saveAs(void);
|
||||
/// Save a copy of the document under a new file name
|
||||
bool saveCopy(void);
|
||||
/// This method is used to save properties or very small amounts of data to an XML document.
|
||||
virtual void Save (Base::Writer &writer) const;
|
||||
/// This method is used to restore properties from an XML document.
|
||||
|
|
|
@ -701,6 +701,10 @@ bool View3DInventor::onMsg(const char* pMsg, const char** ppReturn)
|
|||
getGuiDocument()->saveAs();
|
||||
return true;
|
||||
}
|
||||
else if (strcmp("SaveCopy",pMsg) == 0) {
|
||||
getGuiDocument()->saveCopy();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -711,6 +715,8 @@ bool View3DInventor::onHasMsg(const char* pMsg) const
|
|||
return true;
|
||||
else if (strcmp("SaveAs",pMsg) == 0)
|
||||
return true;
|
||||
else if (strcmp("SaveCopy",pMsg) == 0)
|
||||
return true;
|
||||
else if (strcmp("Undo",pMsg) == 0) {
|
||||
App::Document* doc = getAppDocument();
|
||||
return doc && doc->getAvailableUndos() > 0;
|
||||
|
|
|
@ -468,8 +468,8 @@ MenuItem* StdWorkbench::setupMenuBar() const
|
|||
file->setCommand("&File");
|
||||
*file << "Std_New" << "Std_Open" << "Separator" << "Std_CloseActiveWindow"
|
||||
<< "Std_CloseAllWindows" << "Separator" << "Std_Save" << "Std_SaveAs"
|
||||
<< "Std_Revert" << "Separator" << "Std_Import" << "Std_Export"
|
||||
<< "Std_MergeProjects" << "Std_ProjectInfo"
|
||||
<< "Std_SaveCopy" << "Std_Revert" << "Separator" << "Std_Import"
|
||||
<< "Std_Export" << "Std_MergeProjects" << "Std_ProjectInfo"
|
||||
<< "Separator" << "Std_Print" << "Std_PrintPreview" << "Std_PrintPdf"
|
||||
<< "Separator" << "Std_RecentFiles" << "Separator" << "Std_Quit";
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user