[BUG_FIXED] Fix ANSI replace/replace all bug.

[NEW_FEATURE] Add find/replace dialog memorize capacity.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@342 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2008-10-16 21:57:08 +00:00
parent d2c8c52c51
commit c16b93830a
7 changed files with 265 additions and 10 deletions

View File

@ -1414,6 +1414,12 @@ bool Notepad_plus::matchInList(const TCHAR *fileName, const vector<generic_strin
return false;
}
void Notepad_plus::saveFindHistory()
{
_findReplaceDlg.saveFindHistory();
(NppParameters::getInstance())->writeFindHistory();
}
void Notepad_plus::saveUserDefineLangs()
{
if (ScintillaEditView::getUserDefineDlg()->isDirty())
@ -7771,6 +7777,8 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
scnN.nmhdr.idFrom = 0;
_pluginsManager.notify(&scnN);
saveFindHistory();
_lastRecentFileList.saveLRFL();
saveScintillaParams(SCIV_PRIMARY);
saveScintillaParams(SCIV_SECOND);

View File

@ -153,6 +153,8 @@ public:
inline void saveSession(const Session & session);
inline void saveFindHistory();
void getCurrentOpenedFiles(Session & session);
bool fileLoadSession(const TCHAR *fn = NULL);

View File

@ -425,6 +425,11 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
_transparentFuncAddr(NULL), _enableThemeDialogTextureFuncAddr(NULL),\
_isTaskListRBUTTONUP_Active(false), _fileSaveDlgFilterIndex(-1), _asNotepadStyle(false)
{
_findHistory.nbFindHistoryPath = 0;
_findHistory.nbFindHistoryFilter = 0;
_findHistory.nbFindHistoryFind = 0;
_findHistory.nbFindHistoryReplace = 0;
//Get windows version
_winVersion = getWindowsVersion();
@ -906,6 +911,10 @@ bool NppParameters::getUserParametersFromXmlTree()
TiXmlElement HistoryNode(TEXT("History"));
root->InsertEndChild(HistoryNode);
//Find history
feedFindHistoryParameters(root);
return true;
}
@ -1298,6 +1307,77 @@ void NppParameters::feedFileListParameters(TiXmlNode *node)
}
}
void NppParameters::feedFindHistoryParameters(TiXmlNode *node)
{
_findHistory.nbMaxFindHistoryPath = 10;
_findHistory.nbMaxFindHistoryFilter = 10;
_findHistory.nbMaxFindHistoryFind = 10;
_findHistory.nbMaxFindHistoryReplace = 10;
TiXmlNode *findHistoryRoot = node->FirstChildElement(TEXT("FindHistory"));
if (!findHistoryRoot) return;
(findHistoryRoot->ToElement())->Attribute(TEXT("nbMaxFindHistoryPath"), &_findHistory.nbMaxFindHistoryPath);
if ((_findHistory.nbMaxFindHistoryPath > 0) && (_findHistory.nbMaxFindHistoryPath <= NB_MAX_FINDHISTORY_PATH))
{
for (TiXmlNode *childNode = findHistoryRoot->FirstChildElement(TEXT("Path"));
childNode && (_findHistory.nbFindHistoryPath < NB_MAX_FINDHISTORY_PATH);
childNode = childNode->NextSibling(TEXT("Path")) )
{
const TCHAR *filePath = (childNode->ToElement())->Attribute(TEXT("name"));
if (filePath)
{
_findHistory.FindHistoryPath[_findHistory.nbFindHistoryPath++] = new generic_string(filePath);
}
}
}
(findHistoryRoot->ToElement())->Attribute(TEXT("nbMaxFindHistoryFilter"), &_findHistory.nbMaxFindHistoryFilter);
if ((_findHistory.nbMaxFindHistoryFilter > 0) && (_findHistory.nbMaxFindHistoryFilter <= NB_MAX_FINDHISTORY_FILTER))
{
for (TiXmlNode *childNode = findHistoryRoot->FirstChildElement(TEXT("Filter"));
childNode && (_findHistory.nbFindHistoryFilter < NB_MAX_FINDHISTORY_FILTER);
childNode = childNode->NextSibling(TEXT("Filter")))
{
const TCHAR *fileFilter = (childNode->ToElement())->Attribute(TEXT("name"));
if (fileFilter)
{
_findHistory.FindHistoryFilter[_findHistory.nbFindHistoryFilter++] = new generic_string(fileFilter);
}
}
}
(findHistoryRoot->ToElement())->Attribute(TEXT("nbMaxFindHistoryFind"), &_findHistory.nbMaxFindHistoryFind);
if ((_findHistory.nbMaxFindHistoryFind > 0) && (_findHistory.nbMaxFindHistoryFind <= NB_MAX_FINDHISTORY_FIND))
{
for (TiXmlNode *childNode = findHistoryRoot->FirstChildElement(TEXT("Find"));
childNode && (_findHistory.nbFindHistoryFind < NB_MAX_FINDHISTORY_FIND);
childNode = childNode->NextSibling(TEXT("Find")))
{
const TCHAR *fileFind = (childNode->ToElement())->Attribute(TEXT("name"));
if (fileFind)
{
_findHistory.FindHistoryFind[_findHistory.nbFindHistoryFind++] = new generic_string(fileFind);
}
}
}
(findHistoryRoot->ToElement())->Attribute(TEXT("nbMaxFindHistoryReplace"), &_findHistory.nbMaxFindHistoryReplace);
if ((_findHistory.nbMaxFindHistoryReplace > 0) && (_findHistory.nbMaxFindHistoryReplace <= NB_MAX_FINDHISTORY_REPLACE))
{
for (TiXmlNode *childNode = findHistoryRoot->FirstChildElement(TEXT("Replace"));
childNode && (_findHistory.nbFindHistoryReplace < NB_MAX_FINDHISTORY_REPLACE);
childNode = childNode->NextSibling(TEXT("Replace")))
{
const TCHAR *fileReplace = (childNode->ToElement())->Attribute(TEXT("name"));
if (fileReplace)
{
_findHistory.FindHistoryReplace[_findHistory.nbFindHistoryReplace++] = new generic_string(fileReplace);
}
}
}
}
void NppParameters::feedShortcut(TiXmlNode *node)
{
TiXmlNode *shortcutsRoot = node->FirstChildElement(TEXT("InternalCommands"));
@ -3756,6 +3836,62 @@ bool NppParameters::writeGUIParams()
return true;
}
bool NppParameters::writeFindHistory()
{
if (!_pXmlUserDoc) return false;
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));
if (!nppRoot) return false;
TiXmlNode *findHistoryRoot = nppRoot->FirstChildElement(TEXT("FindHistory"));
if (!findHistoryRoot)
{
TiXmlElement element(TEXT("FindHistory"));
findHistoryRoot = nppRoot->InsertEndChild(element);
}
int i;
findHistoryRoot->Clear();
(findHistoryRoot->ToElement())->SetAttribute(TEXT("nbMaxFindHistoryPath"), _findHistory.nbMaxFindHistoryPath);
(findHistoryRoot->ToElement())->SetAttribute(TEXT("nbMaxFindHistoryFilter"), _findHistory.nbMaxFindHistoryFilter);
(findHistoryRoot->ToElement())->SetAttribute(TEXT("nbMaxFindHistoryFind"), _findHistory.nbMaxFindHistoryFind);
(findHistoryRoot->ToElement())->SetAttribute(TEXT("nbMaxFindHistoryReplace"), _findHistory.nbMaxFindHistoryReplace);
TiXmlElement hist_element(TEXT(""));
hist_element.SetValue(TEXT("Path"));
for (i = 0; i < _findHistory.nbFindHistoryPath; i++)
{
(hist_element.ToElement())->SetAttribute(TEXT("name"), _findHistory.FindHistoryPath[i]->c_str());
findHistoryRoot->InsertEndChild(hist_element);
}
hist_element.SetValue(TEXT("Filter"));
for (i = 0; i < _findHistory.nbFindHistoryFilter; i++)
{
(hist_element.ToElement())->SetAttribute(TEXT("name"), _findHistory.FindHistoryFilter[i]->c_str());
findHistoryRoot->InsertEndChild(hist_element);
}
hist_element.SetValue(TEXT("Find"));
for (i = 0; i < _findHistory.nbFindHistoryFind; i++)
{
(hist_element.ToElement())->SetAttribute(TEXT("name"), _findHistory.FindHistoryFind[i]->c_str());
findHistoryRoot->InsertEndChild(hist_element);
}
hist_element.SetValue(TEXT("Replace"));
for (i = 0; i < _findHistory.nbFindHistoryReplace; i++)
{
(hist_element.ToElement())->SetAttribute(TEXT("name"), _findHistory.FindHistoryReplace[i]->c_str());
findHistoryRoot->InsertEndChild(hist_element);
}
return true;
}
void NppParameters::insertDockingParamNode(TiXmlNode *GUIRoot)
{
TiXmlElement DMNode(TEXT("GUIConfig"));

View File

@ -642,6 +642,11 @@ const int NB_MAX_USER_LANG = 30;
const int NB_MAX_EXTERNAL_LANG = 30;
const int LANG_NAME_LEN = 32;
const int NB_MAX_FINDHISTORY_FIND = 30;
const int NB_MAX_FINDHISTORY_REPLACE = 30;
const int NB_MAX_FINDHISTORY_PATH = 30;
const int NB_MAX_FINDHISTORY_FILTER = 20;
struct Lang
{
LangType _langID;
@ -775,6 +780,24 @@ public:
};
};
struct FindHistory {
int nbMaxFindHistoryPath;
int nbMaxFindHistoryFilter;
int nbMaxFindHistoryFind;
int nbMaxFindHistoryReplace;
int nbFindHistoryPath;
int nbFindHistoryFilter;
int nbFindHistoryFind;
int nbFindHistoryReplace;
generic_string *FindHistoryPath[NB_MAX_FINDHISTORY_PATH];
generic_string *FindHistoryFilter[NB_MAX_FINDHISTORY_FILTER];
generic_string *FindHistoryFind[NB_MAX_FINDHISTORY_FIND];
generic_string *FindHistoryReplace[NB_MAX_FINDHISTORY_REPLACE];
};
const int NB_LANG = 80;
const bool DUP = true;
@ -927,6 +950,7 @@ public:
void writeUserDefinedLang();
void writeShortcuts();
void writeSession(const Session & session, const TCHAR *fileName = NULL);
bool writeFindHistory();
bool isExistingUserLangName(const TCHAR *newName) const {
@ -1086,8 +1110,9 @@ public:
}
bool getContextMenuFromXmlTree(HMENU mainMenuHadle);
winVer getWinVersion() { return _winVersion;};
FindHistory & getFindHistory() {return _findHistory;};
private:
NppParameters();
~NppParameters();
@ -1108,6 +1133,8 @@ private:
int _nbFile;
int _nbMaxFile;
FindHistory _findHistory;
UserLangContainer *_userLangArray[NB_MAX_USER_LANG];
int _nbUserLang;
TCHAR _userDefineLangPath[MAX_PATH];
@ -1194,6 +1221,7 @@ private:
void feedFileListParameters(TiXmlNode *node);
void feedScintillaParam(bool whichOne, TiXmlNode *node);
void feedDockingManager(TiXmlNode *node);
void feedFindHistoryParameters(TiXmlNode *node);
bool feedStylerArray(TiXmlNode *node);
void getAllWordStyles(TCHAR *lexerName, TiXmlNode *lexerNode);

View File

@ -252,6 +252,7 @@ generic_string FindReplaceDlg::getTextFromCombo(HWND hCombo, bool isUnicode) con
{
::SendMessage(hCombo, WM_GETTEXT, MAX_PATH - 1, (LPARAM)str);
}
#endif
return generic_string(str);
}
@ -310,6 +311,8 @@ void FindReplaceDlg::create(int dialogID, bool isRTL)
_tab.reSizeTo(rect);
_tab.display();
fillFindHistory();
ETDTProc enableDlgTheme = (ETDTProc)::SendMessage(_hParent, NPPM_GETENABLETHEMETEXTUREFUNC, 0, 0);
if (enableDlgTheme)
enableDlgTheme(_hSelf, ETDT_ENABLETAB);
@ -317,14 +320,76 @@ void FindReplaceDlg::create(int dialogID, bool isRTL)
goToCenter();
}
void FindReplaceDlg::fillFindHistory()
{
FindHistory& findHistory = (NppParameters::getInstance())->getFindHistory();
fillComboHistory(IDD_FINDINFILES_DIR_COMBO, findHistory.nbFindHistoryPath, findHistory.FindHistoryPath);
fillComboHistory(IDD_FINDINFILES_FILTERS_COMBO, findHistory.nbFindHistoryFilter, findHistory.FindHistoryFilter);
fillComboHistory(IDFINDWHAT, findHistory.nbFindHistoryFind, findHistory.FindHistoryFind);
fillComboHistory(IDREPLACEWITH, findHistory.nbFindHistoryReplace, findHistory.FindHistoryReplace);
}
void FindReplaceDlg::fillComboHistory(int id, int count, generic_string **pStrings)
{
int i;
bool isUnicode = false;
HWND hCombo;
hCombo = ::GetDlgItem(_hSelf, id);
for (i = 0; i < count; i++)
{
addText2Combo(pStrings[i]->c_str(), hCombo, isUnicode);
}
::SendMessage(hCombo, CB_SETCURSEL, 0, 0); // select first item
}
void FindReplaceDlg::saveFindHistory()
{
if (! isCreated()) return;
FindHistory& findHistory = (NppParameters::getInstance())->getFindHistory();
saveComboHistory(IDD_FINDINFILES_DIR_COMBO, findHistory.nbMaxFindHistoryPath, findHistory.nbFindHistoryPath, findHistory.FindHistoryPath);
saveComboHistory(IDD_FINDINFILES_FILTERS_COMBO, findHistory.nbMaxFindHistoryFilter, findHistory.nbFindHistoryFilter, findHistory.FindHistoryFilter);
saveComboHistory(IDFINDWHAT, findHistory.nbMaxFindHistoryFind, findHistory.nbFindHistoryFind, findHistory.FindHistoryFind);
saveComboHistory(IDREPLACEWITH, findHistory.nbMaxFindHistoryReplace, findHistory.nbFindHistoryReplace, findHistory.FindHistoryReplace);
}
void FindReplaceDlg::saveComboHistory(int id, int maxcount, int& oldcount, generic_string **pStrings)
{
int i, count;
bool isUnicode = false;
HWND hCombo;
TCHAR text[500]; //yniq - any need for dynamic allocation?
hCombo = ::GetDlgItem(_hSelf, id);
count = ::SendMessage(hCombo, CB_GETCOUNT, 0, 0);
count = min(count, maxcount);
for (i = 0; i < count; i++)
{
::SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM) text);
if (i < oldcount)
*pStrings[i] = text;
else
pStrings[i] = new generic_string(text);
}
for (; i < oldcount; i++) delete pStrings[i];
oldcount = count;
}
void FindReplaceDlg::updateCombos()
{
/*
bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit;
HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH);
addText2Combo(getTextFromCombo(hReplaceCombo).c_str(), hReplaceCombo, isUnicode);
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
addText2Combo(getTextFromCombo(hFindCombo).c_str(), hFindCombo, isUnicode);
*/
updateCombo(IDREPLACEWITH);
updateCombo(IDFINDWHAT);
}
bool Finder::notify(SCNotification *notification)
@ -546,10 +611,11 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
{
if (_currentStatus == REPLACE_DLG)
{
bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit;
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH);
generic_string str2Search = getTextFromCombo(hFindCombo);
generic_string str2Replace = getTextFromCombo(hReplaceCombo);
generic_string str2Search = getTextFromCombo(hFindCombo, isUnicode);
generic_string str2Replace = getTextFromCombo(hReplaceCombo, isUnicode);
updateCombos();
processReplace(str2Search.c_str(), str2Replace.c_str());
}
@ -850,6 +916,7 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, FindOption *options)
int flags = Searching::buildSearchFlags(pOptions);
(*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags);
//::SendMessageA(_hParent, WM_SETTEXT, 0, (LPARAM)pText);
int posFind = (*_ppEditView)->searchInTarget(pText, startPosition, endPosition);
if (posFind == -1) //no match found in target, check if a new target should be used
{
@ -1048,32 +1115,40 @@ int FindReplaceDlg::processRange(ProcessOperation op, const TCHAR *txt2find, con
int stringSizeReplace = 0;
TCHAR *pTextFind = NULL;//new TCHAR[stringSizeFind + 1];
if (!txt2find) {
if (!txt2find)
{
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
generic_string str2Search = getTextFromCombo(hFindCombo, isUnicode);
stringSizeFind = str2Search.length();
pTextFind = new TCHAR[stringSizeFind + 1];
lstrcpy(pTextFind, str2Search.c_str());
} else {
}
else
{
stringSizeFind = lstrlen(txt2find);
pTextFind = new TCHAR[stringSizeFind + 1];
lstrcpy(pTextFind, txt2find);
}
if (!pTextFind[0]) {
if (!pTextFind[0])
{
delete [] pTextFind;
return nbProcessed;
}
TCHAR *pTextReplace = NULL;
if (op == ProcessReplaceAll) {
if (!txt2replace) {
if (op == ProcessReplaceAll)
{
if (!txt2replace)
{
HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH);
generic_string str2Replace = getTextFromCombo(hReplaceCombo, isUnicode);
stringSizeReplace = str2Replace.length();
pTextReplace = new TCHAR[stringSizeReplace + 1];
lstrcpy(pTextReplace, str2Replace.c_str());
} else {
}
else
{
stringSizeReplace = lstrlen(txt2replace);
pTextReplace = new TCHAR[stringSizeReplace + 1];
lstrcpy(pTextReplace, txt2replace);
@ -1231,6 +1306,8 @@ int FindReplaceDlg::processRange(ProcessOperation op, const TCHAR *txt2find, con
endRange += replaceDelta; //adjust end of range in case of replace
nbProcessed++;
//::SendMessageA(_hParent, WM_SETTEXT, 0, (LPARAM)pTextFind);
targetStart = (*_ppEditView)->searchInTarget(pTextFind, startRange, endRange);
}
delete [] pTextFind;

View File

@ -330,6 +330,7 @@ public :
_isFindingInFiles = false;
showFindInFilesButton();
};
void saveFindHistory();
protected :
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
@ -393,6 +394,9 @@ private :
HWND hCombo = ::GetDlgItem(_hSelf, comboID);
addText2Combo(getTextFromCombo(hCombo, isUnicode).c_str(), hCombo, isUnicode);
};
void fillFindHistory();
void fillComboHistory(int id, int count, generic_string **pStrings);
void saveComboHistory(int id, int maxcount, int& oldcount, generic_string **pStrings);
};
//FindIncrementDlg: incremental search dialog, docked in rebar

View File

@ -110,7 +110,7 @@
IntermediateDirectory="Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops;.\no_ms_shit.vsprops"
CharacterSet="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool