Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update syntax highlighting and fixed opaque text marking #129

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
121 changes: 121 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
; Top-most EditorConfig file
root = true

[*]
indent_style = tab
indent_size = 4
guidelines = 110

[*.il]
indent_style = space
indent_size = 2
[*.{yml,yaml}]
indent_style = space
indent_size = 2
[*.csproj]
indent_style = space
indent_size = 2
[*.config]
indent_style = space
indent_size = 2
[*.nuspec]
indent_style = space
indent_size = 2
[*.vsixmanifest]
indent_style = space
indent_size = 2
[*.vsct]
indent_style = space
indent_size = 2

[*.cs]
# New line preferences
csharp_new_line_before_open_brace = methods, types, control_blocks, local_functions
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_within_query_expression_clauses = false

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = false
csharp_indent_switch_labels = true
csharp_indent_labels = one_less

# Avoid 'this.' in generated code unless absolutely necessary, but allow developers to use it
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent

# Do not use 'var' when generating code, but allow developers to use it
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = false:silent

# Use language keywords instead of BCL types when generating code, but allow developers to use either
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent

# Using directives
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = true

# Wrapping
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false

# Code style
csharp_prefer_braces = true:silent

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent

# Pattern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

# Null checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = do_not_ignore
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
16 changes: 8 additions & 8 deletions ILSpy.Core/AvalonEdit/TextMarkerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,21 @@ protected override void ColorizeLine(DocumentLine line)
foregroundBrush = new SolidColorBrush(marker.ForegroundColor.Value);
//foregroundBrush.Freeze();
}

ChangeLinePart(
Math.Max(marker.StartOffset, lineStart),
Math.Min(marker.EndOffset, lineEnd),
element => {
if (foregroundBrush != null) {
element.TextRunProperties.ForegroundBrush = foregroundBrush;
}
// TODO: change font style
//string tf = element.TextRunProperties.Typeface;
//element.TextRunProperties.SetTypeface(new Typeface(
// tf.FontFamily,
// marker.FontStyle ?? tf.Style,
// marker.FontWeight ?? tf.Weight,
// tf.Stretch
//));

var tf = element.TextRunProperties.Typeface;
element.TextRunProperties.Typeface = new Typeface(
tf.FontFamily,
marker.FontStyle ?? tf.Style,
marker.FontWeight ?? tf.Weight
);
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion ILSpy.Core/ILSpy.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<ItemGroup>
<EmbeddedResource Include="README.txt" />
<EmbeddedResource Include="..\doc\*.txt" />
<EmbeddedResource Include="Themes\ILAsm-Mode.xshd;Themes\CSharp-Mode.xshd" />
<EmbeddedResource Include="Themes\ILAsm-Mode.xshd;Themes\CSharp-Mode.xshd;Themes\ILAsm-Mode-Dark.xshd" />
<EmbeddedResource Include="**\*.resx;Assets\*;**\*.paml" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>

Expand Down
20 changes: 18 additions & 2 deletions ILSpy.Core/Options/DisplaySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,22 @@ public bool HighlightMatchingBraces
}
}

public void CopyValues(DisplaySettings s)
bool highlightCurrentLine = false;

public bool HighlightCurrentLine
{
get { return highlightCurrentLine; }
set
{
if (highlightCurrentLine != value)
{
highlightCurrentLine = value;
OnPropertyChanged();
}
}
}

public void CopyValues(DisplaySettings s)
{
this.SelectedFont = s.selectedFont;
this.SelectedFontSize = s.selectedFontSize;
Expand All @@ -287,6 +302,7 @@ public void CopyValues(DisplaySettings s)
this.IndentationTabSize = s.indentationTabSize;
this.IndentationSize = s.indentationSize;
this.HighlightMatchingBraces = s.highlightMatchingBraces;
}
this.HighlightCurrentLine = s.highlightCurrentLine;
}
}
}
1 change: 1 addition & 0 deletions ILSpy.Core/Options/DisplaySettingsPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<CheckBox IsChecked="{Binding EnableWordWrap}" Content="{x:Static properties:Resources.EnableWordWrap}"></CheckBox>
<CheckBox IsChecked="{Binding FoldBraces}" Content="{x:Static properties:Resources.EnableFoldingBlocksBraces}"></CheckBox>
<CheckBox IsChecked="{Binding HighlightMatchingBraces}" Content="{x:Static properties:Resources.HighlightMatchingBraces}"></CheckBox>
<CheckBox IsChecked="{Binding HighlightCurrentLine}" Content="{x:Static properties:Resources.HighlightCurrentLine}"></CheckBox>
<CheckBox IsChecked="{Binding SortResults}" Content="{x:Static properties:Resources.SortResultsFitness}"></CheckBox>
<CheckBox IsChecked="{Binding ExpandMemberDefinitions}" Content="{x:Static properties:Resources.ExpandMemberDefinitionsAfterDecompilation}"></CheckBox>
<CheckBox IsChecked="{Binding ExpandUsingDeclarations}" Content="{x:Static properties:Resources.ExpandUsingDeclarationsAfterDecompilation}"></CheckBox>
Expand Down
6 changes: 4 additions & 2 deletions ILSpy.Core/Options/DisplaySettingsPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ public static DisplaySettings LoadDisplaySettings(ILSpySettings settings)
s.IndentationSize = (int?)e.Attribute("IndentationSize") ?? 4;
s.IndentationTabSize = (int?)e.Attribute("IndentationTabSize") ?? 4;
s.HighlightMatchingBraces = (bool?)e.Attribute("HighlightMatchingBraces") ?? true;
s.HighlightCurrentLine = (bool?)e.Attribute("HighlightCurrentLine") ?? true;

return s;
return s;
}

public void Save(XElement root)
Expand All @@ -151,8 +152,9 @@ public void Save(XElement root)
section.SetAttributeValue("IndentationSize", s.IndentationSize);
section.SetAttributeValue("IndentationTabSize", s.IndentationTabSize);
section.SetAttributeValue("HighlightMatchingBraces", s.HighlightMatchingBraces);
section.SetAttributeValue("HighlightCurrentLine", s.HighlightCurrentLine);

XElement existingElement = root.Element("DisplaySettings");
XElement existingElement = root.Element("DisplaySettings");
if (existingElement != null)
existingElement.ReplaceWith(section);
else
Expand Down
19 changes: 14 additions & 5 deletions ILSpy.Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ILSpy.Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@ Are you sure you want to continue?</value>
</data>
<data name="HighlightMatchingBraces" xml:space="preserve">
<value>Highlight matching braces</value>
</data>
<data name="HighlightCurrentLine" xml:space="preserve">
<value>Highlight current line</value>
</data>
<data name="SelectLanguageDropdownTooltip" xml:space="preserve">
<value>Select language to decompile to</value>
Expand Down
3 changes: 3 additions & 0 deletions ILSpy.Core/Properties/Resources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -729,4 +729,7 @@
<data name="SearchMSDN" xml:space="preserve">
<value>搜索MSDN...</value>
</data>
<data name="HighlightCurrentLine" xml:space="preserve">
<value>高亮当前行</value>
</data>
</root>
4 changes: 2 additions & 2 deletions ILSpy.Core/TextView/DecompilerTextView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonia="clr-namespace:Avalonia;assembly=SharpTreeView"
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties"
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties"
xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
x:Class="ICSharpCode.ILSpy.TextView.DecompilerTextView">
<Grid>
Expand All @@ -12,7 +12,7 @@
Background="{DynamicResource ThemeCodeBackgroundBrush}"
Foreground="{DynamicResource ThemeCodeForegroundBrush}">
</ae:TextEditor>
<Border Name="waitAdorner" Background="#C0FFFFFF" IsVisible="false">
<Border Name="waitAdorner" Background="#C0FFFFFF" IsVisible="false">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock FontSize="14" Text="{x:Static properties:Resources.Decompiling}" />
<ProgressBar Name="progressBar" Height="16" Margin="0, 4" />
Expand Down
29 changes: 23 additions & 6 deletions ILSpy.Core/TextView/DecompilerTextView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ public DecompilerTextView()
// TemplateApplied += (s,e) =>

ShowLineMargin();
SetHighlightCurrentLine();

// add marker service & margin
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);

// Selection highlight. TODO: Pull value from resource key, HighlightColorKey
textEditor.TextArea.SelectionBrush = new SolidColorBrush(0x333399FF);
textEditor.TextArea.SelectionBorder = new Pen(color: 0xFF3399ff, thickness: 1);
}

private void InitializeComponent()
Expand Down Expand Up @@ -150,9 +155,14 @@ void RemoveEditCommand(RoutedCommand command)

void CurrentDisplaySettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "ShowLineNumbers") {
if (e.PropertyName == nameof(DisplaySettings.ShowLineNumbers))
{
ShowLineMargin();
}
else if (e.PropertyName == nameof(DisplaySettings.HighlightCurrentLine))
{
SetHighlightCurrentLine();
}
}

void ShowLineMargin()
Expand All @@ -163,11 +173,16 @@ void ShowLineMargin()
}
}
}


void SetHighlightCurrentLine()
{
textEditor.Options.HighlightCurrentLine = DisplaySettingsPanel.CurrentDisplaySettings.HighlightCurrentLine;
}

#endregion

#region Tooltip support

void TextViewMouseHoverStopped(object sender, PointerEventArgs e)
{
ToolTip.SetIsOpen(this, false);
Expand Down Expand Up @@ -605,7 +620,9 @@ internal void JumpToReference(ReferenceSegment referenceSegment)
foreach (var r in references) {
if (reference.Equals(r.Reference)) {
var mark = textMarkerService.Create(r.StartOffset, r.Length);
mark.BackgroundColor = r.IsDefinition ? Colors.LightSeaGreen : Colors.GreenYellow;
// TODO: Get color from FindResourceKey(...) and NOT hard-coded
// mark.BackgroundColor = (Color)(r.IsDefinition ? FindResource(ResourceKeys.TextMarkerDefinitionBackgroundColor) : FindResource(ResourceKeys.TextMarkerBackgroundColor));
mark.BackgroundColor = r.IsDefinition ? Color.FromUInt32(0x7720B2AA) : Color.FromUInt32(0x77C71585); // LightSeaGreen : MediumVioletRed;
localReferenceMarks.Add(mark);
}
}
Expand Down Expand Up @@ -744,7 +761,7 @@ Task<AvaloniaEditTextOutput> SaveToDiskAsync(DecompilationContext context, strin
DecompileNodes(context, new PlainTextOutput(w));
} catch (OperationCanceledException) {
w.WriteLine();
w.WriteLine("Decompiled was cancelled.");
w.WriteLine("Decompiled was canceled.");
throw;
}
}
Expand Down
Loading