diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index aacba39d..d2121395 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -31,6 +31,7 @@ #include "FileDialog.h" #include "EncodingMapper.h" #include "VerticalFileSwitcher.h" +#include BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encoding) @@ -289,7 +290,8 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) _pluginsManager.notify(&scnN); } - bool res = MainFileManager->saveBuffer(id, filename, isCopy); + generic_string error_msg; + bool res = MainFileManager->saveBuffer(id, filename, isCopy, &error_msg); if (!isCopy) { @@ -298,11 +300,20 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) } if (!res) - _nativeLangSpeaker.messageBox("FileLockedWarning", - _pPublicInterface->getHSelf(), - TEXT("Please check if this file is opened in another program."), - TEXT("Save failed"), - MB_OK); + { + if(error_msg.empty()) + { + _nativeLangSpeaker.messageBox("FileLockedWarning", + _pPublicInterface->getHSelf(), + TEXT("Please check if this file is opened in another program."), + TEXT("Save failed"), + MB_OK); + } + else + { + ::MessageBox(_pPublicInterface->getHSelf(), error_msg.c_str(), TEXT("Save failed"), MB_OK); + } + } return res; } diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index b0c4c990..db58e20d 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -595,7 +595,7 @@ bool FileManager::moveFile(BufferID id, const TCHAR * newFileName) return true; } -bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) { +bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, generic_string * error_msg) { Buffer * buffer = getBufferByID(id); bool isHidden = false; bool isSys = false; @@ -636,9 +636,10 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) { int lengthDoc = _pscratchTilla->getCurrentDocLen(); char* buf = (char*)_pscratchTilla->execute(SCI_GETCHARACTERPOINTER); //to get characters directly from Scintilla buffer + size_t items_written = 0; if (encoding == -1) //no special encoding; can be handled directly by Utf8_16_Write { - UnicodeConvertor.fwrite(buf, lengthDoc); + items_written = UnicodeConvertor.fwrite(buf, lengthDoc); } else { @@ -654,11 +655,20 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) { int incompleteMultibyteChar = 0; const char *newData = wmc->encode(SC_CP_UTF8, encoding, buf+i, grabSize, &newDataLen, &incompleteMultibyteChar); grabSize -= incompleteMultibyteChar; - UnicodeConvertor.fwrite(newData, newDataLen); + items_written = UnicodeConvertor.fwrite(newData, newDataLen); } } UnicodeConvertor.fclose(); + // Error, we didn't write the entire document to disk. + // Note that fwrite() doesn't return the number of bytes written, but rather the number of ITEMS. + if(items_written != 1) + { + if(error_msg != NULL) + *error_msg = TEXT("Not enough space on disk to save file."); + return false; + } + if (isHidden) ::SetFileAttributes(fullpath, attrib | FILE_ATTRIBUTE_HIDDEN); diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 730ac67f..06c2a67b 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -101,7 +101,7 @@ public: bool reloadBuffer(BufferID id); bool reloadBufferDeferred(BufferID id); - bool saveBuffer(BufferID id, const TCHAR * filename, bool isCopy = false); + bool saveBuffer(BufferID id, const TCHAR * filename, bool isCopy = false, generic_string * error_msg = NULL); bool deleteFile(BufferID id); bool moveFile(BufferID id, const TCHAR * newFilename);