📄 parameters.cpp.svn-base
字号:
childNode && (_nbUserLang < NB_MAX_USER_LANG);
childNode = childNode->NextSibling("UserLang") )
{
const char *name = (childNode->ToElement())->Attribute("name");
const char *ext = (childNode->ToElement())->Attribute("ext");
try {
if (!name || !name[0] || !ext) throw int(missingName);
_userLangArray[_nbUserLang] = new UserLangContainer(name, ext);
_nbUserLang++;
TiXmlNode *settingsRoot = childNode->FirstChildElement("Settings");
if (!settingsRoot) throw int(loadFailed);
feedUserSettings(settingsRoot);
TiXmlNode *keywordListsRoot = childNode->FirstChildElement("KeywordLists");
if (!keywordListsRoot) throw int(loadFailed);
feedUserKeywordList(keywordListsRoot);
TiXmlNode *stylesRoot = childNode->FirstChildElement("Styles");
if (!stylesRoot) throw int(loadFailed);
feedUserStyles(stylesRoot);
} catch (int e) {
if (e == loadFailed)
delete _userLangArray[--_nbUserLang];
}
}
}
void NppParameters::writeUserDefinedLang()
{
if (!_pXmlUserLangDoc)
{
//do the treatment
_pXmlUserLangDoc = new TiXmlDocument(_userDefineLangPath);
}
//before remove the branch, we allocate and copy the char * which will be destroyed
stylerStrOp(DUP);
TiXmlNode *root = _pXmlUserLangDoc->FirstChild("NotepadPlus");
if (root)
{
_pXmlUserLangDoc->RemoveChild(root);
}
_pXmlUserLangDoc->InsertEndChild(TiXmlElement("NotepadPlus"));
root = _pXmlUserLangDoc->FirstChild("NotepadPlus");
for (int i = 0 ; i < _nbUserLang ; i++)
{
insertUserLang2Tree(root, _userLangArray[i]);
}
_pXmlUserLangDoc->SaveFile();
stylerStrOp(FREE);
}
void NppParameters::insertCmd(TiXmlNode *shortcutsRoot, const CommandShortcut & cmd)
{
TiXmlNode *sc = shortcutsRoot->InsertEndChild(TiXmlElement("Shortcut"));
sc->ToElement()->SetAttribute("name", cmd._name);
sc->ToElement()->SetAttribute("id", cmd.getID());
sc->ToElement()->SetAttribute("Ctrl", cmd._isCtrl?"yes":"no");
sc->ToElement()->SetAttribute("Alt", cmd._isAlt?"yes":"no");
sc->ToElement()->SetAttribute("Shift", cmd._isShift?"yes":"no");
sc->ToElement()->SetAttribute("Key", cmd._key);
}
void NppParameters::insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & macro)
{
TiXmlNode *macroRoot = macrosRoot->InsertEndChild(TiXmlElement("Macro"));
macroRoot->ToElement()->SetAttribute("name", macro._name);
macroRoot->ToElement()->SetAttribute("Ctrl", macro._isCtrl?"yes":"no");
macroRoot->ToElement()->SetAttribute("Alt", macro._isAlt?"yes":"no");
macroRoot->ToElement()->SetAttribute("Shift", macro._isShift?"yes":"no");
macroRoot->ToElement()->SetAttribute("Key", macro._key);
for (size_t i = 0 ; i < macro._macro.size() ; i++)
{
TiXmlNode *actionNode = macroRoot->InsertEndChild(TiXmlElement("Action"));
const recordedMacroStep & action = macro._macro[i];
actionNode->ToElement()->SetAttribute("type", action.MacroType);
actionNode->ToElement()->SetAttribute("message", action.message);
actionNode->ToElement()->SetAttribute("wParam", action.wParameter);
actionNode->ToElement()->SetAttribute("lParam", action.lParameter);
actionNode->ToElement()->SetAttribute("sParam", action.sParameter.c_str());
}
}
void NppParameters::insertUserCmd(TiXmlNode *userCmdRoot, const UserCommand & userCmd)
{
TiXmlNode *cmdRoot = userCmdRoot->InsertEndChild(TiXmlElement("Command"));
cmdRoot->ToElement()->SetAttribute("name", userCmd._name);
cmdRoot->ToElement()->SetAttribute("Ctrl", userCmd._isCtrl?"yes":"no");
cmdRoot->ToElement()->SetAttribute("Alt", userCmd._isAlt?"yes":"no");
cmdRoot->ToElement()->SetAttribute("Shift", userCmd._isShift?"yes":"no");
cmdRoot->ToElement()->SetAttribute("Key", userCmd._key);
cmdRoot->InsertEndChild(TiXmlText(userCmd._cmd.c_str()));
}
void NppParameters::insertPluginCmd(TiXmlNode *pluginCmdRoot, const PluginCmdShortcut & pluginCmd)
{
TiXmlNode *pluginCmdNode = pluginCmdRoot->InsertEndChild(TiXmlElement("PluginCommand"));
pluginCmdNode->ToElement()->SetAttribute("moduleName", pluginCmd._moduleName);
pluginCmdNode->ToElement()->SetAttribute("internalID", pluginCmd._internalID);
pluginCmdNode->ToElement()->SetAttribute("Ctrl", pluginCmd._isCtrl?"yes":"no");
pluginCmdNode->ToElement()->SetAttribute("Alt", pluginCmd._isAlt?"yes":"no");
pluginCmdNode->ToElement()->SetAttribute("Shift", pluginCmd._isShift?"yes":"no");
pluginCmdNode->ToElement()->SetAttribute("Key", pluginCmd._key);
}
void NppParameters::insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMap & scintKeyMap)
{
TiXmlNode *keyRoot = scintKeyRoot->InsertEndChild(TiXmlElement("ScintKey"));
keyRoot->ToElement()->SetAttribute("name", scintKeyMap._name);
keyRoot->ToElement()->SetAttribute("id", scintKeyMap.getID());
keyRoot->ToElement()->SetAttribute("Ctrl", scintKeyMap._isCtrl?"yes":"no");
keyRoot->ToElement()->SetAttribute("Alt", scintKeyMap._isAlt?"yes":"no");
keyRoot->ToElement()->SetAttribute("Shift", scintKeyMap._isShift?"yes":"no");
keyRoot->ToElement()->SetAttribute("Key", scintKeyMap._key);
keyRoot->ToElement()->SetAttribute("ScintID", scintKeyMap.getScintillaKey());
keyRoot->ToElement()->SetAttribute("menuCmdID", scintKeyMap.getMenuCmdID());
}
void NppParameters::writeSession(const Session & session, const char *fileName)
{
const char *pathName = fileName?fileName:_sessionPath;
_pXmlSessionDoc = new TiXmlDocument(pathName);
TiXmlNode *root = _pXmlSessionDoc->InsertEndChild(TiXmlElement("NotepadPlus"));
if (root)
{
TiXmlNode *sessionNode = root->InsertEndChild(TiXmlElement("Session"));
(sessionNode->ToElement())->SetAttribute("actifIndex", (int)session._actifIndex);
for (size_t i = 0 ; i < session._files.size() ; i++)
{
TiXmlNode *fileNameNode = sessionNode->InsertEndChild(TiXmlElement("File"));
(fileNameNode->ToElement())->SetAttribute("firstVisibleLine", session._files[i]._firstVisibleLine);
(fileNameNode->ToElement())->SetAttribute("xOffset", session._files[i]._xOffset);
(fileNameNode->ToElement())->SetAttribute("startPos", session._files[i]._startPos);
(fileNameNode->ToElement())->SetAttribute("endPos", session._files[i]._endPos);
TiXmlText fileNameFullPath(session._files[i]._fileName.c_str());
fileNameNode->InsertEndChild(fileNameFullPath);
for (size_t j = 0 ; j < session._files[i].marks.size() ; j++)
{
size_t markLine = session._files[i].marks[j];
TiXmlNode *markNode = fileNameNode->InsertEndChild(TiXmlElement("Mark"));
markNode->ToElement()->SetAttribute("line", markLine);
}
}
}
_pXmlSessionDoc->SaveFile();
}
void NppParameters::writeShortcuts(bool rewriteCmdSc, bool rewriteMacrosSc, bool rewriteUserCmdSc, bool rewriteScintillaKey, bool rewritePluginCmdSc)
{
if (!_pXmlShortcutDoc)
{
//do the treatment
_pXmlShortcutDoc = new TiXmlDocument(_shortcutsPath);
}
TiXmlNode *root = _pXmlShortcutDoc->FirstChild("NotepadPlus");
if (!root)
{
root = _pXmlShortcutDoc->InsertEndChild(TiXmlElement("NotepadPlus"));
//root = _pXmlShortcutDoc->FirstChild("NotepadPlus");
}
if (rewriteCmdSc)
{
TiXmlNode *cmdRoot = root->FirstChild("InternalCommands");
if (cmdRoot)
root->RemoveChild(cmdRoot);
cmdRoot = root->InsertEndChild(TiXmlElement("InternalCommands"));
for (size_t i = 0 ; i < _shortcuts.size() ; i++)
{
insertCmd(cmdRoot, _shortcuts[i]);
}
}
if (rewriteMacrosSc)
{
TiXmlNode *macrosRoot = root->FirstChild("Macros");
if (macrosRoot)
root->RemoveChild(macrosRoot);
macrosRoot = root->InsertEndChild(TiXmlElement("Macros"));
for (size_t i = 0 ; i < _macros.size() ; i++)
{
insertMacro(macrosRoot, _macros[i]);
}
}
if (rewriteUserCmdSc)
{
TiXmlNode *userCmdRoot = root->FirstChild("UserDefinedCommands");
if (userCmdRoot)
root->RemoveChild(userCmdRoot);
userCmdRoot = root->InsertEndChild(TiXmlElement("UserDefinedCommands"));
for (size_t i = 0 ; i < _userCommands.size() ; i++)
{
insertUserCmd(userCmdRoot, _userCommands[i]);
}
}
if (rewriteScintillaKey)
{
TiXmlNode *scitillaKeyRoot = root->FirstChild("ScintillaKeys");
if (scitillaKeyRoot)
root->RemoveChild(scitillaKeyRoot);
scitillaKeyRoot = root->InsertEndChild(TiXmlElement("ScintillaKeys"));
for (size_t i = 0 ; i < _scintillaModifiedKeys.size() ; i++)
{
insertScintKey(scitillaKeyRoot, _scintillaModifiedKeys[i]);
}
}
if (rewritePluginCmdSc)
{
TiXmlNode *pluginCmdRoot = root->FirstChild("PluginCommands");
if (pluginCmdRoot)
root->RemoveChild(pluginCmdRoot);
pluginCmdRoot = root->InsertEndChild(TiXmlElement("PluginCommands"));
for (size_t i = 0 ; i < _pluginCustomizedCmds.size() ; i++)
{
insertPluginCmd(pluginCmdRoot, _pluginCustomizedCmds[i]);
}
}
if (rewriteCmdSc || rewriteMacrosSc || rewriteUserCmdSc || rewriteScintillaKey || rewritePluginCmdSc)
_pXmlShortcutDoc->SaveFile();
}
int NppParameters::addUserLangToEnd(const UserLangContainer & userLang, const char *newName)
{
if (isExistingUserLangName(newName))
return -1;
_userLangArray[_nbUserLang] = new UserLangContainer();
*(_userLangArray[_nbUserLang]) = userLang;
strcpy(_userLangArray[_nbUserLang]->_name, newName);
_nbUserLang++;
return _nbUserLang-1;
}
void NppParameters::removeUserLang(int index)
{
if (index >= _nbUserLang )
return;
delete _userLangArray[index];
for (int i = index ; i < (_nbUserLang - 1) ; i++)
_userLangArray[i] = _userLangArray[i+1];
_nbUserLang--;
}
int NppParameters::getIndexFromKeywordListName(const char *name)
{
if (!name) return -1;
if (!strcmp(name, "Folder+")) return 1;
else if (!strcmp(name, "Folder-")) return 2;
else if (!strcmp(name, "Operators"))return 3;
else if (!strcmp(name, "Comment")) return 4;
else if (!strcmp(name, "Words1")) return 5;
else if (!strcmp(name, "Words2")) return 6;
else if (!strcmp(name, "Words3")) return 7;
else if (!strcmp(name, "Words4")) return 8;
else if (!strcmp(name, "Delimiters")) return 0;
else return -1;
}
void NppParameters::feedUserSettings(TiXmlNode *settingsRoot)
{
const char *boolStr;
TiXmlNode *globalSettingNode = settingsRoot->FirstChildElement("Global");
if (globalSettingNode)
{
boolStr = (globalSettingNode->ToElement())->Attribute("caseIgnored");
if (boolStr)
_userLangArray[_nbUserLang - 1]->_isCaseIgnored = !strcmp("yes", boolStr);
}
TiXmlNode *treatAsSymbolNode = settingsRoot->FirstChildElement("TreatAsSymbol");
if (treatAsSymbolNode)
{
boolStr = (treatAsSymbolNode->ToElement())->Attribute("comment");
if (boolStr)
_userLangArray[_nbUserLang - 1]->_isCommentSymbol = !strcmp("yes", boolStr);
boolStr = (treatAsSymbolNode->ToElement())->Attribute("commentLine");
if (boolStr)
_userLangArray[_nbUserLang - 1]->_isCommentLineSymbol = !strcmp("yes", boolStr);
}
TiXmlNode *prefixNode = settingsRoot->FirstChildElement("Prefix");
if (prefixNode)
{
char names[nbPrefixListAllowed][7] = {"words1","words2","words3","words4"};
for (int i = 0 ; i < nbPrefixListAllowed ; i++)
{
boolStr = (prefixNode->ToElement())->Attribute(names[i]);
if (boolStr)
_userLangArray[_nbUserLang - 1]->_isPrefix[i] = !strcmp("yes", boolStr);
}
}
}
void NppParameters::feedUserKeywordList(TiXmlNode *node)
{
for (TiXmlNode *childNode = node->FirstChildElement("Keywords");
childNode ;
childNode = childNode->NextSibling("Keywords"))
{
const char *keywordsName = (childNode->ToElement())->Attribute("name");
int i = getIndexFromKeywordListName(keywordsName);
if (i != -1)
{
TiXmlNode *valueNode = childNode->FirstChild();
const char *kwl = (valueNode)?valueNode->Value():(strcmp(keywordsName, "Delimiters")?"":"000000");
strcpy(_userLangArray[_nbUserLang - 1]->_keywordLists[i], kwl);
}
}
}
void NppParameters::feedUserStyles(TiXmlNode *node)
{
for (TiXmlNode *childNode = node->FirstChildElement("WordsStyle");
childNode ;
childNode = childNode->NextSibling("WordsStyle"))
{
int id;
const char *styleIDStr = (childNode->ToElement())->Attribute("styleID", &id);
if (styleIDStr)
{
_userLangArray[_nbUserLang - 1]->_styleArray.addStyler(id, childNode);
}
}
}
bool NppParameters::feedStylerArray(TiXmlNode *node)
{
TiXmlNode *styleRoot = node->FirstChildElement("LexerStyles");
if (!styleRoot) return false;
// For each lexer
for (TiXmlNode *childNode = styleRoot->FirstChildElement("LexerType");
childNode ;
childNode = childNode->NextSibling("LexerType") )
{
if (!_lexerStylerArray.hasEnoughSpace()) return false;
TiXmlElement *element = childNode->ToElement();
const char *lexerName = element->Attribute("name");
const char *lexerDesc = element->Attribute("desc");
const char *lexerUserExt = element->Attribute("ext");
if (lexerName)
{
_lexerStylerArray.addLexerStyler(lexerName, lexerDesc, lexerUserExt, childNode);
}
}
// The global styles for all lexers
TiXmlNode *globalStyleRoot = node->FirstChildElement("GlobalStyles");
if (!globalStyleRoot) return false;
for (TiXmlNode *childNode = globalStyleRoot->FirstChildElement("WidgetStyle");
childNode ;
childNode = childNode->NextSibling("WidgetStyle") )
{
if (!_widgetStyleArray.hasEnoughSpace()) return false;
TiXmlElement *element = childNode->ToElement();
const char *styleIDStr = element->Attribute("styleID");
int styleID = -1;
if ((styleID = decStrVal(styleIDStr)) != -1)
{
_widgetStyleArray.addStyler(styleID, childNode);
}
}
return true;
}
void LexerStylerArray::addLexerStyler(const char *lexerName, const char *lexerDesc, const char *lexerUserExt , TiXmlNode *lexerNode)
{
LexerStyler & ls = _lexerStylerArray[_nbLexerStyler++];
ls.setLexerName(lexerName);
if (lexerDesc)
ls.setLexerDesc(lexerDesc);
if (lexerUserExt)
ls.setLexerUserExt(lexerUserExt);
for (TiXmlNode *childNode = lexerNode->FirstChildElement("WordsStyle");
childNode ;
childNode = childNode->NextSibling("WordsStyle") )
{
if (!ls.hasEnoughSpace()) return;
TiXmlElement *element = childNode->ToElement();
const char *styleIDStr = element->Attribute("styleID");
if (styleIDStr)
{
int styleID = -1;
if ((styleID = decStrVal(styleIDStr)) != -1)
{
ls.addStyler(styleID, childNode);
}
}
}
}
void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
{
_styleArray[_nbStyler]._styleID = styleID;
if (styleNode)
{
TiXmlElement *element = styleNode->ToElement();
// Pour _fgColor, _bgColor :
// RGB() | (result & 0xFF000000) c'est pour le cas de -1 (0xFFFFFFFF)
// retourn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -