@ -5,22 +5,26 @@ using System;
@@ -5,22 +5,26 @@ using System;
using System.Collections.Generic ;
using System.Collections.Specialized ;
using System.ComponentModel ;
using System.Globalization ;
using System.IO ;
using System.Linq ;
using System.Windows ;
using System.Windows.Controls ;
using System.Windows.Media ;
using System.Xml ;
using System.Xml.Linq ;
using ICSharpCode.AvalonEdit.Editing ;
using ICSharpCode.AvalonEdit.Folding ;
using ICSharpCode.AvalonEdit.Highlighting ;
using ICSharpCode.AvalonEdit.Highlighting.Xshd ;
using ICSharpCode.AvalonEdit.Rendering ;
using ICSharpCode.Core ;
using ICSharpCode.SharpDevelop ;
using ICSharpCode.SharpDevelop.Bookmarks ;
using ICSharpCode.SharpDevelop.Editor ;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit ;
using ICSharpCode.SharpDevelop.Gui ;
using Microsoft.Win32 ;
namespace ICSharpCode.AvalonEdit.AddIn.Options
{
@ -130,6 +134,8 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -130,6 +134,8 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
}
customizationList = CustomizedHighlightingColor . LoadColors ( ) ;
CreateDefaultEntries ( null , out defaultText , defaultEntries ) ;
languageComboBox . Items . Clear ( ) ;
languageComboBox . Items . Add ( new XshdSyntaxDefinition { Name = "All languages" } ) ;
foreach ( XshdSyntaxDefinition def in allSyntaxDefinitions )
@ -144,7 +150,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -144,7 +150,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
XshdSyntaxDefinition xshd = ( XshdSyntaxDefinition ) languageComboBox . SelectedItem ;
if ( xshd ! = null ) {
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 ) {
// Create entries for all customizable colors in the syntax highlighting definition
@ -168,18 +176,16 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -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"
defaultText = new SimpleHighlightingItem ( CustomizableHighlightingColorizer . DefaultTextAndBackground , ta = > ta . Document . Text = "Normal text" ) {
Foreground = SystemColors . WindowTextColor ,
Background = SystemColors . WindowColor
} ;
defaultText = new CustomizedHighlightingItem ( customizationList , defaultText , null , canSetFont : false ) ;
if ( language ! = null )
defaultText = new CustomizedHighlightingItem ( customizationList , defaultText , language , canSetFont : false ) ;
defaultText . PropertyChanged + = item_PropertyChanged ;
l istBox . I tems. Add ( defaultText ) ;
items . Add ( defaultText ) ;
// Create entry for "Selected text"
IHighlightingItem selectedText = new SimpleHighlightingItem (
@ -192,11 +198,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -192,11 +198,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
Foreground = SystemColors . HighlightTextColor ,
Background = SystemColors . HighlightColor
} ;
selectedText = new CustomizedHighlightingItem ( customizationList , selectedText , null , canSetFont : false ) ;
if ( language ! = null )
selectedText = new CustomizedHighlightingItem ( customizationList , selectedText , language , canSetFont : false ) ;
selectedText . PropertyChanged + = item_PropertyChanged ;
l istBox . I tems. Add ( selectedText ) ;
items . Add ( selectedText ) ;
// Create entry for "Non-printable characters"
IHighlightingItem nonPrintChars = new SimpleHighlightingItem (
@ -207,11 +211,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -207,11 +211,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{
Foreground = Colors . LightGray
} ;
nonPrintChars = new CustomizedHighlightingItem ( customizationList , nonPrintChars , null , canSetFont : false , canSetBackground : false ) ;
if ( language ! = null )
nonPrintChars = new CustomizedHighlightingItem ( customizationList , nonPrintChars , language , canSetFont : false ) ;
nonPrintChars = new CustomizedHighlightingItem ( customizationList , nonPrintChars , language , canSetFont : false , canSetBackground : false ) ;
nonPrintChars . PropertyChanged + = item_PropertyChanged ;
l istBox . I tems. Add ( nonPrintChars ) ;
items . Add ( nonPrintChars ) ;
// Create entry for "Line numbers"
IHighlightingItem lineNumbers = new SimpleHighlightingItem (
@ -225,11 +227,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -225,11 +227,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{
Foreground = Colors . Gray
} ;
lineNumbers = new CustomizedHighlightingItem ( customizationList , lineNumbers , null , canSetFont : false , canSetBackground : false ) ;
if ( language ! = null )
lineNumbers = new CustomizedHighlightingItem ( customizationList , lineNumbers , language , canSetFont : false ) ;
lineNumbers = new CustomizedHighlightingItem ( customizationList , lineNumbers , language , canSetFont : false , canSetBackground : false ) ;
lineNumbers . PropertyChanged + = item_PropertyChanged ;
l istBox . I tems. Add ( lineNumbers ) ;
items . Add ( lineNumbers ) ;
// Create entry for "Bracket highlight"
IHighlightingItem bracketHighlight = new SimpleHighlightingItem (
@ -247,11 +247,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -247,11 +247,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
Foreground = BracketHighlightRenderer . DefaultBorder ,
Background = BracketHighlightRenderer . DefaultBackground
} ;
bracketHighlight = new CustomizedHighlightingItem ( customizationList , bracketHighlight , null , canSetFont : false ) ;
if ( language ! = null )
bracketHighlight = new CustomizedHighlightingItem ( customizationList , bracketHighlight , language , canSetFont : false ) ;
bracketHighlight . PropertyChanged + = item_PropertyChanged ;
l istBox . I tems. Add ( bracketHighlight ) ;
items . Add ( bracketHighlight ) ;
// Create entry for "Folding controls"
IHighlightingItem foldingControls = new SimpleHighlightingItem (
@ -266,11 +264,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -266,11 +264,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
Foreground = Colors . Gray ,
Background = Colors . White
} ;
foldingControls = new CustomizedHighlightingItem ( customizationList , foldingControls , null , canSetFont : false ) ;
if ( language ! = null )
foldingControls = new CustomizedHighlightingItem ( customizationList , foldingControls , language , canSetFont : false ) ;
foldingControls . PropertyChanged + = item_PropertyChanged ;
l istBox . I tems. Add ( foldingControls ) ;
items . Add ( foldingControls ) ;
// Create entry for "Selected folding controls"
IHighlightingItem selectedFoldingControls = new SimpleHighlightingItem (
@ -285,11 +281,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -285,11 +281,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
Foreground = Colors . Black ,
Background = Colors . White
} ;
selectedFoldingControls = new CustomizedHighlightingItem ( customizationList , selectedFoldingControls , null , canSetFont : false ) ;
if ( language ! = null )
selectedFoldingControls = new CustomizedHighlightingItem ( customizationList , selectedFoldingControls , language , canSetFont : false ) ;
selectedFoldingControls . PropertyChanged + = item_PropertyChanged ;
l istBox . I tems. Add ( selectedFoldingControls ) ;
items . Add ( selectedFoldingControls ) ;
// Create entry for "Folding text markers"
IHighlightingItem foldingTextMarker = new SimpleHighlightingItem (
@ -303,14 +297,25 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -303,14 +297,25 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{
Foreground = Colors . Gray
} ;
foldingTextMarker = new CustomizedHighlightingItem ( customizationList , foldingTextMarker , null , canSetFont : false , canSetBackground : false ) ;
if ( language ! = null )
foldingControls = new CustomizedHighlightingItem ( customizationList , foldingTextMarker , language , canSetFont : false , canSetBackground : false ) ;
foldingTextMarker = new CustomizedHighlightingItem ( customizationList , foldingTextMarker , language , canSetFont : false , canSetBackground : false ) ;
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 ( ) ;
}
@ -358,5 +363,227 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
@@ -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 ) ;
}
}
}