Browse Source

Introduced new FormatLines() overload in IFormattingStrategy for more convenience.

pull/403/head
Andreas Weizel 12 years ago
parent
commit
84c262df0f
  1. 27
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs
  2. 2
      src/Main/Base/Project/Src/Editor/Commands/ReformatSelection.cs
  3. 10
      src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs

27
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs

@ -262,6 +262,21 @@ namespace CSharpBinding.FormattingStrategy @@ -262,6 +262,21 @@ namespace CSharpBinding.FormattingStrategy
return regions > endregions;
}
public override void FormatLines(ITextEditor textArea)
{
using (textArea.Document.OpenUndoGroup()) {
// In any other case: Simply format selection or whole document
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(SD.ProjectService.CurrentProject);
int formattedTextOffset = 0;
int formattedTextLength = textArea.Document.TextLength;
if (textArea.SelectionLength != 0) {
formattedTextOffset = textArea.SelectionStart;
formattedTextLength = textArea.SelectionLength;
}
CSharpFormatterHelper.Format(textArea, formattedTextOffset, formattedTextLength, formattingOptions.OptionsContainer);
}
}
public override void FormatLine(ITextEditor textArea, char ch) // used for comment tag formater/inserter
{
using (textArea.Document.OpenUndoGroup()) {
@ -425,18 +440,6 @@ namespace CSharpBinding.FormattingStrategy @@ -425,18 +440,6 @@ namespace CSharpBinding.FormattingStrategy
}
}
return;
case (char) 0:
// In any other case: Simply format selection or whole document
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(SD.ProjectService.CurrentProject);
int formattedTextOffset = 0;
int formattedTextLength = textArea.Document.TextLength;
if (textArea.SelectionLength != 0) {
formattedTextOffset = textArea.SelectionStart;
formattedTextLength = textArea.SelectionLength;
}
CSharpFormatterHelper.Format(textArea, formattedTextOffset, formattedTextLength, formattingOptions.OptionsContainer);
break;
}
}

2
src/Main/Base/Project/Src/Editor/Commands/ReformatSelection.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Commands @@ -35,7 +35,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Commands
if (editor == null)
return;
editor.Language.FormattingStrategy.FormatLine(editor, (char) 0);
editor.Language.FormattingStrategy.FormatLines(editor);
}
}
}

10
src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs

@ -28,6 +28,12 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -28,6 +28,12 @@ namespace ICSharpCode.SharpDevelop.Editor
/// </summary>
public interface IFormattingStrategy
{
/// <summary>
/// Formats content in current selection or whole open file, if nothing is selected.
/// </summary>
/// <param name="editor">Current text editor.</param>
void FormatLines(ITextEditor editor);
/// <summary>
/// This function formats a specific line after <code>charTyped</code> is pressed.
/// </summary>
@ -53,6 +59,10 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -53,6 +59,10 @@ namespace ICSharpCode.SharpDevelop.Editor
{
internal static readonly DefaultFormattingStrategy DefaultInstance = new DefaultFormattingStrategy();
public virtual void FormatLines(ITextEditor textArea)
{
}
public virtual void FormatLine(ITextEditor editor, char charTyped)
{
}

Loading…
Cancel
Save