Browse Source

Add folding support.

pull/1/head
Daniel Grunwald 15 years ago
parent
commit
d07a18dc43
  1. 26
      ILSpy/Disassembler/ReflectionDisassembler.cs
  2. 4
      ILSpy/ITextOutput.cs
  3. 5
      ILSpy/TextView/DecompilerTextView.cs
  4. 3
      ILSpy/TextView/ILAsm-Mode.xshd
  5. 5
      ILSpy/TextView/SmartTextOutput.cs

26
ILSpy/Disassembler/ReflectionDisassembler.cs

@ -18,6 +18,7 @@ namespace ICSharpCode.ILSpy.Disassembler @@ -18,6 +18,7 @@ namespace ICSharpCode.ILSpy.Disassembler
ITextOutput output;
CancellationToken cancellationToken;
bool detectControlStructure;
bool isInType; // whether we are currently disassembling a whole type (-> defaultCollapsed for foldings)
MethodBodyDisassembler methodBodyDisassembler;
public ReflectionDisassembler(ITextOutput output, bool detectControlStructure, CancellationToken cancellationToken)
@ -123,9 +124,8 @@ namespace ICSharpCode.ILSpy.Disassembler @@ -123,9 +124,8 @@ namespace ICSharpCode.ILSpy.Disassembler
output.Write("unmanaged ");
WriteFlags(method.ImplAttributes & ~(MethodImplAttributes.CodeTypeMask | MethodImplAttributes.ManagedMask), methodImpl);
output.WriteLine();
output.Unindent();
OpenBlock();
OpenBlock(isInType);
WriteAttributes(method.CustomAttributes);
if (method.HasBody)
@ -195,8 +195,8 @@ namespace ICSharpCode.ILSpy.Disassembler @@ -195,8 +195,8 @@ namespace ICSharpCode.ILSpy.Disassembler
WriteFlags(property.Attributes, propertyAttributes);
property.PropertyType.WriteTo(output);
output.Write(' ');
output.WriteLine(DisassemblerHelpers.Escape(property.Name));
OpenBlock();
output.Write(DisassemblerHelpers.Escape(property.Name));
OpenBlock(false);
WriteAttributes(property.CustomAttributes);
WriteNestedMethod(".get", property.GetMethod);
WriteNestedMethod(".set", property.SetMethod);
@ -235,8 +235,8 @@ namespace ICSharpCode.ILSpy.Disassembler @@ -235,8 +235,8 @@ namespace ICSharpCode.ILSpy.Disassembler
WriteFlags(ev.Attributes, eventAttributes);
ev.EventType.WriteTo(output);
output.Write(' ');
output.WriteLine(DisassemblerHelpers.Escape(ev.Name));
OpenBlock();
output.Write(DisassemblerHelpers.Escape(ev.Name));
OpenBlock(false);
WriteAttributes(ev.CustomAttributes);
WriteNestedMethod(".add", ev.AddMethod);
WriteNestedMethod(".remove", ev.RemoveMethod);
@ -293,17 +293,19 @@ namespace ICSharpCode.ILSpy.Disassembler @@ -293,17 +293,19 @@ namespace ICSharpCode.ILSpy.Disassembler
const TypeAttributes masks = TypeAttributes.ClassSemanticMask | TypeAttributes.VisibilityMask | TypeAttributes.LayoutMask | TypeAttributes.StringFormatMask;
WriteFlags(type.Attributes & ~masks, typeAttributes);
output.WriteLine(DisassemblerHelpers.Escape(type.Name));
output.Write(DisassemblerHelpers.Escape(type.Name));
if (type.BaseType != null) {
output.WriteLine();
output.Indent();
output.Write("extends ");
type.BaseType.WriteTo(output);
output.Unindent();
output.WriteLine();
}
OpenBlock();
OpenBlock(isInType);
bool oldIsInType = isInType;
isInType = true;
WriteAttributes(type.CustomAttributes);
if (type.HasLayoutInfo) {
output.WriteLine(".pack {0}", type.PackingSize);
@ -357,6 +359,7 @@ namespace ICSharpCode.ILSpy.Disassembler @@ -357,6 +359,7 @@ namespace ICSharpCode.ILSpy.Disassembler
output.WriteLine();
}
CloseBlock();
isInType = oldIsInType;
}
#endregion
@ -394,9 +397,10 @@ namespace ICSharpCode.ILSpy.Disassembler @@ -394,9 +397,10 @@ namespace ICSharpCode.ILSpy.Disassembler
output.Write(")");
}
void OpenBlock()
void OpenBlock(bool defaultCollapsed)
{
output.MarkFoldStart();
output.MarkFoldStart(defaultCollapsed: defaultCollapsed);
output.WriteLine();
output.WriteLine("{");
output.Indent();
}

4
ILSpy/ITextOutput.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.ILSpy @@ -32,7 +32,7 @@ namespace ICSharpCode.ILSpy
void WriteDefinition(string text, object definition);
void WriteReference(string text, object reference);
void MarkFoldStart(string collapsedText = "...", bool defaultClosed = false);
void MarkFoldStart(string collapsedText = "...", bool defaultCollapsed = false);
void MarkFoldEnd();
}
@ -101,7 +101,7 @@ namespace ICSharpCode.ILSpy @@ -101,7 +101,7 @@ namespace ICSharpCode.ILSpy
Write(text);
}
void ITextOutput.MarkFoldStart(string collapsedText, bool defaultClosed)
void ITextOutput.MarkFoldStart(string collapsedText, bool defaultCollapsed)
{
}

5
ILSpy/TextView/DecompilerTextView.cs

@ -13,6 +13,7 @@ using System.Windows.Media.Animation; @@ -13,6 +13,7 @@ using System.Windows.Media.Animation;
using System.Windows.Threading;
using System.Xml;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using Mono.Cecil;
@ -25,6 +26,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -25,6 +26,7 @@ namespace ICSharpCode.ILSpy.TextView
sealed partial class DecompilerTextView : UserControl
{
readonly ReferenceElementGenerator referenceElementGenerator;
readonly FoldingManager foldingManager;
internal MainWindow mainWindow;
DefinitionLookup definitionLookup;
@ -46,6 +48,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -46,6 +48,7 @@ namespace ICSharpCode.ILSpy.TextView
this.referenceElementGenerator = new ReferenceElementGenerator(this);
textEditor.TextArea.TextView.ElementGenerators.Add(referenceElementGenerator);
textEditor.Text = "Welcome to ILSpy!";
foldingManager = FoldingManager.Install(textEditor.TextArea);
}
public void Decompile(IEnumerable<ILSpyTreeNodeBase> treeNodes)
@ -66,12 +69,14 @@ namespace ICSharpCode.ILSpy.TextView @@ -66,12 +69,14 @@ namespace ICSharpCode.ILSpy.TextView
if (currentCancellationTokenSource == myCancellationTokenSource) {
currentCancellationTokenSource = null;
waitAdorner.Visibility = Visibility.Collapsed;
foldingManager.Clear();
try {
SmartTextOutput textOutput = task.Result;
referenceElementGenerator.References = textOutput.References;
definitionLookup = textOutput.DefinitionLookup;
textEditor.SyntaxHighlighting = ILSpy.Language.Current.SyntaxHighlighting;
textEditor.Text = textOutput.ToString();
foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1);
} catch (AggregateException ex) {
textEditor.SyntaxHighlighting = null;
referenceElementGenerator.References = null;

3
ILSpy/TextView/ILAsm-Mode.xshd

@ -1,9 +1,7 @@ @@ -1,9 +1,7 @@
<SyntaxDefinition name="ILAsm" extensions=".il" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="// comment" />
<Color name="String" foreground="Magenta" exampleText="&quot;Hello, World!&quot;" />
<Color name="Punctuation" foreground="DarkGreen" exampleText="a(b.c);" />
<Color name="NumberLiteral" foreground="DarkBlue" exampleText="3.1415" />
<Color name="MethodCall" foreground="MidnightBlue" fontWeight="bold" exampleText="o.ToString();" />
<Color name="Instructions" foreground="Blue" exampleText="nop;" />
<Color name="Keywords" foreground="Blue" fontWeight="bold" exampleText="true" />
<Color name="Directives" foreground="Green" fontWeight="bold" exampleText=".class" />
@ -506,7 +504,6 @@ @@ -506,7 +504,6 @@
<Begin>"</Begin>
<End>"</End>
</Span>
<Rule color="MethodCall">[\d\w_]+(?=(\s*\())</Rule>
<Rule color="NumberLiteral">\b0[xX][0-9a-fA-F]+|\b(\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?</Rule>
<!--<Rule color="Punctuation">
[?,.;()\[\]{}+\-/%*&lt;&gt;^+~!|&amp;]+

5
ILSpy/TextView/SmartTextOutput.cs

@ -129,9 +129,10 @@ namespace ICSharpCode.ILSpy.TextView @@ -129,9 +129,10 @@ namespace ICSharpCode.ILSpy.TextView
references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = reference });
}
public void MarkFoldStart(string collapsedText, bool defaultClosed)
public void MarkFoldStart(string collapsedText, bool defaultCollapsed)
{
openFoldings.Push(new NewFolding { StartOffset = b.Length, Name = collapsedText, DefaultClosed = defaultClosed });
WriteIndent();
openFoldings.Push(new NewFolding { StartOffset = b.Length, Name = collapsedText, DefaultClosed = defaultCollapsed });
}
public void MarkFoldEnd()

Loading…
Cancel
Save