7 changed files with 316 additions and 61 deletions
@ -0,0 +1,164 @@
@@ -0,0 +1,164 @@
|
||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Controls.Primitives; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
|
||||
namespace CSharpBinding.FormattingStrategy |
||||
{ |
||||
/// <summary>
|
||||
/// Offers an attached property to bind a formatting option to a ComboBox.
|
||||
/// </summary>
|
||||
public static class FormattingOptionBinding |
||||
{ |
||||
public static readonly DependencyProperty ContainerProperty = |
||||
DependencyProperty.RegisterAttached("Container", typeof(CSharpFormattingOptionsContainer), |
||||
typeof(FormattingOptionBinding), |
||||
new FrameworkPropertyMetadata(OnContainerPropertyChanged)); |
||||
public static readonly DependencyProperty OptionProperty = |
||||
DependencyProperty.RegisterAttached("Option", typeof(string), typeof(FormattingOptionBinding), |
||||
new FrameworkPropertyMetadata(OnOptionPropertyChanged)); |
||||
|
||||
public static CSharpFormattingOptionsContainer GetContainer(Selector element) |
||||
{ |
||||
return (CSharpFormattingOptionsContainer) element.GetValue(ContainerProperty); |
||||
} |
||||
|
||||
public static void SetContainer(Selector element, CSharpFormattingOptionsContainer enumType) |
||||
{ |
||||
element.SetValue(ContainerProperty, enumType); |
||||
} |
||||
|
||||
public static string GetOption(Selector element) |
||||
{ |
||||
return (string) element.GetValue(OptionProperty); |
||||
} |
||||
|
||||
public static void SetOption(Selector element, string enumType) |
||||
{ |
||||
element.SetValue(OptionProperty, enumType); |
||||
} |
||||
|
||||
static void OnContainerPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
// No op?
|
||||
} |
||||
|
||||
static void OnOptionPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
string option = e.NewValue as string; |
||||
ComboBox comboBox = o as ComboBox; |
||||
if ((option != null) && (comboBox != null)) { |
||||
// Add "default" entry in ComboBox
|
||||
// TODO Add located resource!
|
||||
comboBox.Items.Add(new ComboBoxItem { Content = "(default)", Tag = null }); |
||||
comboBox.SelectedIndex = 0; |
||||
|
||||
CSharpFormattingOptionsContainer container = GetContainer(comboBox); |
||||
if (container != null) { |
||||
Type optionType = container.GetOptionType(option); |
||||
FillComboValues(comboBox, optionType); |
||||
object currentValue = container.GetOption(option); |
||||
comboBox.SelectedItem = comboBox.Items.OfType<ComboBoxItem>().FirstOrDefault(item => currentValue.Equals(item.Tag)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void FillComboValues(ComboBox comboBox, Type type) |
||||
{ |
||||
if (type == typeof(bool)) { |
||||
FillBoolComboValues(comboBox); |
||||
} else if (type == typeof(BraceStyle)) { |
||||
FillBraceStyleComboValues(comboBox); |
||||
} else if (type == typeof(PropertyFormatting)) { |
||||
FillPropertyFormattingComboValues(comboBox); |
||||
} else if (type == typeof(Wrapping)) { |
||||
FillWrappingComboValues(comboBox); |
||||
} else if (type == typeof(NewLinePlacement)) { |
||||
FillNewLinePlacementComboValues(comboBox); |
||||
} else if (type == typeof(UsingPlacement)) { |
||||
FillUsingPlacementComboValues(comboBox); |
||||
} else if (type == typeof(EmptyLineFormatting)) { |
||||
FillEmptyLineFormattingComboValues(comboBox); |
||||
} |
||||
} |
||||
|
||||
static void FillBoolComboValues(ComboBox comboBox) |
||||
{ |
||||
// TODO Add located resources!
|
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Yes", Tag = true }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "No", Tag = false }); |
||||
} |
||||
|
||||
static void FillBraceStyleComboValues(ComboBox comboBox) |
||||
{ |
||||
// TODO Add located resources!
|
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Do not change", Tag = BraceStyle.DoNotChange }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "End of line", Tag = BraceStyle.EndOfLine }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "End of line without space", Tag = BraceStyle.EndOfLineWithoutSpace }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Next line", Tag = BraceStyle.NextLine }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Next line shifted", Tag = BraceStyle.NextLineShifted }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Next line shifted 2", Tag = BraceStyle.NextLineShifted2 }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Banner style", Tag = BraceStyle.BannerStyle }); |
||||
} |
||||
|
||||
static void FillPropertyFormattingComboValues(ComboBox comboBox) |
||||
{ |
||||
// TODO Add located resources!
|
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Allow one line", Tag = PropertyFormatting.AllowOneLine }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Force one line", Tag = PropertyFormatting.ForceOneLine }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Force new line", Tag = PropertyFormatting.ForceNewLine }); |
||||
} |
||||
|
||||
static void FillWrappingComboValues(ComboBox comboBox) |
||||
{ |
||||
// TODO Add located resources!
|
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Do not change", Tag = Wrapping.DoNotChange }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Do not wrap", Tag = Wrapping.DoNotWrap }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Wrap always", Tag = Wrapping.WrapAlways }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Wrap if too long", Tag = Wrapping.WrapIfTooLong }); |
||||
} |
||||
|
||||
static void FillNewLinePlacementComboValues(ComboBox comboBox) |
||||
{ |
||||
// TODO Add located resources!
|
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Do not care", Tag = NewLinePlacement.DoNotCare }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "New line", Tag = NewLinePlacement.NewLine }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Same line", Tag = NewLinePlacement.SameLine }); |
||||
} |
||||
|
||||
static void FillUsingPlacementComboValues(ComboBox comboBox) |
||||
{ |
||||
// TODO Add located resources!
|
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Top of file", Tag = UsingPlacement.TopOfFile }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Inside namespace", Tag = UsingPlacement.InsideNamespace }); |
||||
} |
||||
|
||||
static void FillEmptyLineFormattingComboValues(ComboBox comboBox) |
||||
{ |
||||
// TODO Add located resources!
|
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Do not change", Tag = EmptyLineFormatting.DoNotChange }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Indent", Tag = EmptyLineFormatting.Indent }); |
||||
comboBox.Items.Add(new ComboBoxItem { Content = "Do not indent", Tag = EmptyLineFormatting.DoNotIndent }); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue