Print Page | Close Window

How to load the Lex Syntax from a resource

Printed From: Codejock Forums
Category: General
Forum Name: Articles and Tutorials
Forum Description: Articles and Tutorials
Printed Date: 01 March 2024 at 5:07am
Software Version: Web Wiz Forums 12.04 -

Topic: How to load the Lex Syntax from a resource
Posted By: elmue
Subject: How to load the Lex Syntax from a resource
Date Posted: 13 June 2010 at 10:25pm

The samples MDITextEditor and GUI_VisualStudio demonstrate how to use the SyntaxEdit control.
But both load the Lex Syntax and the color theme from files.
At least 3 files are required in the samples:

I need only one syntax for my project and don't want to fill the disk with unnecessarry files.

As an Xtreme manual does not exist I had to dive deep into the code to find out how to load the syntax from a resource rather than from files.
I will explain this here so others can save the time that I spent in finding out how to do this.

When tracing through the code I found several bugs.
You must first fix these bugs and then recompile the entire library.

Edit the file XTPSyntaxEditLexColorFileReader.cpp:

In the demo GUI_VisualStudio in the constructor CGUI_VisualStudioView() remove the line

GetEditCtrl().SetConfigFile(CXTPSyntaxEditCtrl::GetModulePath() + _T("EditConfig\\SyntaxEdit.ini"));

and replace it with the following code:

CString s_Theme = ";Comment";
CString s_Scheme;

GetEditCtrl().SetSyntaxAndColorScheme(s_Scheme, s_Theme);



The function GetResource() loads the Syntax scheme from the resources into a string.

I tried to set a color theme via s_Theme but it does not work. (There are more bugs still in the code)
But this does not matter because all the colors are already defined in the syntax scheme.
The color theme is only needed if you want to override these colors.

Please note that the "parsing" that is done for the string
is very primitive.
The string must be exactly of the above format.
It MUST end with "\r\n" !

The scheme name "CPP" is completely meaningless.

The string s_Theme must not be empty!

The comment in the code is misleading:
//m_sIniSet = _T("[Schemes]\r\nCPP\r\n[Themes]\r\nDefault\r\nAlternative\r\n");

This comment makes you think that it would be possible to add more than one Theme or more than one Scheme.
But this is not possible. The rest of the code was not designed for that.

The color of the line numbers must be set separately.


Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 -
Copyright ©2001-2021 Web Wiz Ltd. -