[BUG]Fix bug when pasting to bookmarked lines in Unicode version.

[BUG]Fix (temporary) memory leak when a file cannot be opened if it consumes too much memory.
Add string tokenizer routine in Common.
Update VS2003 project file for TinyXMLA.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@355 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
harrybharry 2008-11-19 13:19:50 +00:00
parent 8bd91ca178
commit 1cc93da80e
5 changed files with 102 additions and 46 deletions

View File

@ -121,6 +121,26 @@ void ClientRectToScreenRect(HWND hWnd, RECT* rect)
rect->bottom = pt.y;
};
std::vector<std::generic_string> tokenizeString(const std::generic_string & tokenString, const char delim) {
//Vector is created on stack and copied on return
std::vector<std::generic_string> tokens;
// Skip delimiters at beginning.
std::string::size_type lastPos = tokenString.find_first_not_of(delim, 0);
// Find first "non-delimiter".
std::string::size_type pos = tokenString.find_first_of(delim, lastPos);
while (pos != std::string::npos || lastPos != std::string::npos)
{
// Found a token, add it to the vector.
tokens.push_back(tokenString.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = tokenString.find_first_not_of(delim, pos);
// Find next "non-delimiter"
pos = tokenString.find_first_of(delim, lastPos);
}
return tokens;
}
void ScreenRectToClientRect(HWND hWnd, RECT* rect)
{

View File

@ -92,6 +92,7 @@ void writeLog(const TCHAR *logFileName, const TCHAR *log2write);
int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep);
int getCpFromStringValue(const char * encodingStr);
std::generic_string purgeMenuItemString(const TCHAR * menuItemStr, bool keepAmpersand = false);
std::vector<std::generic_string> tokenizeString(const std::generic_string & tokenString, const char delim);
void ClientRectToScreenRect(HWND hWnd, RECT* rect);
void ScreenRectToClientRect(HWND hWnd, RECT* rect);

View File

@ -617,10 +617,19 @@ private:
};
void pasteToMarkedLines() {
int clipFormat;
#ifdef UNICODE
clipFormat = CF_UNICODETEXT;
#else
clipFormat = CF_TEXT;
#endif
BOOL canPaste = ::IsClipboardFormatAvailable(clipFormat);
if (!canPaste)
return;
int lastLine = _pEditView->lastZeroBasedLineNumber();
::OpenClipboard(_hSelf);
HANDLE clipboardData = ::GetClipboardData(CF_TEXT);
HANDLE clipboardData = ::GetClipboardData(clipFormat);
int len = ::GlobalSize(clipboardData);
LPVOID clipboardDataPtr = ::GlobalLock(clipboardData);

View File

@ -338,8 +338,6 @@ void FileManager::init(Notepad_plus * pNotepadPlus, ScintillaEditView * pscratch
_pscratchTilla->execute(SCI_ADDREFDOCUMENT, 0, _scratchDocDefault);
}
void FileManager::checkFilesystemChanges() {
for(size_t i = 0; i < _nrBufs; i++) {
if (_buffers[i]->checkFileState()){} //something has changed. Triggers update automatically
@ -358,7 +356,6 @@ Buffer * FileManager::getBufferByIndex(int index) {
return _buffers.at(index);
}
void FileManager::beNotifiedOfBufferChange(Buffer * theBuf, int mask) {
_pNotepadPlus->notifyBufferChanged(theBuf, mask);
};
@ -384,8 +381,10 @@ void FileManager::closeBuffer(BufferID id, ScintillaEditView * identifier) {
}
BufferID FileManager::loadFile(const TCHAR * filename, Document doc) {
bool ownDoc = false;
if (doc == NULL) {
doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT);
ownDoc = true;
}
TCHAR fullpath[MAX_PATH];
@ -413,7 +412,8 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc) {
BufferID retval = _nextBufferID++;
return id;
} else { //failed loading, release document
_pscratchTilla->execute(SCI_RELEASEDOCUMENT, 0, doc); //Failure, so release document
if (ownDoc)
_pscratchTilla->execute(SCI_RELEASEDOCUMENT, 0, doc); //Failure, so release document
return BUFFER_INVALID;
}
}
@ -573,27 +573,27 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d
bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language) {
const int blockSize = 128 * 1024; //128 kB
char data[blockSize];
FILE *fp = generic_fopen(filename, TEXT("rb"));
if (!fp)
return false;
//Setup scratchtilla for new filedata
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc);
bool ro = _pscratchTilla->execute(SCI_GETREADONLY) != 0;
if (ro) {
_pscratchTilla->execute(SCI_SETREADONLY, false);
}
_pscratchTilla->execute(SCI_CLEARALL);
if (language < L_EXTERNAL) {
_pscratchTilla->execute(SCI_SETLEXER, ScintillaEditView::langNames[language].lexerID);
} else {
int id = language - L_EXTERNAL;
TCHAR * name = NppParameters::getInstance()->getELCFromIndex(id)._name;
_pscratchTilla->execute(SCI_SETLEXERLANGUAGE, 0, (LPARAM)name);
}
bool success = true;
__try {
FILE *fp = generic_fopen(filename, TEXT("rb"));
if (!fp)
return false;
//Setup scratchtilla for new filedata
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc);
bool ro = _pscratchTilla->execute(SCI_GETREADONLY) != 0;
if (ro) {
_pscratchTilla->execute(SCI_SETREADONLY, false);
}
_pscratchTilla->execute(SCI_CLEARALL);
if (language < L_EXTERNAL) {
_pscratchTilla->execute(SCI_SETLEXER, ScintillaEditView::langNames[language].lexerID);
} else {
int id = language - L_EXTERNAL;
TCHAR * name = NppParameters::getInstance()->getELCFromIndex(id)._name;
_pscratchTilla->execute(SCI_SETLEXERLANGUAGE, 0, (LPARAM)name);
}
size_t lenFile = 0;
size_t lenConvert = 0; //just in case conversion results in 0, but file not empty
do {
@ -601,22 +601,22 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Rea
lenConvert = UnicodeConvertor->convert(data, lenFile);
_pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf()));
} while (lenFile > 0);
fclose(fp);
_pscratchTilla->execute(SCI_EMPTYUNDOBUFFER);
_pscratchTilla->execute(SCI_SETSAVEPOINT);
if (ro) {
_pscratchTilla->execute(SCI_SETREADONLY, true);
}
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
return true;
}__except(filter(GetExceptionCode(), GetExceptionInformation())) {
} __except(filter(GetExceptionCode(), GetExceptionInformation())) {
printStr(TEXT("File is too big to be opened by Notepad++"));
return false;
}
success = false;
}
fclose(fp);
_pscratchTilla->execute(SCI_EMPTYUNDOBUFFER);
_pscratchTilla->execute(SCI_SETSAVEPOINT);
if (ro) {
_pscratchTilla->execute(SCI_SETREADONLY, true);
}
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
return success;
}
BufferID FileManager::getBufferFromName(const TCHAR * name) {
TCHAR fullpath[MAX_PATH];
::GetFullPathName(name, MAX_PATH, fullpath, NULL);

View File

@ -21,8 +21,8 @@
Name="VCCLCompilerTool"
AdditionalOptions="/EHa"
Optimization="0"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\Common;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;TIXML_USE_STL"
AdditionalIncludeDirectories="..\..\scintilla\include;..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\ScitillaComponent;..\src\TinyXml;..\src\TinyXml\tinyXmlA;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\Preference;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\WindowsDlg"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;TIXML_USE_STL;TIXMLA_USE_STL"
MinimalRebuild="TRUE"
ExceptionHandling="FALSE"
BasicRuntimeChecks="0"
@ -97,8 +97,8 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
FavorSizeOrSpeed="2"
OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\Common;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;TIXML_USE_STL"
AdditionalIncludeDirectories="..\..\scintilla\include;..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\ScitillaComponent;..\src\TinyXml;..\src\TinyXml\tinyXmlA;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\Preference;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\WindowsDlg"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;TIXML_USE_STL;TIXMLA_USE_STL"
StringPooling="TRUE"
ExceptionHandling="FALSE"
RuntimeLibrary="4"
@ -167,8 +167,8 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
Name="VCCLCompilerTool"
AdditionalOptions="/EHa"
Optimization="0"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\Common;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;TIXML_USE_STL"
AdditionalIncludeDirectories="..\..\scintilla\include;..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\ScitillaComponent;..\src\TinyXml;..\src\TinyXml\tinyXmlA;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\Preference;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\WindowsDlg"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;TIXML_USE_STL;TIXMLA_USE_STL"
MinimalRebuild="TRUE"
ExceptionHandling="FALSE"
BasicRuntimeChecks="0"
@ -244,8 +244,8 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
FavorSizeOrSpeed="2"
OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\Common;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;TIXML_USE_STL"
AdditionalIncludeDirectories="..\..\scintilla\include;..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\ScitillaComponent;..\src\TinyXml;..\src\TinyXml\tinyXmlA;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\Preference;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\WindowsDlg"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;TIXML_USE_STL;TIXMLA_USE_STL"
StringPooling="TRUE"
ExceptionHandling="FALSE"
RuntimeLibrary="4"
@ -409,6 +409,19 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
<File
RelativePath="..\src\TinyXml\tinyxmlparser.cpp">
</File>
<Filter
Name="TinyXMLA"
Filter="">
<File
RelativePath="..\src\TinyXml\tinyXmlA\tinystrA.cpp">
</File>
<File
RelativePath="..\src\TinyXml\tinyXmlA\tinyxmlA.cpp">
</File>
<File
RelativePath="..\src\TinyXml\tinyXmlA\tinyxmlerrorA.cpp">
</File>
</Filter>
</Filter>
<Filter
Name="WinControls"
@ -633,6 +646,19 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
<File
RelativePath="..\src\TinyXml\tinyxml.h">
</File>
<Filter
Name="TinyXMLA"
Filter="">
<File
RelativePath="..\src\TinyXml\tinyXmlA\tinystrA.h">
</File>
<File
RelativePath="..\src\TinyXml\tinyXmlA\tinyxmlA.h">
</File>
<File
RelativePath="..\src\TinyXml\tinyXmlA\tinyxmlparserA.cpp">
</File>
</Filter>
</Filter>
<Filter
Name="WinControls"