/// <summary>
/// Inserts the PInvoke signature at the current cursor position.
/// </summary>
/// <param name="textArea">The text editor.</param>
/// <param name="signature">A PInvoke signature string.</param>
public void Generate(TextArea textArea, string signature)
{
IndentStyle oldIndentStyle = textArea.TextEditorProperties.IndentStyle;
bool oldEnableEndConstructs = PropertyService.Get("VBBinding.TextEditor.EnableEndConstructs", true);
try {
textArea.BeginUpdate();
textArea.Document.UndoStack.StartUndoGroup();
textArea.TextEditorProperties.IndentStyle = IndentStyle.Smart;
PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", false);
string[] lines = signature.Replace("\r\n", "\n").Split('\n');
for (int i = 0; i < lines.Length; ++i) {
textArea.InsertString(lines[i]);
// Insert new line if not the last line.
if ( i < (lines.Length - 1))
{
Return(textArea);
}
}
} finally {
textArea.Document.UndoStack.EndUndoGroup();
textArea.TextEditorProperties.IndentStyle = oldIndentStyle;
PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", oldEnableEndConstructs);
textArea.EndUpdate();
textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
textArea.Document.CommitUpdate();
}
}