From 46d99570d86bf0b4e852e75d49770c893c8e1c10 Mon Sep 17 00:00:00 2001 From: Ed Harvey Date: Wed, 30 Nov 2011 01:59:35 +1100 Subject: [PATCH] Improved display of resource strings and serialized objects --- ILSpy/Controls/ResourceObjectTable.xaml | 62 ++++++++++++++++++ ILSpy/Controls/ResourceObjectTable.xaml.cs | 58 +++++++++++++++++ ILSpy/Controls/ResourceStringTable.xaml | 64 ++++++++++++++----- ILSpy/Controls/ResourceStringTable.xaml.cs | 2 +- ILSpy/ILSpy.csproj | 6 ++ .../ResourceNodes/ResourcesFileTreeNode.cs | 32 +++++++--- 6 files changed, 199 insertions(+), 25 deletions(-) create mode 100644 ILSpy/Controls/ResourceObjectTable.xaml create mode 100644 ILSpy/Controls/ResourceObjectTable.xaml.cs diff --git a/ILSpy/Controls/ResourceObjectTable.xaml b/ILSpy/Controls/ResourceObjectTable.xaml new file mode 100644 index 000000000..7e9da6bac --- /dev/null +++ b/ILSpy/Controls/ResourceObjectTable.xaml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ILSpy/Controls/ResourceObjectTable.xaml.cs b/ILSpy/Controls/ResourceObjectTable.xaml.cs new file mode 100644 index 000000000..9c23e31b3 --- /dev/null +++ b/ILSpy/Controls/ResourceObjectTable.xaml.cs @@ -0,0 +1,58 @@ +// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace ICSharpCode.ILSpy.Controls +{ + /// + /// Interaction logic for ResourceObjectTable.xaml + /// + public partial class ResourceObjectTable : UserControl + { + public ResourceObjectTable(IEnumerable resources,Size maxSize) + { + InitializeComponent(); + // set size to fit decompiler window + // TODO: there should be a more transparent way to do this + Width = maxSize.Width; + MaxHeight = maxSize.Height; + resourceListView.ItemsSource = resources; + } + + void ExecuteCopy(object sender, ExecutedRoutedEventArgs args) + { + StringBuilder sb = new StringBuilder(); + foreach (var item in resourceListView.SelectedItems) + { + sb.AppendLine(item.ToString()); + } + Clipboard.SetText(sb.ToString()); + } + + void CanExecuteCopy(object sender, CanExecuteRoutedEventArgs args) + { + args.CanExecute = true; + } + } +} \ No newline at end of file diff --git a/ILSpy/Controls/ResourceStringTable.xaml b/ILSpy/Controls/ResourceStringTable.xaml index e5782a33b..d8bc32552 100644 --- a/ILSpy/Controls/ResourceStringTable.xaml +++ b/ILSpy/Controls/ResourceStringTable.xaml @@ -1,26 +1,58 @@  - + - + - + + + + + + + + + + + + + \ No newline at end of file diff --git a/ILSpy/Controls/ResourceStringTable.xaml.cs b/ILSpy/Controls/ResourceStringTable.xaml.cs index 9d48d2b86..51430fee9 100644 --- a/ILSpy/Controls/ResourceStringTable.xaml.cs +++ b/ILSpy/Controls/ResourceStringTable.xaml.cs @@ -35,7 +35,7 @@ namespace ICSharpCode.ILSpy.Controls InitializeComponent(); // set size to fit decompiler window // TODO: there should be a more transparent way to do this - MaxWidth = maxSize.Width; + Width = maxSize.Width; MaxHeight = maxSize.Height; resourceListView.ItemsSource = strings; } diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index fb0d86312..20c281acf 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -104,6 +104,9 @@ + + ResourceObjectTable.xaml + @@ -272,6 +275,9 @@ + + Designer + SearchBox.cs diff --git a/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs b/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs index 30256cebf..9632ce186 100644 --- a/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs +++ b/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.ILSpy.TreeNodes sealed class ResourcesFileTreeNode : ResourceTreeNode { readonly ICollection> stringTableEntries = new ObservableCollection>(); - readonly ICollection> otherEntries = new ObservableCollection>(); + readonly ICollection otherEntries = new ObservableCollection(); public ResourcesFileTreeNode(EmbeddedResource er) : base(er) @@ -104,10 +104,11 @@ namespace ICSharpCode.ILSpy.TreeNodes return; } + string entryType = entry.Value.GetType().FullName; if (entry.Value is System.Globalization.CultureInfo) { - otherEntries.Add(new KeyValuePair(keyString, ((System.Globalization.CultureInfo)entry.Value).DisplayName)); + otherEntries.Add(new ResourceObjectRepresentation(keyString, entryType, ((System.Globalization.CultureInfo)entry.Value).DisplayName)); } else { - otherEntries.Add(new KeyValuePair(keyString, entry.Value.ToString())); + otherEntries.Add(new ResourceObjectRepresentation(keyString, entryType, entry.Value.ToString())); } } @@ -121,26 +122,41 @@ namespace ICSharpCode.ILSpy.TreeNodes smartOutput.AddUIElement( delegate { return new ResourceStringTable(stringTableEntries, - new System.Windows.Size(MainWindow.Instance.mainPane.ActualWidth - 40, - MainWindow.Instance.mainPane.ActualHeight - 100)); + new System.Windows.Size(MainWindow.Instance.mainPane.ActualWidth - 45, + MainWindow.Instance.mainPane.ActualHeight)); } ); } output.WriteLine(); + output.WriteLine(); } if (otherEntries.Count != 0) { ISmartTextOutput smartOutput = output as ISmartTextOutput; if (null != smartOutput) { smartOutput.AddUIElement( delegate { - return new ResourceStringTable(otherEntries, - new System.Windows.Size(MainWindow.Instance.mainPane.ActualWidth - 40, - MainWindow.Instance.mainPane.ActualHeight - 100)); + return new ResourceObjectTable(otherEntries, + new System.Windows.Size(MainWindow.Instance.mainPane.ActualWidth - 45, + MainWindow.Instance.mainPane.ActualHeight)); } ); } output.WriteLine(); } } + + internal class ResourceObjectRepresentation + { + public ResourceObjectRepresentation(string key, string type, string value) + { + this.Key = key; + this.Type = type; + this.Value = value; + } + + public string Key { get; private set; } + public string Type { get; private set; } + public string Value { get; private set; } + } } }