Browse Source

IndentationSize and ConvertTabsToSpaces settings can now be defined in separate policies together with other formatting options.

pull/494/head
Andreas Weizel 11 years ago
parent
commit
6ff259e9de
  1. 9
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormatter.cs
  2. 138
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs
  3. 67
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs
  4. 53
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/FormattingOptionBinding.cs
  5. 35
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingEditor.xaml
  6. 33
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingEditor.xaml.cs
  7. 12
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditorOptions.cs

9
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormatter.cs

@ -31,7 +31,14 @@ namespace CSharpBinding.FormattingStrategy @@ -31,7 +31,14 @@ namespace CSharpBinding.FormattingStrategy
/// </summary>
public static void Format(ITextEditor editor, int offset, int length, CSharpFormattingOptionsContainer optionsContainer)
{
var formatter = new CSharpFormatter(optionsContainer.GetEffectiveOptions(), editor.ToEditorOptions());
TextEditorOptions editorOptions = editor.ToEditorOptions();
int? indentationSize = optionsContainer.GetEffectiveIndentationSize();
if (indentationSize.HasValue)
editorOptions.IndentSize = indentationSize.Value;
bool? convertTabsToSpaces = optionsContainer.GetEffectiveConvertTabsToSpaces();
if (convertTabsToSpaces.HasValue)
editorOptions.TabsToSpaces = convertTabsToSpaces.Value;
var formatter = new CSharpFormatter(optionsContainer.GetEffectiveOptions(), editorOptions);
formatter.AddFormattingRegion(new DomRegion(editor.Document.GetLocation(offset), editor.Document.GetLocation(offset + length)));
var changes = formatter.AnalyzeFormatting(editor.Document, SyntaxTree.Parse(editor.Document));
changes.ApplyChanges(offset, length);

138
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs

@ -34,8 +34,13 @@ namespace CSharpBinding.FormattingStrategy @@ -34,8 +34,13 @@ namespace CSharpBinding.FormattingStrategy
/// </summary>
internal class CSharpFormattingOptionsContainer : INotifyPropertyChanged
{
private const string IndentationSizePropertyName = "IndentationSize";
private const string ConvertTabsToSpacesPropertyName = "ConvertTabsToSpaces";
CSharpFormattingOptionsContainer parent;
CSharpFormattingOptions cachedOptions;
int? indentationSize;
bool? convertTabsToSpaces;
readonly HashSet<string> activeOptions;
@ -106,6 +111,8 @@ namespace CSharpBinding.FormattingStrategy @@ -106,6 +111,8 @@ namespace CSharpBinding.FormattingStrategy
foreach (var activeOption in options.activeOptions)
activeOptions.Add(activeOption);
cachedOptions = options.cachedOptions.Clone();
indentationSize = options.indentationSize;
convertTabsToSpaces = options.convertTabsToSpaces;
OnPropertyChanged(null);
}
@ -128,6 +135,14 @@ namespace CSharpBinding.FormattingStrategy @@ -128,6 +135,14 @@ namespace CSharpBinding.FormattingStrategy
// All properties might have changed -> update everything
cachedOptions = CreateCachedOptions();
OnPropertyChanged(e.PropertyName);
} else if (e.PropertyName == IndentationSizePropertyName) {
if (!indentationSize.HasValue) {
indentationSize = GetEffectiveIndentationSize();
}
} else if (e.PropertyName == ConvertTabsToSpacesPropertyName) {
if (!convertTabsToSpaces.HasValue) {
convertTabsToSpaces = GetEffectiveConvertTabsToSpaces();
}
} else {
// Some other property has changed, check if we have our own value for it
if (!activeOptions.Contains(e.PropertyName)) {
@ -150,10 +165,18 @@ namespace CSharpBinding.FormattingStrategy @@ -150,10 +165,18 @@ namespace CSharpBinding.FormattingStrategy
public object GetOption(string option)
{
// Run up the hierarchy until we find a defined value for property
if (activeOptions.Contains(option)) {
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if (propertyInfo != null) {
return propertyInfo.GetValue(cachedOptions);
if (option == IndentationSizePropertyName) {
if (indentationSize.HasValue)
return indentationSize.Value;
} else if (option == ConvertTabsToSpacesPropertyName) {
if (convertTabsToSpaces.HasValue)
return convertTabsToSpaces.Value;
} else {
if (activeOptions.Contains(option)) {
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if (propertyInfo != null) {
return propertyInfo.GetValue(cachedOptions);
}
}
}
@ -188,6 +211,68 @@ namespace CSharpBinding.FormattingStrategy @@ -188,6 +211,68 @@ namespace CSharpBinding.FormattingStrategy
return null;
}
public int? IndentationSize
{
get {
return indentationSize;
}
set {
indentationSize = value;
OnPropertyChanged(IndentationSizePropertyName);
}
}
/// <summary>
/// Retrieves the value of "IndentationSize" option by looking at current and (if nothing set here) parent
/// containers.
/// </summary>
public int? GetEffectiveIndentationSize()
{
// Run up the hierarchy until we find a defined value for property
CSharpFormattingOptionsContainer container = this;
do
{
int? val = container.indentationSize;
if (val.HasValue) {
return val.Value;
}
container = container.parent;
} while (container != null);
return null;
}
public bool? ConvertTabsToSpaces
{
get {
return convertTabsToSpaces;
}
set {
convertTabsToSpaces = value;
OnPropertyChanged(ConvertTabsToSpacesPropertyName);
}
}
/// <summary>
/// Retrieves the value of v option by looking at current and (if nothing set here) parent
/// containers.
/// </summary>
public bool? GetEffectiveConvertTabsToSpaces()
{
// Run up the hierarchy until we find a defined value for property
CSharpFormattingOptionsContainer container = this;
do
{
bool? val = container.convertTabsToSpaces;
if (val.HasValue) {
return val.Value;
}
container = container.parent;
} while (container != null);
return null;
}
/// <summary>
/// Sets an option.
/// </summary>
@ -197,18 +282,32 @@ namespace CSharpBinding.FormattingStrategy @@ -197,18 +282,32 @@ namespace CSharpBinding.FormattingStrategy
{
if (value != null) {
// Save value in option values and cached options
activeOptions.Add(option);
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if ((propertyInfo != null) && (propertyInfo.PropertyType == value.GetType())) {
propertyInfo.SetValue(cachedOptions, value);
if (option == IndentationSizePropertyName) {
if (value is int)
indentationSize = (int) value;
} else if (option == ConvertTabsToSpacesPropertyName) {
if (value is bool)
convertTabsToSpaces = (bool) value;
} else {
activeOptions.Add(option);
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if ((propertyInfo != null) && (propertyInfo.PropertyType == value.GetType())) {
propertyInfo.SetValue(cachedOptions, value);
}
}
} else {
// Reset this option
activeOptions.Remove(option);
// Update formatting options object from parents
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if (propertyInfo != null) {
propertyInfo.SetValue(cachedOptions, GetEffectiveOption(option));
if (option == IndentationSizePropertyName) {
indentationSize = null;
} else if (option == ConvertTabsToSpacesPropertyName) {
convertTabsToSpaces = null;
} else {
activeOptions.Remove(option);
// Update formatting options object from parents
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if (propertyInfo != null) {
propertyInfo.SetValue(cachedOptions, GetEffectiveOption(option));
}
}
}
OnPropertyChanged(option);
@ -221,6 +320,11 @@ namespace CSharpBinding.FormattingStrategy @@ -221,6 +320,11 @@ namespace CSharpBinding.FormattingStrategy
/// <returns>Option's type.</returns>
public Type GetOptionType(string option)
{
if (option == IndentationSizePropertyName)
return typeof(int);
if (option == ConvertTabsToSpacesPropertyName)
return typeof(bool);
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if (propertyInfo != null) {
return propertyInfo.PropertyType;
@ -275,6 +379,9 @@ namespace CSharpBinding.FormattingStrategy @@ -275,6 +379,9 @@ namespace CSharpBinding.FormattingStrategy
// Silently ignore loading error, then this property will be "as parent" automatically
}
}
indentationSize = formatProperties.Get(IndentationSizePropertyName, new int?());
convertTabsToSpaces = formatProperties.Get(ConvertTabsToSpacesPropertyName, new bool?());
}
}
@ -291,8 +398,13 @@ namespace CSharpBinding.FormattingStrategy @@ -291,8 +398,13 @@ namespace CSharpBinding.FormattingStrategy
formatProperties.Set(activeOption, val);
}
}
if (indentationSize.HasValue)
formatProperties.Set(IndentationSizePropertyName, indentationSize.Value);
if (convertTabsToSpaces.HasValue)
formatProperties.Set(ConvertTabsToSpacesPropertyName, convertTabsToSpaces.Value);
parentProperties.SetNestedProperties("CSharpFormatting", formatProperties);
}
}
}

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

@ -48,7 +48,7 @@ namespace CSharpBinding.FormattingStrategy @@ -48,7 +48,7 @@ namespace CSharpBinding.FormattingStrategy
DocumentAccessor acc = new DocumentAccessor(editor.Document, lineNr, lineNr);
CSharpIndentationStrategy indentStrategy = new CSharpIndentationStrategy();
indentStrategy.IndentationString = editor.Options.IndentationString;
indentStrategy.IndentationString = GetIndentationString(editor);
indentStrategy.Indent(acc, false);
string t = acc.Text;
@ -62,33 +62,64 @@ namespace CSharpBinding.FormattingStrategy @@ -62,33 +62,64 @@ namespace CSharpBinding.FormattingStrategy
{
DocumentAccessor acc = new DocumentAccessor(editor.Document, beginLine, endLine);
CSharpIndentationStrategy indentStrategy = new CSharpIndentationStrategy();
indentStrategy.IndentationString = editor.Options.IndentationString;
indentStrategy.IndentationString = GetIndentationString(editor);
indentStrategy.Indent(acc, true);
}
CSharpFormattingOptionsContainer GetOptionsContainerForEditor(ITextEditor editor)
{
var currentProject = SD.ProjectService.FindProjectContainingFile(editor.FileName);
if (currentProject != null) {
var persistence = CSharpFormattingOptionsPersistence.GetProjectOptions(currentProject);
if (persistence != null) {
return persistence.OptionsContainer;
}
}
return null;
}
string GetIndentationString(ITextEditor editor)
{
// Get current indentation option values
int indentationSize = editor.Options.IndentationSize;
bool convertTabsToSpaces = editor.Options.ConvertTabsToSpaces;
var container = GetOptionsContainerForEditor(editor);
if (container != null) {
int? effectiveIndentationSize = container.GetEffectiveIndentationSize();
if (effectiveIndentationSize.HasValue)
indentationSize = effectiveIndentationSize.Value;
bool? effectiveConvertTabsToSpaces = container.GetEffectiveConvertTabsToSpaces();
if (effectiveConvertTabsToSpaces.HasValue)
convertTabsToSpaces = effectiveConvertTabsToSpaces.Value;
}
return ICSharpCode.AvalonEdit.TextEditorOptions.GetIndentationString(1, indentationSize, convertTabsToSpaces);
}
/* NR indent engine (temporarily?) disabled as per #447
static void IndentSingleLine(CacheIndentEngine engine, IDocument document, IDocumentLine line)
{
engine.Update(line.EndOffset);
if (engine.NeedsReindent) {
var indentation = TextUtilities.GetWhitespaceAfter(document, line.Offset);
// replacing the indentation in two steps is necessary to make the caret move accordingly.
document.Replace(indentation.Offset, indentation.Length, "");
document.Replace(indentation.Offset, 0, engine.ThisLineIndent);
engine.ResetEngineToPosition(line.Offset);
}
engine.Update(line.EndOffset);
if (engine.NeedsReindent) {
var indentation = TextUtilities.GetWhitespaceAfter(document, line.Offset);
// replacing the indentation in two steps is necessary to make the caret move accordingly.
document.Replace(indentation.Offset, indentation.Length, "");
document.Replace(indentation.Offset, 0, engine.ThisLineIndent);
engine.ResetEngineToPosition(line.Offset);
}
}
static CacheIndentEngine CreateIndentEngine(IDocument document, TextEditorOptions options)
{
IProject currentProject = null;
var projectService = SD.GetService<IProjectService>();
if (projectService != null) {
currentProject = projectService.FindProjectContainingFile(new FileName(document.FileName));
}
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(currentProject);
var engine = new CSharpIndentEngine(document, options, formattingOptions.OptionsContainer.GetEffectiveOptions());
return new CacheIndentEngine(engine);
IProject currentProject = null;
var projectService = SD.GetService<IProjectService>();
if (projectService != null) {
currentProject = projectService.FindProjectContainingFile(new FileName(document.FileName));
}
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(currentProject);
var engine = new CSharpIndentEngine(document, options, formattingOptions.OptionsContainer.GetEffectiveOptions());
return new CacheIndentEngine(engine);
}
*/
#endregion

53
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/FormattingOptionBinding.cs

@ -22,6 +22,7 @@ using System.Windows; @@ -22,6 +22,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using ICSharpCode.NRefactory.CSharp;
using CSharpBinding.OptionPanels;
namespace CSharpBinding.FormattingStrategy
{
@ -32,11 +33,8 @@ namespace CSharpBinding.FormattingStrategy @@ -32,11 +33,8 @@ namespace CSharpBinding.FormattingStrategy
{
public static readonly DependencyProperty ContainerProperty =
DependencyProperty.RegisterAttached("Container", typeof(CSharpFormattingOptionsContainer),
typeof(FormattingOptionBinding),
new FrameworkPropertyMetadata());
public static readonly DependencyProperty OptionProperty =
DependencyProperty.RegisterAttached("Option", typeof(string), typeof(FormattingOptionBinding),
new FrameworkPropertyMetadata(OnOptionPropertyChanged));
typeof(FormattingOptionBinding),
new FrameworkPropertyMetadata((o, e) => UpdateOptionBinding(o)));
public static CSharpFormattingOptionsContainer GetContainer(Selector element)
{
@ -48,21 +46,26 @@ namespace CSharpBinding.FormattingStrategy @@ -48,21 +46,26 @@ namespace CSharpBinding.FormattingStrategy
element.SetValue(ContainerProperty, container);
}
public static string GetOption(Selector element)
public static readonly DependencyProperty FormattingOptionProperty =
DependencyProperty.RegisterAttached("FormattingOption", typeof(FormattingOption),
typeof(FormattingOptionBinding),
new FrameworkPropertyMetadata((o, e) => UpdateOptionBinding(o)));
public static FormattingOption GetFormattingOption(Selector element)
{
return (string) element.GetValue(OptionProperty);
return (FormattingOption) element.GetValue(FormattingOptionProperty);
}
public static void SetOption(Selector element, string option)
public static void SetFormattingOption(Selector element, FormattingOption container)
{
element.SetValue(OptionProperty, option);
element.SetValue(FormattingOptionProperty, container);
}
static void OnOptionPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
static void UpdateOptionBinding(DependencyObject o)
{
string option = e.NewValue as string;
ComboBox comboBox = o as ComboBox;
CSharpFormattingOptionsContainer container = GetContainer(comboBox);
FormattingOption option = GetFormattingOption(comboBox);
if ((option != null) && (comboBox != null) && (container != null)) {
if (container != null) {
if (container.Parent != null) {
@ -72,17 +75,24 @@ namespace CSharpBinding.FormattingStrategy @@ -72,17 +75,24 @@ namespace CSharpBinding.FormattingStrategy
Tag = null
});
comboBox.SelectedIndex = 0;
} else if (option.AlwaysAllowDefault) {
// Also add "default" entry, but without changeable text by container
comboBox.Items.Add(new ComboBoxItem {
Content = "(default)",
Tag = null
});
comboBox.SelectedIndex = 0;
}
Type optionType = container.GetOptionType(option);
Type optionType = container.GetOptionType(option.Option);
FillComboValues(comboBox, optionType);
UpdateComboBoxValue(container, option, comboBox);
UpdateComboBoxValue(container, option.Option, comboBox);
comboBox.SelectionChanged += ComboBox_SelectionChanged;
container.PropertyChanged += (sender, eventArgs) =>
{
if ((eventArgs.PropertyName == null) || (eventArgs.PropertyName == option))
UpdateComboBoxValue(container, option, comboBox);
if ((eventArgs.PropertyName == null) || (eventArgs.PropertyName == option.Option))
UpdateComboBoxValue(container, option.Option, comboBox);
};
}
}
@ -98,13 +108,13 @@ namespace CSharpBinding.FormattingStrategy @@ -98,13 +108,13 @@ namespace CSharpBinding.FormattingStrategy
{
ComboBox comboBox = sender as ComboBox;
if (comboBox != null) {
string option = GetOption(comboBox);
FormattingOption option = GetFormattingOption(comboBox);
CSharpFormattingOptionsContainer container = GetContainer(comboBox);
if ((container != null) && (option != null)) {
ComboBoxItem selectedItem = comboBox.SelectedItem as ComboBoxItem;
if (selectedItem != null) {
// Set option to appropriate value
container.SetOption(option, selectedItem.Tag);
container.SetOption(option.Option, selectedItem.Tag);
}
}
}
@ -140,11 +150,10 @@ namespace CSharpBinding.FormattingStrategy @@ -140,11 +150,10 @@ namespace CSharpBinding.FormattingStrategy
static void FillIntComboValues(ComboBox comboBox)
{
comboBox.Items.Add(new ComboBoxItem { Content = "0", Tag = 0 });
comboBox.Items.Add(new ComboBoxItem { Content = "1", Tag = 1 });
comboBox.Items.Add(new ComboBoxItem { Content = "2", Tag = 2 });
comboBox.Items.Add(new ComboBoxItem { Content = "3", Tag = 3 });
comboBox.Items.Add(new ComboBoxItem { Content = "4", Tag = 4 });
for (int i = 0; i < 11; i++)
{
comboBox.Items.Add(new ComboBoxItem { Content = i.ToString(), Tag = i });
}
}
static void FillBraceStyleComboValues(ComboBox comboBox)

35
src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingEditor.xaml

@ -274,13 +274,13 @@ @@ -274,13 +274,13 @@
<DataTemplate>
<Grid Margin="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" MaxWidth="400" />
<ColumnDefinition Width="Auto" SharedSizeGroup="ComboBoxColumn" />
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="1" Margin="0,0,0,0" MinWidth="100"
VerticalAlignment="Center"
format:FormattingOptionBinding.Container="{Binding ElementName=CSharpFormattingEditor_Self, Path=OptionsContainer}"
format:FormattingOptionBinding.Option="{Binding Option}" />
format:FormattingOptionBinding.FormattingOption="{Binding}" />
<sd:RestrictDesiredSize RestrictHeight="False" MinWidth="150">
<TextBlock Grid.Column="0"
Text="{Binding Text}"
@ -297,9 +297,38 @@ @@ -297,9 +297,38 @@
</UserControl.Resources>
<DockPanel>
<Grid DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MaxWidth="400" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0"
Content="{core:Localize Dialog.Options.IDEOptions.TextEditor.Behaviour.IndentLabel}" />
<ComboBox Grid.Column="1" Grid.Row="0" MinWidth="100" Margin="0,0,0,3"
format:FormattingOptionBinding.Container="{Binding ElementName=CSharpFormattingEditor_Self, Path=OptionsContainer}">
<format:FormattingOptionBinding.FormattingOption>
<local:FormattingOption Option="IndentationSize" AlwaysAllowDefault="True" />
</format:FormattingOptionBinding.FormattingOption>
</ComboBox>
<Label Grid.Column="0" Grid.Row="1"
Content="{core:Localize Dialog.Options.IDEOptions.TextEditor.Behaviour.ConvertTabsToSpacesCheckBox}" />
<ComboBox Grid.Column="1" Grid.Row="1" MinWidth="100" Margin="0,0,0,3"
format:FormattingOptionBinding.Container="{Binding ElementName=CSharpFormattingEditor_Self, Path=OptionsContainer}">
<format:FormattingOptionBinding.FormattingOption>
<local:FormattingOption Option="ConvertTabsToSpaces" AlwaysAllowDefault="True" />
</format:FormattingOptionBinding.FormattingOption>
</ComboBox>
</Grid>
<Grid
Visibility="{Binding Path=AllowPresets, Converter={StaticResource boolToVisibilityConverter}}"
DockPanel.Dock="Top">
DockPanel.Dock="Top" Margin="0,5,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />

33
src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingEditor.xaml.cs

@ -29,21 +29,13 @@ using CSharpBinding.FormattingStrategy; @@ -29,21 +29,13 @@ using CSharpBinding.FormattingStrategy;
namespace CSharpBinding.OptionPanels
{
/// <summary>
/// Marker interface for group or option container.
/// It doesn't need to have any members.
/// </summary>
internal interface IFormattingItemContainer
{
}
/// <summary>
/// Represents a container item for other container items in formatting editor list
/// </summary>
[ContentProperty("Children")]
internal class FormattingGroupContainer : DependencyObject, IFormattingItemContainer
internal class FormattingGroupContainer : DependencyObject
{
readonly ObservableCollection<IFormattingItemContainer> children = new ObservableCollection<IFormattingItemContainer>();
readonly ObservableCollection<DependencyObject> children = new ObservableCollection<DependencyObject>();
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(FormattingGroupContainer),
@ -54,7 +46,7 @@ namespace CSharpBinding.OptionPanels @@ -54,7 +46,7 @@ namespace CSharpBinding.OptionPanels
set { SetValue(TextProperty, value); }
}
public ObservableCollection<IFormattingItemContainer> Children
public ObservableCollection<DependencyObject> Children
{
get {
return children;
@ -66,7 +58,7 @@ namespace CSharpBinding.OptionPanels @@ -66,7 +58,7 @@ namespace CSharpBinding.OptionPanels
/// Represents a container for formatting options.
/// </summary>
[ContentProperty("Children")]
internal class FormattingOptionContainer : DependencyObject, IFormattingItemContainer
internal class FormattingOptionContainer : DependencyObject
{
readonly ObservableCollection<FormattingOption> children = new ObservableCollection<FormattingOption>();
@ -91,11 +83,26 @@ namespace CSharpBinding.OptionPanels @@ -91,11 +83,26 @@ namespace CSharpBinding.OptionPanels
set { SetValue(TextProperty, value); }
}
// public static readonly DependencyProperty AlwaysAllowDefaultProperty =
// DependencyProperty.Register("AlwaysAllowDefault", typeof(bool), typeof(FormattingOption),
// new FrameworkPropertyMetadata());
//
// public bool AlwaysAllowDefault {
// get { return (bool)GetValue(AlwaysAllowDefaultProperty); }
// set { SetValue(AlwaysAllowDefaultProperty, value); }
// }
public string Option
{
get;
set;
}
public bool AlwaysAllowDefault
{
get;
set;
}
}
/// <summary>
@ -197,7 +204,7 @@ namespace CSharpBinding.OptionPanels @@ -197,7 +204,7 @@ namespace CSharpBinding.OptionPanels
}
}
public ObservableCollection<IFormattingItemContainer> RootChildren
public ObservableCollection<DependencyObject> RootChildren
{
get {
// rootEntries object is only the root container, its children should be shown directly

12
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditorOptions.cs

@ -264,11 +264,19 @@ namespace ICSharpCode.AvalonEdit @@ -264,11 +264,19 @@ namespace ICSharpCode.AvalonEdit
/// Gets text required to indent from the specified <paramref name="column"/> to the next indentation level.
/// </summary>
public virtual string GetIndentationString(int column)
{
return GetIndentationString(column, IndentationSize, ConvertTabsToSpaces);
}
/// <summary>
/// Gets text required to indent from the specified <paramref name="column"/> to the next indentation level,
/// considering given <paramref name="indentationSize"/> and <paramref name="convertTabsToSpaces"/> settings.
/// </summary>
public static string GetIndentationString(int column, int indentationSize, bool convertTabsToSpaces)
{
if (column < 1)
throw new ArgumentOutOfRangeException("column", column, "Value must be at least 1.");
int indentationSize = this.IndentationSize;
if (ConvertTabsToSpaces) {
if (convertTabsToSpaces) {
return new string(' ', indentationSize - ((column - 1) % indentationSize));
} else {
return "\t";

Loading…
Cancel
Save