Browse Source

implement importer for .vssettings syntax highlighting and fix some styling/theming bugs

pull/26/head
Siegfried Pammer 13 years ago
parent
commit
f35b3e2268
  1. 2
      SharpDevelop.sln
  2. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  3. 37
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs
  4. 12
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
  5. 13
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml
  6. 299
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  7. 16
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingMargin.cs
  8. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd
  9. 30
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs
  10. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLineLinkText.cs
  11. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  12. 4
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml
  13. 6
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs
  14. 117
      src/Main/Base/Project/Src/Util/MultiDictionary.cs

2
SharpDevelop.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
# SharpDevelop 4.2.0.8634-beta # SharpDevelop 4.2.0.8783
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}"
ProjectSection(SolutionItems) = postProject ProjectSection(SolutionItems) = postProject
EndProjectSection EndProjectSection

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

@ -64,6 +64,9 @@
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Xaml" /> <Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase"> <Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework> <RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference> </Reference>
@ -241,7 +244,6 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\MyersDiff" />
<Folder Include="Src\HiddenDefinition" /> <Folder Include="Src\HiddenDefinition" />
</ItemGroup> </ItemGroup>
</Project> </Project>

37
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs

@ -43,6 +43,35 @@ namespace ICSharpCode.AvalonEdit.AddIn
} }
} }
#region Brushes
public static readonly DependencyProperty AddedLineBrushProperty =
DependencyProperty.Register("AddedLineBrush", typeof(Brush), typeof(ChangeMarkerMargin),
new FrameworkPropertyMetadata(Brushes.LightGreen));
public Brush AddedLineBrush {
get { return (Brush)GetValue(AddedLineBrushProperty); }
set { SetValue(AddedLineBrushProperty, value); }
}
public static readonly DependencyProperty ChangedLineBrushProperty =
DependencyProperty.Register("ChangedLineBrush", typeof(Brush), typeof(ChangeMarkerMargin),
new FrameworkPropertyMetadata(Brushes.LightBlue));
public Brush ChangedLineBrush {
get { return (Brush)GetValue(ChangedLineBrushProperty); }
set { SetValue(ChangedLineBrushProperty, value); }
}
public static readonly DependencyProperty UnsavedLineBrushProperty =
DependencyProperty.Register("UnsavedLineBrush", typeof(Brush), typeof(ChangeMarkerMargin),
new FrameworkPropertyMetadata(Brushes.Yellow));
public Brush UnsavedLineBrush {
get { return (Brush)GetValue(UnsavedLineBrushProperty); }
set { SetValue(UnsavedLineBrushProperty, value); }
}
#endregion
protected override void OnRender(DrawingContext drawingContext) protected override void OnRender(DrawingContext drawingContext)
{ {
Size renderSize = this.RenderSize; Size renderSize = this.RenderSize;
@ -52,7 +81,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
var zeroLineInfo = changeWatcher.GetChange(0); var zeroLineInfo = changeWatcher.GetChange(0);
foreach (VisualLine line in textView.VisualLines) { foreach (VisualLine line in textView.VisualLines) {
Rect rect = new Rect(0, line.VisualTop - textView.ScrollOffset.Y, 5, line.Height); Rect rect = new Rect(0, line.VisualTop - textView.ScrollOffset.Y - 1, 5, line.Height + 2);
LineChangeInfo info = changeWatcher.GetChange(line.FirstDocumentLine.LineNumber); LineChangeInfo info = changeWatcher.GetChange(line.FirstDocumentLine.LineNumber);
@ -64,14 +93,14 @@ namespace ICSharpCode.AvalonEdit.AddIn
case ChangeType.None: case ChangeType.None:
break; break;
case ChangeType.Added: case ChangeType.Added:
drawingContext.DrawRectangle(Brushes.LightGreen, null, rect); drawingContext.DrawRectangle(AddedLineBrush, null, rect);
break; break;
case ChangeType.Deleted: case ChangeType.Deleted:
case ChangeType.Modified: case ChangeType.Modified:
drawingContext.DrawRectangle(Brushes.LightBlue, null, rect); drawingContext.DrawRectangle(ChangedLineBrush, null, rect);
break; break;
case ChangeType.Unsaved: case ChangeType.Unsaved:
drawingContext.DrawRectangle(Brushes.Yellow, null, rect); drawingContext.DrawRectangle(UnsavedLineBrush, null, rect);
break; break;
default: default:
throw new Exception("Invalid value for ChangeType"); throw new Exception("Invalid value for ChangeType");

12
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs

@ -12,6 +12,7 @@ using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.SharpDevelop.Project.Commands;
namespace ICSharpCode.AvalonEdit.AddIn namespace ICSharpCode.AvalonEdit.AddIn
{ {
@ -24,6 +25,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
public const string SelectedText = "Selected text"; public const string SelectedText = "Selected text";
public const string NonPrintableCharacters = "Non-printable characters"; public const string NonPrintableCharacters = "Non-printable characters";
public const string LineNumbers = "Line numbers"; public const string LineNumbers = "Line numbers";
public const string LinkText = "Link text";
public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable<CustomizedHighlightingColor> customizations) public static void ApplyCustomizationsToDefaultElements(TextEditor textEditor, IEnumerable<CustomizedHighlightingColor> customizations)
{ {
@ -42,6 +44,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
bool assignedSelectedText = false; bool assignedSelectedText = false;
bool assignedNonPrintableCharacter = false; bool assignedNonPrintableCharacter = false;
bool assignedLineNumbers = false; bool assignedLineNumbers = false;
bool assignedLinkText = false;
foreach (CustomizedHighlightingColor color in customizations) { foreach (CustomizedHighlightingColor color in customizations) {
switch (color.Name) { switch (color.Name) {
case DefaultTextAndBackground: case DefaultTextAndBackground:
@ -88,6 +91,15 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (color.Foreground != null) if (color.Foreground != null)
textEditor.LineNumbersForeground = CreateFrozenBrush(color.Foreground.Value); textEditor.LineNumbersForeground = CreateFrozenBrush(color.Foreground.Value);
break; break;
case LinkText:
if (assignedLinkText)
continue;
assignedLinkText = true;
if (color.Foreground != null)
textEditor.TextArea.TextView.LinkTextForegroundBrush = CreateFrozenBrush(color.Foreground.Value);
if (color.Background != null)
textEditor.TextArea.TextView.LinkTextBackgroundBrush = CreateFrozenBrush(color.Background.Value);
break;
} }
} }
} }

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

@ -1,4 +1,11 @@
<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"> <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:widgets="http://icsharpcode.net/sharpdevelop/widgets"
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> <FrameworkElement.Resources>
<BooleanToVisibilityConverter x:Key="boolToVisibility" /> <BooleanToVisibilityConverter x:Key="boolToVisibility" />
</FrameworkElement.Resources> </FrameworkElement.Resources>
@ -39,6 +46,10 @@
<core:RestrictDesiredSize Height="50" MinWidth="200"> <core:RestrictDesiredSize Height="50" MinWidth="200">
<avalonedit:TextEditor Name="textEditor" IsReadOnly="True" /> <avalonedit:TextEditor Name="textEditor" IsReadOnly="True" />
</core:RestrictDesiredSize> </core:RestrictDesiredSize>
<widgets:StackPanelWithSpacing Orientation="Vertical" SpaceBetweenItems="5" Margin="0,5">
<Button Click="ImportButtonClick" Content="{core:Localize Dialog.HighlightingEditor.Import}" />
<Button Click="ExportButtonClick" Content="{core:Localize Dialog.HighlightingEditor.Export}" />
</widgets:StackPanelWithSpacing>
</StackPanel> </StackPanel>
<ComboBox Name="languageComboBox" DockPanel.Dock="Top" SelectionChanged="LanguageComboBox_SelectionChanged"> <ComboBox Name="languageComboBox" DockPanel.Dock="Top" SelectionChanged="LanguageComboBox_SelectionChanged">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>

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

@ -5,22 +5,26 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Xml; using System.Xml;
using System.Xml.Linq;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Folding; using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd; using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Bookmarks; using ICSharpCode.SharpDevelop.Bookmarks;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using Microsoft.Win32;
namespace ICSharpCode.AvalonEdit.AddIn.Options namespace ICSharpCode.AvalonEdit.AddIn.Options
{ {
@ -130,6 +134,8 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
} }
customizationList = CustomizedHighlightingColor.LoadColors(); customizationList = CustomizedHighlightingColor.LoadColors();
CreateDefaultEntries(null, out defaultText, defaultEntries);
languageComboBox.Items.Clear(); languageComboBox.Items.Clear();
languageComboBox.Items.Add(new XshdSyntaxDefinition { Name = "All languages" }); languageComboBox.Items.Add(new XshdSyntaxDefinition { Name = "All languages" });
foreach (XshdSyntaxDefinition def in allSyntaxDefinitions) foreach (XshdSyntaxDefinition def in allSyntaxDefinitions)
@ -144,7 +150,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem; XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
if (xshd != null) { if (xshd != null) {
IHighlightingItem defaultText; IHighlightingItem defaultText;
CreateDefaultEntries(languageComboBox.SelectedIndex == 0 ? null : xshd.Name, out defaultText); List<IHighlightingItem> list = new List<IHighlightingItem>();
CreateDefaultEntries(languageComboBox.SelectedIndex == 0 ? null : xshd.Name, out defaultText, list);
listBox.Items.AddRange(list);
if (languageComboBox.SelectedIndex > 0) { if (languageComboBox.SelectedIndex > 0) {
// Create entries for all customizable colors in the syntax highlighting definition // Create entries for all customizable colors in the syntax highlighting definition
@ -168,18 +176,16 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
} }
} }
void CreateDefaultEntries(string language, out IHighlightingItem defaultText) void CreateDefaultEntries(string language, out IHighlightingItem defaultText, IList<IHighlightingItem> items)
{ {
// Create entry for "default text/background" // Create entry for "default text/background"
defaultText = new SimpleHighlightingItem(CustomizableHighlightingColorizer.DefaultTextAndBackground, ta => ta.Document.Text = "Normal text") { defaultText = new SimpleHighlightingItem(CustomizableHighlightingColorizer.DefaultTextAndBackground, ta => ta.Document.Text = "Normal text") {
Foreground = SystemColors.WindowTextColor, Foreground = SystemColors.WindowTextColor,
Background = SystemColors.WindowColor Background = SystemColors.WindowColor
}; };
defaultText = new CustomizedHighlightingItem(customizationList, defaultText, null, canSetFont: false); defaultText = new CustomizedHighlightingItem(customizationList, defaultText, language, canSetFont: false);
if (language != null)
defaultText = new CustomizedHighlightingItem(customizationList, defaultText, language, canSetFont: false);
defaultText.PropertyChanged += item_PropertyChanged; defaultText.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(defaultText); items.Add(defaultText);
// Create entry for "Selected text" // Create entry for "Selected text"
IHighlightingItem selectedText = new SimpleHighlightingItem( IHighlightingItem selectedText = new SimpleHighlightingItem(
@ -192,11 +198,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
Foreground = SystemColors.HighlightTextColor, Foreground = SystemColors.HighlightTextColor,
Background = SystemColors.HighlightColor Background = SystemColors.HighlightColor
}; };
selectedText = new CustomizedHighlightingItem(customizationList, selectedText, null, canSetFont: false); selectedText = new CustomizedHighlightingItem(customizationList, selectedText, language, canSetFont: false);
if (language != null)
selectedText = new CustomizedHighlightingItem(customizationList, selectedText, language, canSetFont: false);
selectedText.PropertyChanged += item_PropertyChanged; selectedText.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(selectedText); items.Add(selectedText);
// Create entry for "Non-printable characters" // Create entry for "Non-printable characters"
IHighlightingItem nonPrintChars = new SimpleHighlightingItem( IHighlightingItem nonPrintChars = new SimpleHighlightingItem(
@ -207,11 +211,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{ {
Foreground = Colors.LightGray Foreground = Colors.LightGray
}; };
nonPrintChars = new CustomizedHighlightingItem(customizationList, nonPrintChars, null, canSetFont: false, canSetBackground: false); nonPrintChars = new CustomizedHighlightingItem(customizationList, nonPrintChars, language, canSetFont: false, canSetBackground: false);
if (language != null)
nonPrintChars = new CustomizedHighlightingItem(customizationList, nonPrintChars, language, canSetFont: false);
nonPrintChars.PropertyChanged += item_PropertyChanged; nonPrintChars.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(nonPrintChars); items.Add(nonPrintChars);
// Create entry for "Line numbers" // Create entry for "Line numbers"
IHighlightingItem lineNumbers = new SimpleHighlightingItem( IHighlightingItem lineNumbers = new SimpleHighlightingItem(
@ -225,11 +227,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{ {
Foreground = Colors.Gray Foreground = Colors.Gray
}; };
lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, null, canSetFont: false, canSetBackground: false); lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, language, canSetFont: false, canSetBackground: false);
if (language != null)
lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, language, canSetFont: false);
lineNumbers.PropertyChanged += item_PropertyChanged; lineNumbers.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(lineNumbers); items.Add(lineNumbers);
// Create entry for "Bracket highlight" // Create entry for "Bracket highlight"
IHighlightingItem bracketHighlight = new SimpleHighlightingItem( IHighlightingItem bracketHighlight = new SimpleHighlightingItem(
@ -247,11 +247,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
Foreground = BracketHighlightRenderer.DefaultBorder, Foreground = BracketHighlightRenderer.DefaultBorder,
Background = BracketHighlightRenderer.DefaultBackground Background = BracketHighlightRenderer.DefaultBackground
}; };
bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, null, canSetFont: false); bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, language, canSetFont: false);
if (language != null)
bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, language, canSetFont: false);
bracketHighlight.PropertyChanged += item_PropertyChanged; bracketHighlight.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(bracketHighlight); items.Add(bracketHighlight);
// Create entry for "Folding controls" // Create entry for "Folding controls"
IHighlightingItem foldingControls = new SimpleHighlightingItem( IHighlightingItem foldingControls = new SimpleHighlightingItem(
@ -266,11 +264,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
Foreground = Colors.Gray, Foreground = Colors.Gray,
Background = Colors.White Background = Colors.White
}; };
foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, null, canSetFont: false); foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, language, canSetFont: false);
if (language != null)
foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, language, canSetFont: false);
foldingControls.PropertyChanged += item_PropertyChanged; foldingControls.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(foldingControls); items.Add(foldingControls);
// Create entry for "Selected folding controls" // Create entry for "Selected folding controls"
IHighlightingItem selectedFoldingControls = new SimpleHighlightingItem( IHighlightingItem selectedFoldingControls = new SimpleHighlightingItem(
@ -285,11 +281,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
Foreground = Colors.Black, Foreground = Colors.Black,
Background = Colors.White Background = Colors.White
}; };
selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, null, canSetFont: false); selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, language, canSetFont: false);
if (language != null)
selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, language, canSetFont: false);
selectedFoldingControls.PropertyChanged += item_PropertyChanged; selectedFoldingControls.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(selectedFoldingControls); items.Add(selectedFoldingControls);
// Create entry for "Folding text markers" // Create entry for "Folding text markers"
IHighlightingItem foldingTextMarker = new SimpleHighlightingItem( IHighlightingItem foldingTextMarker = new SimpleHighlightingItem(
@ -303,14 +297,25 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{ {
Foreground = Colors.Gray Foreground = Colors.Gray
}; };
foldingTextMarker = new CustomizedHighlightingItem(customizationList, foldingTextMarker, null, canSetFont: false, canSetBackground: false); foldingTextMarker = new CustomizedHighlightingItem(customizationList, foldingTextMarker, language, canSetFont: false, canSetBackground: false);
if (language != null)
foldingControls = new CustomizedHighlightingItem(customizationList, foldingTextMarker, language, canSetFont: false, canSetBackground: false);
foldingTextMarker.PropertyChanged += item_PropertyChanged; foldingTextMarker.PropertyChanged += item_PropertyChanged;
listBox.Items.Add(foldingTextMarker); items.Add(foldingTextMarker);
IHighlightingItem linkText = new SimpleHighlightingItem(
CustomizableHighlightingColorizer.LinkText,
ta => {
ta.Document.Text = "http://icsharpcode.net" + Environment.NewLine + "me@example.com";
})
{
Foreground = Colors.Blue,
Background = Colors.Transparent
};
linkText = new CustomizedHighlightingItem(customizationList, linkText, language, canSetFont: false);
linkText.PropertyChanged += item_PropertyChanged;
items.Add(linkText);
} }
void item_PropertyChanged(object sender, PropertyChangedEventArgs e) void item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
UpdatePreview(); UpdatePreview();
} }
@ -358,5 +363,227 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
} }
} }
} }
void ImportButtonClick(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog {
Filter = @"All known settings|*.vssettings;*.sdsettings|Visual Studio settings (*.vssettings)|*.vssettings|SharpDevelop settings (*.sdsettings)|*.sdsettings",
CheckFileExists = true
};
if (dialog.ShowDialog() != true)
return;
switch (Path.GetExtension(dialog.FileName).ToUpperInvariant()) {
case ".VSSETTINGS":
LoadVSSettings(XDocument.Load(dialog.FileName));
break;
case ".SDSETTINGS":
LoadSDSettings(XDocument.Load(dialog.FileName));
break;
}
}
#region VSSettings
void LoadVSSettings(XDocument document)
{
XElement[] items;
if (!CheckVersionAndFindCategory(document, out items) || items == null) {
Core.MessageService.ShowError("Settings version not supported!");
return;
}
foreach (var item in items) {
string key = item.Attribute("Name").Value;
var entry = ParseEntry(item);
foreach (var sdKey in mapping[key]) {
IHighlightingItem color;
if (FindSDColor(sdKey, out color)) {
color.Bold = entry.Item3;
color.Foreground = entry.Item1;
color.Background = entry.Item2;
}
}
}
}
readonly List<IHighlightingItem> defaultEntries = new List<IHighlightingItem>();
IHighlightingItem defaultText;
bool FindSDColor(string sdKey, out IHighlightingItem item)
{
string language = null;
int dot = sdKey.IndexOf('.');
if (dot > 0) {
language = sdKey.Substring(0, dot);
sdKey = sdKey.Substring(dot + 1);
}
if ((language == null && languageComboBox.SelectedIndex == 0)
|| (language == ((XshdSyntaxDefinition)languageComboBox.SelectedItem).Name)) {
item = listBox.Items.OfType<IHighlightingItem>().FirstOrDefault(i => i.Name == sdKey);
} else if (language == null) {
item = defaultEntries.FirstOrDefault(i => i.Name == sdKey);
} else {
var def = allSyntaxDefinitions.FirstOrDefault(d => d.Name == language);
var highlighting = HighlightingManager.Instance.GetDefinition(language);
item = null;
if (def != null && highlighting != null) {
var color = def.Elements.OfType<XshdColor>().FirstOrDefault(i => i.Name == sdKey);
if (color != null) {
item = new NamedColorHighlightingItem(defaultText, color) { ParentDefinition = highlighting };
item = new CustomizedHighlightingItem(customizationList, item, language);
}
}
}
return item != null;
}
// VS => SD
static readonly MultiDictionary<string, string> mapping = new MultiDictionary<string, string>(StringComparer.Ordinal) {
{ "Brace Matching (Rectangle)", "Bracket highlight" },
{ "Collapsible Text", "" },
{ "Comment", "" },
{ "Comment", "C#.Comment" },
{ "Compiler Error", "" },
{ "CSS Comment", "" },
{ "CSS Keyword", "" },
{ "CSS Property Name", "" },
{ "CSS Property Value", "" },
{ "CSS Selector", "" },
{ "CSS String Value", "" },
{ "Excluded Code", "" },
{ "HTML Attribute Value", "" },
{ "HTML Attribute", "" },
{ "HTML Comment", "" },
{ "HTML Element Name", "" },
{ "HTML Entity", "" },
{ "HTML Operator", "" },
{ "HTML Server-Side Script", "" },
{ "HTML Tag Delimiter", "" },
{ "Identifier", "" },
{ "Inactive Selected Text", "" },
{ "Indicator Margin", "" },
{ "Keyword", "" },
{ "Line Numbers", "Line numbers" },
{ "MarkerFormatDefinition/HighlightedReference", "" },
{ "Number", "" },
{ "Operator", "" },
{ "outlining.collapsehintadornment", "" },
{ "outlining.square", "" },
{ "outlining.verticalrule", "" },
{ "Plain Text", "" },
{ "Plain Text", "Default text/background" },
{ "Preprocessor Keyword", "" },
{ "Preprocessor Keyword", "C#.Preprocessor" },
{ "Razor Code", "" },
{ "Script Comment", "" },
{ "Script Identifier", "" },
{ "Script Keyword", "" },
{ "Script Number", "" },
{ "Script Operator", "" },
{ "Script String", "" },
{ "Selected Text", "" },
{ "Selected Text", "Selected text" },
{ "String", "" },
{ "String", "C#.String" },
{ "String(C# @ Verbatim)", "" },
{ "Syntax Error", "" },
{ "urlformat", "" },
{ "User Types", "" },
{ "User Types(Delegates)", "" },
{ "User Types(Enums)", "" },
{ "User Types(Interfaces)", "" },
{ "User Types(Value types)", "" },
{ "Warning", "" },
{ "XAML Attribute Quotes", "" },
{ "XAML Attribute Value", "" },
{ "XAML Attribute", "" },
{ "XAML CData Section", "" },
{ "XAML Comment", "" },
{ "XAML Delimiter", "" },
{ "XAML Markup Extension Class", "" },
{ "XAML Markup Extension Parameter Name", "" },
{ "XAML Markup Extension Parameter Value", "" },
{ "XAML Name", "" },
{ "XAML Text", "" },
{ "XML Attribute Quotes", "" },
{ "XML Attribute Value", "" },
{ "XML Attribute", "" },
{ "XML CData Section", "" },
{ "XML Comment", "" },
{ "XML Delimiter", "" },
{ "XML Doc Comment", "" },
{ "XML Doc Tag", "" },
{ "XML Name", "" },
{ "XML Text", "" },
};
Tuple<Color, Color, bool> ParseEntry(XElement element)
{
Color fore = Colors.Transparent;
Color back = Colors.Transparent;
bool isBold = false;
var attribute = element.Attribute("Foreground");
if (attribute != null)
fore = ParseColor(attribute.Value);
attribute = element.Attribute("Background");
if (attribute != null)
back = ParseColor(attribute.Value);
attribute = element.Attribute("BoldFont");
if (attribute != null)
isBold = attribute.Value == "Yes";
return Tuple.Create(fore, back, isBold);
}
Color ParseColor(string s)
{
if (string.IsNullOrWhiteSpace(s))
return Colors.Transparent;
if (s.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
s = s.Substring(2);
if (s.Substring(0, 2) == "02")
return Colors.Transparent;
try {
byte b = byte.Parse(s.Substring(2, 2), NumberStyles.HexNumber);
byte g = byte.Parse(s.Substring(4, 2), NumberStyles.HexNumber);
byte r = byte.Parse(s.Substring(6, 2), NumberStyles.HexNumber);
return Color.FromRgb(r, g, b);
} catch (FormatException) {
return Colors.Transparent;
}
}
bool CheckVersionAndFindCategory(XDocument document, out XElement[] categoryItems)
{
categoryItems = null;
var node = document.Root;
var appID = document.Root.Element("ApplicationIdentity");
var category = document.Root.Descendants("Category").FirstOrDefault(e => e.Attribute("GUID") != null && e.Attribute("GUID").Value == "{A27B4E24-A735-4D1D-B8E7-9716E1E3D8E0}");
if (category != null)
categoryItems = category.Descendants("Item").ToArray();
if (node.Name != "UserSettings" || appID == null || category == null)
return false;
return appID.Attribute("version") != null && appID.Attribute("version").Value == "10.0";
}
#endregion
#region SDSettings
void LoadSDSettings(XDocument document)
{
var p = Properties.Load(document.CreateReader());
customizationList = p.Get("CustomizedHighlightingRules", new List<CustomizedHighlightingColor>());
LanguageComboBox_SelectionChanged(null, null);
}
#endregion
void ExportButtonClick(object sender, RoutedEventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog {
Filter = @"SharpDevelop settings (*.sdsettings)|*.sdsettings",
};
if (dialog.ShowDialog() != true)
return;
Properties p = new Properties();
p.Set("CustomizedHighlightingRules", customizationList);
p.Save(dialog.FileName);
}
} }
} }

16
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingMargin.cs

@ -3,12 +3,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.TextFormatting; using System.Windows.Media.TextFormatting;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Utils; using ICSharpCode.AvalonEdit.Utils;
@ -92,10 +92,16 @@ namespace ICSharpCode.AvalonEdit.Folding
static void OnUpdateBrushes(DependencyObject d, DependencyPropertyChangedEventArgs e) static void OnUpdateBrushes(DependencyObject d, DependencyPropertyChangedEventArgs e)
{ {
FoldingMargin m = null;
if (d is FoldingMargin)
m = (FoldingMargin)d;
else if (d is TextEditor)
m = ((TextEditor)d).TextArea.LeftMargins.FirstOrDefault(c => c is FoldingMargin) as FoldingMargin;
if (m == null) return;
if (e.Property.Name == FoldingMarkerBrushProperty.Name) if (e.Property.Name == FoldingMarkerBrushProperty.Name)
foldingControlPen = MakeFrozenPen((Brush)e.NewValue); m.foldingControlPen = MakeFrozenPen((Brush)e.NewValue);
if (e.Property.Name == SelectedFoldingMarkerBrushProperty.Name) if (e.Property.Name == SelectedFoldingMarkerBrushProperty.Name)
selectedFoldingControlPen = MakeFrozenPen((Brush)e.NewValue); m.selectedFoldingControlPen = MakeFrozenPen((Brush)e.NewValue);
} }
#endregion #endregion
@ -181,8 +187,8 @@ namespace ICSharpCode.AvalonEdit.Folding
return markers[index]; return markers[index];
} }
static Pen foldingControlPen = MakeFrozenPen((Brush)FoldingMarkerBrushProperty.DefaultMetadata.DefaultValue); Pen foldingControlPen = MakeFrozenPen((Brush)FoldingMarkerBrushProperty.DefaultMetadata.DefaultValue);
static Pen selectedFoldingControlPen = MakeFrozenPen((Brush)SelectedFoldingMarkerBrushProperty.DefaultMetadata.DefaultValue); Pen selectedFoldingControlPen = MakeFrozenPen((Brush)SelectedFoldingMarkerBrushProperty.DefaultMetadata.DefaultValue);
static Pen MakeFrozenPen(Brush brush) static Pen MakeFrozenPen(Brush brush)
{ {

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

@ -97,7 +97,7 @@
</Span> </Span>
<Span color="String" multiline="true"> <Span color="String" multiline="true">
<Begin color="String">@"</Begin> <Begin>@"</Begin>
<End>"</End> <End>"</End>
<RuleSet> <RuleSet>
<!-- span for escape sequences --> <!-- span for escape sequences -->

30
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

@ -538,6 +538,36 @@ namespace ICSharpCode.AvalonEdit.Rendering
get { return (Brush)GetValue(NonPrintableCharacterBrushProperty); } get { return (Brush)GetValue(NonPrintableCharacterBrushProperty); }
set { SetValue(NonPrintableCharacterBrushProperty, value); } set { SetValue(NonPrintableCharacterBrushProperty, value); }
} }
/// <summary>
/// LinkTextForegroundBrush dependency property.
/// </summary>
public static readonly DependencyProperty LinkTextForegroundBrushProperty =
DependencyProperty.Register("LinkTextForegroundBrush", typeof(Brush), typeof(TextView),
new FrameworkPropertyMetadata(Brushes.Blue));
/// <summary>
/// Gets/sets the Brush used for displaying link texts.
/// </summary>
public Brush LinkTextForegroundBrush {
get { return (Brush)GetValue(LinkTextForegroundBrushProperty); }
set { SetValue(LinkTextForegroundBrushProperty, value); }
}
/// <summary>
/// LinkTextBackgroundBrush dependency property.
/// </summary>
public static readonly DependencyProperty LinkTextBackgroundBrushProperty =
DependencyProperty.Register("LinkTextBackgroundBrush", typeof(Brush), typeof(TextView),
new FrameworkPropertyMetadata(Brushes.Transparent));
/// <summary>
/// Gets/sets the Brush used for the background of link texts.
/// </summary>
public Brush LinkTextBackgroundBrush {
get { return (Brush)GetValue(LinkTextBackgroundBrushProperty); }
set { SetValue(LinkTextBackgroundBrushProperty, value); }
}
#endregion #endregion
#region Redraw methods / VisualLine invalidation #region Redraw methods / VisualLine invalidation

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLineLinkText.cs

@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Documents; using System.Windows.Documents;
@ -46,7 +47,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// <inheritdoc/> /// <inheritdoc/>
public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context) public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)
{ {
this.TextRunProperties.SetForegroundBrush(Brushes.Blue); this.TextRunProperties.SetForegroundBrush(context.TextView.LinkTextForegroundBrush);
this.TextRunProperties.SetBackgroundBrush(context.TextView.LinkTextBackgroundBrush);
this.TextRunProperties.SetTextDecorations(TextDecorations.Underline); this.TextRunProperties.SetTextDecorations(TextDecorations.Underline);
return base.CreateTextRun(startVisualColumn, context); return base.CreateTextRun(startVisualColumn, context);
} }

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

@ -818,6 +818,7 @@
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\AsyncDiscoveryState.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\AsyncDiscoveryState.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\DiscoveryNetworkCredential.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\DiscoveryNetworkCredential.cs" />
<Compile Include="Src\Services\ProjectService\ProjectLoader.cs" /> <Compile Include="Src\Services\ProjectService\ProjectLoader.cs" />
<Compile Include="Src\Util\MultiDictionary.cs" />
<Compile Include="Src\Util\DotnetDetection.cs" /> <Compile Include="Src\Util\DotnetDetection.cs" />
<Compile Include="Src\Util\FakeXmlViewContent.cs" /> <Compile Include="Src\Util\FakeXmlViewContent.cs" />
<Compile Include="Src\Util\KeyComparer.cs" /> <Compile Include="Src\Util\KeyComparer.cs" />

4
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml

@ -227,9 +227,9 @@
</Border> </Border>
<!-- Content --> <!-- Content -->
<Border x:Name="ContentBorder" Padding="0 0 8 8" Grid.Row="1" Grid.Column="0" MinWidth="200" Background="White"> <Border x:Name="ContentBorder" Padding="0 0 8 8" Grid.Row="1" Grid.Column="0" MinWidth="200">
<aero:SystemDropShadowChrome> <aero:SystemDropShadowChrome>
<Border BorderThickness="1" Padding="0" Margin="0" BorderBrush="{StaticResource OuterBorderBrush}"> <Border BorderThickness="1" Padding="0" Margin="0" Background="White" BorderBrush="{StaticResource OuterBorderBrush}">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<local:ContextActionsControl x:Name="ActionsTreeView" <local:ContextActionsControl x:Name="ActionsTreeView"
DataContext="{Binding Actions}"> DataContext="{Binding Actions}">

6
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -91,6 +91,12 @@ namespace ICSharpCode.SharpDevelop
list.Add(o); list.Add(o);
} }
public static void AddRange(this IList arrayList, IEnumerable elements)
{
foreach (object o in elements)
arrayList.Add(o);
}
public static ReadOnlyCollection<T> AsReadOnly<T>(this IList<T> arr) public static ReadOnlyCollection<T> AsReadOnly<T>(this IList<T> arr)
{ {
return new ReadOnlyCollection<T>(arr); return new ReadOnlyCollection<T>(arr);

117
src/Main/Base/Project/Src/Util/MultiDictionary.cs

@ -0,0 +1,117 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory;
using Mono.Collections.Generic;
namespace ICSharpCode.SharpDevelop
{
/// <summary>
/// A dictionary that allows multiple pairs with the same key.
/// </summary>
public class MultiDictionary<TKey, TValue> : ILookup<TKey, TValue>
{
Dictionary<TKey, List<TValue>> dict;
public MultiDictionary()
{
}
public MultiDictionary(IEqualityComparer<TKey> comparer)
{
dict = new Dictionary<TKey, List<TValue>>(comparer);
}
public void Add(TKey key, TValue value)
{
List<TValue> valueList;
if (!dict.TryGetValue(key, out valueList)) {
valueList = new List<TValue>();
dict.Add(key, valueList);
}
valueList.Add(value);
}
public bool Remove(TKey key, TValue value)
{
List<TValue> valueList;
if (dict.TryGetValue(key, out valueList)) {
if (valueList.Remove(value)) {
if (valueList.Count == 0)
dict.Remove(key);
return true;
}
}
return false;
}
public void Clear()
{
dict.Clear();
}
public IEnumerable<TValue> this[TKey key] {
get {
List<TValue> list;
if (dict.TryGetValue(key, out list))
return list.AsReadOnly();
else
return new TValue[0];
}
}
public int Count {
get { return dict.Count; }
}
IEnumerable<TValue> ILookup<TKey, TValue>.this[TKey key] {
get { return this[key]; }
}
bool ILookup<TKey, TValue>.Contains(TKey key)
{
return dict.ContainsKey(key);
}
public IEnumerator<IGrouping<TKey, TValue>> GetEnumerator()
{
foreach (var pair in dict)
yield return new Grouping(pair.Key, pair.Value);
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
sealed class Grouping : IGrouping<TKey, TValue>
{
readonly TKey key;
readonly List<TValue> values;
public Grouping(TKey key, List<TValue> values)
{
this.key = key;
this.values = values;
}
public TKey Key {
get { return key; }
}
public IEnumerator<TValue> GetEnumerator()
{
return values.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return values.GetEnumerator();
}
}
}
}
Loading…
Cancel
Save