Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Syntax Edit
  New Posts New Posts RSS Feed - Default syntax highlight
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Default syntax highlight

 Post Reply Post Reply
Author
Message
carl357 View Drop Down
Newbie
Newbie


Joined: 31 December 2008
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote carl357 Quote  Post ReplyReply Direct Link To This Post Topic: Default syntax highlight
    Posted: 31 December 2008 at 1:31pm
Hello,

I'm seriously considering purchasing this component but I cannot find a way to make it stick to only one syntax highlight mode. I mean, highlight only one language and doing it by default, regardless of the file extension.

Another question. Does it exist a document explaining how to use it? I found the examples very useful but I miss a place to look for reference, for example, the way to use the ini or schclass files.
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 27 January 2009 at 6:09pm
It is easy - when you run syntax edit base app you should tell your app where to get schemes - usually this is a folder EditConfig in same place you put your app (exe). In this folder there are subfolders Schemas and Themes and also ini-file (by default - SyntaxEdit.ini). I copy this file as SyntaxEditVC.ini and clean it to have only one scheme:
[Schemes]
CPP=Schemas/_cpp.schclass  ; Visual C++
[Themes]
Default=Themes/colorSchema0.ini
Alternative=Themes/colorSchema1.ini

 

Find in your app the line (this is MFC version but VB looks similar)

GetEditCtrl().SetConfigFile(CXTPSyntaxEditCtrl::GetModulePath() + _T("EditConfig\\SyntaxEditVC.ini"));
 
Now you will have only 1 syntax highlight mode
Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2009 at 1:52pm
On a similar note, I tried to experiment with the syntax editor control but I can't seem to find the necessary information to make it operate as I wanted it to.

My objective was to make the control work with a single file type as described at the start of this thread. In my case I was making a little adhoc SQL query editor.

I added the appropriate configuration files _sql.schclass, colorSchema0.ini and the syntaxEdit.ini consists of:

[Schemes]
SQL=Schemas/_sql.schclass        ; SQL Query

[Themes]
Default=Themes/colorSchema0.ini

When I tried to use the control in a program dialog I experienced the following problems:

1. I did not load an ".sql" file, but rather copy/pasted a query I'd already written in notepad. No syntax highlighting appeared.
2. I tried typing in text, "SELECT", which should have been colored but it did not.

The syntax edit control seems to require that a file with a matching extent is opened. Is there a way to get the syntax colors working without loading a file and have the syntax editor use and apply colors according to the specified schema?

Thank you in advance for any help you can provide.

Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2009 at 1:59pm
Call SyntaxEdit.DataManager.FileExt = ".sql" in your initialization step
Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2009 at 5:33pm
Thank you for the ultrafast response! 

Works perfectly with the exception noted below. Actual code for anyone doing the same type of thing:

    CXTPSyntaxEditBufferManager* pDataMan = m_syntaxEdit.GetEditBuffer();
    if (pDataMan)
        pDataMan->SetFileExt(_T(".sql"));

The only issue is that there seems to be some kind of thread lock after the ext is set even with no text in the box. Roughly 5 seconds until the dialog opens I don't know what's going on in there yet to be more helpful.



Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2009 at 5:43pm
You need to understand last year syntaxedit modifications - e.g. this is modification to use non-ini and file-based configuration [sScheme and sColorTheme  - multi-lines strings with syntax and colors - see MDITextEditor sample code
and flag m_bUseMonitor = FALSE will fix your thread-related problem
 
CMDITextEditorView::CMDITextEditorView() .......
GetEditCtrl().SetConfigFile(_T(""), FALSE);

GetEditCtrl().m_bUseMonitor = FALSE;

if (GetEditCtrl().GetEditBuffer())

GetEditCtrl().GetEditBuffer()->SetFileExt(_T(".cpp"));

GetEditCtrl().SetSyntaxAndColorScheme(sScheme, sColorTheme);

Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 19 November 2009 at 2:37pm
I appreciate the fast response Mark.

If I understand correctly then, the only way to make this work is in non-ini, non-file-based mode? Setting m_bUseMonitor=FALSE in conjunction with the current .ini file based mode had no effect. I know it's not the file loading that takes all the time as that's nearly instantaneous. I load/parse text files all the time and nothing ever takes 5+ seconds even loaded from a distant network asset. It is also not the content parsing as there's nothing in the edit box yet.

Doesn't that render the file-based option useless?

Incidentally I went through the carpal-tunnel exercise of concatenating the strings in the _sql.schclass file to convert it to .h include and it failed immediately with:

Error    1    error C2143: syntax error : missing ';' before '+='

even though I followed the outline from _cpp_schclass.h meticulously. Obviously something doesn't like this as a header! So I never was able to see if "m_bUseMonitor=FALSE" solved the issue in non-file-based mode.

If I can get the non-file based mode working with _sql_schclass.h I'll post it so anyone can use it if that's permissible.


Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 19 November 2009 at 2:45pm
You can use any code to read your syntax and color scheme files into 2 strings and keep \r\n inside and use this 2 strings in

GetEditCtrl().SetSyntaxAndColorScheme(sScheme, sColorTheme); //my h-files to make compiled version [prebuid CPP case - like default]

Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 19 November 2009 at 8:57pm
Instead of carpal-tunnel exercise - use open your schclass-file in MS Word and replace all paragraphs ^p to \r\n"); ^p sb += _T("
Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 20 November 2009 at 2:51pm
I did the paragraph find/replace with Notepad++ instead of word and it saved all the typing, thank you 

Problems remain. This is the first block of file _sql_schclass.h:

CString sScheme, sColorTheme, sb;

/// SQL ///   
sb += _T("
lexClass:
    parent:file        = <*.sql>
    name            = c_SQL
    caseSensitive    = 0
    txt:colorFG    = 0x000000
    global:EditReparceTimeout_ms = 15000
    global:OnScreenSchcacheLifeTime_sec = 0
    global:ParserThreadIdleLifeTime_sec = 300
");

and at end of file:

sScheme = sb;
sb.Empty();

But of course produces the following errors on compile (for each block):

Error    1    error C2001: newline in constant

Since every line of text on a new line in the block either needs a '\' or remove all the line feeds.

I did solve this error:

Error    1    error C2143: syntax error : missing ';' before '+='

The config header file(s) cannot be included as "real header" files at the top of the cpp, but has to be embedded since it's code not class! Doh!

BOOL CQueryEditor::OnInitDialog()
{
    CXTPDialog::OnInitDialog();

    CRect rc;
    GetDlgItem(IDC_PLACEHOLDER)->GetWindowRect( &rc );
    ScreenToClient( &rc );

    BOOL bCreate = m_ctrlSynEdit.Create(this, TRUE, TRUE);
    m_ctrlSynEdit.ModifyStyleEx(0, WS_EX_CLIENTEDGE);   
    m_ctrlSynEdit.MoveWindow(&rc); //&rcEdit);   

    #include "_sql_schclass.h"
    #include "ColorsDataEntry.h"

...
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 20 November 2009 at 2:56pm
You can find it in our sample:

CMDITextEditorView::CMDITextEditorView() : m_dwLastUpdate(0), m_dwParserStart(0) {

.....

#include "_cpp1_schclass.h"

#include "ColorsDataEntry.h"

GetEditCtrl().SetConfigFile(_T(""), FALSE);

GetEditCtrl().m_bUseMonitor = FALSE;

if (GetEditCtrl().GetEditBuffer())

GetEditCtrl().GetEditBuffer()->SetFileExt(_T(".cpp"));

GetEditCtrl().SetSyntaxAndColorScheme(sScheme, sColorTheme);

return;

Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 25 November 2009 at 2:56pm
Do you know what causes the huge lag when using the "file" based method? I'd really like to use it and it works perfectly except for the lag.

It's even more pronounced in Debug vs Release so maybe related to memory allocation/deallocation? I'm just guessing here but hope someone might have the answer.

Thank you!
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 25 November 2009 at 3:57pm
Guess some thread searching by all file system (may be including network drives)? Try to debug and see. At least it was one of the reason to introduce another mode - much faster and flexi. Not too many users use syntaxedit in different apps same time and like to force syntax and color scheme updates in sync mode.
Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 30 November 2009 at 3:34pm
uploads/20091130_152844__sql_schclass.zip

The ".h" file method doesn't seem to work either. I have attached _sql_schclass.h if anyone is interested.

The dialog opening speed is very good. Probably because it's not doing anything Maybe I've got something wrong in the header file. If so I'll be darned if I know what it is. I didn't seem to encounter any error messages.

I performed the following tests:

1. I copy/pasted some SQL into the edit box. No syntax highlighting.
2. I typed some SQL directly into the edit box. No syntax highlighting.

Code:

    m_ctrlSynEdit.SetConfigFile(_T(""), FALSE);
    m_ctrlSynEdit.m_bUseMonitor = FALSE;

    CXTPSyntaxEditBufferManager* pDataMan = m_ctrlSynEdit.GetEditBuffer();   
    ASSERT(pDataMan);
    if (pDataMan)
    {
        #include "_sql_schclass.h"
        #include "ColorsDataEntry.h"
        m_ctrlSynEdit.SetSyntaxAndColorScheme(sScheme, sColorTheme, FALSE, FALSE);
    }

Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 30 November 2009 at 4:05pm

You string - one long text. Need to change e.g. instead of your line sb += _T("lexClass:"); use sb += _T("lexClass:\r\n"); and code will work

Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 07 December 2009 at 8:45pm
Thank you mark, that did the trick with the ".h" file.

My ".h" file produced a number of errors and wouldn't highlight properly but it did "sort of" work. I prefer the external file schema since you don't have to recompile every time you change a setting. I guess I'll have to trace until I find where the lag is coming from.
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 07 December 2009 at 8:57pm
Fine - use existed demo app handler - you don't need to compile it.
I put it in demo compile-time to make stand-alone demo without any extra files.

void CMDITextEditorView::OnReloadSyntax() {

//read from you syntax_scheme file into CString sScheme - and keep CR-LF between lines.
//same for extra_color_scheme - read into CString sColorTheme - and keep CR-LF between lines.
if (GetEditCtrl().GetEditBuffer())

GetEditCtrl().SetSyntaxAndColorScheme(sScheme, sColorTheme, TRUE, TRUE); }

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

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

This page was generated in 0.203 seconds.