Page 1 of 1

wxStyledTextCtrl keyword lists

Posted: Tue Sep 08, 2020 9:57 am
by Antipole
I am using a wxStyledTextCtrl window for JavaScript source code. Using wxFormBuilder, I have set the window style to C++ and provided my own list of JavaScript keywords thus:

Code: Select all

pane->SetKeyWords(0, keywordsSupported + keywordsUnsupported);
where keywordsSupported and keywordsUnsupported are lists of JavaScript keywords. These words get displayed in blue.
All this works well for me.

I note that the SetKeyWords method allows for different sets of keywords, as specified in its first parameter. The above example uses set 0.
I would like to be able to use different colours for different sets of keywords. For example, I could use a different colour for keywordsUnsupported.

Can anyone show me how to utilise different sets of keywords and display them differently?

Re: wxStyledTextCtrl keyword lists

Posted: Tue Sep 08, 2020 2:19 pm
Did you look at stc sample?

Thank you.

Re: wxStyledTextCtrl keyword lists

Posted: Tue Sep 08, 2020 3:00 pm
by New Pagodi
You can only use keywords lists that the lexer will actually assign. For the c++ lexer this is currently

Code: Select all

keyword list                      number   corresponding style
-------------                       ---    ---------------
Primary keywords and identifiers     0     wxSTC_C_WORD
Secondary keywords and identifiers   1     wxSTC_C_WORD2
Documentation comment keywords       2     wxSTC_C_COMMENTDOCKEYWORD
Global classes and typedefs          3     wxSTC_C_GLOBALCLASS
Preprocessor definitions             4     wxSTC_C_IDENTIFIER
So to use the "Secondary keywords and identifiers", you could do something like

Code: Select all

m_stc->SetKeyWords(1,"with yield");
m_stc->StyleSetForeground(wxSTC_C_WORD2,wxColour(255,0,128) );
This will give the keywords "with" and "yield" a reddish color and set them bold.

The wxSTC_C_COMMENTDOCKEYWORD is a special case. It will only apply in doxygen blocks (blocks enclosed in /** */ or single lines starting with ///) and only apply to keywords starting with @ or /. You can use the other 4 lists as you see fit.

If you try to assign keyword lists 5,6, or 7, nothing will happen because the lexer will not use those lists.

Re: wxStyledTextCtrl keyword lists

Posted: Mon Sep 14, 2020 10:12 am
by Antipole
New Pagodi...

Thank you - thank you - thank you. -- just what I needed and very clear.

My plugin is now working as I desire!