"SAVE TO RTF" AND MEMORY STREAM

Hi,
the final step for integrating your codeeditor control in our application: we have a report the prints our code snippets. So, we pick RTF from the code editor control and write it to the third party report component.
When using "SaveStream", the provided stream seems to be closed inside the "SaveStream" method. So we cannot provide a "MemoryStream", where we would use "Seek(0, SeekLocation.Begin)" and read the content afterwards. Workaround: save to a temp file and read its content.
Is this fixable? But it is only a minor issue, because this report is rarely used.
Best regards
Wolfgang
Hi Wolfgang,
You can use overloaded method that writes to the TextWriter instead like this:
public virtual void SaveEditContentToStream(MemoryStream stream)
{
TextWriter writer = new StreamWriter(stream);
try
{
syntaxEdit1.SaveStream(writer, new Alternet.Editor.Serialization.RtfExport());
// do something with memorystream
}
finally
{
writer.Close();
}
}
regards,
Andrew
Many thanks, wrapping the MemoryStream in a TextWriter works.
Now one more question about RTF export: I create an invisible SyntaxEdit control, insert the code snippet and save it to RTF using a stream.
There are two problems with code formatting, which seem to be related to the control performing an asynchronous code analysis.
See this sample: http://www.hg-online.de/downloads/SyntaxEditRTF.zip
Start it and click the button "Print" => it creates an invisible syntax edit form, first loads a file "sourc1.vb" and saves it to RTF, then loads "source2.vb" and also saves it.
Problem with first file: class names ("Console") should have a light blue color => the RTF has black font. In the GUI, those blue class names appear after a small delay.
Problem with second result file: here everything is broken, because the colors seem to be picked from the first file.
Workaround for the second problem seems to be to create the VbParser for each newly loaded file.
I think I need a method to wait for the code parser to finish its work. This would resolve both issues.
Best regards
Wolfgang
Hi Wolfgang,
I have answered you via email.
regards,
Andrew
Just for the records: this code has to be added:
f2.textSource1.LoadFile(fileName);
f2.textSource1.FileName = fileName;
parser.Prepare(fileName, f2.textSource1.Lines, null, false);
parser.ForceReparseText(true);
f2.syntaxEdit1.SaveFile("test1.rtf", new RtfExport());
But this causes Problems in the "SnippetParsers" sample => continued by email...
Hi Andrew,
this is broken in .v3: the method "ForceReparseText" now deadlocks. Previously, it had a boolean Parameter which was removed in .v3.

To reproduce: I picked the "SnippetsParser" sample and added this Code to a button click (code switches to VB.NET and loads the code, then waits for syntax coloring and saves to RTF file):

csharp = false;
UpdateSource();
this.vbMethodParser.Prepare(string.Empty, this.vbSnippetSource.Lines, null, false);
//WKnauf 16.05.2018: parameter was removed in .v3.
//this.vbMethodParser.ForceReparseText(true);
this.vbMethodParser.ForceReparseText();
this.syntaxEdit1.SaveFile("test1.rtf", new RtfExport());
I can provide you with a full sample if necessary.

This blocks us from upgrading to .v3
Best regards
Wolfgang
Hi Wolfgang,
I have sent your a quick fix via e-mail.
regards,
Andrew
The fix works, thank you!