Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit a81b6c2

Browse files
julodnikdgrunwald
authored andcommitted
Add Underline attribute in syntax highlighting
1 parent 2bdddf3 commit a81b6c2

15 files changed

Lines changed: 77 additions & 8 deletions

File tree

data/resources/StringResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,9 @@ Examples: "120", "MainClass", "Main.cs, 120".</value>
17291729
<data name="Dialog.HighlightingEditor.ColorDlg.Italic" xml:space="preserve">
17301730
<value>Italic</value>
17311731
</data>
1732+
<data name="Dialog.HighlightingEditor.ColorDlg.Underline" xml:space="preserve">
1733+
<value>Underlined</value>
1734+
</data>
17321735
<data name="Dialog.HighlightingEditor.Export" xml:space="preserve">
17331736
<value>Export highlighting colors</value>
17341737
</data>

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingColor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class CustomizedHighlightingColor
4343

4444
public bool Bold { get; set; }
4545
public bool Italic { get; set; }
46+
public bool Underline { get; set; }
4647
public Color? Foreground { get; set; }
4748
public Color? Background { get; set; }
4849

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ void AllPropertiesChanged()
6666
{
6767
OnPropertyChanged("Bold");
6868
OnPropertyChanged("Italic");
69+
OnPropertyChanged("Underline");
6970
OnPropertyChanged("Foreground");
7071
OnPropertyChanged("UseDefaultForeground");
7172
OnPropertyChanged("Background");
7273
OnPropertyChanged("UseDefaultBackground");
7374
OnPropertyChanged("IsCustomized");
7475
}
7576

76-
void SetCustomization(bool? bold = null, bool? italic = null,
77+
void SetCustomization(bool? bold = null, bool? italic = null, bool? underline = null,
7778
Color? foreground = null, bool? useDefaultForeground = null,
7879
Color? background = null, bool? useDefaultBackground = null)
7980
{
@@ -82,6 +83,7 @@ void SetCustomization(bool? bold = null, bool? italic = null,
8283
newColor.Name = this.Name;
8384
newColor.Bold = bold ?? this.Bold;
8485
newColor.Italic = italic ?? this.Italic;
86+
newColor.Underline = underline ?? this.Underline;
8587

8688
if (useDefaultBackground ?? this.UseDefaultBackground)
8789
newColor.Background = null;
@@ -99,7 +101,7 @@ void SetCustomization(bool? bold = null, bool? italic = null,
99101
else if (customization != null)
100102
customizationList.Remove(customization);
101103

102-
if (newColor.Bold == original.Bold && newColor.Italic == original.Italic &&
104+
if (newColor.Bold == original.Bold && newColor.Italic == original.Italic && newColor.Underline == original.Underline &&
103105
(newColor.Background == null) == original.UseDefaultBackground &&
104106
(newColor.Background == null || newColor.Background == original.Background) &&
105107
(newColor.Foreground == null) == original.UseDefaultForeground &&
@@ -140,6 +142,15 @@ public bool Italic {
140142
}
141143
}
142144

145+
public bool Underline {
146+
get {
147+
return (customization != null) ? customization.Underline : original.Underline;
148+
}
149+
set {
150+
SetCustomization(underline: value);
151+
}
152+
}
153+
143154
public Color Foreground {
144155
get {
145156
return (customization != null) ? (customization.Foreground ?? original.Foreground) : original.Foreground;
@@ -191,7 +202,7 @@ public bool IsCustomized {
191202
public void Reset()
192203
{
193204
original.Reset();
194-
SetCustomization(original.Bold, original.Italic, original.Foreground, original.UseDefaultForeground, original.Background, original.UseDefaultBackground);
205+
SetCustomization(original.Bold, original.Italic, original.Underline, original.Foreground, original.UseDefaultForeground, original.Background, original.UseDefaultBackground);
195206
AllPropertiesChanged();
196207
}
197208

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
Content="{core:Localize Dialog.HighlightingEditor.ColorDlg.Bold}"/>
4545
<CheckBox IsEnabled="{Binding CanSetFont}" IsChecked="{Binding Italic}"
4646
Content="{core:Localize Dialog.HighlightingEditor.ColorDlg.Italic}"/>
47+
<CheckBox IsEnabled="{Binding CanSetFont}" IsChecked="{Binding Underline}"
48+
Content="{core:Localize Dialog.HighlightingEditor.ColorDlg.Underline}"/>
4749
<Button Name="resetButton" IsEnabled="{Binding IsCustomized}" HorizontalAlignment="Left"
4850
Click="ResetButtonClick" Style="{x:Static core:GlobalStyles.ButtonStyle}" Margin="0,4"
4951
Content="Reset" />

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public interface IHighlightingItem : INotifyPropertyChanged
4343
/// </summary>
4444
bool Italic { get; set; }
4545

46+
/// <summary>
47+
/// Gets/Sets whether the element uses an underlined font.
48+
/// </summary>
49+
bool Underline { get; set; }
50+
4651
Color Foreground { get; set; }
4752
bool UseDefaultForeground { get; set; }
4853
Color Background { get; set; }

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ public bool Italic {
6868
}
6969
}
7070

71+
public bool Underline {
72+
get {
73+
return color.Underline;
74+
}
75+
set {
76+
throw new NotSupportedException();
77+
}
78+
}
79+
7180
public Color Foreground {
7281
get {
7382
Color? c = color.Foreground != null ? color.Foreground.GetColor(null) : null;
@@ -161,7 +170,12 @@ public void ShowExample(TextArea exampleTextArea)
161170
marker.ForegroundColor = item.Foreground;
162171
marker.FontStyle = item.Italic ? FontStyles.Italic : FontStyles.Normal;
163172
marker.FontWeight = item.Bold ? FontWeights.Bold : FontWeights.Normal;
164-
});
173+
if(item.Underline)
174+
{
175+
marker.MarkerColor = item.Foreground;
176+
marker.MarkerTypes = TextMarkerTypes.NormalUnderline;
177+
}
178+
});
165179
}
166180
} else {
167181
exampleTextArea.Document.Text = exampleText;

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/SimpleHighlightingItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public event PropertyChangedEventHandler PropertyChanged { add {} remove {} }
4040
public string Name { get; private set; }
4141
public bool Bold { get; set; }
4242
public bool Italic { get; set; }
43+
public bool Underline { get; set; }
4344

4445
public Color Foreground { get; set; }
4546
public bool UseDefaultForeground { get; set; }

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ internal static HighlightingColor CustomizeColor(string name, IEnumerable<Custom
267267
Background = CreateBrush(customization.Background),
268268
Foreground = CreateBrush(customization.Foreground),
269269
FontWeight = customization.Bold ? FontWeights.Bold : FontWeights.Normal,
270-
FontStyle = customization.Italic ? FontStyles.Italic : FontStyles.Normal
270+
FontStyle = customization.Italic ? FontStyles.Italic : FontStyles.Normal,
271+
Underline = customization.Underline
271272
};
272273
}
273274
}

src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ void SetPreview(TextBlock preview, System.Drawing.Font font)
103103
preview.FontWeight = FontWeights.Bold;
104104
else
105105
preview.FontWeight = FontWeights.Normal;
106+
if (font.Underline)
107+
preview.TextDecorations = TextDecorations.Underline;
106108
}
107109
}
108110
}

src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void SetHighlighting(int offset, int length, HighlightingColor color)
113113
{
114114
if (color == null)
115115
throw new ArgumentNullException("color");
116-
if (color.Foreground == null && color.Background == null && color.FontStyle == null && color.FontWeight == null) {
116+
if (color.Foreground == null && color.Background == null && color.FontStyle == null && color.FontWeight == null && color.Underline == null) {
117117
// Optimization: don't split the HighlightingState when we're not changing
118118
// any property. For example, the "Punctuation" color in C# is
119119
// empty by default.

0 commit comments

Comments
 (0)