Browse Source

Fix #1468: Implement 'Expand using declarations after decompilation' setting.

pull/1471/head
Siegfried Pammer 6 years ago
parent
commit
56447a944f
  1. 13
      ICSharpCode.Decompiler/DecompilerSettings.cs
  2. 13
      ICSharpCode.Decompiler/Output/TextTokenWriter.cs
  3. 1
      ILSpy/DecompilationOptions.cs
  4. 2
      ILSpy/Languages/CSharpLanguage.cs
  5. 13
      ILSpy/Options/DisplaySettings.cs
  6. 1
      ILSpy/Options/DisplaySettingsPanel.xaml
  7. 2
      ILSpy/Options/DisplaySettingsPanel.xaml.cs

13
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -686,6 +686,19 @@ namespace ICSharpCode.Decompiler @@ -686,6 +686,19 @@ namespace ICSharpCode.Decompiler
}
}
bool expandUsingDeclarations = false;
[Browsable(false)]
public bool ExpandUsingDeclarations {
get { return expandUsingDeclarations; }
set {
if (expandUsingDeclarations != value) {
expandUsingDeclarations = value;
OnPropertyChanged();
}
}
}
bool decompileMemberBodies = true;
/// <summary>

13
ICSharpCode.Decompiler/Output/TextTokenWriter.cs

@ -23,9 +23,7 @@ using ICSharpCode.Decompiler.CSharp; @@ -23,9 +23,7 @@ using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using SRM = System.Reflection.Metadata;
namespace ICSharpCode.Decompiler
{
@ -40,9 +38,6 @@ namespace ICSharpCode.Decompiler @@ -40,9 +38,6 @@ namespace ICSharpCode.Decompiler
bool firstUsingDeclaration;
bool lastUsingDeclaration;
public bool FoldBraces = false;
public bool ExpandMemberDefinitions = false;
public TextTokenWriter(ITextOutput output, DecompilerSettings settings, IDecompilerTypeSystem typeSystem)
{
if (output == null)
@ -96,7 +91,7 @@ namespace ICSharpCode.Decompiler @@ -96,7 +91,7 @@ namespace ICSharpCode.Decompiler
}
if (firstUsingDeclaration) {
output.MarkFoldStart(defaultCollapsed: true);
output.MarkFoldStart(defaultCollapsed: !settings.ExpandUsingDeclarations);
firstUsingDeclaration = false;
}
@ -220,15 +215,15 @@ namespace ICSharpCode.Decompiler @@ -220,15 +215,15 @@ namespace ICSharpCode.Decompiler
}
if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration)
braceLevelWithinType++;
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces) {
output.MarkFoldStart(defaultCollapsed: !ExpandMemberDefinitions && braceLevelWithinType == 1);
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || settings.FoldBraces) {
output.MarkFoldStart(defaultCollapsed: !settings.ExpandMemberDefinitions && braceLevelWithinType == 1);
}
output.Write("{");
break;
case "}":
output.Write('}');
if (role != Roles.RBrace) break;
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces)
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || settings.FoldBraces)
output.MarkFoldEnd();
if (braceLevelWithinType >= 0)
braceLevelWithinType--;

1
ILSpy/DecompilationOptions.cs

@ -83,6 +83,7 @@ namespace ICSharpCode.ILSpy @@ -83,6 +83,7 @@ namespace ICSharpCode.ILSpy
var newSettings = this.DecompilerSettings = settings.Clone();
newSettings.SetLanguageVersion(languageVersion);
newSettings.ExpandMemberDefinitions = displaySettings.ExpandMemberDefinitions;
newSettings.ExpandUsingDeclarations = displaySettings.ExpandUsingDeclarations;
newSettings.FoldBraces = displaySettings.FoldBraces;
newSettings.ShowDebugInfo = displaySettings.ShowDebugInfo;
}

2
ILSpy/Languages/CSharpLanguage.cs

@ -121,7 +121,7 @@ namespace ICSharpCode.ILSpy @@ -121,7 +121,7 @@ namespace ICSharpCode.ILSpy
void WriteCode(ITextOutput output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem)
{
syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem) { FoldBraces = settings.FoldBraces, ExpandMemberDefinitions = settings.ExpandMemberDefinitions };
TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem);
if (output is ISmartTextOutput highlightingOutput) {
tokenWriter = new CSharpHighlightingTokenWriter(tokenWriter, highlightingOutput);
}

13
ILSpy/Options/DisplaySettings.cs

@ -155,6 +155,18 @@ namespace ICSharpCode.ILSpy.Options @@ -155,6 +155,18 @@ namespace ICSharpCode.ILSpy.Options
}
}
bool expandUsingDeclarations = false;
public bool ExpandUsingDeclarations {
get { return expandUsingDeclarations; }
set {
if (expandUsingDeclarations != value) {
expandUsingDeclarations = value;
OnPropertyChanged();
}
}
}
bool showDebugInfo;
public bool ShowDebugInfo {
@ -179,6 +191,7 @@ namespace ICSharpCode.ILSpy.Options @@ -179,6 +191,7 @@ namespace ICSharpCode.ILSpy.Options
this.SortResults = s.sortResults;
this.FoldBraces = s.foldBraces;
this.ExpandMemberDefinitions = s.expandMemberDefinitions;
this.ExpandUsingDeclarations = s.expandUsingDeclarations;
}
}
}

1
ILSpy/Options/DisplaySettingsPanel.xaml

@ -67,6 +67,7 @@ @@ -67,6 +67,7 @@
<CheckBox IsChecked="{Binding FoldBraces}">Enable folding on all blocks in braces</CheckBox>
<CheckBox IsChecked="{Binding SortResults}">Sort results by fitness</CheckBox>
<CheckBox IsChecked="{Binding ExpandMemberDefinitions}">Expand member definitions after decompilation</CheckBox>
<CheckBox IsChecked="{Binding ExpandUsingDeclarations}">Expand using declarations after decompilation</CheckBox>
</StackPanel>
</GroupBox>
</Grid>

2
ILSpy/Options/DisplaySettingsPanel.xaml.cs

@ -107,6 +107,7 @@ namespace ICSharpCode.ILSpy.Options @@ -107,6 +107,7 @@ namespace ICSharpCode.ILSpy.Options
s.SortResults = (bool?)e.Attribute("SortResults") ?? true;
s.FoldBraces = (bool?)e.Attribute("FoldBraces") ?? false;
s.ExpandMemberDefinitions = (bool?)e.Attribute("ExpandMemberDefinitions") ?? false;
s.ExpandUsingDeclarations = (bool?)e.Attribute("ExpandUsingDeclarations") ?? false;
return s;
}
@ -126,6 +127,7 @@ namespace ICSharpCode.ILSpy.Options @@ -126,6 +127,7 @@ namespace ICSharpCode.ILSpy.Options
section.SetAttributeValue("SortResults", s.SortResults);
section.SetAttributeValue("FoldBraces", s.FoldBraces);
section.SetAttributeValue("ExpandMemberDefinitions", s.ExpandMemberDefinitions);
section.SetAttributeValue("ExpandUsingDeclarations", s.ExpandUsingDeclarations);
XElement existingElement = root.Element("DisplaySettings");
if (existingElement != null)

Loading…
Cancel
Save