Browse Source

Started work on SD2-1592 - Add back highlighting editor for AvalonEdit

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5572 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
061496afc3
  1. 6
      samples/XamlDesigner/XamlDesigner.sln
  2. 3
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin
  3. 9
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  4. 65
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingRule.cs
  5. 197
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CustomizedHighlightingItem.cs
  6. 46
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml
  7. 92
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  8. 52
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/IHighlightingItem.cs
  9. 133
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs
  10. 40
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/ColorPicker.xaml.cs
  11. 7
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/RectangleSelection.cs
  12. 7
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs
  13. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingManager.cs
  14. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/IHighlightingDefinition.cs
  15. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd
  16. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd
  17. 41
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/VBNET-Mode.xshd
  18. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/SaveXshdVisitor.cs
  19. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V1Loader.cs
  20. 14
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs
  21. 7
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs
  22. 14
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs
  23. 3
      src/Main/Base/Project/Src/Editor/AddInHighlightingResource.cs
  24. 8
      src/Main/Base/Project/Src/Gui/Components/ColorPicker.xaml
  25. 59
      src/Main/Base/Project/Src/Gui/Components/ColorPicker.xaml.cs
  26. 6
      src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopColorDialog.cs

6
samples/XamlDesigner/XamlDesigner.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
# SharpDevelop 3.1.0.4545
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.0.5563
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlDesigner", "XamlDesigner.csproj", "{27DA2B5C-2AAA-4478-AB00-3E184273C241}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfDesign", "..\..\src\AddIns\DisplayBindings\WpfDesign\WpfDesign\Project\WpfDesign.csproj", "{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}"

3
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin

@ -135,6 +135,9 @@ @@ -135,6 +135,9 @@
<OptionPanel id = "Behavior"
label = "${res:Dialog.Options.IDEOptions.TextEditor.Behaviour.PanelName}"
class = "ICSharpCode.AvalonEdit.AddIn.Options.BehaviorOptions"/>
<OptionPanel id = "Highlighting"
label = "${res:Dialog.Options.TextEditorOptions.EditHighlighting.Title}"
class = "ICSharpCode.AvalonEdit.AddIn.Options.HighlightingOptions"/>
</OptionPanel>
</Path>
</AddIn>

9
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -92,6 +92,7 @@ @@ -92,6 +92,7 @@
<Compile Include="Src\Commands\SortSelectionCommand.cs" />
<Compile Include="Src\Commands\SurroundWithCommand.cs" />
<Compile Include="Src\CustomCommands.cs" />
<Compile Include="Src\CustomizedHighlightingRule.cs" />
<Compile Include="Src\DocumentPrinter.cs" />
<Compile Include="Src\IncrementalSearch.cs" />
<Compile Include="Src\InlineUIElementGenerator.cs" />
@ -101,11 +102,18 @@ @@ -101,11 +102,18 @@
<DependentUpon>BehaviorOptions.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Options\CustomizedHighlightingItem.cs" />
<Compile Include="Src\Options\GeneralEditorOptions.xaml.cs">
<DependentUpon>GeneralEditorOptions.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Options\CodeEditorOptions.cs" />
<Compile Include="Src\Options\HighlightingOptions.xaml.cs">
<DependentUpon>HighlightingOptions.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Options\IHighlightingItem.cs" />
<Compile Include="Src\Options\NamedColorHighlightingItem.cs" />
<Compile Include="Src\Options\TextViewOptions.xaml.cs">
<DependentUpon>TextViewOptions.xaml</DependentUpon>
<SubType>Code</SubType>
@ -174,6 +182,7 @@ @@ -174,6 +182,7 @@
<Page Include="Src\Commands\SortOptionsDialog.xaml" />
<Page Include="Src\Options\BehaviorOptions.xaml" />
<Page Include="Src\Options\GeneralEditorOptions.xaml" />
<Page Include="Src\Options\HighlightingOptions.xaml" />
<Page Include="Src\Options\TextViewOptions.xaml" />
<Page Include="Src\Snippets\SnippetOptionPanel.xaml">
<DependentUpon>SnippetOptionPanel.cs</DependentUpon>

65
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingRule.cs

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Media;
using ICSharpCode.Core;
namespace ICSharpCode.AvalonEdit.AddIn
{
/// <summary>
/// Holds a customized highlighting color.
/// </summary>
public class CustomizedHighlightingColor
{
/// <summary>
/// The language to which this customization applies. null==all languages.
/// </summary>
public string Language;
/// <summary>
/// The name of the highlighting color being modified.
/// </summary>
public string Name;
public bool Bold, Italic;
public Color? Foreground, Background;
public static List<CustomizedHighlightingColor> LoadColors()
{
return PropertyService.Get("CustomizedHighlightingRules", new List<CustomizedHighlightingColor>());
}
/// <summary>
/// Saves the set of colors.
/// </summary>
public static void SaveColors(IEnumerable<CustomizedHighlightingColor> colors)
{
lock (staticLockObj) {
activeColors = null;
PropertyService.Set("CustomizedHighlightingRules", colors.ToList());
}
}
static ReadOnlyCollection<CustomizedHighlightingColor> activeColors;
static readonly object staticLockObj = new object();
public static ReadOnlyCollection<CustomizedHighlightingColor> ActiveColors {
get {
lock (staticLockObj) {
if (activeColors == null)
activeColors = LoadColors().AsReadOnly();
return activeColors;
}
}
}
}
}

197
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CustomizedHighlightingItem.cs

@ -0,0 +1,197 @@ @@ -0,0 +1,197 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Windows.Media;
namespace ICSharpCode.AvalonEdit.AddIn.Options
{
sealed class CustomizedHighlightingItem : IHighlightingItem
{
readonly IHighlightingItem original;
readonly List<CustomizedHighlightingColor> customizationList;
readonly string language;
CustomizedHighlightingColor customization;
public CustomizedHighlightingItem(List<CustomizedHighlightingColor> customizationList, IHighlightingItem original, string language)
{
if (customizationList == null)
throw new ArgumentNullException("customizationList");
if (original == null)
throw new ArgumentNullException("original");
this.customizationList = customizationList;
this.original = original;
this.language = language;
foreach (CustomizedHighlightingColor c in customizationList) {
if (c.Language == language && c.Name == this.Name) {
this.customization = c;
break;
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null) {
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
void AllPropertiesChanged()
{
OnPropertyChanged("Bold");
OnPropertyChanged("Italic");
OnPropertyChanged("Foreground");
OnPropertyChanged("UseDefaultForeground");
OnPropertyChanged("Background");
OnPropertyChanged("UseDefaultBackground");
OnPropertyChanged("IsCustomized");
}
void SetCustomization(bool? bold = null, bool? italic = null,
Color? foreground = null, bool? useDefaultForeground = null,
Color? background = null, bool? useDefaultBackground = null)
{
CustomizedHighlightingColor newColor = new CustomizedHighlightingColor();
newColor.Language = language;
newColor.Name = this.Name;
newColor.Bold = bold ?? this.Bold;
newColor.Italic = italic ?? this.Italic;
if (useDefaultBackground ?? this.UseDefaultBackground)
newColor.Background = null;
else
newColor.Background = background ?? this.Background;
if (useDefaultForeground ?? this.UseDefaultForeground)
newColor.Foreground = null;
else
newColor.Foreground = foreground ?? this.Foreground;
// remove existing customization
if (language == null)
customizationList.RemoveAll(c => c.Name == this.Name);
else if (customization != null)
customizationList.Remove(customization);
if (newColor.Bold == original.Bold && newColor.Italic == original.Italic &&
(newColor.Background == null) == original.UseDefaultBackground &&
(newColor.Background == null || newColor.Background == original.Background) &&
(newColor.Foreground == null) == original.UseDefaultForeground &&
(newColor.Foreground == null || newColor.Foreground == original.Foreground))
{
// all settings at default values, customization entry not necessary
this.customization = null;
} else {
this.customization = newColor;
// insert at beginning to ensure language-specific entries take preference over generic entries
customizationList.Insert(0, newColor);
}
AllPropertiesChanged();
}
public string Name {
get {
return original.Name;
}
}
public bool Bold {
get {
return (customization != null) ? customization.Bold : original.Bold;
}
set {
SetCustomization(bold: value);
}
}
public bool Italic {
get {
return (customization != null) ? customization.Italic : original.Italic;
}
set {
SetCustomization(italic: value);
}
}
public Color Foreground {
get {
return (customization != null) ? (customization.Foreground ?? original.Foreground) : original.Foreground;
}
set {
SetCustomization(foreground: value, useDefaultForeground: (value == original.Foreground) ? default(bool?) : false);
}
}
public bool UseDefaultForeground {
get {
return (customization != null) ? (customization.Foreground == null) : original.UseDefaultForeground;
}
set {
SetCustomization(useDefaultForeground: value);
}
}
public Color Background {
get {
return (customization != null) ? (customization.Background ?? original.Background) : original.Background;
}
set {
SetCustomization(background: value, useDefaultBackground: (value == original.Background) ? default(bool?) : false);
}
}
public bool UseDefaultBackground {
get {
return (customization != null) ? (customization.Background == null) : original.UseDefaultBackground;
}
set {
SetCustomization(useDefaultBackground: value);
}
}
public bool CanUseDefaultColors {
get { return original.CanUseDefaultColors; }
}
public bool CanSetForeground {
get { return true; }
}
public bool CanSetBackground {
get { return true; }
}
public bool CanSetFont {
get { return true; }
}
public bool IsCustomized {
get { return customization != null || original.IsCustomized; }
}
public void Reset()
{
original.Reset();
SetCustomization(original.Bold, original.Italic, original.Foreground, original.UseDefaultForeground, original.Background, original.UseDefaultBackground);
AllPropertiesChanged();
}
public void ShowExample(ICSharpCode.AvalonEdit.Rendering.TextView exampleTextView)
{
original.ShowExample(exampleTextView);
}
public override string ToString()
{
return this.Name; }
}
}

46
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
<gui:OptionPanel x:Class="ICSharpCode.AvalonEdit.AddIn.Options.HighlightingOptions" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:core="http://icsharpcode.net/sharpdevelop/core" xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit" xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop" xmlns:local="clr-namespace:ICSharpCode.AvalonEdit.AddIn.Options">
<FrameworkElement.Resources>
<BooleanToVisibilityConverter x:Key="boolToVisibility" />
</FrameworkElement.Resources>
<DockPanel>
<StackPanel DockPanel.Dock="Right" Margin="4,0,8,0" DataContext="{Binding SelectedItem, ElementName=listBox}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" MinWidth="75" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0"
Content="{core:StringParse ${res:Dialog.HighlightingEditor.ColorDlg.Foreground}:}"
Visibility="{Binding CanSetBackground, Converter={StaticResource boolToVisibility}}" />
<gui:ColorPicker Value="{Binding Foreground}"
Text="{Binding UseDefaultForeground, Converter={x:Static local:BooleanToDefaultStringConverter.Instance}}"
Grid.Column="1" Grid.Row="0"
Visibility="{Binding CanSetForeground, Converter={StaticResource boolToVisibility}}" />
<Label Grid.Column="0" Grid.Row="1"
Content="{core:StringParse ${res:Dialog.HighlightingEditor.ColorDlg.Background}:}"
Visibility="{Binding CanSetBackground, Converter={StaticResource boolToVisibility}}" />
<gui:ColorPicker Value="{Binding Background}"
Text="{Binding UseDefaultBackground, Converter={x:Static local:BooleanToDefaultStringConverter.Instance}}"
Grid.Column="1" Grid.Row="1"
Visibility="{Binding CanSetBackground, Converter={StaticResource boolToVisibility}}" />
</Grid>
<CheckBox IsEnabled="{Binding CanSetFont}" IsChecked="{Binding Bold}" Content="{core:Localize Dialog.HighlightingEditor.ColorDlg.Bold}"/>
<CheckBox IsEnabled="{Binding CanSetFont}" IsChecked="{Binding Italic}" Content="{core:Localize Dialog.HighlightingEditor.ColorDlg.Italic}"/>
<Button Name="resetButton" IsEnabled="{Binding IsCustomized}" Click="ResetButtonClick">Reset</Button>
<Label Content="{core:StringParse ${res:Dialog.HighlightingEditor.SampleText}:}" />
<Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
BorderThickness="1">
<avalonedit:TextView Name="textView" Width="140" Height="40" />
</Border>
</StackPanel>
<ComboBox Name="languageComboBox" DockPanel.Dock="Top"/>
<core:RestrictDesiredSize>
<ListBox Name="listBox" />
</core:RestrictDesiredSize>
</DockPanel>
</gui:OptionPanel>

92
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Xml;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.AvalonEdit.AddIn.Options
{
public partial class HighlightingOptions : OptionPanel
{
public HighlightingOptions()
{
InitializeComponent();
}
List<CustomizedHighlightingColor> customizationList;
XshdSyntaxDefinition LoadBuiltinXshd(string name)
{
using (Stream s = typeof(HighlightingManager).Assembly.GetManifestResourceStream(name)) {
using (XmlTextReader reader = new XmlTextReader(s)) {
return HighlightingLoader.LoadXshd(reader);
}
}
}
public override void LoadOptions()
{
base.LoadOptions();
var syntaxDefinitions =
from name in typeof(HighlightingManager).Assembly.GetManifestResourceNames()
where name.StartsWith(typeof(HighlightingManager).Namespace + ".Resources.", StringComparison.OrdinalIgnoreCase)
where name.EndsWith(".xshd", StringComparison.OrdinalIgnoreCase)
select LoadBuiltinXshd(name);
var namedColors =
from def in syntaxDefinitions
from color in def.Elements.OfType<XshdColor>()
where color.ExampleText != null
group color by color.Name into g
orderby g.Key
select g.First();
customizationList = CustomizedHighlightingColor.LoadColors();
foreach (XshdColor namedColor in namedColors) {
listBox.Items.Add(new CustomizedHighlightingItem(customizationList, new NamedColorHighlightingItem(namedColor), null));
}
if (listBox.Items.Count > 0)
listBox.SelectedIndex = 0;
}
public override bool SaveOptions()
{
CustomizedHighlightingColor.SaveColors(customizationList);
return base.SaveOptions();
}
void ResetButtonClick(object sender, RoutedEventArgs e)
{
((IHighlightingItem)resetButton.DataContext).Reset();
}
}
sealed class BooleanToDefaultStringConverter : IValueConverter
{
public static readonly BooleanToDefaultStringConverter Instance = new BooleanToDefaultStringConverter();
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)value)
return "(Default)";
else
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
}

52
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/IHighlightingItem.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.ComponentModel;
using System.Windows.Media;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering;
namespace ICSharpCode.AvalonEdit.AddIn.Options
{
/// <summary>
/// Represents an item visible in the highlighting editor.
/// </summary>
public interface IHighlightingItem : INotifyPropertyChanged
{
string Name { get; }
/// <summary>
/// Gets/Sets whether the element uses bold font.
/// </summary>
bool Bold { get; set; }
/// <summary>
/// Gets/Sets whether the element uses italic font.
/// </summary>
bool Italic { get; set; }
Color Foreground { get; set; }
bool UseDefaultForeground { get; set; }
Color Background { get; set; }
bool UseDefaultBackground { get; set; }
bool CanUseDefaultColors { get; }
bool CanSetForeground { get; }
bool CanSetBackground { get; }
bool CanSetFont { get; }
bool IsCustomized { get; }
void Reset();
/// <summary>
/// Shows an example
/// </summary>
void ShowExample(TextView exampleTextView);
}
}

133
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs

@ -0,0 +1,133 @@ @@ -0,0 +1,133 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
namespace ICSharpCode.AvalonEdit.AddIn.Options
{
sealed class NamedColorHighlightingItem : IHighlightingItem
{
readonly XshdColor color;
public NamedColorHighlightingItem(XshdColor color)
{
if (color == null)
throw new ArgumentNullException("color");
this.color = color;
}
public string Name {
get { return color.Name; }
}
public bool Bold {
get {
return color.FontWeight == FontWeights.Bold;
}
set {
throw new NotSupportedException();
}
}
public bool Italic {
get {
return color.FontStyle == FontStyles.Italic;
}
set {
throw new NotSupportedException();
}
}
public Color Foreground {
get {
Color? c = color.Foreground != null ? color.Foreground.GetColor(null) : null;
if (c != null)
return c.Value;
else
return Colors.Black;
}
set {
throw new NotSupportedException();
}
}
public bool UseDefaultForeground {
get {
return color.Foreground == null;
}
set {
throw new NotSupportedException();
}
}
public Color Background {
get {
Color? c = color.Background != null ? color.Background.GetColor(null) : null;
if (c != null)
return c.Value;
else
return Colors.White;
}
set {
throw new NotSupportedException();
}
}
public bool UseDefaultBackground {
get {
return color.Background == null;
}
set {
throw new NotSupportedException();
}
}
public bool CanUseDefaultColors {
get { return true; }
}
public bool CanSetForeground {
get { return false; }
}
public bool CanSetBackground {
get { return false; }
}
public bool CanSetFont {
get { return false; }
}
public bool IsCustomized {
get { return false; }
}
public void Reset()
{
}
public override string ToString()
{
return color.Name;
}
public void ShowExample(ICSharpCode.AvalonEdit.Rendering.TextView exampleTextView)
{
throw new NotImplementedException();
}
event System.ComponentModel.PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add {} remove {} }
}
}

40
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/ColorPicker.xaml.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -31,7 +31,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
public static readonly DependencyProperty ColorProperty =
DependencyProperty.Register("Color", typeof(Color), typeof(ColorPicker),
new FrameworkPropertyMetadata(new Color(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
new FrameworkPropertyMetadata(new Color(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public Color Color {
get { return (Color)GetValue(ColorProperty); }
@ -118,27 +118,25 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -118,27 +118,25 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
if (updating) return;
updating = true;
if (e.Property == ColorProperty) {
UpdateSource(ColorSource.Hsv);
UpdateRest(ColorSource.Hsv);
}
else if (e.Property == HProperty || e.Property == SProperty || e.Property == VProperty) {
var c = ColorHelper.ColorFromHsv(H, S / 100.0, V / 100.0);
c.A = A;
Color = c;
UpdateRest(ColorSource.Hsv);
}
else if (e.Property == RProperty || e.Property == GProperty || e.Property == BProperty || e.Property == AProperty) {
Color = Color.FromArgb(A, R, G, B);
UpdateRest(ColorSource.Rgba);
}
else if (e.Property == HexProperty) {
Color = ColorHelper.ColorFromString(Hex);
UpdateRest(ColorSource.Hex);
try {
if (e.Property == ColorProperty) {
UpdateSource(ColorSource.Hsv);
UpdateRest(ColorSource.Hsv);
} else if (e.Property == HProperty || e.Property == SProperty || e.Property == VProperty) {
var c = ColorHelper.ColorFromHsv(H, S / 100.0, V / 100.0);
c.A = A;
Color = c;
UpdateRest(ColorSource.Hsv);
} else if (e.Property == RProperty || e.Property == GProperty || e.Property == BProperty || e.Property == AProperty) {
Color = Color.FromArgb(A, R, G, B);
UpdateRest(ColorSource.Rgba);
} else if (e.Property == HexProperty) {
Color = ColorHelper.ColorFromString(Hex);
UpdateRest(ColorSource.Hex);
}
} finally {
updating = false;
}
updating = false;
}
void UpdateRest(ColorSource source)

7
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/RectangleSelection.cs

@ -272,7 +272,12 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -272,7 +272,12 @@ namespace ICSharpCode.AvalonEdit.Editing
/// <inheritdoc/>
public override string ToString()
{
return "[RectangleSelection " + document.GetLocation(StartOffset) + " to " + document.GetLocation(EndOffset) + "]";
// It's possible that ToString() gets called on old (invalid) selections, e.g. for "change from... to..." debug message
// make sure we don't crash even when the desired locations don't exist anymore.
if (StartOffset < document.TextLength && EndOffset < document.TextLength)
return "[RectangleSelection " + document.GetLocation(StartOffset) + " to " + document.GetLocation(EndOffset) + "]";
else
return "[RectangleSelection " + StartOffset + " to " + EndOffset + "]";
}
}
}

7
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs

@ -41,6 +41,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -41,6 +41,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </summary>
public HighlightingBrush Foreground { get; set; }
/// <summary>
/// Gets/sets the background color applied by the highlighting.
/// </summary>
public HighlightingBrush Background { get; set; }
/// <summary>
/// Creates a new HighlightingColor instance.
/// </summary>
@ -61,6 +66,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -61,6 +66,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
if (info.GetBoolean("HasStyle"))
this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style"));
this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush));
this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush));
}
/// <summary>
@ -79,6 +85,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -79,6 +85,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
if (this.FontStyle.HasValue)
info.AddValue("Style", this.FontStyle.Value.ToString());
info.AddValue("Foreground", this.Foreground);
info.AddValue("Background", this.Background);
}
/// <summary>

6
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingManager.cs

@ -98,6 +98,12 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -98,6 +98,12 @@ namespace ICSharpCode.AvalonEdit.Highlighting
return GetDefinition().GetNamedColor(name);
}
public IEnumerable<HighlightingColor> NamedHighlightingColors {
get {
return GetDefinition().NamedHighlightingColors;
}
}
public override string ToString()
{
return this.Name;

6
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/IHighlightingDefinition.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace ICSharpCode.AvalonEdit.Highlighting
@ -37,5 +38,10 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -37,5 +38,10 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </summary>
/// <returns>The highlighting color, or null if it is not found.</returns>
HighlightingColor GetNamedColor(string name);
/// <summary>
/// Gets the list of named highlighting colors.
/// </summary>
IEnumerable<HighlightingColor> NamedHighlightingColors { get; }
}
}

6
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
<?xml version="1.0"?>
<SyntaxDefinition name="C#" extensions=".cs" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<!-- The named colors 'Comment' and 'String' are used in SharpDevelop to detect if a line is inside a multiline string/comment -->
<Color name="Comment" foreground="Green"/>
<Color name="String" foreground="Blue"/>
<Color name="Char" foreground="Magenta"/>
<Color name="Comment" foreground="Green" exampleText = "// comment" />
<Color name="String" foreground="Blue" exampleText = "string text = &quot;Hello, World!&quot;"/>
<Color name="Char" foreground="Magenta" exampleText = "char linefeed = '\n';"/>
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
<!-- Color -->
<xsd:attributeGroup name="ColorAttributes">
<xsd:attribute name="foreground" type="xsd:string" use="optional" />
<xsd:attribute name="background" type="xsd:string" use="optional" />
<xsd:attribute name="fontWeight" type="FontWeight" use="optional" />
<xsd:attribute name="fontStyle" type="FontStyle" use="optional" />
</xsd:attributeGroup>
@ -44,6 +45,7 @@ @@ -44,6 +45,7 @@
<xsd:element name="Color">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="exampleText" type="xsd:string" use="optional" />
<xsd:attributeGroup ref="ColorAttributes"/>
</xsd:complexType>
</xsd:element>

41
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/VBNET-Mode.xshd

@ -4,8 +4,18 @@ @@ -4,8 +4,18 @@
<!-- Updated 2005 by Daniel Grunwald for VB.NET 2.0 -->
<!-- Converted to AvalonEdit format by Daniel Grunwald in 2010 -->
<SyntaxDefinition name="VBNET" extensions=".vb" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" />
<Color name="String" />
<Color name="Comment" foreground="Green" exampleText="' comment" />
<Color name="String" exampleText="Dim text As String = &quot;Hello, World!&quot;" />
<Color name="DateLiteral" foreground="Blue" exampleText="Dim endOfWorld As DateTime = #2012-12-21#" />
<Color name="Preprocessor" foreground="Maroon" exampleText="#Region &quot;Title&quot;" />
<Color name="DataTypes" foreground="#FF6F002F" exampleText="Dim b As Boolean = True" />
<Color name="Operators" foreground="#FF8515EA" exampleText="If a OrElse b Then"/>
<Color name="Constants" foreground="Blue" exampleText="Dim b As Boolean = True" />
<Color name="Keywords" foreground="Blue" exampleText="If a OrElse b Then" />
<Color name="FunctionKeywords" foreground="Blue" exampleText="CInt(a)" />
<Color name="ContextKeywords" foreground="Blue" exampleText="Declare Unicode Sub SomeMethod" />
<RuleSet ignoreCase="true">
<Span color="String">
<Begin>"</Begin>
@ -14,11 +24,10 @@ @@ -14,11 +24,10 @@
<Span begin="&quot;&quot;" end="" />
</RuleSet>
</Span>
<Span foreground="Maroon" ruleSet="PreprocessorSet">
<Span color="Preprocessor" ruleSet="PreprocessorSet">
<Begin>(?&lt;=(^\s*))\#</Begin>
</Span>
<Span foreground="Blue">
<!-- Date Literal -->
<Span color="DateLiteral">
<Begin>(?&lt;!(^\s*))\#</Begin>
<End>\#</End>
</Span>
@ -31,7 +40,7 @@ @@ -31,7 +40,7 @@
<Span color="Comment">
<Begin>\bREM\b</Begin>
</Span>
<Keywords foreground="#FF6F002F">
<Keywords color="DataTypes">
<Word>Boolean</Word>
<Word>Byte</Word>
<Word>Char</Word>
@ -50,7 +59,7 @@ @@ -50,7 +59,7 @@
<Word>UShort</Word>
<Word>Variant</Word>
</Keywords>
<Keywords foreground="#FF8515EA">
<Keywords color="Operators">
<Word>AddressOf</Word>
<Word>And</Word>
<Word>AndAlso</Word>
@ -64,17 +73,15 @@ @@ -64,17 +73,15 @@
<Word>OrElse</Word>
<Word>Xor</Word>
</Keywords>
<Keywords foreground="Blue">
<Keywords color="Constants">
<Word>False</Word>
<Word>Me</Word>
<Word>MyBase</Word>
<Word>MyClass</Word>
<Word>Nothing</Word>
<Word>True</Word>
<Word>As</Word>
<Word>Of</Word>
<Word>New</Word>
<Word>End</Word>
</Keywords>
<Keywords color="FunctionKeywords">
<Word>CBool</Word>
<Word>CByte</Word>
<Word>CChar</Word>
@ -96,6 +103,12 @@ @@ -96,6 +103,12 @@
<Word>GetType</Word>
<Word>TryCast</Word>
<Word>TypeOf</Word>
</Keywords>
<Keywords color="Keywords">
<Word>As</Word>
<Word>Of</Word>
<Word>New</Word>
<Word>End</Word>
<Word>ByRef</Word>
<Word>ByVal</Word>
<Word>Optional</Word>
@ -188,6 +201,8 @@ @@ -188,6 +201,8 @@
<Word>Next</Word>
<Word>Select</Word>
<Word>Case</Word>
</Keywords>
<Keywords color="ContextKeywords">
<Word>Ansi</Word>
<Word>Auto</Word>
<Word>Unicode</Word>
@ -196,7 +211,7 @@ @@ -196,7 +211,7 @@
</Keywords>
</RuleSet>
<RuleSet name="PreprocessorSet" ignoreCase="true">
<Keywords foreground="Maroon" fontWeight="bold">
<Keywords fontWeight="bold">
<Word>Const</Word>
<Word>If</Word>
<Word>ElseIf</Word>

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/SaveXshdVisitor.cs

@ -99,6 +99,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -99,6 +99,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
{
if (color.Foreground != null)
writer.WriteAttributeString("foreground", color.Foreground.ToString());
if (color.Background != null)
writer.WriteAttributeString("background", color.Background.ToString());
if (color.FontWeight != null)
writer.WriteAttributeString("fontWeight", V2Loader.FontWeightConverter.ConvertToInvariantString(color.FontWeight.Value).ToLowerInvariant());
if (color.FontStyle != null)
@ -111,6 +113,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -111,6 +113,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
if (color.Name != null)
writer.WriteAttributeString("name", color.Name);
WriteColorAttributes(color);
if (color.ExampleText != null)
writer.WriteAttributeString("exampleText", color.ExampleText);
writer.WriteEndElement();
return null;
}

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V1Loader.cs

@ -89,7 +89,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -89,7 +89,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
static XshdColor GetColorFromElement(XmlElement element)
{
if (!element.HasAttribute("bold") && !element.HasAttribute("italic") && !element.HasAttribute("color"))
if (!element.HasAttribute("bold") && !element.HasAttribute("italic") && !element.HasAttribute("color") && !element.HasAttribute("bgcolor"))
return null;
XshdColor color = new XshdColor();
if (element.HasAttribute("bold"))
@ -98,6 +98,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -98,6 +98,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
color.FontStyle = XmlConvert.ToBoolean(element.GetAttribute("italic")) ? FontStyles.Italic : FontStyles.Normal;
if (element.HasAttribute("color"))
color.Foreground = ParseColor(element.GetAttribute("color"));
if (element.HasAttribute("bgcolor"))
color.Background = ParseColor(element.GetAttribute("bgcolor"));
return color;
}

14
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs

@ -241,6 +241,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -241,6 +241,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
// throw Error(reader, "A named color must have at least one element.");
color.Name = reader.GetAttribute("name");
CheckElementName(reader, color.Name);
color.ExampleText = reader.GetAttribute("exampleText");
return color;
}
@ -263,7 +264,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -263,7 +264,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
{
XshdColor color = new XshdColor();
SetPosition(color, reader);
color.Foreground = ParseForeground(reader as IXmlLineInfo, reader.GetAttribute("foreground"));
color.Foreground = ParseColor(reader as IXmlLineInfo, reader.GetAttribute("foreground"));
color.Background = ParseColor(reader as IXmlLineInfo, reader.GetAttribute("background"));
color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight"));
color.FontStyle = ParseFontStyle(reader.GetAttribute("fontStyle"));
return color;
@ -273,14 +275,14 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -273,14 +275,14 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
internal readonly static FontWeightConverter FontWeightConverter = new FontWeightConverter();
internal readonly static FontStyleConverter FontStyleConverter = new FontStyleConverter();
static HighlightingBrush ParseForeground(IXmlLineInfo lineInfo, string foreground)
static HighlightingBrush ParseColor(IXmlLineInfo lineInfo, string color)
{
if (string.IsNullOrEmpty(foreground))
if (string.IsNullOrEmpty(color))
return null;
if (foreground.StartsWith("SystemColors.", StringComparison.Ordinal))
return GetSystemColorBrush(lineInfo, foreground);
if (color.StartsWith("SystemColors.", StringComparison.Ordinal))
return GetSystemColorBrush(lineInfo, color);
else
return FixedColorHighlightingBrush((Color?)ColorConverter.ConvertFromInvariantString(foreground));
return FixedColorHighlightingBrush((Color?)ColorConverter.ConvertFromInvariantString(color));
}
internal static SystemColorHighlightingBrush GetSystemColorBrush(IXmlLineInfo lineInfo, string name)

7
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs

@ -189,6 +189,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -189,6 +189,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
c.Name = color.Name;
c.Foreground = color.Foreground;
c.Background = color.Background;
c.FontStyle = color.FontStyle;
c.FontWeight = color.FontWeight;
return c;
@ -372,6 +373,12 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -372,6 +373,12 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
return null;
}
public IEnumerable<HighlightingColor> NamedHighlightingColors {
get {
return colorDict.Values;
}
}
public override string ToString()
{
return this.Name;

14
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs

@ -28,6 +28,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -28,6 +28,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
/// </summary>
public HighlightingBrush Foreground { get; set; }
/// <summary>
/// Gets/sets the background brush.
/// </summary>
public HighlightingBrush Background { get; set; }
/// <summary>
/// Gets/sets the font weight.
/// </summary>
@ -38,6 +43,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -38,6 +43,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
/// </summary>
public FontStyle? FontStyle { get; set; }
/// <summary>
/// Gets/Sets the example text that demonstrates where the color is used.
/// </summary>
public string ExampleText { get; set; }
/// <summary>
/// Creates a new XshdColor instance.
/// </summary>
@ -54,10 +64,12 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -54,10 +64,12 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
throw new ArgumentNullException("info");
this.Name = info.GetString("Name");
this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush));
this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush));
if (info.GetBoolean("HasWeight"))
this.FontWeight = System.Windows.FontWeight.FromOpenTypeWeight(info.GetInt32("Weight"));
if (info.GetBoolean("HasStyle"))
this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style"));
this.ExampleText = info.GetString("ExampleText");
}
/// <summary>
@ -70,12 +82,14 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd @@ -70,12 +82,14 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
throw new ArgumentNullException("info");
info.AddValue("Name", this.Name);
info.AddValue("Foreground", this.Foreground);
info.AddValue("Background", this.Background);
info.AddValue("HasWeight", this.FontWeight.HasValue);
if (this.FontWeight.HasValue)
info.AddValue("Weight", this.FontWeight.Value.ToOpenTypeWeight());
info.AddValue("HasStyle", this.FontStyle.HasValue);
if (this.FontStyle.HasValue)
info.AddValue("Style", this.FontStyle.Value.ToString());
info.AddValue("ExampleText", this.ExampleText);
}
/// <inheritdoc/>

3
src/Main/Base/Project/Src/Editor/AddInHighlightingResource.cs

@ -54,8 +54,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -54,8 +54,7 @@ namespace ICSharpCode.SharpDevelop.Editor
using (Stream stream = OpenStream(name)) {
using (XmlTextReader reader = new XmlTextReader(stream)) {
XshdSyntaxDefinition xshd = HighlightingLoader.LoadXshd(reader);
return HighlightingLoader.Load(xshd, resolver);
return HighlightingLoader.Load(reader, resolver);
}
}
}

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

@ -2,13 +2,7 @@ @@ -2,13 +2,7 @@
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 Name="button" Click="ButtonClick">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="3" BorderBrush="Black" BorderThickness="1.5" Background="{TemplateBinding Background}">

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

@ -18,50 +18,59 @@ using System.Windows.Media; @@ -18,50 +18,59 @@ using System.Windows.Media;
namespace ICSharpCode.SharpDevelop.Gui
{
/// <summary>
/// Interaction logic for ColorPicker.xaml
/// A user control for choosing a color.
/// </summary>
public partial class ColorPicker : UserControl
{
SharpDevelopColorDialog dialog;
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(Color), typeof(ColorPicker));
DependencyProperty.Register("Value", typeof(Color), typeof(ColorPicker), new FrameworkPropertyMetadata(new Color(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged));
public Color Value {
get { return (Color)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public ColorPicker()
{
InitializeComponent();
dialog = new SharpDevelopColorDialog();
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(ColorPicker),
new FrameworkPropertyMetadata(OnValueChanged));
public string Text {
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
void ButtonClick(object sender, RoutedEventArgs e)
static void OnValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
if (dialog.ShowWpfDialog() == true) {
this.Value = dialog.WpfColor;
ColorPicker picker = obj as ColorPicker;
if (picker != null) {
Color color = picker.Value;
picker.button.Background = new SolidColorBrush(color);
// find a foreground color that is visible on the background
if (color.A < 128)
picker.button.Foreground = SystemColors.WindowTextBrush;
else if (0.299f * color.R + 0.587f * color.G + 0.114f * color.B > 128)
picker.button.Foreground = Brushes.Black;
else
picker.button.Foreground = Brushes.WhiteSmoke;
picker.button.Content = picker.Text ?? color.ToString();
}
}
}
public class ColorToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public ColorPicker()
{
if (value is Color)
return new SolidColorBrush((Color)value);
throw new NotSupportedException();
InitializeComponent();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
void ButtonClick(object sender, RoutedEventArgs e)
{
if (value is SolidColorBrush)
return (value as SolidColorBrush).Color;
throw new NotSupportedException();
using (SharpDevelopColorDialog dlg = new SharpDevelopColorDialog()) {
dlg.WpfColor = this.Value;
if (dlg.ShowWpfDialog() == true) {
// use SetCurrentValue instead of SetValue so that two-way data binding can be used
SetCurrentValue(ValueProperty, dlg.WpfColor);
}
}
}
}
}

6
src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopColorDialog.cs

@ -90,7 +90,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -90,7 +90,11 @@ namespace ICSharpCode.SharpDevelop.Gui
public System.Windows.Media.Color WpfColor {
get {
return System.Windows.Media.Color.FromArgb(this.Color.A, this.Color.R, this.Color.G, this.Color.B);
var c = this.Color;
return System.Windows.Media.Color.FromArgb(c.A, c.R, c.G, c.B);
}
set {
this.Color = System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
}
}
}

Loading…
Cancel
Save