Make number of languages and and styles unlimited and independent

A clean version of #10483 thanks to @ozone10 and @chcg.
The proper fix for #10206 without any compile-time limits.

Fix #10483, fix #10206, close #10491
This commit is contained in:
Ivan Ustûžanin 2021-08-31 21:58:12 +03:00 committed by Don Ho
parent d4781bd4a3
commit 156784722a
9 changed files with 277 additions and 551 deletions

View File

@ -681,13 +681,11 @@ LRESULT Notepad_plus::init(HWND hwnd)
// Initialize the default foreground & background color
//
{
StyleArray & globalStyles = nppParam.getGlobalStylers();
int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT);
if (i != -1)
const Style * pStyle = nppParam.getGlobalStylers().findByID(STYLE_DEFAULT);
if (pStyle)
{
Style & style = globalStyles.getStyler(i);
nppParam.setCurrentDefaultFgColor(style._fgColor);
nppParam.setCurrentDefaultBgColor(style._bgColor);
nppParam.setCurrentDefaultFgColor(pStyle->_fgColor);
nppParam.setCurrentDefaultBgColor(pStyle->_bgColor);
}
}
@ -2259,12 +2257,9 @@ void Notepad_plus::setupColorSampleBitmapsOnMainMenuItems()
for (int j = 0; j < sizeof(bitmapOnStyleMenuItemsInfo) / sizeof(bitmapOnStyleMenuItemsInfo[0]); ++j)
{
StyleArray& stylers = NppParameters::getInstance().getMiscStylerArray();
int iFind = stylers.getStylerIndexByID(bitmapOnStyleMenuItemsInfo[j].styleIndic);
if (iFind != -1)
const Style * pStyle = NppParameters::getInstance().getMiscStylerArray().findByID(bitmapOnStyleMenuItemsInfo[j].styleIndic);
if (pStyle)
{
Style const* pStyle = &(stylers.getStyler(iFind));
HDC hDC = GetDC(NULL);
const int bitmapXYsize = 16;
@ -6369,16 +6364,7 @@ generic_string Notepad_plus::getLangFromMenu(const Buffer * buf)
Style * Notepad_plus::getStyleFromName(const TCHAR *styleName)
{
StyleArray & stylers = (NppParameters::getInstance()).getMiscStylerArray();
int i = stylers.getStylerIndexByName(styleName);
Style * st = NULL;
if (i != -1)
{
Style & style = stylers.getStyler(i);
st = &style;
}
return st;
return NppParameters::getInstance().getMiscStylerArray().findByName(styleName);
}
bool Notepad_plus::noOpenedDoc() const

View File

@ -1796,67 +1796,68 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
drawDocumentMapColoursFromStylerArray();
// Update default fg/bg colors in Parameters for both internal/plugins docking dialog
StyleArray & globalStyles = (NppParameters::getInstance()).getGlobalStylers();
int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT);
Style & style = globalStyles.getStyler(i);
(NppParameters::getInstance()).setCurrentDefaultFgColor(style._fgColor);
(NppParameters::getInstance()).setCurrentDefaultBgColor(style._bgColor);
const Style * pStyle = NppParameters::getInstance().getGlobalStylers().findByID(STYLE_DEFAULT);
if (pStyle)
{
NppParameters::getInstance().setCurrentDefaultFgColor(pStyle->_fgColor);
NppParameters::getInstance().setCurrentDefaultBgColor(pStyle->_bgColor);
}
NppDarkMode::calculateTreeViewStyle();
auto refreshOnlyTreeView = static_cast<LPARAM>(TRUE);
// Set default fg/bg colors on internal docking dialog
if (_pFuncList)
if (pStyle && _pFuncList)
{
_pFuncList->setBackgroundColor(style._bgColor);
_pFuncList->setForegroundColor(style._fgColor);
_pFuncList->setBackgroundColor(pStyle->_bgColor);
_pFuncList->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pFuncList->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
if (_pAnsiCharPanel)
if (pStyle && _pAnsiCharPanel)
{
_pAnsiCharPanel->setBackgroundColor(style._bgColor);
_pAnsiCharPanel->setForegroundColor(style._fgColor);
_pAnsiCharPanel->setBackgroundColor(pStyle->_bgColor);
_pAnsiCharPanel->setForegroundColor(pStyle->_fgColor);
}
if (_pDocumentListPanel)
if (pStyle && _pDocumentListPanel)
{
_pDocumentListPanel->setBackgroundColor(style._bgColor);
_pDocumentListPanel->setForegroundColor(style._fgColor);
_pDocumentListPanel->setBackgroundColor(pStyle->_bgColor);
_pDocumentListPanel->setForegroundColor(pStyle->_fgColor);
}
if (_pClipboardHistoryPanel)
if (pStyle && _pClipboardHistoryPanel)
{
_pClipboardHistoryPanel->setBackgroundColor(style._bgColor);
_pClipboardHistoryPanel->setForegroundColor(style._fgColor);
_pClipboardHistoryPanel->setBackgroundColor(pStyle->_bgColor);
_pClipboardHistoryPanel->setForegroundColor(pStyle->_fgColor);
_pClipboardHistoryPanel->redraw(true);
}
if (_pProjectPanel_1)
if (pStyle && _pProjectPanel_1)
{
_pProjectPanel_1->setBackgroundColor(style._bgColor);
_pProjectPanel_1->setForegroundColor(style._fgColor);
_pProjectPanel_1->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_1->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_1->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
if (_pProjectPanel_2)
if (pStyle && _pProjectPanel_2)
{
_pProjectPanel_2->setBackgroundColor(style._bgColor);
_pProjectPanel_2->setForegroundColor(style._fgColor);
_pProjectPanel_2->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_2->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_2->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
if (_pProjectPanel_3)
if (pStyle && _pProjectPanel_3)
{
_pProjectPanel_3->setBackgroundColor(style._bgColor);
_pProjectPanel_3->setForegroundColor(style._fgColor);
_pProjectPanel_3->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_3->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_3->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
if (_pFileBrowser)
if (pStyle && _pFileBrowser)
{
_pFileBrowser->setBackgroundColor(style._bgColor);
_pFileBrowser->setForegroundColor(style._fgColor);
_pFileBrowser->setBackgroundColor(pStyle->_bgColor);
_pFileBrowser->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pFileBrowser->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
@ -2534,13 +2535,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
ScintillaViewParams &svp = const_cast<ScintillaViewParams &>(nppParam.getSVP());
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
COLORREF multiEdgeColor = liteGrey;
int i = stylers.getStylerIndexByName(TEXT("Edge colour"));
if (i != -1)
const Style * pStyle = NppParameters::getInstance().getMiscStylerArray().findByName(TEXT("Edge colour"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
multiEdgeColor = style._fgColor;
multiEdgeColor = pStyle->_fgColor;
}
const size_t twoPower13 = 8192;

View File

@ -926,8 +926,8 @@ bool NppParameters::reloadStylers(const TCHAR* stylePath)
_pXmlUserStylerDoc = NULL;
return false;
}
_lexerStylerVect.eraseAll();
_widgetStyleArray.setNbStyler( 0 );
_lexerStylerVect.clear();
_widgetStyleArray.clear();
getUserStylersFromXmlTree();
@ -1594,22 +1594,19 @@ UserLangContainer* NppParameters::getULCFromName(const TCHAR *userLangName)
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;
const Style * pStyle = _widgetStyleArray.findByName(TEXT("Current line background colour"));
if (!pStyle)
return COLORREF(-1);
return pStyle->_bgColor;
}
void NppParameters::setCurLineHilitingColour(COLORREF colour2Set)
{
int i = _widgetStyleArray.getStylerIndexByName(TEXT("Current line background colour"));
if (i == -1)
Style * pStyle = _widgetStyleArray.findByName(TEXT("Current line background colour"));
if (!pStyle)
return;
Style& style = _widgetStyleArray.getStyler(i);
style._bgColor = colour2Set;
pStyle->_bgColor = colour2Set;
}
@ -2774,11 +2771,11 @@ std::pair<unsigned char, unsigned char> NppParameters::feedUserLang(TiXmlNode *n
feedUserStyles(stylesRoot);
// styles that were not read from xml file should get default values
for (int i=0; i<SCE_USER_STYLE_TOTAL_STYLES; ++i)
for (int i = 0 ; i < SCE_USER_STYLE_TOTAL_STYLES ; ++i)
{
Style & style = _userLangArray[_nbUserLang - 1]->_styles.getStyler(i);
if (style._styleID == -1)
_userLangArray[_nbUserLang - 1]->_styles.addStyler(i, globalMappper().styleNameMapper[i].c_str());
const Style * pStyle = _userLangArray[_nbUserLang - 1]->_styles.findByID(i);
if (!pStyle)
_userLangArray[_nbUserLang - 1]->_styles.addStyler(i, globalMappper().styleNameMapper[i]);
}
}
@ -3098,12 +3095,8 @@ void NppParameters::writeNonDefaultUDL()
void NppParameters::writeNeed2SaveUDL()
{
stylerStrOp(DUP);
writeDefaultUDL();
writeNonDefaultUDL();
stylerStrOp(FREE);
}
@ -3570,8 +3563,6 @@ bool NppParameters::feedStylerArray(TiXmlNode *node)
childNode ;
childNode = childNode->NextSibling(TEXT("LexerType")) )
{
if (!_lexerStylerVect.hasEnoughSpace()) return false;
TiXmlElement *element = childNode->ToElement();
const TCHAR *lexerName = element->Attribute(TEXT("name"));
const TCHAR *lexerDesc = element->Attribute(TEXT("desc"));
@ -3597,8 +3588,6 @@ bool NppParameters::feedStylerArray(TiXmlNode *node)
childNode ;
childNode = childNode->NextSibling(TEXT("WidgetStyle")) )
{
if (!_widgetStyleArray.hasEnoughSpace()) return false;
TiXmlElement *element = childNode->ToElement();
const TCHAR *styleIDStr = element->Attribute(TEXT("styleID"));
@ -3613,7 +3602,8 @@ bool NppParameters::feedStylerArray(TiXmlNode *node)
void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt , TiXmlNode *lexerNode)
{
LexerStyler & ls = _lexerStylerVect[_nbLexerStyler++];
_lexerStylerVect.emplace_back();
LexerStyler & ls = _lexerStylerVect.back();
ls.setLexerName(lexerName);
if (lexerDesc)
ls.setLexerDesc(lexerDesc);
@ -3625,9 +3615,6 @@ void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexer
childNode ;
childNode = childNode->NextSibling(TEXT("WordsStyle")) )
{
if (!ls.hasEnoughSpace())
return;
TiXmlElement *element = childNode->ToElement();
const TCHAR *styleIDStr = element->Attribute(TEXT("styleID"));
@ -3642,35 +3629,19 @@ void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexer
}
}
void LexerStylerArray::eraseAll()
{
for (int i = 0 ; i < _nbLexerStyler ; ++i)
{
_lexerStylerVect[i].setNbStyler( 0 );
}
_nbLexerStyler = 0;
}
void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
{
int index = _nbStyler;
bool isUser = styleID >> 16 == L_USER;
if (isUser)
{
styleID = (styleID & 0xFFFF);
index = styleID;
if (index >= SCE_USER_STYLE_TOTAL_STYLES || _styleVect[index]._styleID != -1)
return;
}
else
{
if (index >= STYLE_ARR_MAX_SIZE)
if (styleID >= SCE_USER_STYLE_TOTAL_STYLES || findByID(styleID))
return;
}
_styleVect[index]._styleID = styleID;
_styleVect.emplace_back();
Style & s = _styleVect.back();
s._styleID = styleID;
if (styleNode)
{
@ -3684,16 +3655,16 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
if (str)
{
if (isUser)
_styleVect[index]._styleDesc = globalMappper().styleNameMapper[index].c_str();
s._styleDesc = globalMappper().styleNameMapper[styleID];
else
_styleVect[index]._styleDesc = str;
s._styleDesc = str;
}
str = element->Attribute(TEXT("fgColor"));
if (str)
{
unsigned long result = hexStrVal(str);
_styleVect[index]._fgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000);
s._fgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000);
}
@ -3701,49 +3672,51 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
if (str)
{
unsigned long result = hexStrVal(str);
_styleVect[index]._bgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000);
s._bgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000);
}
str = element->Attribute(TEXT("colorStyle"));
if (str)
{
_styleVect[index]._colorStyle = decStrVal(str);
s._colorStyle = decStrVal(str);
}
str = element->Attribute(TEXT("fontName"));
_styleVect[index]._fontName = str;
if (str)
{
s._fontName = str;
}
str = element->Attribute(TEXT("fontStyle"));
if (str)
{
_styleVect[index]._fontStyle = decStrVal(str);
s._fontStyle = decStrVal(str);
}
str = element->Attribute(TEXT("fontSize"));
if (str)
{
_styleVect[index]._fontSize = decStrVal(str);
s._fontSize = decStrVal(str);
}
str = element->Attribute(TEXT("nesting"));
if (str)
{
_styleVect[index]._nesting = decStrVal(str);
s._nesting = decStrVal(str);
}
str = element->Attribute(TEXT("keywordClass"));
if (str)
{
_styleVect[index]._keywordClass = getKwClassFromName(str);
s._keywordClass = getKwClassFromName(str);
}
TiXmlNode *v = styleNode->FirstChild();
if (v)
{
_styleVect[index]._keywords = new generic_string(v->Value());
s._keywords = v->Value();
}
}
++_nbStyler;
}
bool NppParameters::writeRecentFileHistorySettings(int nbMaxFile) const
@ -7089,14 +7062,11 @@ generic_string NppParameters::writeStyles(LexerStylerArray & lexersStylers, Styl
{
TiXmlElement *grElement = grChildNode->ToElement();
const TCHAR *styleName = grElement->Attribute(TEXT("name"));
int i = pLs->getStylerIndexByName(styleName);
if (i != -1)
const Style * pStyle = pLs->findByName(styleName);
Style * pStyle2Sync = pLs2 ? pLs2->findByName(styleName) : nullptr;
if (pStyle && pStyle2Sync)
{
Style & style = pLs->getStyler(i);
Style & style2Sync = pLs2->getStyler(i);
writeStyle2Element(style, style2Sync, grElement);
writeStyle2Element(*pStyle, *pStyle2Sync, grElement);
}
}
}
@ -7126,14 +7096,11 @@ generic_string NppParameters::writeStyles(LexerStylerArray & lexersStylers, Styl
{
TiXmlElement *grElement = grChildNode->ToElement();
const TCHAR *styleName = grElement->Attribute(TEXT("name"));
int i = pLs->getStylerIndexByName(styleName);
if (i != -1)
const Style * pStyle = pLs->findByName(styleName);
Style * pStyle2Sync = pLs2 ? pLs2->findByName(styleName) : nullptr;
if (pStyle && pStyle2Sync)
{
Style & style = pLs->getStyler(i);
Style & style2Sync = pLs2->getStyler(i);
writeStyle2Element(style, style2Sync, grElement);
writeStyle2Element(*pStyle, *pStyle2Sync, grElement);
}
}
}
@ -7149,14 +7116,11 @@ generic_string NppParameters::writeStyles(LexerStylerArray & lexersStylers, Styl
{
TiXmlElement *pElement = childNode->ToElement();
const TCHAR *styleName = pElement->Attribute(TEXT("name"));
int i = _widgetStyleArray.getStylerIndexByName(styleName);
if (i != -1)
const Style * pStyle = _widgetStyleArray.findByName(styleName);
Style * pStyle2Sync = globalStylers.findByName(styleName);
if (pStyle && pStyle2Sync)
{
Style & style = _widgetStyleArray.getStyler(i);
Style & style2Sync = globalStylers.getStyler(i);
writeStyle2Element(style, style2Sync, pElement);
writeStyle2Element(*pStyle, *pStyle2Sync, pElement);
}
}
@ -7194,7 +7158,7 @@ bool NppParameters::insertTabInfo(const TCHAR *langName, int tabInfo)
return false;
}
void NppParameters::writeStyle2Element(Style & style2Write, Style & style2Sync, TiXmlElement *element)
void NppParameters::writeStyle2Element(const Style & style2Write, Style & style2Sync, TiXmlElement *element)
{
if (HIBYTE(HIWORD(style2Write._fgColor)) != 0xFF)
{
@ -7217,13 +7181,13 @@ void NppParameters::writeStyle2Element(Style & style2Write, Style & style2Sync,
element->SetAttribute(TEXT("colorStyle"), style2Write._colorStyle);
}
if (style2Write._fontName)
if (!style2Write._fontName.empty())
{
const TCHAR *oldFontName = element->Attribute(TEXT("fontName"));
if (lstrcmp(oldFontName, style2Write._fontName))
const TCHAR * oldFontName = element->Attribute(TEXT("fontName"));
if (oldFontName && oldFontName != style2Write._fontName)
{
element->SetAttribute(TEXT("fontName"), style2Write._fontName);
style2Sync._fontName = style2Write._fontName = element->Attribute(TEXT("fontName"));
style2Sync._fontName = style2Write._fontName;
}
}
@ -7241,14 +7205,14 @@ void NppParameters::writeStyle2Element(Style & style2Write, Style & style2Sync,
}
if (style2Write._keywords)
if (!style2Write._keywords.empty())
{
TiXmlNode *teteDeNoeud = element->LastChild();
if (teteDeNoeud)
teteDeNoeud->SetValue(style2Write._keywords->c_str());
teteDeNoeud->SetValue(style2Write._keywords.c_str());
else
element->InsertEndChild(TiXmlText(style2Write._keywords->c_str()));
element->InsertEndChild(TiXmlText(style2Write._keywords.c_str()));
}
}
@ -7291,10 +7255,9 @@ void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *user
TiXmlElement *styleRootElement = (rootElement->InsertEndChild(TiXmlElement(TEXT("Styles"))))->ToElement();
for (int i = 0 ; i < SCE_USER_STYLE_TOTAL_STYLES ; ++i)
for (const Style & style2Write : userLang->_styles)
{
TiXmlElement *styleElement = (styleRootElement->InsertEndChild(TiXmlElement(TEXT("WordsStyle"))))->ToElement();
Style style2Write = userLang->_styles.getStyler(i);
if (style2Write._styleID == -1)
continue;
@ -7322,7 +7285,7 @@ void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *user
styleElement->SetAttribute(TEXT("colorStyle"), style2Write._colorStyle);
}
if (style2Write._fontName)
if (!style2Write._fontName.empty())
{
styleElement->SetAttribute(TEXT("fontName"), style2Write._fontName);
}
@ -7348,43 +7311,6 @@ void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *user
}
}
void NppParameters::stylerStrOp(bool op)
{
for (int i = 0 ; i < _nbUserLang ; ++i)
{
for (int j = 0 ; j < SCE_USER_STYLE_TOTAL_STYLES ; ++j)
{
Style & style = _userLangArray[i]->_styles.getStyler(j);
if (op == DUP)
{
const size_t strLen = lstrlen(style._styleDesc) + 1;
TCHAR *str = new TCHAR[strLen];
wcscpy_s(str, strLen, style._styleDesc);
style._styleDesc = str;
if (style._fontName)
{
const size_t strLen2 = lstrlen(style._fontName) + 1;
str = new TCHAR[strLen2];
wcscpy_s(str, strLen2, style._fontName);
style._fontName = str;
}
else
{
str = new TCHAR[2];
str[0] = str[1] = '\0';
style._fontName = str;
}
}
else
{
delete [] style._styleDesc;
delete [] style._fontName;
}
}
}
}
void NppParameters::addUserModifiedIndex(size_t index)
{
size_t len = _customizedShortcuts.size();

View File

@ -380,81 +380,21 @@ const int COLORSTYLE_ALL = COLORSTYLE_FOREGROUND|COLORSTYLE_BACKGROUND;
struct Style
struct Style final
{
int _styleID = -1;
const TCHAR* _styleDesc = nullptr;
int _styleID = STYLE_NOT_USED;
generic_string _styleDesc;
COLORREF _fgColor = COLORREF(STYLE_NOT_USED);
COLORREF _bgColor = COLORREF(STYLE_NOT_USED);
int _colorStyle = COLORSTYLE_ALL;
const TCHAR* _fontName = nullptr;
generic_string _fontName;
int _fontStyle = FONTSTYLE_NONE;
int _fontSize = STYLE_NOT_USED;
int _nesting = FONTSTYLE_NONE;
int _keywordClass = STYLE_NOT_USED;
generic_string* _keywords = nullptr;
Style() = default;
Style(const Style & style)
{
_styleID = style._styleID;
_styleDesc = style._styleDesc;
_fgColor = style._fgColor;
_bgColor = style._bgColor;
_colorStyle = style._colorStyle;
_fontName = style._fontName;
_fontSize = style._fontSize;
_fontStyle = style._fontStyle;
_keywordClass = style._keywordClass;
_nesting = style._nesting;
_keywords = (style._keywords) ? new generic_string(*(style._keywords)) : nullptr;
}
~Style()
{
delete _keywords;
}
Style& operator = (const Style & style)
{
if (this != &style)
{
_styleID = style._styleID;
_styleDesc = style._styleDesc;
_fgColor = style._fgColor;
_bgColor = style._bgColor;
_colorStyle = style._colorStyle;
_fontName = style._fontName;
_fontSize = style._fontSize;
_fontStyle = style._fontStyle;
_keywordClass = style._keywordClass;
_nesting = style._nesting;
if (!(_keywords) && style._keywords)
_keywords = new generic_string(*(style._keywords));
else if (_keywords && style._keywords)
_keywords->assign(*(style._keywords));
else if (_keywords && !(style._keywords))
{
delete (_keywords);
_keywords = nullptr;
}
}
return *this;
}
void setKeywords(const TCHAR *str)
{
if (!_keywords)
_keywords = new generic_string(str);
else
*_keywords = str;
}
generic_string _keywords;
};
@ -470,70 +410,53 @@ struct GlobalOverride final
bool enableUnderLine = false;
};
const int STYLE_ARR_MAX_SIZE = 31;
struct StyleArray
{
public:
StyleArray & operator=(const StyleArray & sa)
{
if (this != &sa)
{
this->_nbStyler = sa._nbStyler;
for (int i = 0 ; i < _nbStyler ; ++i)
{
this->_styleVect[i] = sa._styleVect[i];
}
}
return *this;
}
//auto size() const { return _styleVect.size(); }
auto begin() { return _styleVect.begin(); }
auto end() { return _styleVect.end(); }
void clear() { _styleVect.clear(); }
int getNbStyler() const {return _nbStyler;};
void setNbStyler(int nb) {_nbStyler = nb;};
Style& getStyler(size_t index)
Style & getStyler(size_t index)
{
assert(index < STYLE_ARR_MAX_SIZE);
assert(index < _styleVect.size());
return _styleVect[index];
}
bool hasEnoughSpace() {return (_nbStyler < STYLE_ARR_MAX_SIZE);};
void addStyler(int styleID, TiXmlNode *styleNode);
void addStyler(int styleID, const TCHAR *styleName)
void addStyler(int styleID, const generic_string & styleName)
{
_styleVect[styleID]._styleID = styleID;
_styleVect[styleID]._styleDesc = styleName;
_styleVect[styleID]._fgColor = black;
_styleVect[styleID]._bgColor = white;
++_nbStyler;
_styleVect.emplace_back();
Style & s = _styleVect.back();
s._styleID = styleID;
s._styleDesc = styleName;
s._fgColor = black;
s._bgColor = white;
}
int getStylerIndexByID(int id)
Style * findByID(int id)
{
for (int i = 0 ; i < _nbStyler ; ++i)
for (size_t i = 0 ; i < _styleVect.size() ; ++i)
{
if (_styleVect[i]._styleID == id)
return i;
return &(_styleVect[i]);
}
return -1;
return nullptr;
}
int getStylerIndexByName(const TCHAR *name) const
Style * findByName(const generic_string & name)
{
if (!name)
return -1;
for (int i = 0 ; i < _nbStyler ; ++i)
for (size_t i = 0 ; i < _styleVect.size() ; ++i)
{
if (!lstrcmp(_styleVect[i]._styleDesc, name))
return i;
if (_styleVect[i]._styleDesc == name)
return &(_styleVect[i]);
}
return -1;
return nullptr;
}
protected:
std::vector<Style> _styleVect = std::vector<Style>(STYLE_ARR_MAX_SIZE);
int _nbStyler = 0;
std::vector<Style> _styleVect;
};
@ -579,49 +502,33 @@ private :
const int MAX_LEXER_STYLE = 100;
struct LexerStylerArray
{
public :
LexerStylerArray() : _nbLexerStyler(0){};
size_t getNbLexer() const { return _lexerStylerVect.size(); }
void clear() { _lexerStylerVect.clear(); }
LexerStylerArray & operator=(const LexerStylerArray & lsa)
{
if (this != &lsa)
{
this->_nbLexerStyler = lsa._nbLexerStyler;
for (int i = 0 ; i < this->_nbLexerStyler ; ++i)
this->_lexerStylerVect[i] = lsa._lexerStylerVect[i];
}
return *this;
}
int getNbLexer() const {return _nbLexerStyler;};
LexerStyler & getLexerFromIndex(int index)
LexerStyler & getLexerFromIndex(size_t index)
{
assert(index < _lexerStylerVect.size());
return _lexerStylerVect[index];
};
const TCHAR * getLexerNameFromIndex(int index) const {return _lexerStylerVect[index].getLexerName();}
const TCHAR * getLexerDescFromIndex(int index) const {return _lexerStylerVect[index].getLexerDesc();}
const TCHAR * getLexerNameFromIndex(size_t index) const { return _lexerStylerVect[index].getLexerName(); }
const TCHAR * getLexerDescFromIndex(size_t index) const { return _lexerStylerVect[index].getLexerDesc(); }
LexerStyler * getLexerStylerByName(const TCHAR *lexerName) {
if (!lexerName) return NULL;
for (int i = 0 ; i < _nbLexerStyler ; ++i)
if (!lexerName) return nullptr;
for (size_t i = 0 ; i < _lexerStylerVect.size() ; ++i)
{
if (!lstrcmp(_lexerStylerVect[i].getLexerName(), lexerName))
return &(_lexerStylerVect[i]);
}
return NULL;
return nullptr;
};
bool hasEnoughSpace() {return (_nbLexerStyler < MAX_LEXER_STYLE);};
void addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt, TiXmlNode *lexerNode);
void eraseAll();
private :
std::vector<LexerStyler> _lexerStylerVect = std::vector<LexerStyler>(MAX_LEXER_STYLE);
int _nbLexerStyler;
std::vector<LexerStyler> _lexerStylerVect;
};
@ -1107,10 +1014,8 @@ public:
this->_forcePureLC = ulc._forcePureLC;
this->_decimalSeparator = ulc._decimalSeparator;
this->_foldCompact = ulc._foldCompact;
int nbStyler = this->_styles.getNbStyler();
for (int i = 0 ; i < nbStyler ; ++i)
for (Style & st : this->_styles)
{
Style & st = this->_styles.getStyler(i);
if (st._bgColor == COLORREF(-1))
st._bgColor = white;
if (st._fgColor == COLORREF(-1))
@ -1375,8 +1280,6 @@ struct UdlXmlFileState final {
};
const int NB_LANG = 100;
const bool DUP = true;
const bool FREE = false;
const int RECENTFILES_SHOWFULLPATH = -1;
const int RECENTFILES_SHOWONLYFILENAME = 0;
@ -1958,14 +1861,13 @@ private:
void getActions(TiXmlNode *node, Macro & macro);
bool getShortcuts(TiXmlNode *node, Shortcut & sc);
void writeStyle2Element(Style & style2Write, Style & style2Sync, TiXmlElement *element);
void writeStyle2Element(const Style & style2Write, Style & style2Sync, TiXmlElement *element);
void insertUserLang2Tree(TiXmlNode *node, UserLangContainer *userLang);
void insertCmd(TiXmlNode *cmdRoot, const CommandShortcut & cmd);
void insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & macro);
void insertUserCmd(TiXmlNode *userCmdRoot, const UserCommand & userCmd);
void insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMap & scintKeyMap);
void insertPluginCmd(TiXmlNode *pluginCmdRoot, const PluginCmdShortcut & pluginCmd);
void stylerStrOp(bool op);
TiXmlElement * insertGUIConfigBoolNode(TiXmlNode *r2w, const TCHAR *name, bool bVal);
void insertDockingParamNode(TiXmlNode *GUIRoot);
void writeExcludedLangList(TiXmlElement *element);

View File

@ -4259,43 +4259,40 @@ void Finder::setFinderStyle()
LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(lexerName);
if (pStyler)
{
int i = pStyler->getStylerIndexByID(SCE_SEARCHRESULT_CURRENT_LINE);
if (i != -1)
const Style * pStyle = pStyler->findByID(SCE_SEARCHRESULT_CURRENT_LINE);
if (pStyle)
{
Style & style = pStyler->getStyler(i);
_scintView.execute(SCI_SETCARETLINEBACK, style._bgColor);
_scintView.execute(SCI_SETCARETLINEBACK, pStyle->_bgColor);
}
}
_scintView.setSearchResultLexer();
// Override foreground & background colour by default foreground & background coulour
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
int iStyleDefault = stylers.getStylerIndexByID(STYLE_DEFAULT);
if (iStyleDefault != -1)
Style * pStyleDefault = stylers.findByID(STYLE_DEFAULT);
if (pStyleDefault)
{
Style & styleDefault = stylers.getStyler(iStyleDefault);
_scintView.setStyle(styleDefault);
_scintView.setStyle(*pStyleDefault);
GlobalOverride & go = NppParameters::getInstance().getGlobalOverrideStyle();
if (go.isEnable())
{
int iGlobalOverride = stylers.getStylerIndexByName(TEXT("Global override"));
if (iGlobalOverride != -1)
const Style * pStyleGlobalOverride = stylers.findByName(TEXT("Global override"));
if (pStyleGlobalOverride)
{
Style & styleGlobalOverride = stylers.getStyler(iGlobalOverride);
if (go.enableFg)
{
styleDefault._fgColor = styleGlobalOverride._fgColor;
pStyleDefault->_fgColor = pStyleGlobalOverride->_fgColor;
}
if (go.enableBg)
{
styleDefault._bgColor = styleGlobalOverride._bgColor;
pStyleDefault->_bgColor = pStyleGlobalOverride->_bgColor;
}
}
}
_scintView.execute(SCI_STYLESETFORE, SCE_SEARCHRESULT_DEFAULT, styleDefault._fgColor);
_scintView.execute(SCI_STYLESETBACK, SCE_SEARCHRESULT_DEFAULT, styleDefault._bgColor);
_scintView.execute(SCI_STYLESETFORE, SCE_SEARCHRESULT_DEFAULT, pStyleDefault->_fgColor);
_scintView.execute(SCI_STYLESETBACK, SCE_SEARCHRESULT_DEFAULT, pStyleDefault->_bgColor);
}
_scintView.execute(SCI_COLOURISE, 0, -1);

View File

@ -513,18 +513,16 @@ void ScintillaEditView::setSpecialStyle(const Style & styleToSet)
if ( styleToSet._colorStyle & COLORSTYLE_BACKGROUND )
execute(SCI_STYLESETBACK, styleID, styleToSet._bgColor);
if (styleToSet._fontName && lstrcmp(styleToSet._fontName, TEXT("")) != 0)
if (!styleToSet._fontName.empty())
{
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
if (!NppParameters::getInstance().isInFontList(styleToSet._fontName))
{
execute(SCI_STYLESETFONT, styleID, reinterpret_cast<LPARAM>(DEFAULT_FONT_NAME));
}
else
{
const char * fontNameA = wmc.wchar2char(styleToSet._fontName, CP_UTF8);
execute(SCI_STYLESETFONT, styleID, reinterpret_cast<LPARAM>(fontNameA));
std::string fontNameA = wstring2string(styleToSet._fontName, CP_UTF8);
execute(SCI_STYLESETFONT, styleID, reinterpret_cast<LPARAM>(fontNameA.c_str()));
}
}
int fontStyle = styleToSet._fontStyle;
@ -558,18 +556,15 @@ void ScintillaEditView::setStyle(Style styleToSet)
if (go.isEnable())
{
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
int i = stylers.getStylerIndexByName(TEXT("Global override"));
if (i != -1)
const Style * pStyle = NppParameters::getInstance().getMiscStylerArray().findByName(TEXT("Global override"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
if (go.enableFg)
{
if (style._colorStyle & COLORSTYLE_FOREGROUND)
if (pStyle->_colorStyle & COLORSTYLE_FOREGROUND)
{
styleToSet._colorStyle |= COLORSTYLE_FOREGROUND;
styleToSet._fgColor = style._fgColor;
styleToSet._fgColor = pStyle->_fgColor;
}
else
{
@ -582,10 +577,10 @@ void ScintillaEditView::setStyle(Style styleToSet)
if (go.enableBg)
{
if (style._colorStyle & COLORSTYLE_BACKGROUND)
if (pStyle->_colorStyle & COLORSTYLE_BACKGROUND)
{
styleToSet._colorStyle |= COLORSTYLE_BACKGROUND;
styleToSet._bgColor = style._bgColor;
styleToSet._bgColor = pStyle->_bgColor;
}
else
{
@ -595,30 +590,30 @@ void ScintillaEditView::setStyle(Style styleToSet)
styleToSet._colorStyle &= ~COLORSTYLE_BACKGROUND;
}
}
if (go.enableFont && style._fontName && style._fontName[0])
styleToSet._fontName = style._fontName;
if (go.enableFontSize && (style._fontSize > 0))
styleToSet._fontSize = style._fontSize;
if (go.enableFont && !pStyle->_fontName.empty())
styleToSet._fontName = pStyle->_fontName;
if (go.enableFontSize && (pStyle->_fontSize > 0))
styleToSet._fontSize = pStyle->_fontSize;
if (style._fontStyle != STYLE_NOT_USED)
if (pStyle->_fontStyle != STYLE_NOT_USED)
{
if (go.enableBold)
{
if (style._fontStyle & FONTSTYLE_BOLD)
if (pStyle->_fontStyle & FONTSTYLE_BOLD)
styleToSet._fontStyle |= FONTSTYLE_BOLD;
else
styleToSet._fontStyle &= ~FONTSTYLE_BOLD;
}
if (go.enableItalic)
{
if (style._fontStyle & FONTSTYLE_ITALIC)
if (pStyle->_fontStyle & FONTSTYLE_ITALIC)
styleToSet._fontStyle |= FONTSTYLE_ITALIC;
else
styleToSet._fontStyle &= ~FONTSTYLE_ITALIC;
}
if (go.enableUnderLine)
{
if (style._fontStyle & FONTSTYLE_UNDERLINE)
if (pStyle->_fontStyle & FONTSTYLE_UNDERLINE)
styleToSet._fontStyle |= FONTSTYLE_UNDERLINE;
else
styleToSet._fontStyle &= ~FONTSTYLE_UNDERLINE;
@ -864,15 +859,13 @@ void ScintillaEditView::setUserLexer(const TCHAR *userLangName)
sprintf(intBuffer, "%" PRIuPTR, reinterpret_cast<uintptr_t>(_currentBufferID)); // use numeric value of BufferID pointer
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("userDefine.currentBufferID"), reinterpret_cast<LPARAM>(intBuffer));
for (int i = 0 ; i < SCE_USER_STYLE_TOTAL_STYLES ; ++i)
for (const Style & style : userLangContainer->_styles)
{
Style & style = userLangContainer->_styles.getStyler(i);
if (style._styleID == STYLE_NOT_USED)
continue;
char nestingBuffer[32];
sprintf(nestingBuffer, "userDefine.nesting.%02d", i );
sprintf(nestingBuffer, "userDefine.nesting.%02d", style._styleID);
sprintf(intBuffer, "%d", style._nesting);
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>(nestingBuffer), reinterpret_cast<LPARAM>(intBuffer));
@ -893,18 +886,16 @@ void ScintillaEditView::setExternalLexer(LangType typeDoc)
LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(name);
if (pStyler)
{
for (int i = 0 ; i < pStyler->getNbStyler() ; ++i)
for (const Style & style : *pStyler)
{
Style & style = pStyler->getStyler(i);
setStyle(style);
if (style._keywordClass >= 0 && style._keywordClass <= KEYWORDSET_MAX)
{
basic_string<char> keywordList("");
if (style._keywords)
if (!style._keywords.empty())
{
keywordList = wstring2string(*(style._keywords), CP_ACP);
keywordList = wstring2string(style._keywords, CP_ACP);
}
execute(SCI_SETKEYWORDS, style._keywordClass, reinterpret_cast<LPARAM>(getCompleteKeywordList(keywordList, typeDoc, style._keywordClass)));
}
@ -982,9 +973,8 @@ void ScintillaEditView::setJsLexer()
LexerStyler *pNewStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(newLexerName);
if (pNewStyler) // New js styler is available, so we can use it do more modern styling
{
for (int i = 0, nb = pNewStyler->getNbStyler(); i < nb; ++i)
for (const Style & style : *pNewStyler)
{
Style & style = pNewStyler->getStyler(i);
setStyle(style);
}
@ -1024,9 +1014,8 @@ void ScintillaEditView::setJsLexer()
if (pOldStyler)
{
for (int i = 0, nb = pOldStyler->getNbStyler(); i < nb; ++i)
for (Style style : *pOldStyler) //not by reference, but copy
{
Style style = pOldStyler->getStyler(i); //not by reference, but copy
int cppID = style._styleID;
switch (style._styleID)
@ -1293,14 +1282,13 @@ void ScintillaEditView::makeStyle(LangType language, const TCHAR **keywordArray)
LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(lexerName);
if (pStyler)
{
for (int i = 0, nb = pStyler->getNbStyler(); i < nb ; ++i)
for (const Style & style : *pStyler)
{
Style & style = pStyler->getStyler(i);
setStyle(style);
if (keywordArray)
{
if ((style._keywordClass != STYLE_NOT_USED) && (style._keywords))
keywordArray[style._keywordClass] = style._keywords->c_str();
if ((style._keywordClass != STYLE_NOT_USED) && (!style._keywords.empty()))
keywordArray[style._keywordClass] = style._keywords.c_str();
}
}
}
@ -1360,119 +1348,68 @@ void ScintillaEditView::setWordChars()
void ScintillaEditView::defineDocType(LangType typeDoc)
{
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
int iStyleDefault = stylers.getStylerIndexByID(STYLE_DEFAULT);
if (iStyleDefault != -1)
Style * pStyleDefault = stylers.findByID(STYLE_DEFAULT);
if (pStyleDefault)
{
Style & styleDefault = stylers.getStyler(iStyleDefault);
styleDefault._colorStyle = COLORSTYLE_ALL; //override transparency
setStyle(styleDefault);
pStyleDefault->_colorStyle = COLORSTYLE_ALL; //override transparency
setStyle(*pStyleDefault);
}
execute(SCI_STYLECLEARALL);
Style *pStyle;
Style defaultIndicatorStyle;
const Style * pStyle;
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE;
defaultIndicatorStyle._bgColor = red;
pStyle = &defaultIndicatorStyle;
int iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_SMART;
defaultIndicatorStyle._bgColor = liteGreen;
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_SMART);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_INC;
defaultIndicatorStyle._bgColor = blue;
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_INC);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_TAGMATCH;
defaultIndicatorStyle._bgColor = RGB(0x80, 0x00, 0xFF);
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGMATCH);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_TAGATTR;
defaultIndicatorStyle._bgColor = yellow;
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGATTR);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1;
defaultIndicatorStyle._bgColor = cyan;
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT1);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2;
defaultIndicatorStyle._bgColor = orange;
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT2);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3;
defaultIndicatorStyle._bgColor = yellow;
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT3);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4;
defaultIndicatorStyle._bgColor = purple;
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT4);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5;
defaultIndicatorStyle._bgColor = darkGreen;
pStyle = &defaultIndicatorStyle;
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT5);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
// Il faut surtout faire un test ici avant d'exécuter SCI_SETCODEPAGE
// Sinon y'aura un soucis de performance!
@ -1554,13 +1491,12 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
if (pStyler)
{
int i = pStyler->getStylerIndexByName(TEXT("DEFAULT"));
if (i != -1)
const Style * pStyle = pStyler->findByName(TEXT("DEFAULT"));
if (pStyle)
{
Style & style = pStyler->getStyler(i);
nfoStyle._bgColor = style._bgColor;
nfoStyle._fgColor = style._fgColor;
nfoStyle._colorStyle = style._colorStyle;
nfoStyle._bgColor = pStyle->_bgColor;
nfoStyle._fgColor = pStyle->_fgColor;
nfoStyle._colorStyle = pStyle->_colorStyle;
}
}
setSpecialStyle(nfoStyle);
@ -1769,30 +1705,26 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
}
//All the global styles should put here
int indexOfIndentGuide = stylers.getStylerIndexByID(STYLE_INDENTGUIDE);
if (indexOfIndentGuide != -1)
pStyle = stylers.findByID(STYLE_INDENTGUIDE);
if (pStyle)
{
Style & styleIG = stylers.getStyler(indexOfIndentGuide);
setStyle(styleIG);
setStyle(*pStyle);
}
int indexOfBraceLight = stylers.getStylerIndexByID(STYLE_BRACELIGHT);
if (indexOfBraceLight != -1)
pStyle = stylers.findByID(STYLE_BRACELIGHT);
if (pStyle)
{
Style & styleBL = stylers.getStyler(indexOfBraceLight);
setStyle(styleBL);
setStyle(*pStyle);
}
//setStyle(STYLE_CONTROLCHAR, liteGrey);
int indexBadBrace = stylers.getStylerIndexByID(STYLE_BRACEBAD);
if (indexBadBrace != -1)
pStyle = stylers.findByID(STYLE_BRACEBAD);
if (pStyle)
{
Style & styleBB = stylers.getStyler(indexBadBrace);
setStyle(styleBB);
setStyle(*pStyle);
}
int indexLineNumber = stylers.getStylerIndexByID(STYLE_LINENUMBER);
if (indexLineNumber != -1)
pStyle = stylers.findByID(STYLE_LINENUMBER);
if (pStyle)
{
Style & styleLN = stylers.getStyler(indexLineNumber);
setSpecialStyle(styleLN);
setSpecialStyle(*pStyle);
}
setTabSettings(NppParameters::getInstance().getLangFromID(typeDoc));
@ -2617,21 +2549,19 @@ void ScintillaEditView::performGlobalStyles()
NppParameters& nppParams = NppParameters::getInstance();
StyleArray & stylers = nppParams.getMiscStylerArray();
int i = stylers.getStylerIndexByName(TEXT("Current line background colour"));
if (i != -1)
const Style * pStyle = stylers.findByName(TEXT("Current line background colour"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
execute(SCI_SETCARETLINEBACK, style._bgColor);
execute(SCI_SETCARETLINEBACK, pStyle->_bgColor);
}
COLORREF selectColorBack = grey;
COLORREF selectColorFore = black;
i = stylers.getStylerIndexByName(TEXT("Selected text colour"));
if (i != -1)
pStyle = stylers.findByName(TEXT("Selected text colour"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
selectColorBack = style._bgColor;
selectColorFore = style._fgColor;
selectColorBack = pStyle->_bgColor;
selectColorFore = pStyle->_fgColor;
}
execute(SCI_SETSELBACK, 1, selectColorBack);
@ -2639,61 +2569,55 @@ void ScintillaEditView::performGlobalStyles()
execute(SCI_SETSELFORE, 1, selectColorFore);
COLORREF caretColor = black;
i = stylers.getStylerIndexByID(SCI_SETCARETFORE);
if (i != -1)
pStyle = stylers.findByID(SCI_SETCARETFORE);
if (pStyle)
{
Style & style = stylers.getStyler(i);
caretColor = style._fgColor;
caretColor = pStyle->_fgColor;
}
execute(SCI_SETCARETFORE, caretColor);
COLORREF edgeColor = liteGrey;
i = stylers.getStylerIndexByName(TEXT("Edge colour"));
if (i != -1)
pStyle = stylers.findByName(TEXT("Edge colour"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
edgeColor = style._fgColor;
edgeColor = pStyle->_fgColor;
}
execute(SCI_SETEDGECOLOUR, edgeColor);
::SendMessage(_hParent, NPPM_INTERNAL_EDGEMULTISETSIZE, 0, 0);
COLORREF foldMarginColor = grey;
COLORREF foldMarginHiColor = white;
i = stylers.getStylerIndexByName(TEXT("Fold margin"));
if (i != -1)
pStyle = stylers.findByName(TEXT("Fold margin"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
foldMarginHiColor = style._fgColor;
foldMarginColor = style._bgColor;
foldMarginHiColor = pStyle->_fgColor;
foldMarginColor = pStyle->_bgColor;
}
execute(SCI_SETFOLDMARGINCOLOUR, true, foldMarginColor);
execute(SCI_SETFOLDMARGINHICOLOUR, true, foldMarginHiColor);
COLORREF bookmarkMarginColor = veryLiteGrey;
i = stylers.getStylerIndexByName(TEXT("Bookmark margin"));
if (i == -1)
pStyle = stylers.findByName(TEXT("Bookmark margin"));
if (!pStyle)
{
int j = stylers.getStylerIndexByName(TEXT("Line number margin"));
if (j != -1)
pStyle = stylers.findByName(TEXT("Line number margin"));
if (pStyle)
{
Style & style = stylers.getStyler(j);
bookmarkMarginColor = style._bgColor;
bookmarkMarginColor = pStyle->_bgColor;
}
}
else
{
Style & style = stylers.getStyler(i);
bookmarkMarginColor = style._bgColor;
bookmarkMarginColor = pStyle->_bgColor;
}
execute(SCI_SETMARGINTYPEN, _SC_MARGE_SYBOLE, SC_MARGIN_COLOUR);
execute(SCI_SETMARGINBACKN, _SC_MARGE_SYBOLE, bookmarkMarginColor);
COLORREF urlHoveredFG = grey;
i = stylers.getStylerIndexByName(TEXT("URL hovered"));
if (i != -1)
pStyle = stylers.findByName(TEXT("URL hovered"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
urlHoveredFG = style._fgColor;
urlHoveredFG = pStyle->_fgColor;
}
execute(SCI_INDICSETHOVERFORE, URL_INDIC, urlHoveredFG);
@ -2707,11 +2631,10 @@ void ScintillaEditView::performGlobalStyles()
execute(SCI_MARKERENABLEHIGHLIGHT, true);
COLORREF wsSymbolFgColor = black;
i = stylers.getStylerIndexByName(TEXT("White space symbol"));
if (i != -1)
pStyle = stylers.findByName(TEXT("White space symbol"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
wsSymbolFgColor = style._fgColor;
wsSymbolFgColor = pStyle->_fgColor;
}
execute(SCI_SETWHITESPACEFORE, true, wsSymbolFgColor);
}
@ -3785,19 +3708,17 @@ void ScintillaEditView::getFoldColor(COLORREF& fgColor, COLORREF& bgColor, COLOR
{
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
int i = stylers.getStylerIndexByName(TEXT("Fold"));
if (i != -1)
const Style * pStyle = stylers.findByName(TEXT("Fold"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
fgColor = style._bgColor;
bgColor = style._fgColor;
fgColor = pStyle->_bgColor;
bgColor = pStyle->_fgColor;
}
i = stylers.getStylerIndexByName(TEXT("Fold active"));
if (i != -1)
pStyle = stylers.findByName(TEXT("Fold active"));
if (pStyle)
{
Style & style = stylers.getStyler(i);
activeFgColor = style._fgColor;
activeFgColor = pStyle->_fgColor;
}
}

View File

@ -199,10 +199,6 @@ public:
for (BufferStyleMap::iterator it(_hotspotStyles.begin()); it != _hotspotStyles.end(); ++it )
{
for (StyleMap::iterator it2(it->second->begin()) ; it2 != it->second->end() ; ++it2)
{
delete [] it2->second._fontName;
}
delete it->second;
}
}

View File

@ -1763,7 +1763,7 @@ INT_PTR CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPAR
::SendMessage(hFontNameCombo, CB_SETITEMDATA, k, reinterpret_cast<LPARAM>(fontlist[j].c_str()));
}
i = ::SendMessage(hFontNameCombo, CB_FINDSTRINGEXACT, static_cast<WPARAM>(-1), reinterpret_cast<LPARAM>(style._fontName));
i = ::SendMessage(hFontNameCombo, CB_FINDSTRINGEXACT, static_cast<WPARAM>(-1), reinterpret_cast<LPARAM>(style._fontName.c_str()));
if (i == CB_ERR)
i = 0;
::SendMessage(hFontNameCombo, CB_SETCURSEL, i, 0);

View File

@ -146,11 +146,11 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
::EnableWindow(::GetDlgItem(_hSelf, IDOK), _isDirty);
::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/);
loadLangListFromNppParam();
updateGlobalOverrideCtrls();
setVisualFromStyleList();
goToCenter();
loadLangListFromNppParam();
return TRUE;
}
@ -545,7 +545,7 @@ void WordStyleDlg::loadLangListFromNppParam()
::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(TEXT("Global Styles")));
// All the lexers
for (int i = 0, nb = _lsArray.getNbLexer() ; i < nb ; ++i)
for (size_t i = 0, nb = _lsArray.getNbLexer() ; i < nb ; ++i)
{
::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(_lsArray.getLexerDescFromIndex(i)));
}
@ -675,7 +675,7 @@ void WordStyleDlg::updateUserKeywords()
len += 1;
TCHAR *kw = new TCHAR[len];
::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_GETTEXT, len, reinterpret_cast<LPARAM>(kw));
style.setKeywords(kw);
style._keywords = kw;
delete [] kw;
}
@ -808,10 +808,9 @@ void WordStyleDlg::setStyleListFromLexer(int index)
StyleArray & lexerStyler = index?_lsArray.getLexerFromIndex(index-1):_globalStyles;
for (int i = 0, nb = lexerStyler.getNbStyler(); i < nb ; ++i)
for (const Style & style : lexerStyler)
{
Style & style = lexerStyler.getStyler(i);
::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(style._styleDesc));
::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(style._styleDesc.c_str()));
}
::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_SETCURSEL, 0, 0);
setVisualFromStyleList();
@ -824,7 +823,7 @@ void WordStyleDlg::setVisualFromStyleList()
Style & style = getCurrentStyler();
// Global override style
if (style._styleDesc && lstrcmp(style._styleDesc, TEXT("Global override")) == 0)
if (style._styleDesc == TEXT("Global override"))
{
showGlobalOverrideCtrls(true);
}
@ -874,7 +873,7 @@ void WordStyleDlg::setVisualFromStyleList()
}
// Selected text colour style
if (style._styleDesc && lstrcmp(style._styleDesc, TEXT("Selected text colour")) == 0)
if (style._styleDesc == TEXT("Selected text colour"))
{
isEnable = false; // disable by default for "Selected text colour" style
@ -895,9 +894,9 @@ void WordStyleDlg::setVisualFromStyleList()
//-- font name
isEnable = false;
LRESULT iFontName;
if (style._fontName != NULL)
if (!style._fontName.empty())
{
iFontName = ::SendMessage(_hFontNameCombo, CB_FINDSTRING, 1, reinterpret_cast<LPARAM>(style._fontName));
iFontName = ::SendMessage(_hFontNameCombo, CB_FINDSTRING, 1, reinterpret_cast<LPARAM>(style._fontName.c_str()));
if (iFontName == CB_ERR)
iFontName = 0;
isEnable = true;
@ -964,7 +963,7 @@ void WordStyleDlg::setVisualFromStyleList()
kws = TEXT("");
::SendDlgItemMessage(_hSelf, IDC_DEF_KEYWORDS_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(kws));
const TCHAR *ckwStr = (style._keywords)?style._keywords->c_str():TEXT("");
const TCHAR *ckwStr = style._keywords.c_str();
::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(ckwStr));
}