wxStyledTextCtrl keyword lists Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Antipole
In need of some credit
In need of some credit
Posts: 8
Joined: Thu May 28, 2020 5:38 pm

wxStyledTextCtrl keyword lists

Post by Antipole » Tue Sep 08, 2020 9:57 am

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?
Thanks

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4540
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxStyledTextCtrl keyword lists

Post by ONEEYEMAN » Tue Sep 08, 2020 2:19 pm

Hi,
Did you look at stc sample?

Thank you.

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 361
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: wxStyledTextCtrl keyword lists

Post by New Pagodi » Tue Sep 08, 2020 3:00 pm

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) );
m_stc->StyleSetWeight(wxSTC_C_WORD2,wxSTC_WEIGHT_BOLD);
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.

Antipole
In need of some credit
In need of some credit
Posts: 8
Joined: Thu May 28, 2020 5:38 pm

Re: wxStyledTextCtrl keyword lists

Post by Antipole » Mon Sep 14, 2020 10:12 am

New Pagodi...

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

My plugin is now working as I desire!

Post Reply