Browse Source

- Fixed bugs in OptionBinding

- implemented ColorPicker
- added ColorPicker to XAML option dialog

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4947 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
b55d031490
  1. 9
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs
  2. 25
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/CodeCompletion.xaml
  3. 11
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/CodeCompletion.xaml.cs
  4. 39
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/XamlBindingOptions.cs
  5. 16
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs
  6. 5
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  7. 21
      src/Main/Base/Project/Src/Gui/Components/ColorPicker.xaml
  8. 67
      src/Main/Base/Project/Src/Gui/Components/ColorPicker.xaml.cs
  9. 50
      src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs

9
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs

@ -5,16 +5,18 @@ @@ -5,16 +5,18 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.AvalonEdit.Xml;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Xml;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
@ -338,5 +340,10 @@ namespace ICSharpCode.XamlBinding @@ -338,5 +340,10 @@ namespace ICSharpCode.XamlBinding
return default(T);
}
public static Brush ToBrush(this Color color)
{
return new SolidColorBrush(color);
}
}
}

25
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/CodeCompletion.xaml

@ -1,4 +1,9 @@ @@ -1,4 +1,9 @@
<gui:OptionPanel x:Class="ICSharpCode.XamlBinding.Options.CodeCompletion" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop" xmlns:addin="clr-namespace:ICSharpCode.XamlBinding" xmlns:sd="http://icsharpcode.net/sharpdevelop/core" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<gui:OptionPanel x:Class="ICSharpCode.XamlBinding.Options.CodeCompletion"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:addin="clr-namespace:ICSharpCode.XamlBinding"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<GroupBox Header="{sd:Localize AddIns.XamlBinding.Options.CodeCompletionGroupLabel}">
<StackPanel>
@ -23,15 +28,15 @@ @@ -23,15 +28,15 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="1" DockPanel.Dock="Left" Content="{sd:Localize AddIns.XamlBinding.Options.PropertyColor}" Grid.Column="0" />
<Label Grid.Row="2" DockPanel.Dock="Left" Content="{sd:Localize AddIns.XamlBinding.Options.EventColor}" Grid.Column="0" />
<Label Grid.Row="3" DockPanel.Dock="Left" Content="{sd:Localize AddIns.XamlBinding.Options.NamespaceDeclarationColor}" Grid.Column="0" />
<Label Grid.Row="4" DockPanel.Dock="Left" Content="{sd:Localize AddIns.XamlBinding.Options.IngoredElementColor}" Grid.Column="0" />
<Button Grid.Row="1" Background="{sd:OptionBinding addin:XamlBindingOptions.PropertyForegroundBrush}" Content="{sd:OptionBinding addin:XamlBindingOptions.PropertyForegroundBrush}" Foreground="WhiteSmoke" Click="ButtonClick" Grid.Column="1" />
<TextBlock Grid.ColumnSpan="1" Margin="3" Text="{sd:Localize AddIns.XamlBinding.Options.HighlightingDescription}" Grid.Column="0" Grid.Row="0" />
<Button Grid.Row="2" Background="{sd:OptionBinding addin:XamlBindingOptions.EventForegroundBrush}" Content="{sd:OptionBinding addin:XamlBindingOptions.EventForegroundBrush}" Foreground="WhiteSmoke" Click="ButtonClick" Grid.Column="1" />
<Button Grid.Row="3" Background="{sd:OptionBinding addin:XamlBindingOptions.NamespaceDeclarationForegroundBrush}" Content="{sd:OptionBinding addin:XamlBindingOptions.NamespaceDeclarationForegroundBrush}" Foreground="WhiteSmoke" Click="ButtonClick" Grid.Column="1" />
<Button Grid.Row="4" Background="{sd:OptionBinding addin:XamlBindingOptions.IgnoredForegroundBrush}" Content="{sd:OptionBinding addin:XamlBindingOptions.IgnoredForegroundBrush}" Foreground="WhiteSmoke" Click="ButtonClick" Grid.Column="1" />
<TextBlock Grid.ColumnSpan="1" Margin="3" Text="{sd:Localize AddIns.XamlBinding.Options.HighlightingDescription}" />
<Label Grid.Row="1" Content="{sd:Localize AddIns.XamlBinding.Options.PropertyColor}" />
<Label Grid.Row="2" Content="{sd:Localize AddIns.XamlBinding.Options.EventColor}" />
<Label Grid.Row="3" Content="{sd:Localize AddIns.XamlBinding.Options.NamespaceDeclarationColor}" />
<Label Grid.Row="4" Content="{sd:Localize AddIns.XamlBinding.Options.IngoredElementColor}" />
<gui:ColorPicker Grid.Row="1" Grid.Column="1" Value="{sd:OptionBinding addin:XamlBindingOptions.PropertyForegroundColor}" />
<gui:ColorPicker Grid.Row="2" Grid.Column="1" Value="{sd:OptionBinding addin:XamlBindingOptions.EventForegroundColor}" />
<gui:ColorPicker Grid.Row="3" Grid.Column="1" Value="{sd:OptionBinding addin:XamlBindingOptions.NamespaceDeclarationForegroundColor}" />
<gui:ColorPicker Grid.Row="4" Grid.Column="1" Value="{sd:OptionBinding addin:XamlBindingOptions.IgnoredForegroundColor}" />
</Grid>
</GroupBox>
</StackPanel>

11
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/CodeCompletion.xaml.cs

@ -30,17 +30,6 @@ namespace ICSharpCode.XamlBinding.Options @@ -30,17 +30,6 @@ namespace ICSharpCode.XamlBinding.Options
InitializeComponent();
}
void ButtonClick(object sender, RoutedEventArgs e)
{
SharpDevelopColorDialog dialog = new SharpDevelopColorDialog();
if (dialog.ShowWpfDialog() ?? false) {
Button b = sender as Button;
b.Background = new SolidColorBrush(dialog.WpfColor);
b.Content = (sender as Button).Background;
}
}
public override bool SaveOptions()
{
if (base.SaveOptions()) {

39
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/XamlBindingOptions.cs

@ -30,13 +30,6 @@ namespace ICSharpCode.XamlBinding @@ -30,13 +30,6 @@ namespace ICSharpCode.XamlBinding
}
}
public static IEnumerable<Brush> Colors {
get {
foreach (var item in typeof(Brushes).GetProperties())
yield return item.GetValue(null, null) as Brush;
}
}
public static bool UseExtensionCompletion {
get { return Properties.Get("UseExtensionCompletion", true); }
set { Properties.Set("UseExtensionCompletion", value); }
@ -52,43 +45,43 @@ namespace ICSharpCode.XamlBinding @@ -52,43 +45,43 @@ namespace ICSharpCode.XamlBinding
set { Properties.Set("EventHandlerNamePattern", value); }
}
public static Brush PropertyForegroundBrush {
get { return Properties.Get("PropertyForeground", Brushes.CadetBlue); }
public static Color PropertyForegroundColor {
get { return Properties.Get("PropertyForeground", Colors.CadetBlue); }
set { Properties.Set("PropertyForeground", value); }
}
public static Brush PropertyBackgroundBrush {
get { return Properties.Get("PropertyBackground", Brushes.Transparent); }
public static Color PropertyBackgroundColor {
get { return Properties.Get("PropertyBackground", Colors.Transparent); }
set { Properties.Set("PropertyBackground", value); }
}
public static Brush EventForegroundBrush {
get { return Properties.Get("EventForeground", Brushes.Green); }
public static Color EventForegroundColor {
get { return Properties.Get("EventForeground", Colors.Green); }
set { Properties.Set("EventForeground", value); }
}
public static Brush EventBackgroundBrush {
get { return Properties.Get("EventBackground", Brushes.Transparent); }
public static Color EventBackgroundColor {
get { return Properties.Get("EventBackground", Colors.Transparent); }
set { Properties.Set("EventBackground", value); }
}
public static Brush NamespaceDeclarationForegroundBrush {
get { return Properties.Get("NamespaceDeclarationForeground", Brushes.Orange); }
public static Color NamespaceDeclarationForegroundColor {
get { return Properties.Get("NamespaceDeclarationForeground", Colors.Orange); }
set { Properties.Set("NamespaceDeclarationForeground", value); }
}
public static Brush NamespaceDeclarationBackgroundBrush {
get { return Properties.Get("NamespaceDeclarationBackground", Brushes.Transparent); }
public static Color NamespaceDeclarationBackgroundColor {
get { return Properties.Get("NamespaceDeclarationBackground", Colors.Transparent); }
set { Properties.Set("NamespaceDeclarationBackground", value); }
}
public static Brush IgnoredForegroundBrush {
get { return Properties.Get("IgnoredForeground", Brushes.LightGray); }
public static Color IgnoredForegroundColor {
get { return Properties.Get("IgnoredForeground", Colors.LightGray); }
set { Properties.Set("IgnoredForeground", value); }
}
public static Brush IgnoredBackgroundBrush {
get { return Properties.Get("IgnoredBackground", Brushes.Transparent); }
public static Color IgnoredBackgroundColor {
get { return Properties.Get("IgnoredBackground", Colors.Transparent); }
set { Properties.Set("IgnoredBackground", value); }
}
}

16
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs

@ -297,26 +297,26 @@ namespace ICSharpCode.XamlBinding @@ -297,26 +297,26 @@ namespace ICSharpCode.XamlBinding
#region highlight helpers
void HighlightProperty(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.PropertyForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.PropertyBackgroundBrush);
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.PropertyForegroundColor.ToBrush());
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.PropertyBackgroundColor.ToBrush());
}
void HighlightEvent(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.EventForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.EventBackgroundBrush);
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.EventForegroundColor.ToBrush());
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.EventBackgroundColor.ToBrush());
}
void HighlightNamespaceDeclaration(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.NamespaceDeclarationForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.NamespaceDeclarationBackgroundBrush);
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.NamespaceDeclarationForegroundColor.ToBrush());
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.NamespaceDeclarationBackgroundColor.ToBrush());
}
void HighlightIgnored(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.IgnoredForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.IgnoredBackgroundBrush);
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.IgnoredForegroundColor.ToBrush());
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.IgnoredBackgroundColor.ToBrush());
}
#endregion

5
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -135,6 +135,10 @@ @@ -135,6 +135,10 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Gui\BrowserDisplayBinding\BrowserDisplayBinding.cs" />
<Compile Include="Src\Gui\Components\ColorPicker.xaml.cs">
<DependentUpon>ColorPicker.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Gui\Components\LocalizedPropertyGrid\StringParserPropertyContainer.cs" />
<Compile Include="Src\Gui\Components\SideBar\TextEditorSideBar.cs" />
<Compile Include="Src\Gui\Dialogs\AddOpenWithEntryDialog.cs" />
@ -878,6 +882,7 @@ @@ -878,6 +882,7 @@
<Private>False</Private>
</ProjectReference>
<Page Include="Src\Gui\App.xaml" />
<Page Include="Src\Gui\Components\ColorPicker.xaml" />
<Page Include="Src\Gui\Dialogs\TabbedOptionsDialog.xaml" />
<Page Include="Src\Gui\Dialogs\TreeViewOptionsDialog.xaml" />
<Page Include="Src\Gui\Workbench\WpfWorkbench.xaml" />

21
src/Main/Base/Project/Src/Gui/Components/ColorPicker.xaml

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
<UserControl x:Class="ICSharpCode.SharpDevelop.Gui.ColorPicker" x:Name="colorPicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Gui">
<UserControl.Resources>
<local:ColorToBrushConverter x:Key="converter" />
</UserControl.Resources>
<Button Content="{Binding Value, ElementName=colorPicker}"
Background="{Binding Value, ElementName=colorPicker, Converter={StaticResource converter}}"
Foreground="WhiteSmoke"
Click="ButtonClick">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="3" BorderBrush="Black" BorderThickness="1.5" Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding Content}"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</UserControl>

67
src/Main/Base/Project/Src/Gui/Components/ColorPicker.xaml.cs

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace ICSharpCode.SharpDevelop.Gui
{
/// <summary>
/// Interaction logic for ColorPicker.xaml
/// </summary>
public partial class ColorPicker : UserControl
{
SharpDevelopColorDialog dialog;
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(Color), typeof(ColorPicker));
public Color Value {
get { return (Color)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public ColorPicker()
{
InitializeComponent();
dialog = new SharpDevelopColorDialog();
}
void ButtonClick(object sender, RoutedEventArgs e)
{
if (dialog.ShowWpfDialog() ?? false) {
this.Value = dialog.WpfColor;
}
}
}
public class ColorToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is Color)
return new SolidColorBrush((Color)value);
throw new NotSupportedException();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is SolidColorBrush)
return (value as SolidColorBrush).Color;
throw new NotSupportedException();
}
}
}

50
src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs

@ -6,12 +6,10 @@ @@ -6,12 +6,10 @@
// </file>
using System;
using System.Linq;
using System.ComponentModel;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace ICSharpCode.Core.Presentation
@ -23,7 +21,7 @@ namespace ICSharpCode.Core.Presentation @@ -23,7 +21,7 @@ namespace ICSharpCode.Core.Presentation
/// Properties accessed by this binding have to be managed by a custom
/// settings class, which contains all settings as static properties or fields.<br />
/// Do not use PropertyService directly!<br />
/// This markup extension can only be used in OptionPanels or other <br />classes implementing IOptionBindingContainer!
/// This markup extension can only be used in OptionPanels or other <br />containers implementing IOptionBindingContainer!
/// </remarks>
/// <example>
/// <code>
@ -74,24 +72,40 @@ namespace ICSharpCode.Core.Presentation @@ -74,24 +72,40 @@ namespace ICSharpCode.Core.Presentation
IOptionBindingContainer container = TryFindContainer(target as FrameworkElement);
if (container == null)
throw new InvalidOperationException("This extension can only be used in OptionPanels");
throw new InvalidOperationException("This extension can be used in OptionPanels only!");
container.AddBinding(this);
object result = null;
if (this.propertyInfo is PropertyInfo)
result = (propertyInfo as PropertyInfo).GetValue(null, null);
else {
this.propertyInfo = t.GetField(name[1]);
if (this.propertyInfo is FieldInfo)
result = (propertyInfo as FieldInfo).GetValue(null);
try {
object result = null;
if (this.propertyInfo is PropertyInfo)
result = (propertyInfo as PropertyInfo).GetValue(null, null);
else {
this.propertyInfo = t.GetField(name[1]);
if (this.propertyInfo is FieldInfo)
result = (propertyInfo as FieldInfo).GetValue(null);
}
return ConvertOnDemand(result, dp.PropertyType);
} catch (Exception e) {
throw new Exception("Failing to convert " + dp.Name + " " + dp.PropertyType, e);
}
}
object ConvertOnDemand(object result, Type returnType)
{
if (returnType.IsInstanceOfType(result) || returnType == typeof(object))
return result;
Type returnType = dp.PropertyType;
if (returnType == typeof(string)) {
var converter = TypeDescriptor.GetConverter(result.GetType());
return converter.ConvertToString(result);
}
if (dp.PropertyType.IsGenericType && dp.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) {
returnType = dp.PropertyType.GetGenericArguments().First();
if (result is string) {
var converter = TypeDescriptor.GetConverter(returnType);
return converter.ConvertFromString(result as string);
}
return Convert.ChangeType(result, returnType);
@ -113,12 +127,16 @@ namespace ICSharpCode.Core.Presentation @@ -113,12 +127,16 @@ namespace ICSharpCode.Core.Presentation
object value = target.GetValue(dp);
Type returnType = null;
if (propertyInfo is PropertyInfo)
returnType = (propertyInfo as PropertyInfo).PropertyType;
if (propertyInfo is FieldInfo)
returnType = (propertyInfo as FieldInfo).FieldType;
value = Convert.ChangeType(value, returnType);
if (returnType == null)
return false;
value = ConvertOnDemand(value, returnType);
if (propertyInfo is PropertyInfo) {
(propertyInfo as PropertyInfo).SetValue(null, value, null);

Loading…
Cancel
Save