Default syntax highlight |
Post Reply |
Author | |
carl357
Newbie Joined: 31 December 2008 Status: Offline Points: 1 |
Post Options
Thanks(0)
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. |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
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
|
|
Algae
Senior Member Joined: 08 January 2007 Location: United States Status: Offline Points: 217 |
Post Options
Thanks(0)
|
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. |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
Call SyntaxEdit.DataManager.FileExt = ".sql" in your initialization step
|
|
Algae
Senior Member Joined: 08 January 2007 Location: United States Status: Offline Points: 217 |
Post Options
Thanks(0)
|
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. |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
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); |
|
Algae
Senior Member Joined: 08 January 2007 Location: United States Status: Offline Points: 217 |
Post Options
Thanks(0)
|
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. |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
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] |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
Instead of carpal-tunnel exercise - use open your schclass-file in MS Word and replace all paragraphs ^p to \r\n"); ^p sb += _T("
|
|
Algae
Senior Member Joined: 08 January 2007 Location: United States Status: Offline Points: 217 |
Post Options
Thanks(0)
|
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" ... |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
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; |
|
Algae
Senior Member Joined: 08 January 2007 Location: United States Status: Offline Points: 217 |
Post Options
Thanks(0)
|
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! |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
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.
|
|
Algae
Senior Member Joined: 08 January 2007 Location: United States Status: Offline Points: 217 |
Post Options
Thanks(0)
|
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); } |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
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 |
|
Algae
Senior Member Joined: 08 January 2007 Location: United States Status: Offline Points: 217 |
Post Options
Thanks(0)
|
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. |
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
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); } |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |