[BUG_FIXED] (Author: Andreas Jonsson) Fix saving file fails silently bug.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@953 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
37efb3f8ea
commit
f1a2acd85f
@ -31,6 +31,7 @@
|
||||
#include "FileDialog.h"
|
||||
#include "EncodingMapper.h"
|
||||
#include "VerticalFileSwitcher.h"
|
||||
#include <TCHAR.h>
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user