Stingray Studio : Objective Edit User’s Guide : Chapter 6 Customization : Changing Keywords and Colors at Runtime
Changing Keywords and Colors at Runtime
Objective Edit allows you to change keywords and colors at runtime, overriding those set via the .ini file. Because these .ini file settings are read into containers (arrays and lists) when the editor is initialized, they can be accessed at runtime.
The code examples in this section assume that the file DevStudio.ini is used, containing the following groups:
[ColorGroups]
NumGroups =9
Group1 =Text
Group2 =Text Selection
Group3 =Number
Group4 =Operator
Group5 =Comment
Group6 =Keyword
Group7 =String
Group8 =Symbol
Group9 =String1
Note that keywords correspond to index 5 for containers, while the index for a text selection is 1. If your .ini file differs, change the indices used in these code examples correspondingly.
Keywords
Keywords are stored in protected member of class SECEditLangConfig, CMap<CString, LPCTSTR, unsigned short, unsigned short>* m_KeywordList.
Function CMap<CString, LPCTSTR, unsigned short, unsigned short>* GetKeywordList() provides public access to this list.
Here is how you might add a new keyword "MyKeyword"
 
void CMyController::OnAddKeyword()
{
SECEditLangConfig* pLang = SECEditLangConfig::GetLanguage("DevStudio");
pLang->GetKeywordList()->SetAt("MyKeyword", 5);
SECEditMsg msg(ID_SECEDIT_REFRESH_LANGUAGE);
GetEditModel()->OnUpdate(NULL, &msg);
}
Colors
Colors settings are stored in SECEditColorInfoArray* m_arrColorInfo member of class SECEditLangConfig and are accessible via function SECEditColorInfoArray* GetColorInfoArr().
The following code shows up how to change color for one of the color groups.
Changing the color for a keyword:
SECEditColorInfoArray* GetColorInfoArr()
SECEditLangConfig* pLang = SECEditLangConfig::GetLanguage("DevStudio");
SECEditColorInfo* pOldKWInfo = pLang->GetColorInfo(5);
SECEditColorInfo* pKeywordsInfo = new SECEditColorInfo();
pKeywordsInfo->m_clrText = RGB(0,255,255);
pKeywordsInfo->m_strDisplayName = "Keyword";
SECEditColorInfoArray* pColorInfoArray = pLang->GetColorInfoArr();
delete (*pColorInfoArray)[5]; //index = 5 for Group6
pColorInfoArray->SetAt(5,pKeywordsInfo);
GetEditModel()->OnUpdate(NULL, NULL);
Changing color for a text selection:
SECEditLangConfig* pLang = SECEditLangConfig::GetLanguage("DevStudio");
SECEditColorInfo* pSelectionColorInfo = new SECEditColorInfo();
pSelectionColorInfo->m_clrText = RGB(0,0,255);
pSelectionColorInfo->m_clrBack = RGB(255,0,0);
pSelectionColorInfo->m_strDisplayName = "Text Selection";
SECEditColorInfoArray* pColorInfoArray = pLang->GetColorInfoArr();
delete (*pColorInfoArray)[1]; //index = 1 for Group2
pColorInfoArray->SetAt(1,pSelectionColorInfo);
GetEditModel()->OnUpdate(NULL, NULL);