mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-23 13:54:54 +02:00
Code simplification
This commit is contained in:
parent
592bd76244
commit
a53c25499e
@ -465,7 +465,19 @@ ScintillaKeyDefinition scintKeyDefs[] = { //array of accelerator keys for all po
|
||||
};
|
||||
|
||||
|
||||
static int strVal(const TCHAR *str, int base) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace // anonymous namespace
|
||||
{
|
||||
|
||||
static int strVal(const TCHAR *str, int base)
|
||||
{
|
||||
if (!str) return -1;
|
||||
if (!str[0]) return 0;
|
||||
|
||||
@ -474,17 +486,21 @@ static int strVal(const TCHAR *str, int base) {
|
||||
if (*finStr != '\0')
|
||||
return -1;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
static int decStrVal(const TCHAR *str) {
|
||||
|
||||
static int decStrVal(const TCHAR *str)
|
||||
{
|
||||
return strVal(str, 10);
|
||||
};
|
||||
}
|
||||
|
||||
static int hexStrVal(const TCHAR *str) {
|
||||
static int hexStrVal(const TCHAR *str)
|
||||
{
|
||||
return strVal(str, 16);
|
||||
};
|
||||
}
|
||||
|
||||
static int getKwClassFromName(const TCHAR *str) {
|
||||
static int getKwClassFromName(const TCHAR *str)
|
||||
{
|
||||
if (!lstrcmp(TEXT("instre1"), str)) return LANG_INDEX_INSTR;
|
||||
if (!lstrcmp(TEXT("instre2"), str)) return LANG_INDEX_INSTR2;
|
||||
if (!lstrcmp(TEXT("type1"), str)) return LANG_INDEX_TYPE;
|
||||
@ -497,7 +513,13 @@ static int getKwClassFromName(const TCHAR *str) {
|
||||
return str[0] - '0';
|
||||
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
wstring LocalizationSwitcher::getLangFromXmlFileName(const wchar_t *fn) const
|
||||
@ -1351,12 +1373,149 @@ void NppParameters::destroyInstance()
|
||||
_pSelf = NULL;
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::saveConfig_xml()
|
||||
{
|
||||
if (_pXmlUserDoc)
|
||||
_pXmlUserDoc->SaveFile();
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::setWorkSpaceFilePath(int i, const TCHAR* wsFile)
|
||||
{
|
||||
if (i < 0 || i > 2 || !wsFile)
|
||||
return;
|
||||
_workSpaceFilePathes[i] = wsFile;
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::removeTransparent(HWND hwnd)
|
||||
{
|
||||
if (hwnd != NULL)
|
||||
::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) & ~0x00080000);
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::SetTransparent(HWND hwnd, int percent)
|
||||
{
|
||||
if (!_transparentFuncAddr)
|
||||
return;
|
||||
|
||||
::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) | 0x00080000);
|
||||
if (percent > 255)
|
||||
percent = 255;
|
||||
if (percent < 0)
|
||||
percent = 0;
|
||||
_transparentFuncAddr(hwnd, 0, percent, 0x00000002);
|
||||
}
|
||||
|
||||
|
||||
bool NppParameters::isExistingExternalLangName(const TCHAR *newName) const
|
||||
{
|
||||
if ((!newName) || (!newName[0]))
|
||||
return true;
|
||||
|
||||
for (int i = 0 ; i < _nbExternalLang ; ++i)
|
||||
{
|
||||
if (!lstrcmp(_externalLangArray[i]->_name, newName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const TCHAR* NppParameters::getUserDefinedLangNameFromExt(TCHAR *ext, TCHAR *fullName) const
|
||||
{
|
||||
if ((!ext) || (!ext[0]))
|
||||
return nullptr;
|
||||
|
||||
std::vector<generic_string> extVect;
|
||||
for (int i = 0 ; i < _nbUserLang ; ++i)
|
||||
{
|
||||
extVect.clear();
|
||||
cutString(_userLangArray[i]->_ext.c_str(), extVect);
|
||||
|
||||
for (size_t j = 0, len = extVect.size(); j < len; ++j)
|
||||
{
|
||||
if (!generic_stricmp(extVect[j].c_str(), ext) || (_tcschr(fullName, '.') && !generic_stricmp(extVect[j].c_str(), fullName)))
|
||||
return _userLangArray[i]->_name.c_str();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
int NppParameters::getExternalLangIndexFromName(const TCHAR* externalLangName) const
|
||||
{
|
||||
for (int i = 0 ; i < _nbExternalLang ; ++i)
|
||||
{
|
||||
if (!lstrcmp(externalLangName, _externalLangArray[i]->_name))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
UserLangContainer* NppParameters::getULCFromName(const TCHAR *userLangName)
|
||||
{
|
||||
for (int i = 0 ; i < _nbUserLang ; ++i)
|
||||
{
|
||||
if (0 == lstrcmp(userLangName, _userLangArray[i]->_name.c_str()))
|
||||
return _userLangArray[i];
|
||||
}
|
||||
|
||||
//qui doit etre jamais passer
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
COLORREF NppParameters::getCurLineHilitingColour()
|
||||
{
|
||||
int i = _widgetStyleArray.getStylerIndexByName(TEXT("Current line background colour"));
|
||||
if (i == -1)
|
||||
return i;
|
||||
Style & style = _widgetStyleArray.getStyler(i);
|
||||
return style._bgColor;
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::setCurLineHilitingColour(COLORREF colour2Set)
|
||||
{
|
||||
int i = _widgetStyleArray.getStylerIndexByName(TEXT("Current line background colour"));
|
||||
if (i == -1)
|
||||
return;
|
||||
|
||||
Style& style = _widgetStyleArray.getStyler(i);
|
||||
style._bgColor = colour2Set;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int CALLBACK EnumFontFamExProc(const LOGFONT* lpelfe, const TEXTMETRIC*, DWORD, LPARAM lParam)
|
||||
{
|
||||
std::vector<generic_string>& strVect = *(std::vector<generic_string> *)lParam;
|
||||
const size_t vectSize = strVect.size();
|
||||
const TCHAR* lfFaceName = ((ENUMLOGFONTEX*)lpelfe)->elfLogFont.lfFaceName;
|
||||
|
||||
//Search through all the fonts, EnumFontFamiliesEx never states anything about order
|
||||
//Start at the end though, that's the most likely place to find a duplicate
|
||||
for (int i = vectSize - 1 ; i >= 0 ; i--)
|
||||
{
|
||||
if (0 == lstrcmp(strVect[i].c_str(), lfFaceName))
|
||||
return 1; //we already have seen this typeface, ignore it
|
||||
}
|
||||
|
||||
//We can add the font
|
||||
//Add the face name and not the full name, we do not care about any styles
|
||||
strVect.push_back(lfFaceName);
|
||||
return 1; // I want to get all fonts
|
||||
}
|
||||
|
||||
void NppParameters::setFontList(HWND hWnd)
|
||||
{
|
||||
//---------------//
|
||||
// Sys font list //
|
||||
//---------------//
|
||||
|
||||
LOGFONT lf;
|
||||
_fontlist.clear();
|
||||
_fontlist.push_back(TEXT(""));
|
||||
@ -1365,7 +1524,6 @@ void NppParameters::setFontList(HWND hWnd)
|
||||
lf.lfFaceName[0]='\0';
|
||||
lf.lfPitchAndFamily = 0;
|
||||
HDC hDC = ::GetDC(hWnd);
|
||||
|
||||
::EnumFontFamiliesEx(hDC, &lf, EnumFontFamExProc, (LPARAM)&_fontlist, 0);
|
||||
}
|
||||
|
||||
@ -2623,6 +2781,7 @@ void NppParameters::insertCmd(TiXmlNode *shortcutsRoot, const CommandShortcut &
|
||||
sc->ToElement()->SetAttribute(TEXT("Key"), key._key);
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & macro)
|
||||
{
|
||||
const KeyCombo & key = macro.getKeyCombo();
|
||||
@ -2632,6 +2791,7 @@ void NppParameters::insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & mac
|
||||
macroRoot->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no"));
|
||||
macroRoot->ToElement()->SetAttribute(TEXT("Shift"), key._isShift?TEXT("yes"):TEXT("no"));
|
||||
macroRoot->ToElement()->SetAttribute(TEXT("Key"), key._key);
|
||||
|
||||
for (size_t i = 0, len = macro._macro.size(); i < len ; ++i)
|
||||
{
|
||||
TiXmlNode *actionNode = macroRoot->InsertEndChild(TiXmlElement(TEXT("Action")));
|
||||
@ -2644,6 +2804,7 @@ void NppParameters::insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & mac
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::insertUserCmd(TiXmlNode *userCmdRoot, const UserCommand & userCmd)
|
||||
{
|
||||
const KeyCombo & key = userCmd.getKeyCombo();
|
||||
@ -2656,6 +2817,7 @@ void NppParameters::insertUserCmd(TiXmlNode *userCmdRoot, const UserCommand & us
|
||||
cmdRoot->InsertEndChild(TiXmlText(userCmd._cmd.c_str()));
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::insertPluginCmd(TiXmlNode *pluginCmdRoot, const PluginCmdShortcut & pluginCmd)
|
||||
{
|
||||
const KeyCombo & key = pluginCmd.getKeyCombo();
|
||||
@ -2668,6 +2830,7 @@ void NppParameters::insertPluginCmd(TiXmlNode *pluginCmdRoot, const PluginCmdSho
|
||||
pluginCmdNode->ToElement()->SetAttribute(TEXT("Key"), key._key);
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMap & scintKeyMap)
|
||||
{
|
||||
TiXmlNode *keyRoot = scintKeyRoot->InsertEndChild(TiXmlElement(TEXT("ScintKey")));
|
||||
@ -2683,9 +2846,11 @@ void NppParameters::insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMa
|
||||
|
||||
//Add additional shortcuts
|
||||
size_t size = scintKeyMap.getSize();
|
||||
if (size > 1) {
|
||||
if (size > 1)
|
||||
{
|
||||
TiXmlNode * keyNext;
|
||||
for(size_t i = 1; i < size; ++i) {
|
||||
for (size_t i = 1; i < size; ++i)
|
||||
{
|
||||
keyNext = keyRoot->InsertEndChild(TiXmlElement(TEXT("NextKey")));
|
||||
key = scintKeyMap.getKeyComboByIndex(i);
|
||||
keyNext->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no"));
|
||||
@ -2696,6 +2861,7 @@ void NppParameters::insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMa
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
|
||||
{
|
||||
const TCHAR *pathName = fileName?fileName:_sessionPath.c_str();
|
||||
@ -2760,9 +2926,9 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
|
||||
}
|
||||
}
|
||||
_pXmlSessionDoc->SaveFile();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::writeShortcuts()
|
||||
{
|
||||
if (!_pXmlShortcutDoc)
|
||||
@ -2833,10 +2999,12 @@ void NppParameters::writeShortcuts()
|
||||
_pXmlShortcutDoc->SaveFile();
|
||||
}
|
||||
|
||||
|
||||
int NppParameters::addUserLangToEnd(const UserLangContainer & userLang, const TCHAR *newName)
|
||||
{
|
||||
if (isExistingUserLangName(newName))
|
||||
return -1;
|
||||
|
||||
_userLangArray[_nbUserLang] = new UserLangContainer();
|
||||
*(_userLangArray[_nbUserLang]) = userLang;
|
||||
_userLangArray[_nbUserLang]->_name = newName;
|
||||
@ -2844,6 +3012,7 @@ int NppParameters::addUserLangToEnd(const UserLangContainer & userLang, const TC
|
||||
return _nbUserLang-1;
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::removeUserLang(int index)
|
||||
{
|
||||
if (index >= _nbUserLang )
|
||||
@ -2854,6 +3023,7 @@ void NppParameters::removeUserLang(int index)
|
||||
_nbUserLang--;
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::feedUserSettings(TiXmlNode *settingsRoot)
|
||||
{
|
||||
const TCHAR *boolStr;
|
||||
@ -2902,11 +3072,12 @@ void NppParameters::feedUserSettings(TiXmlNode *settingsRoot)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::feedUserKeywordList(TiXmlNode *node)
|
||||
{
|
||||
const TCHAR * udlVersion = _userLangArray[_nbUserLang - 1]->_udlVersion.c_str();
|
||||
const TCHAR * keywordsName = NULL;
|
||||
TCHAR *kwl = NULL;
|
||||
const TCHAR * keywordsName = nullptr;
|
||||
TCHAR *kwl = nullptr;
|
||||
int id = -1;
|
||||
|
||||
for (TiXmlNode *childNode = node->FirstChildElement(TEXT("Keywords"));
|
||||
@ -2914,7 +3085,7 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node)
|
||||
childNode = childNode->NextSibling(TEXT("Keywords")))
|
||||
{
|
||||
keywordsName = (childNode->ToElement())->Attribute(TEXT("name"));
|
||||
kwl = NULL;
|
||||
kwl = nullptr;
|
||||
|
||||
TiXmlNode *valueNode = childNode->FirstChild();
|
||||
if (valueNode)
|
||||
@ -3067,8 +3238,8 @@ void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexer
|
||||
childNode ;
|
||||
childNode = childNode->NextSibling(TEXT("WordsStyle")) )
|
||||
{
|
||||
|
||||
if (!ls.hasEnoughSpace()) return;
|
||||
if (!ls.hasEnoughSpace())
|
||||
return;
|
||||
|
||||
TiXmlElement *element = childNode->ToElement();
|
||||
const TCHAR *styleIDStr = element->Attribute(TEXT("styleID"));
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user