Skip to content

Commit 85f704d

Browse files
WIP
1 parent a640e4a commit 85f704d

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

ILSpy/Controls/TreeView/SharpTreeView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
VerticalAlignment="Center" />
247247
</Border>
248248
<StackPanel Orientation="Horizontal"
249-
Background="Transparent"
249+
Background="{Binding Background}"
250250
ToolTip="{Binding ToolTip}">
251251
<ContentPresenter Name="icon"
252252
Content="{Binding Icon}"

ILSpy/ViewModels/CompareViewModel.cs

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace ICSharpCode.ILSpy.ViewModels
1616
{
1717
using System.Linq;
18+
using System.Windows.Media;
1819

1920
using ICSharpCode.Decompiler;
2021
using ICSharpCode.Decompiler.TypeSystem;
@@ -90,6 +91,7 @@ Entry MergeTrees(Entry a, Entry b)
9091
{
9192
var m = new Entry() {
9293
Entity = a.Entity,
94+
OtherEntity = b.Entity,
9395
Signature = a.Signature,
9496
};
9597

@@ -367,12 +369,14 @@ public DiffKind RecursiveKind {
367369
get {
368370
if (kind != null)
369371
return kind.Value;
372+
if (Children == null)
373+
return DiffKind.None;
370374

371375
int addCount = 0, removeCount = 0, updateCount = 0;
372376

373377
foreach (var item in Children)
374378
{
375-
switch (item.Kind)
379+
switch (item.RecursiveKind)
376380
{
377381
case DiffKind.Add:
378382
addCount++;
@@ -396,16 +400,20 @@ public DiffKind RecursiveKind {
396400
}
397401
}
398402

399-
public DiffKind Kind { get; set; }
403+
public DiffKind Kind {
404+
get => this.kind ?? DiffKind.None;
405+
set => this.kind = value;
406+
}
400407
public required string Signature { get; init; }
401408
public required ISymbol Entity { get; init; }
409+
public ISymbol? OtherEntity { get; init; }
402410

403411
public Entry? Parent { get; set; }
404412
public List<Entry>? Children { get; set; }
405413

406414
private string GetDebuggerDisplay()
407415
{
408-
return $"Entry{Kind}{Entity?.ToString() ?? Signature}";
416+
return $"Entry{Kind}{Entity.ToString() ?? Signature}";
409417
}
410418
}
411419

@@ -447,33 +455,29 @@ protected override void LoadChildren()
447455
if (entry.Children == null)
448456
return;
449457

450-
foreach (var item in entry.Children)
458+
foreach (var item in entry.Children.OrderBy(e => (-(int)e.RecursiveKind, e.Entity.SymbolKind, e.Signature)))
451459
{
452460
this.Children.Add(new ComparisonEntryTreeNode(item));
453461
}
454462
}
455463

456464
public override object Text {
457465
get {
458-
switch (entry.Entity)
459-
{
460-
case ITypeDefinition t:
461-
return this.Language.TypeToString(t, includeNamespace: false) + GetSuffixString(t.MetadataToken);
462-
case IMethod m:
463-
return this.Language.MethodToString(m, false, false, false) + GetSuffixString(m.MetadataToken);
464-
case IField f:
465-
return this.Language.FieldToString(f, false, false, false) + GetSuffixString(f.MetadataToken);
466-
case IProperty p:
467-
return this.Language.PropertyToString(p, false, false, false) + GetSuffixString(p.MetadataToken);
468-
case IEvent e:
469-
return this.Language.EventToString(e, false, false, false) + GetSuffixString(e.MetadataToken);
470-
case INamespace n:
471-
return n.FullName;
472-
case IModule m:
473-
return m.FullAssemblyName;
474-
default:
475-
return entry.Signature;
476-
}
466+
string? entityText = GetEntityText(entry.Entity);
467+
string? otherText = GetEntityText(entry.OtherEntity);
468+
469+
return entityText + (otherText != null && ? " -> " + otherText : "");
470+
471+
string? GetEntityText(ISymbol? symbol) => symbol switch {
472+
ITypeDefinition t => this.Language.TypeToString(t, includeNamespace: false) + GetSuffixString(t.MetadataToken),
473+
IMethod m => this.Language.MethodToString(m, false, false, false) + GetSuffixString(m.MetadataToken),
474+
IField f => this.Language.FieldToString(f, false, false, false) + GetSuffixString(f.MetadataToken),
475+
IProperty p => this.Language.PropertyToString(p, false, false, false) + GetSuffixString(p.MetadataToken),
476+
IEvent e => this.Language.EventToString(e, false, false, false) + GetSuffixString(e.MetadataToken),
477+
INamespace n => n.FullName,
478+
IModule m => m.FullAssemblyName,
479+
_ => null,
480+
};
477481
}
478482
}
479483

@@ -501,11 +505,6 @@ public override object Icon {
501505
}
502506
}
503507

504-
505-
506-
public DiffKind RecursiveKind => entry.RecursiveKind;
507-
public DiffKind Kind => entry.Kind;
508-
509508
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
510509
{
511510
}
@@ -514,5 +513,21 @@ public override void Decompile(Language language, ITextOutput output, Decompilat
514513
//{
515514
// return RecursiveKind != DiffKind.None ? FilterResult.Match : FilterResult.Hidden;
516515
//}
516+
517+
public Brush Background {
518+
get {
519+
switch (entry.RecursiveKind)
520+
{
521+
case DiffKind.Add:
522+
return Brushes.LightGreen;
523+
case DiffKind.Remove:
524+
return Brushes.LightPink;
525+
case DiffKind.Update:
526+
return Brushes.LightBlue;
527+
}
528+
529+
return Brushes.Transparent;
530+
}
531+
}
517532
}
518533
}

0 commit comments

Comments
 (0)