[BUG_FIXED] Fix the crash issue while the length of config.xml is zero.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@72 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2007-11-13 17:29:59 +00:00
parent a89f6010de
commit 07c17d7c44
5 changed files with 101 additions and 81 deletions

View File

@ -5279,6 +5279,27 @@ bool Notepad_plus::doStreamComment()
return true;
}
bool Notepad_plus::saveScintillaParams(bool whichOne)
{
ScintillaViewParams svp;
ScintillaEditView *pView = (whichOne == SCIV_PRIMARY)?&_mainEditView:&_subEditView;
svp._lineNumberMarginShow = pView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER);
svp._bookMarkMarginShow = pView->hasMarginShowed(ScintillaEditView::_SC_MARGE_SYBOLE);
svp._indentGuideLineShow = pView->isShownIndentGuide();
svp._folderStyle = pView->getFolderStyle();
svp._currentLineHilitingShow = pView->isCurrentLineHiLiting();
svp._wrapSymbolShow = pView->isWrapSymbolVisible();
svp._doWrap = pView->isWrap();
svp._edgeMode = int(pView->execute(SCI_GETEDGEMODE));
svp._edgeNbColumn = int(pView->execute(SCI_GETEDGECOLUMN));
svp._zoom = int(pView->execute(SCI_GETZOOM));
svp._whiteSpaceShow = pView->isInvisibleCharsShown();
svp._eolShow = pView->isEolVisible();
return (NppParameters::getInstance())->writeScintillaParams(svp, whichOne);
}
bool Notepad_plus::addCurrentMacro()
{
vector<MacroShortcut> & theMacros = (NppParameters::getInstance())->getMacroList();
@ -6834,7 +6855,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_pluginsManager.notify(&scnN);
_lastRecentFileList.saveLRFL();
saveScintillaParams(SCIV_PRIMARY);
saveScintillaParams(SCIV_SECOND);
saveGUIParams();

View File

@ -143,26 +143,9 @@ public:
bool doReload(const char *fileName, bool alert = true);
void saveScintillaParams(bool whichOne) {
ScintillaViewParams svp;
ScintillaEditView *pView = (whichOne == SCIV_PRIMARY)?&_mainEditView:&_subEditView;
bool saveScintillaParams(bool whichOne);
svp._lineNumberMarginShow = pView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER);
svp._bookMarkMarginShow = pView->hasMarginShowed(ScintillaEditView::_SC_MARGE_SYBOLE);
svp._indentGuideLineShow = pView->isShownIndentGuide();
svp._folderStyle = pView->getFolderStyle();
svp._currentLineHilitingShow = pView->isCurrentLineHiLiting();
svp._wrapSymbolShow = pView->isWrapSymbolVisible();
svp._doWrap = pView->isWrap();
svp._edgeMode = int(pView->execute(SCI_GETEDGEMODE));
svp._edgeNbColumn = int(pView->execute(SCI_GETEDGECOLUMN));
svp._zoom = int(pView->execute(SCI_GETZOOM));
svp._whiteSpaceShow = pView->isInvisibleCharsShown();
svp._eolShow = pView->isEolVisible();
(NppParameters::getInstance())->writeScintillaParams(svp, whichOne);
};
void saveGUIParams(){
bool saveGUIParams(){
NppGUI & nppGUI = (NppGUI &)(NppParameters::getInstance())->getNppGUI();
nppGUI._statusBarShow = _statusBar.isVisible();
nppGUI._toolBarStatus = _toolBar.getState();
@ -193,7 +176,7 @@ public:
saveDockingParams();
(NppParameters::getInstance())->writeGUIParams();
return (NppParameters::getInstance())->writeGUIParams();
};
void saveDockingParams() {

View File

@ -1467,14 +1467,20 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
_nbStyler++;
}
void NppParameters::writeHistory(const char *fullpath)
bool NppParameters::writeHistory(const char *fullpath)
{
TiXmlNode *historyNode = (_pXmlUserDoc->FirstChild("NotepadPlus"))->FirstChildElement("History");
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild("NotepadPlus");
if (!nppRoot) return false;
TiXmlNode *historyNode = nppRoot->FirstChildElement("History");
if (!historyNode) return false;
TiXmlElement recentFileNode("File");
TiXmlText fileNameFullPath(fullpath);
recentFileNode.InsertEndChild(fileNameFullPath);
(historyNode->ToElement())->InsertEndChild(recentFileNode);
return true;
}
TiXmlNode * NppParameters::getChildElementByAttribut(TiXmlNode *pere, const char *childName,\
@ -2456,50 +2462,55 @@ void NppParameters::feedDockingManager(TiXmlNode *node)
}
}
void NppParameters::writeScintillaParams(const ScintillaViewParams & svp, bool whichOne)
bool NppParameters::writeScintillaParams(const ScintillaViewParams & svp, bool whichOne)
{
if (!_pXmlUserDoc) return;
if (!_pXmlUserDoc) return false;
const char *pViewName = (whichOne == SCIV_PRIMARY)?"ScintillaPrimaryView":"ScintillaSecondaryView";
TiXmlNode *configsRoot = (_pXmlUserDoc->FirstChild("NotepadPlus"))->FirstChildElement("GUIConfigs");
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild("NotepadPlus");
if (!nppRoot) return false;
TiXmlNode *configsRoot = nppRoot->FirstChildElement("GUIConfigs");
if (!configsRoot) return false;
TiXmlNode *scintNode = getChildElementByAttribut(configsRoot, "GUIConfig", "name", pViewName);
if (scintNode)
{
(scintNode->ToElement())->SetAttribute("lineNumberMargin", svp._lineNumberMarginShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("bookMarkMargin", svp._bookMarkMarginShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("indentGuideLine", svp._indentGuideLineShow?"show":"hide");
const char *pFolderStyleStr = (svp._folderStyle == FOLDER_STYLE_SIMPLE)?"simple":
(svp._folderStyle == FOLDER_STYLE_ARROW)?"arrow":
(svp._folderStyle == FOLDER_STYLE_CIRCLE)?"circle":"box";
(scintNode->ToElement())->SetAttribute("folderMarkStyle", pFolderStyleStr);
(scintNode->ToElement())->SetAttribute("currentLineHilitingShow", svp._currentLineHilitingShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("wrapSymbolShow", svp._wrapSymbolShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("Wrap", svp._doWrap?"yes":"no");
char *edgeStr = NULL;
if (svp._edgeMode == EDGE_NONE)
edgeStr = "no";
else if (svp._edgeMode == EDGE_LINE)
edgeStr = "line";
else
edgeStr = "background";
(scintNode->ToElement())->SetAttribute("edge", edgeStr);
(scintNode->ToElement())->SetAttribute("edgeNbColumn", svp._edgeNbColumn);
(scintNode->ToElement())->SetAttribute("zoom", svp._zoom);
(scintNode->ToElement())->SetAttribute("whiteSpaceShow", svp._whiteSpaceShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("eolShow", svp._eolShow?"show":"hide");
}
else {/*create one*/}
if (!scintNode) return false;
(scintNode->ToElement())->SetAttribute("lineNumberMargin", svp._lineNumberMarginShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("bookMarkMargin", svp._bookMarkMarginShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("indentGuideLine", svp._indentGuideLineShow?"show":"hide");
const char *pFolderStyleStr = (svp._folderStyle == FOLDER_STYLE_SIMPLE)?"simple":
(svp._folderStyle == FOLDER_STYLE_ARROW)?"arrow":
(svp._folderStyle == FOLDER_STYLE_CIRCLE)?"circle":"box";
(scintNode->ToElement())->SetAttribute("folderMarkStyle", pFolderStyleStr);
(scintNode->ToElement())->SetAttribute("currentLineHilitingShow", svp._currentLineHilitingShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("wrapSymbolShow", svp._wrapSymbolShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("Wrap", svp._doWrap?"yes":"no");
char *edgeStr = NULL;
if (svp._edgeMode == EDGE_NONE)
edgeStr = "no";
else if (svp._edgeMode == EDGE_LINE)
edgeStr = "line";
else
edgeStr = "background";
(scintNode->ToElement())->SetAttribute("edge", edgeStr);
(scintNode->ToElement())->SetAttribute("edgeNbColumn", svp._edgeNbColumn);
(scintNode->ToElement())->SetAttribute("zoom", svp._zoom);
(scintNode->ToElement())->SetAttribute("whiteSpaceShow", svp._whiteSpaceShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("eolShow", svp._eolShow?"show":"hide");
return true;
}
void NppParameters::writeGUIParams()
bool NppParameters::writeGUIParams()
{
if (!_pXmlUserDoc) return;
if (!_pXmlUserDoc) return false;
TiXmlNode *GUIRoot = (_pXmlUserDoc->FirstChild("NotepadPlus"))->FirstChildElement("GUIConfigs");
if (!GUIRoot)
{
return;
}
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild("NotepadPlus");
if (!nppRoot) return false;
TiXmlNode *GUIRoot = nppRoot->FirstChildElement("GUIConfigs");
if (!GUIRoot) return false;
bool autoDetectionExist = false;
bool checkHistoryFilesExist = false;
@ -2527,7 +2538,7 @@ void NppParameters::writeGUIParams()
{
TiXmlElement *element = childNode->ToElement();
const char *nm = element->Attribute("name");
if (!nm) {return;}
if (!nm) continue;
if (!strcmp(nm, "ToolBar"))
{
@ -2908,7 +2919,7 @@ void NppParameters::writeGUIParams()
}
insertDockingParamNode(GUIRoot);
return true;
}
void NppParameters::insertDockingParamNode(TiXmlNode *GUIRoot)

View File

@ -796,22 +796,27 @@ public:
return _svp[whichOne];
};
void writeNbHistoryFile(int nb) {
if (!_pXmlUserDoc) return;
TiXmlNode *historyNode = (_pXmlUserDoc->FirstChild("NotepadPlus"))->FirstChildElement("History");
if (historyNode)
(historyNode->ToElement())->SetAttribute("nbMaxFile", nb);
bool writeNbHistoryFile(int nb) {
if (!_pXmlUserDoc) return false;
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild("NotepadPlus");
if (!nppRoot) return false;
TiXmlNode *historyNode = nppRoot->FirstChildElement("History");
if (!historyNode) return false;
(historyNode->ToElement())->SetAttribute("nbMaxFile", nb);
return true;
};
void writeHistory(const char *fullpath);
bool writeHistory(const char *fullpath);
TiXmlNode * getChildElementByAttribut(TiXmlNode *pere, const char *childName,\
const char *attributName, const char *attributVal) const;
void writeScintillaParams(const ScintillaViewParams & svp, bool whichOne);
bool writeScintillaParams(const ScintillaViewParams & svp, bool whichOne);
void writeGUIParams();
bool writeGUIParams();
void writeStyles(LexerStylerArray & lexersStylers, StyleArray & globalStylers);

View File

@ -99,18 +99,19 @@ public :
void saveLRFL() const {
NppParameters *pNppParams = NppParameters::getInstance();
pNppParams->writeNbHistoryFile(_userMax);
// if user defined nb recent files smaller than the size of list,
// we just keep the newest ones
int decal = _lrfl.size() - _userMax;
decal = (decal >= 0)?decal:0;
stringList::const_iterator it = _lrfl.begin();
for (int i = 0 ; i < decal ; i++, it++);
for (int i = 0 ; it != _lrfl.end() && (i < _userMax) ; it++, i++)
if (pNppParams->writeNbHistoryFile(_userMax))
{
pNppParams->writeHistory(((const std::string)*it).c_str());
// if user defined nb recent files smaller than the size of list,
// we just keep the newest ones
int decal = _lrfl.size() - _userMax;
decal = (decal >= 0)?decal:0;
stringList::const_iterator it = _lrfl.begin();
for (int i = 0 ; i < decal ; i++, it++);
for (int i = 0 ; it != _lrfl.end() && (i < _userMax) ; it++, i++)
{
pNppParams->writeHistory(((const std::string)*it).c_str());
}
}
};