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 @@ -160,7 +160,7 @@ namespace ICSharpCode.Decompiler.Ast
RunTransformations();
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;
astCompileUnit.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy));
}

6
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

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

12
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -254,6 +254,18 @@ namespace ICSharpCode.Decompiler @@ -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
bool introduceIncrementAndDecrement = true;

1
ILSpy/Options/DecompilerSettingsPanel.xaml

@ -9,5 +9,6 @@ @@ -9,5 +9,6 @@
<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 ShowXmlDocumentation}">Show XML documentation in decompiled code</CheckBox>
<CheckBox IsChecked="{Binding FoldBraces}">Enable folding on all blocks in braces</CheckBox>
</StackPanel>
</UserControl>

2
ILSpy/Options/DecompilerSettingsPanel.xaml.cs

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

Loading…
Cancel
Save