MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / Paste

Method Paste

src/App/PropertyFile.cpp:528–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526}
527
528void PropertyFileIncluded::Paste(const Property& from)
529{
530 aboutToSetValue();
531 const PropertyFileIncluded& prop = dynamic_cast<const PropertyFileIncluded&>(from);
532 // make sure that source and destination file are different
533 if (_cValue != prop._cValue) {
534 // delete old file (if still there)
535 Base::FileInfo fi(_cValue);
536 fi.setPermissions(Base::FileInfo::ReadWrite);
537 fi.deleteFile();
538
539 // get path to destination which can be the transient directory
540 // of another document
541 std::string pathTrans = getDocTransientPath();
542 Base::FileInfo fiSrc(prop._cValue);
543 Base::FileInfo fiDst(pathTrans + "/" + prop._BaseFileName);
544 std::string path = fiSrc.dirPath();
545
546 if (fiSrc.exists()) {
547 fiDst.setFile(getUniqueFileName(fiDst.dirPath(), fiDst.fileName()));
548
549 // if the file is already in transient dir of the document, just use it
550 if (path == pathTrans) {
551 if (!fiSrc.renameFile(fiDst.filePath().c_str())) {
552 std::stringstream str;
553 str << "PropertyFileIncluded::Paste(): "
554 << "Renaming the file '" << fiSrc.filePath() << "' to '" << fiDst.filePath()
555 << "' failed.";
556 throw Base::FileSystemError(str.str());
557 }
558 }
559 else {
560 if (!fiSrc.copyTo(fiDst.filePath().c_str())) {
561 std::stringstream str;
562 str << "PropertyFileIncluded::Paste(): "
563 << "Copying the file '" << fiSrc.filePath() << "' to '" << fiDst.filePath()
564 << "' failed.";
565 throw Base::FileSystemError(str.str());
566 }
567 }
568
569 // set the file again read-only
570 fiDst.setPermissions(Base::FileInfo::ReadOnly);
571 _cValue = fiDst.filePath();
572 }
573 else {
574 _cValue.clear();
575 }
576
577 // set the base name
578 _BaseFileName = prop._BaseFileName;
579 }
580 hasSetValue();
581}
582
583unsigned int PropertyFileIncluded::getMemSize() const
584{

Callers

nothing calls this directly

Calls 13

FileSystemErrorFunction · 0.85
setPermissionsMethod · 0.80
dirPathMethod · 0.80
renameFileMethod · 0.80
deleteFileMethod · 0.45
existsMethod · 0.45
setFileMethod · 0.45
fileNameMethod · 0.45
c_strMethod · 0.45
filePathMethod · 0.45
strMethod · 0.45
copyToMethod · 0.45

Tested by

no test coverage detected