| 981 | } |
| 982 | |
| 983 | bool TextDocument::save( const std::string& path ) { |
| 984 | if ( path.empty() || mDefaultFileName == path || mSaving ) |
| 985 | return false; |
| 986 | mSaving = true; |
| 987 | if ( FileSystem::fileWrite( path, "" ) ) { |
| 988 | IOStreamFile file( path, "wb" ); |
| 989 | std::string oldFilePath( mFilePath ); |
| 990 | URI oldFileURI( mFileURI ); |
| 991 | FileInfo oldFileInfo( mFileRealPath ); |
| 992 | mFilePath = path; |
| 993 | mFileURI = URI( "file://" + mFilePath ); |
| 994 | if ( save( file ) ) { |
| 995 | file.close(); |
| 996 | mFileRealPath = |
| 997 | FileInfo::isLink( mFilePath ) ? FileInfo( mFilePath ).linksTo() : mFilePath; |
| 998 | mSaving = false; |
| 999 | notifyDocumentSaved(); |
| 1000 | return true; |
| 1001 | } else { |
| 1002 | mFilePath = std::move( oldFilePath ); |
| 1003 | mFileURI = std::move( oldFileURI ); |
| 1004 | mFileRealPath = std::move( oldFileInfo ); |
| 1005 | mSaving = false; |
| 1006 | } |
| 1007 | } |
| 1008 | return false; |
| 1009 | } |
| 1010 | |
| 1011 | bool TextDocument::save( IOStream& stream, bool keepUndoRedoStatus ) { |
| 1012 | if ( !stream.isOpen() || linesCount() == 0 ) |
no test coverage detected