Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5572 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
26 changed files with 754 additions and 83 deletions
@ -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; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -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;
} |
||||
} |
||||
} |
||||
@ -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> |
||||
@ -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(); |
||||
} |
||||
} |
||||
} |
||||
@ -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); |
||||
} |
||||
} |
||||
@ -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 {} } |
||||
} |
||||
} |
||||
Loading…
Reference in new issue