Permalink
Browse files

Improved display of resource strings and serialized objects

  • Loading branch information...
EdHarvey committed Nov 29, 2011
1 parent 5be6be9 commit 46d99570d86bf0b4e852e75d49770c893c8e1c10
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<UserControl x:Class="ICSharpCode.ILSpy.Controls.ResourceObjectTable"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+ <UserControl.CommandBindings>
+ <CommandBinding Command="ApplicationCommands.Copy"
+ Executed="ExecuteCopy"
+ CanExecute="CanExecuteCopy" />
+ </UserControl.CommandBindings>
+ <Grid Margin="5,0,0,0">
+ <Grid.Resources>
+ <AlternationConverter x:Key="BackgroundConverter">
+ <SolidColorBrush Color="White"></SolidColorBrush>
+ <SolidColorBrush Color="Beige"></SolidColorBrush>
+ </AlternationConverter>
+ <Style x:Key="alternatingWithBinding"
+ TargetType="{x:Type ListBoxItem}">
+ <Setter Property="Background"
+ Value="{Binding RelativeSource={RelativeSource Self},
+ Path=(ItemsControl.AlternationIndex),
+ Converter={StaticResource BackgroundConverter}}" />
+ </Style>
+ </Grid.Resources>
+ <Grid.RowDefinitions>
+ <RowDefinition />
+ <RowDefinition />
+ </Grid.RowDefinitions>
+ <Label Content="Other Resources"
+ FontFamily="Segoe UI"
+ FontWeight="Bold"
+ FontSize="14" />
+ <ListView Name="resourceListView"
+ FontFamily="Segoe UI"
+ FontSize="12"
+ Foreground="Black"
+ Grid.Row="1"
+ AlternationCount="2"
+ ItemContainerStyle="{StaticResource alternatingWithBinding}">
+ <ListView.View>
+ <GridView AllowsColumnReorder="False">
+ <GridView.Columns>
+ <GridViewColumn DisplayMemberBinding="{Binding Key}">
+ <GridViewColumnHeader Content="Name"
+ HorizontalContentAlignment="Left"
+ FontWeight="Bold" />
+ </GridViewColumn>
+ <GridViewColumn DisplayMemberBinding="{Binding Value}">
+ <GridViewColumnHeader Content="Value (as string)"
+ HorizontalContentAlignment="Left"
+ FontWeight="Bold" />
+ </GridViewColumn>
+ <GridViewColumn DisplayMemberBinding="{Binding Type}">
+ <GridViewColumnHeader Content="Type"
+ HorizontalContentAlignment="Left"
+ FontWeight="Bold" />
+ </GridViewColumn>
+ </GridView.Columns>
+ </GridView>
+ </ListView.View>
+ </ListView>
+ </Grid>
+</UserControl>
@@ -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
+{
+ /// <summary>
+ /// Interaction logic for ResourceObjectTable.xaml
+ /// </summary>
+ 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;
+ }
+ }
+}
@@ -1,26 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
-<UserControl
- x:Class="ICSharpCode.ILSpy.Controls.ResourceStringTable" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+<UserControl x:Class="ICSharpCode.ILSpy.Controls.ResourceStringTable"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+>
<UserControl.CommandBindings>
- <CommandBinding Command="ApplicationCommands.Copy"
- Executed="ExecuteCopy"
- CanExecute="CanExecuteCopy"/>
+ <CommandBinding Command="ApplicationCommands.Copy"
+ Executed="ExecuteCopy"
+ CanExecute="CanExecuteCopy" />
</UserControl.CommandBindings>
- <ListView
- Name="resourceListView"
- SelectionMode="Extended">
+ <Grid Margin="5,0,0,0">
+ <Grid.Resources>
+ <AlternationConverter x:Key="BackgroundConverter">
+ <SolidColorBrush Color="White"></SolidColorBrush>
+ <SolidColorBrush Color="Beige"></SolidColorBrush>
+ </AlternationConverter>
+ <Style x:Key="alternatingWithBinding"
+ TargetType="{x:Type ListBoxItem}">
+ <Setter Property="Background"
+ Value="{Binding RelativeSource={RelativeSource Self},
+ Path=(ItemsControl.AlternationIndex),
+ Converter={StaticResource BackgroundConverter}}" />
+ </Style>
+ </Grid.Resources>
+ <Grid.RowDefinitions>
+ <RowDefinition />
+ <RowDefinition />
+ </Grid.RowDefinitions>
+ <Label Content="String Table"
+ FontFamily="Segoe UI"
+ FontWeight="Bold"
+ FontSize="14" />
+ <ListView Name="resourceListView"
+ FontFamily="Segoe UI"
+ FontSize="12"
+ Foreground="Black"
+ Grid.Row="1"
+ AlternationCount="2"
+ ItemContainerStyle="{StaticResource alternatingWithBinding}">
<ListView.View>
- <GridView
- AllowsColumnReorder="False">
+ <GridView AllowsColumnReorder="False">
<GridView.Columns>
- <GridViewColumn
- Header="Resource id"
- DisplayMemberBinding="{Binding Key}" />
- <GridViewColumn
- Header="Resource value"
- DisplayMemberBinding="{Binding Value}" />
+ <GridViewColumn DisplayMemberBinding="{Binding Key}">
+ <GridViewColumnHeader Content="Name"
+ HorizontalContentAlignment="Left"
+ FontWeight="Bold" />
+ </GridViewColumn>
+ <GridViewColumn DisplayMemberBinding="{Binding Value}">
+ <GridViewColumnHeader Content="Value"
+ HorizontalContentAlignment="Left"
+ FontWeight="Bold" />
+ </GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
+ </Grid>
</UserControl>
@@ -35,7 +35,7 @@ public ResourceStringTable(IEnumerable strings,Size maxSize)
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;
}
View
@@ -104,6 +104,9 @@
<Compile Include="Commands\ExitCommand.cs" />
<Compile Include="Commands\CommandWrapper.cs" />
<Compile Include="Commands\OpenListCommand.cs" />
+ <Compile Include="Controls\ResourceObjectTable.xaml.cs">
+ <DependentUpon>ResourceObjectTable.xaml</DependentUpon>
+ </Compile>
<Compile Include="Controls\DockedPane.cs" />
<Compile Include="Commands\DecompileAllCommand.cs" />
<Compile Include="Commands\ExportCommandAttribute.cs" />
@@ -272,6 +275,9 @@
<EmbeddedResource Include="TextView\ILAsm-Mode.xshd" />
</ItemGroup>
<ItemGroup>
+ <Page Include="Controls\ResourceObjectTable.xaml">
+ <SubType>Designer</SubType>
+ </Page>
<Page Include="Controls\ResourceStringTable.xaml" />
<Page Include="Controls\SearchBoxStyle.xaml">
<DependentUpon>SearchBox.cs</DependentUpon>
@@ -52,7 +52,7 @@ public ILSpyTreeNode CreateNode(string key, object data)
sealed class ResourcesFileTreeNode : ResourceTreeNode
{
readonly ICollection<KeyValuePair<string, string>> stringTableEntries = new ObservableCollection<KeyValuePair<string, string>>();
- readonly ICollection<KeyValuePair<string, string>> otherEntries = new ObservableCollection<KeyValuePair<string, string>>();
+ readonly ICollection<ResourceObjectRepresentation> otherEntries = new ObservableCollection<ResourceObjectRepresentation>();
public ResourcesFileTreeNode(EmbeddedResource er)
: base(er)
@@ -104,10 +104,11 @@ private void ProcessResourceEntry(DictionaryEntry entry)
return;
}
+ string entryType = entry.Value.GetType().FullName;
if (entry.Value is System.Globalization.CultureInfo) {
- otherEntries.Add(new KeyValuePair<string, string>(keyString, ((System.Globalization.CultureInfo)entry.Value).DisplayName));
+ otherEntries.Add(new ResourceObjectRepresentation(keyString, entryType, ((System.Globalization.CultureInfo)entry.Value).DisplayName));
} else {
- otherEntries.Add(new KeyValuePair<string, string>(keyString, entry.Value.ToString()));
+ otherEntries.Add(new ResourceObjectRepresentation(keyString, entryType, entry.Value.ToString()));
}
}
@@ -121,26 +122,41 @@ public override void Decompile(Language language, ITextOutput output, Decompilat
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; }
+ }
}
}

0 comments on commit 46d9957

Please sign in to comment.