Browse Source

Optional enable folding on all blocks in braces

pull/345/head
Ronny Klier 13 years ago
parent
commit
0bcca5473b
  1. 2
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 6
      ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  3. 12
      ICSharpCode.Decompiler/DecompilerSettings.cs
  4. 1
      ILSpy/Options/DecompilerSettingsPanel.xaml
  5. 2
      ILSpy/Options/DecompilerSettingsPanel.xaml.cs

2
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -160,7 +160,7 @@ namespace ICSharpCode.Decompiler.Ast
RunTransformations(); RunTransformations();
astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
var outputFormatter = new TextOutputFormatter(output);
var outputFormatter = new TextOutputFormatter(output) { FoldBraces = context.Settings.FoldBraces };
var formattingPolicy = context.Settings.CSharpFormattingOptions; var formattingPolicy = context.Settings.CSharpFormattingOptions;
astCompileUnit.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy)); astCompileUnit.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy));
} }

6
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -36,6 +36,8 @@ namespace ICSharpCode.Decompiler.Ast
bool firstUsingDeclaration; bool firstUsingDeclaration;
bool lastUsingDeclaration; bool lastUsingDeclaration;
public bool FoldBraces = false;
public TextOutputFormatter(ITextOutput output) public TextOutputFormatter(ITextOutput output)
{ {
if (output == null) if (output == null)
@ -183,7 +185,7 @@ namespace ICSharpCode.Decompiler.Ast
{ {
if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration)
braceLevelWithinType++; braceLevelWithinType++;
if (nodeStack.OfType<BlockStatement>().Count() <= 1) {
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces) {
output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1); output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1);
} }
output.WriteLine(); output.WriteLine();
@ -195,7 +197,7 @@ namespace ICSharpCode.Decompiler.Ast
{ {
output.Unindent(); output.Unindent();
output.Write('}'); output.Write('}');
if (nodeStack.OfType<BlockStatement>().Count() <= 1)
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces)
output.MarkFoldEnd(); output.MarkFoldEnd();
if (braceLevelWithinType >= 0) if (braceLevelWithinType >= 0)
braceLevelWithinType--; braceLevelWithinType--;

12
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -254,6 +254,18 @@ namespace ICSharpCode.Decompiler
} }
} }
} }
bool foldBraces = false;
public bool FoldBraces {
get { return foldBraces; }
set {
if (foldBraces != value) {
foldBraces = value;
OnPropertyChanged("FoldBraces");
}
}
}
#region Options to aid VB decompilation #region Options to aid VB decompilation
bool introduceIncrementAndDecrement = true; bool introduceIncrementAndDecrement = true;

1
ILSpy/Options/DecompilerSettingsPanel.xaml

@ -9,5 +9,6 @@
<CheckBox IsChecked="{Binding QueryExpressions}" IsEnabled="{Binding AnonymousMethods}">Decompile query expressions</CheckBox> <CheckBox IsChecked="{Binding QueryExpressions}" IsEnabled="{Binding AnonymousMethods}">Decompile query expressions</CheckBox>
<CheckBox IsChecked="{Binding UseDebugSymbols}">Use variable names from debug symbols, if available</CheckBox> <CheckBox IsChecked="{Binding UseDebugSymbols}">Use variable names from debug symbols, if available</CheckBox>
<CheckBox IsChecked="{Binding ShowXmlDocumentation}">Show XML documentation in decompiled code</CheckBox> <CheckBox IsChecked="{Binding ShowXmlDocumentation}">Show XML documentation in decompiled code</CheckBox>
<CheckBox IsChecked="{Binding FoldBraces}">Enable folding on all blocks in braces</CheckBox>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

2
ILSpy/Options/DecompilerSettingsPanel.xaml.cs

@ -57,6 +57,7 @@ namespace ICSharpCode.ILSpy.Options
s.QueryExpressions = (bool?)e.Attribute("queryExpressions") ?? s.QueryExpressions; s.QueryExpressions = (bool?)e.Attribute("queryExpressions") ?? s.QueryExpressions;
s.UseDebugSymbols = (bool?)e.Attribute("useDebugSymbols") ?? s.UseDebugSymbols; s.UseDebugSymbols = (bool?)e.Attribute("useDebugSymbols") ?? s.UseDebugSymbols;
s.ShowXmlDocumentation = (bool?)e.Attribute("xmlDoc") ?? s.ShowXmlDocumentation; s.ShowXmlDocumentation = (bool?)e.Attribute("xmlDoc") ?? s.ShowXmlDocumentation;
s.FoldBraces = (bool?)e.Attribute("foldBraces") ?? s.FoldBraces;
return s; return s;
} }
@ -70,6 +71,7 @@ namespace ICSharpCode.ILSpy.Options
section.SetAttributeValue("queryExpressions", s.QueryExpressions); section.SetAttributeValue("queryExpressions", s.QueryExpressions);
section.SetAttributeValue("useDebugSymbols", s.UseDebugSymbols); section.SetAttributeValue("useDebugSymbols", s.UseDebugSymbols);
section.SetAttributeValue("xmlDoc", s.ShowXmlDocumentation); section.SetAttributeValue("xmlDoc", s.ShowXmlDocumentation);
section.SetAttributeValue("foldBraces", s.FoldBraces);
XElement existingElement = root.Element("DecompilerSettings"); XElement existingElement = root.Element("DecompilerSettings");
if (existingElement != null) if (existingElement != null)

Loading…
Cancel
Save