[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; 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() bool Notepad_plus::addCurrentMacro()
{ {
vector<MacroShortcut> & theMacros = (NppParameters::getInstance())->getMacroList(); 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); _pluginsManager.notify(&scnN);
_lastRecentFileList.saveLRFL(); _lastRecentFileList.saveLRFL();
saveScintillaParams(SCIV_PRIMARY); saveScintillaParams(SCIV_PRIMARY);
saveScintillaParams(SCIV_SECOND); saveScintillaParams(SCIV_SECOND);
saveGUIParams(); saveGUIParams();

View File

@ -143,26 +143,9 @@ public:
bool doReload(const char *fileName, bool alert = true); bool doReload(const char *fileName, bool alert = true);
void saveScintillaParams(bool whichOne) { bool saveScintillaParams(bool whichOne);
ScintillaViewParams svp;
ScintillaEditView *pView = (whichOne == SCIV_PRIMARY)?&_mainEditView:&_subEditView;
svp._lineNumberMarginShow = pView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER); bool saveGUIParams(){
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(){
NppGUI & nppGUI = (NppGUI &)(NppParameters::getInstance())->getNppGUI(); NppGUI & nppGUI = (NppGUI &)(NppParameters::getInstance())->getNppGUI();
nppGUI._statusBarShow = _statusBar.isVisible(); nppGUI._statusBarShow = _statusBar.isVisible();
nppGUI._toolBarStatus = _toolBar.getState(); nppGUI._toolBarStatus = _toolBar.getState();
@ -193,7 +176,7 @@ public:
saveDockingParams(); saveDockingParams();
(NppParameters::getInstance())->writeGUIParams(); return (NppParameters::getInstance())->writeGUIParams();
}; };
void saveDockingParams() { void saveDockingParams() {

View File

@ -1467,14 +1467,20 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
_nbStyler++; _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"); TiXmlElement recentFileNode("File");
TiXmlText fileNameFullPath(fullpath); TiXmlText fileNameFullPath(fullpath);
recentFileNode.InsertEndChild(fileNameFullPath); recentFileNode.InsertEndChild(fileNameFullPath);
(historyNode->ToElement())->InsertEndChild(recentFileNode); (historyNode->ToElement())->InsertEndChild(recentFileNode);
return true;
} }
TiXmlNode * NppParameters::getChildElementByAttribut(TiXmlNode *pere, const char *childName,\ TiXmlNode * NppParameters::getChildElementByAttribut(TiXmlNode *pere, const char *childName,\
@ -2456,15 +2462,20 @@ 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"; 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); TiXmlNode *scintNode = getChildElementByAttribut(configsRoot, "GUIConfig", "name", pViewName);
if (scintNode) if (!scintNode) return false;
{
(scintNode->ToElement())->SetAttribute("lineNumberMargin", svp._lineNumberMarginShow?"show":"hide"); (scintNode->ToElement())->SetAttribute("lineNumberMargin", svp._lineNumberMarginShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("bookMarkMargin", svp._bookMarkMarginShow?"show":"hide"); (scintNode->ToElement())->SetAttribute("bookMarkMargin", svp._bookMarkMarginShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("indentGuideLine", svp._indentGuideLineShow?"show":"hide"); (scintNode->ToElement())->SetAttribute("indentGuideLine", svp._indentGuideLineShow?"show":"hide");
@ -2487,19 +2498,19 @@ void NppParameters::writeScintillaParams(const ScintillaViewParams & svp, bool w
(scintNode->ToElement())->SetAttribute("zoom", svp._zoom); (scintNode->ToElement())->SetAttribute("zoom", svp._zoom);
(scintNode->ToElement())->SetAttribute("whiteSpaceShow", svp._whiteSpaceShow?"show":"hide"); (scintNode->ToElement())->SetAttribute("whiteSpaceShow", svp._whiteSpaceShow?"show":"hide");
(scintNode->ToElement())->SetAttribute("eolShow", svp._eolShow?"show":"hide"); (scintNode->ToElement())->SetAttribute("eolShow", svp._eolShow?"show":"hide");
}
else {/*create one*/} return true;
} }
void NppParameters::writeGUIParams() bool NppParameters::writeGUIParams()
{ {
if (!_pXmlUserDoc) return; if (!_pXmlUserDoc) return false;
TiXmlNode *GUIRoot = (_pXmlUserDoc->FirstChild("NotepadPlus"))->FirstChildElement("GUIConfigs"); TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild("NotepadPlus");
if (!GUIRoot) if (!nppRoot) return false;
{
return; TiXmlNode *GUIRoot = nppRoot->FirstChildElement("GUIConfigs");
} if (!GUIRoot) return false;
bool autoDetectionExist = false; bool autoDetectionExist = false;
bool checkHistoryFilesExist = false; bool checkHistoryFilesExist = false;
@ -2527,7 +2538,7 @@ void NppParameters::writeGUIParams()
{ {
TiXmlElement *element = childNode->ToElement(); TiXmlElement *element = childNode->ToElement();
const char *nm = element->Attribute("name"); const char *nm = element->Attribute("name");
if (!nm) {return;} if (!nm) continue;
if (!strcmp(nm, "ToolBar")) if (!strcmp(nm, "ToolBar"))
{ {
@ -2908,7 +2919,7 @@ void NppParameters::writeGUIParams()
} }
insertDockingParamNode(GUIRoot); insertDockingParamNode(GUIRoot);
return true;
} }
void NppParameters::insertDockingParamNode(TiXmlNode *GUIRoot) void NppParameters::insertDockingParamNode(TiXmlNode *GUIRoot)

View File

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

View File

@ -99,8 +99,8 @@ public :
void saveLRFL() const { void saveLRFL() const {
NppParameters *pNppParams = NppParameters::getInstance(); NppParameters *pNppParams = NppParameters::getInstance();
pNppParams->writeNbHistoryFile(_userMax); if (pNppParams->writeNbHistoryFile(_userMax))
{
// if user defined nb recent files smaller than the size of list, // if user defined nb recent files smaller than the size of list,
// we just keep the newest ones // we just keep the newest ones
int decal = _lrfl.size() - _userMax; int decal = _lrfl.size() - _userMax;
@ -112,6 +112,7 @@ public :
{ {
pNppParams->writeHistory(((const std::string)*it).c_str()); pNppParams->writeHistory(((const std::string)*it).c_str());
} }
}
}; };
private: private: