diff --git a/src/App/Document.cpp b/src/App/Document.cpp index be4ba45be..a146f997b 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -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) { diff --git a/src/App/Document.h b/src/App/Document.h index 51f1703e0..af66cbcfc 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -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&, std::ostream&); diff --git a/src/App/DocumentPy.xml b/src/App/DocumentPy.xml index 4eb38bfc5..28810cd3f 100644 --- a/src/App/DocumentPy.xml +++ b/src/App/DocumentPy.xml @@ -23,6 +23,11 @@ Save the document under a new name to disk + + + Save a copy of the document under a new name to disk + + Load the document from the given path diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp index 8fcf53547..51b98fedc 100644 --- a/src/App/DocumentPyImp.cpp +++ b/src/App/DocumentPyImp.cpp @@ -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; diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index f1dc3b46f..f89dd9189 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -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()); diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 74096bf7e..d01edf979 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -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; diff --git a/src/Gui/Document.h b/src/Gui/Document.h index 936c4fe43..21bee19ff 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -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. diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index 6aa73ee59..4f0e0e0f2 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -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; diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index 6b38b4de5..f1bae17cb 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -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";