Andos
Andos

Reputation: 312

Temporaily disabling the C# Rich Edit undo buffer while performing syntax highlighting

I already have a pretty decent syntax highlighter in my Rich Edit control but I have one final problem before it is fully useful: Whenever I run the syntax coloring it records those coloring actions in the undo buffer, which I do not really want. Is there any way to temporarily disable recording undo actions so that after a coloring the user can press undo and it will just undo the user's own actions and not the automated syntax highlighter?

I don't think I have the time to implement the Scintilla.NET editor just to get around this problem though. Any suggestions?

Upvotes: 2

Views: 2064

Answers (2)

Václav Slavík
Václav Slavík

Reputation: 6650

Almost as @Karl Edwall says above, but not quite: Use EM_GETOLEINTERFACE to obtain IRichEditOle interface and query it for IID_ITextDocument.

Once you get that, use (instead of Freeze/Unfreeze from the other answer) the Undo() method:

  • Undo(tomSuspend,NULL); to suspend undo temporarily
  • Undo(tomResume,NULL); to resume it again

(See http://support.microsoft.com/kb/199852.) It requires RichEdit 3.0, but that’s shipping since Windows XP SP1.

Upvotes: 2

Yoshi
Yoshi

Reputation: 3405

You will have to handle undo/redo yourself instead of relying on RTB, which means hooking into the keyboard events to listen for CTRL+Z, etc.

You can see how this author from codeproject did it for a similar RTB-overridden syntax highlighting editor: http://www.codeproject.com/KB/edit/SyntaxHighlighting.aspx

Upvotes: 1

Related Questions