Browse Source

Add bracket highlighting to ILSpy.

pull/1633/head
Siegfried Pammer 6 years ago
parent
commit
722e2c8325
  1. 2
      ILSpy/ILSpy.csproj
  2. 20
      ILSpy/Languages/CSharpHighlightingTokenWriter.cs
  3. 5
      ILSpy/Languages/CSharpLanguage.cs
  4. 6
      ILSpy/Languages/Language.cs
  5. 13
      ILSpy/Options/DisplaySettings.cs
  6. 1
      ILSpy/Options/DisplaySettingsPanel.xaml
  7. 2
      ILSpy/Options/DisplaySettingsPanel.xaml.cs
  8. 9
      ILSpy/Properties/Resources.Designer.cs
  9. 3
      ILSpy/Properties/Resources.resx
  10. 15
      ILSpy/TextView/DecompilerTextView.cs

2
ILSpy/ILSpy.csproj

@ -140,6 +140,7 @@ @@ -140,6 +140,7 @@
<Compile Include="GacInterop.cs" />
<Compile Include="GuessFileType.cs" />
<Compile Include="ContextMenuEntry.cs" />
<Compile Include="Languages\CSharpBracketSearcher.cs" />
<Compile Include="Languages\CSharpILMixedLanguage.cs" />
<Compile Include="Languages\CSharpLanguage.cs" />
<Compile Include="Languages\CSharpLexer.cs" />
@ -206,6 +207,7 @@ @@ -206,6 +207,7 @@
<Compile Include="Search\AbstractSearchStrategy.cs" />
<Compile Include="SolutionWriter.cs" />
<Compile Include="TaskHelper.cs" />
<Compile Include="TextView\BracketHighlightRenderer.cs" />
<Compile Include="TextView\EditorCommands.cs" />
<Compile Include="TextView\FoldingCommands.cs" />
<Compile Include="Commands\SaveCodeContextMenuEntry.cs" />

20
ILSpy/Languages/CSharpHighlightingTokenWriter.cs

@ -1,4 +1,22 @@ @@ -1,4 +1,22 @@
using System;
// Copyright (c) 2018 Siegfried Pammer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.AvalonEdit.Highlighting;

5
ILSpy/Languages/CSharpLanguage.cs

@ -37,6 +37,7 @@ using ICSharpCode.Decompiler.Output; @@ -37,6 +37,7 @@ using ICSharpCode.Decompiler.Output;
using ICSharpCode.Decompiler.Solution;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Util;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
namespace ICSharpCode.ILSpy
@ -634,5 +635,9 @@ namespace ICSharpCode.ILSpy @@ -634,5 +635,9 @@ namespace ICSharpCode.ILSpy
{
return CSharpDecompiler.GetCodeMappingInfo(module, member);
}
CSharpBracketSearcher bracketSearcher = new CSharpBracketSearcher();
public override IBracketSearcher BracketSearcher => bracketSearcher;
}
}

6
ILSpy/Languages/Language.cs

@ -102,6 +102,12 @@ namespace ICSharpCode.ILSpy @@ -102,6 +102,12 @@ namespace ICSharpCode.ILSpy
}
}
public virtual TextView.IBracketSearcher BracketSearcher {
get {
return TextView.DefaultBracketSearcher.DefaultInstance;
}
}
public virtual void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, TypeToString(method.DeclaringTypeDefinition, includeNamespace: true) + "." + method.Name);

13
ILSpy/Options/DisplaySettings.cs

@ -215,6 +215,18 @@ namespace ICSharpCode.ILSpy.Options @@ -215,6 +215,18 @@ namespace ICSharpCode.ILSpy.Options
}
}
bool highlightMatchingBraces = true;
public bool HighlightMatchingBraces {
get { return highlightMatchingBraces; }
set {
if (highlightMatchingBraces != value) {
highlightMatchingBraces = value;
OnPropertyChanged();
}
}
}
public void CopyValues(DisplaySettings s)
{
this.SelectedFont = s.selectedFont;
@ -231,6 +243,7 @@ namespace ICSharpCode.ILSpy.Options @@ -231,6 +243,7 @@ namespace ICSharpCode.ILSpy.Options
this.IndentationUseTabs = s.indentationUseTabs;
this.IndentationTabSize = s.indentationTabSize;
this.IndentationSize = s.indentationSize;
this.HighlightMatchingBraces = s.highlightMatchingBraces;
}
}
}

1
ILSpy/Options/DisplaySettingsPanel.xaml

@ -80,6 +80,7 @@ @@ -80,6 +80,7 @@
<CheckBox IsChecked="{Binding ShowDebugInfo}" Content="{x:Static properties:Resources.ShowInfoFromDebugSymbolsAvailable}"></CheckBox>
<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 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>

2
ILSpy/Options/DisplaySettingsPanel.xaml.cs

@ -114,6 +114,7 @@ namespace ICSharpCode.ILSpy.Options @@ -114,6 +114,7 @@ namespace ICSharpCode.ILSpy.Options
s.IndentationUseTabs = (bool?)e.Attribute("IndentationUseTabs") ?? true;
s.IndentationSize = (int?)e.Attribute("IndentationSize") ?? 4;
s.IndentationTabSize = (int?)e.Attribute("IndentationTabSize") ?? 4;
s.HighlightMatchingBraces = (bool?)e.Attribute("HighlightMatchingBraces") ?? true;
return s;
}
@ -136,6 +137,7 @@ namespace ICSharpCode.ILSpy.Options @@ -136,6 +137,7 @@ namespace ICSharpCode.ILSpy.Options
section.SetAttributeValue("IndentationUseTabs", s.IndentationUseTabs);
section.SetAttributeValue("IndentationSize", s.IndentationSize);
section.SetAttributeValue("IndentationTabSize", s.IndentationTabSize);
section.SetAttributeValue("HighlightMatchingBraces", s.HighlightMatchingBraces);
XElement existingElement = root.Element("DisplaySettings");
if (existingElement != null)

9
ILSpy/Properties/Resources.Designer.cs generated

@ -1152,6 +1152,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1152,6 +1152,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Highlight matching braces.
/// </summary>
public static string HighlightMatchingBraces {
get {
return ResourceManager.GetString("HighlightMatchingBraces", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ILSpy version .
/// </summary>

3
ILSpy/Properties/Resources.resx

@ -742,4 +742,7 @@ Are you sure you want to continue?</value> @@ -742,4 +742,7 @@ Are you sure you want to continue?</value>
<data name="AssemblySaveCodeDirectoryNotEmptyTitle" xml:space="preserve">
<value>Project Directory not empty</value>
</data>
<data name="HighlightMatchingBraces" xml:space="preserve">
<value>Highlight matching braces</value>
</data>
</root>

15
ILSpy/TextView/DecompilerTextView.cs

@ -65,6 +65,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -65,6 +65,7 @@ namespace ICSharpCode.ILSpy.TextView
readonly UIElementGenerator uiElementGenerator;
List<VisualLineElementGenerator> activeCustomElementGenerators = new List<VisualLineElementGenerator>();
RichTextColorizer activeRichTextColorizer;
BracketHighlightRenderer bracketHighlightRenderer;
FoldingManager foldingManager;
ILSpyTreeNode[] decompiledNodes;
@ -103,12 +104,14 @@ namespace ICSharpCode.ILSpy.TextView @@ -103,12 +104,14 @@ namespace ICSharpCode.ILSpy.TextView
this.referenceElementGenerator = new ReferenceElementGenerator(this.JumpToReference, this.IsLink);
textEditor.TextArea.TextView.ElementGenerators.Add(referenceElementGenerator);
this.uiElementGenerator = new UIElementGenerator();
this.bracketHighlightRenderer = new BracketHighlightRenderer(textEditor.TextArea.TextView);
textEditor.TextArea.TextView.ElementGenerators.Add(uiElementGenerator);
textEditor.Options.RequireControlModifierForHyperlinkClick = false;
textEditor.TextArea.TextView.MouseHover += TextViewMouseHover;
textEditor.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped;
textEditor.TextArea.PreviewMouseDown += TextAreaMouseDown;
textEditor.TextArea.PreviewMouseUp += TextAreaMouseUp;
textEditor.TextArea.Caret.PositionChanged += HighlightBrackets;
textEditor.SetBinding(Control.FontFamilyProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFont") });
textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") });
textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("EnableWordWrap") });
@ -245,6 +248,18 @@ namespace ICSharpCode.ILSpy.TextView @@ -245,6 +248,18 @@ namespace ICSharpCode.ILSpy.TextView
}
#endregion
#region Highlight brackets
void HighlightBrackets(object sender, EventArgs e)
{
if (DisplaySettingsPanel.CurrentDisplaySettings.HighlightMatchingBraces) {
var result = MainWindow.Instance.CurrentLanguage.BracketSearcher.SearchBracket(textEditor.Document, textEditor.CaretOffset);
bracketHighlightRenderer.SetHighlight(result);
} else {
bracketHighlightRenderer.SetHighlight(null);
}
}
#endregion
#region RunWithCancellation
/// <summary>
/// Switches the GUI into "waiting" mode, then calls <paramref name="taskCreation"/> to create

Loading…
Cancel
Save