Browse Source

Code cleanup.

pull/1/head
Daniel Grunwald 15 years ago
parent
commit
48dd3c0fd1
  1. 1
      ILSpy/AboutPage.cs
  2. 2
      ILSpy/Controls/SortableGridViewColumn.cs
  3. 198
      ILSpy/CueBannerService.cs
  4. 3
      ILSpy/ILSpy.csproj
  5. 1
      ILSpy/MainWindow.xaml.cs
  6. 14
      ILSpy/OpenFromGacDialog.xaml
  7. 6
      ILSpy/OpenFromGacDialog.xaml.cs
  8. 10
      ILSpy/themes/generic.xaml

1
ILSpy/AboutPage.cs

@ -137,7 +137,6 @@ namespace ICSharpCode.ILSpy
var bands = doc.Root.Elements("band"); var bands = doc.Root.Elements("band");
var currentBand = bands.FirstOrDefault(b => (string)b.Attribute("id") == "stable") ?? bands.First(); var currentBand = bands.FirstOrDefault(b => (string)b.Attribute("id") == "stable") ?? bands.First();
Version version = new Version((string)currentBand.Element("latestVersion")); Version version = new Version((string)currentBand.Element("latestVersion"));
version = new Version(1,0,0,0);
string url = (string)currentBand.Element("downloadUrl"); string url = (string)currentBand.Element("downloadUrl");
if (!(url.StartsWith("http://", StringComparison.Ordinal) || url.StartsWith("https://", StringComparison.Ordinal))) if (!(url.StartsWith("http://", StringComparison.Ordinal) || url.StartsWith("https://", StringComparison.Ordinal)))
url = null; // don't accept non-urls url = null; // don't accept non-urls

2
ILSpy/SortableGridViewColumn.cs → ILSpy/Controls/SortableGridViewColumn.cs

@ -22,7 +22,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy.Controls
{ {
/// <summary> /// <summary>
/// Allows to automatically sort a grid view. /// Allows to automatically sort a grid view.

198
ILSpy/CueBannerService.cs

@ -1,198 +0,0 @@
// Copyright (c) 2008 Jason Kemp
//
// 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.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Media;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Watermark for text boxes; from http://www.ageektrapped.com/blog/the-missing-net-4-cue-banner-in-wpf-i-mean-watermark-in-wpf/.
/// </summary>
public static class CueBannerService
{
//there is absolutely no way to write this statement out
//to look pretty
public static readonly DependencyProperty CueBannerProperty = DependencyProperty.RegisterAttached(
"CueBanner", typeof (object), typeof (CueBannerService),
new FrameworkPropertyMetadata("", CueBannerPropertyChanged));
public static object GetCueBanner(Control control)
{
return control.GetValue(CueBannerProperty);
}
public static void SetCueBanner(Control control, object value)
{
control.SetValue(CueBannerProperty, value);
}
private static void CueBannerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Control control = (Control)d;
control.Loaded += control_Loaded;
if (d is ComboBox || d is TextBox)
{
control.GotFocus += control_GotFocus;
control.LostFocus += control_Loaded;
}
if (d is ItemsControl && !(d is ComboBox))
{
ItemsControl i = (ItemsControl) d;
//for Items property
i.ItemContainerGenerator.ItemsChanged += ItemsChanged;
itemsControls.Add(i.ItemContainerGenerator, i);
//for ItemsSource property
DependencyPropertyDescriptor prop =
DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, i.GetType());
prop.AddValueChanged(i, ItemsSourceChanged);
}
}
private static readonly Dictionary<object, ItemsControl> itemsControls = new Dictionary<object, ItemsControl>();
private static void ItemsSourceChanged(object sender, EventArgs e)
{
ItemsControl c = (ItemsControl)sender;
if (c.ItemsSource != null)
RemoveCueBanner(c);
else
ShowCueBanner(c);
}
private static void ItemsChanged(object sender, ItemsChangedEventArgs e)
{
ItemsControl control;
if (itemsControls.TryGetValue(sender, out control))
{
if (e.ItemCount > 0)
RemoveCueBanner(control);
else
ShowCueBanner(control);
}
}
private static void control_GotFocus(object sender, RoutedEventArgs e)
{
Control c = (Control)sender;
if (ShouldShowCueBanner(c))
{
RemoveCueBanner(c);
}
}
private static void control_Loaded(object sender, RoutedEventArgs e)
{
Control control = (Control)sender;
if (ShouldShowCueBanner(control))
{
ShowCueBanner(control);
}
}
private static void RemoveCueBanner(UIElement control)
{
AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);
Adorner[] adorners = layer.GetAdorners(control);
if (adorners == null) return;
foreach (Adorner adorner in adorners)
{
if (adorner is CueBannerAdorner)
{
adorner.Visibility = Visibility.Hidden;
layer.Remove(adorner);
}
}
}
private static void ShowCueBanner(Control control)
{
AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);
layer.Add(new CueBannerAdorner(control, GetCueBanner(control)));
}
private static bool ShouldShowCueBanner(Control c)
{
DependencyProperty dp = GetDependencyProperty(c);
if (dp == null) return true;
return c.GetValue(dp).Equals("");
}
private static DependencyProperty GetDependencyProperty (Control control)
{
if (control is ComboBox)
return ComboBox.TextProperty;
if (control is TextBoxBase)
return TextBox.TextProperty;
return null;
}
}
internal class CueBannerAdorner : Adorner
{
private readonly ContentPresenter contentPresenter;
public CueBannerAdorner(UIElement adornedElement, object cueBanner) :
base(adornedElement)
{
this.IsHitTestVisible = false;
contentPresenter = new ContentPresenter();
contentPresenter.Content = cueBanner;
contentPresenter.Opacity = 0.7;
contentPresenter.Margin =
new Thickness(Control.Margin.Left + Control.Padding.Left,
Control.Margin.Top + Control.Padding.Top, 0, 0);
}
private Control Control
{
get { return (Control) this.AdornedElement; }
}
protected override Visual GetVisualChild(int index)
{
return contentPresenter;
}
protected override int VisualChildrenCount
{
get { return 1; }
}
protected override Size MeasureOverride(Size constraint)
{
contentPresenter.Measure(Control.RenderSize);
return Control.RenderSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
contentPresenter.Arrange(new Rect(finalSize));
return finalSize;
}
}
}

3
ILSpy/ILSpy.csproj

@ -80,8 +80,8 @@
<Compile Include="AssemblyList.cs" /> <Compile Include="AssemblyList.cs" />
<Compile Include="AssemblyListManager.cs" /> <Compile Include="AssemblyListManager.cs" />
<Compile Include="Controls\SearchBox.cs" /> <Compile Include="Controls\SearchBox.cs" />
<Compile Include="Controls\SortableGridViewColumn.cs" />
<Compile Include="CSharpLanguage.cs" /> <Compile Include="CSharpLanguage.cs" />
<Compile Include="CueBannerService.cs" />
<Compile Include="DecompilationOptions.cs" /> <Compile Include="DecompilationOptions.cs" />
<Compile Include="ExtensionMethods.cs" /> <Compile Include="ExtensionMethods.cs" />
<Compile Include="FilterSettings.cs" /> <Compile Include="FilterSettings.cs" />
@ -116,7 +116,6 @@
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="SessionSettings.cs" /> <Compile Include="SessionSettings.cs" />
<Compile Include="SortableGridViewColumn.cs" />
<Compile Include="TextView\CaretHighlightAdorner.cs" /> <Compile Include="TextView\CaretHighlightAdorner.cs" />
<Compile Include="TextView\DecompilerTextView.cs" /> <Compile Include="TextView\DecompilerTextView.cs" />
<Compile Include="TextView\OutputLengthExceededException.cs" /> <Compile Include="TextView\OutputLengthExceededException.cs" />

1
ILSpy/MainWindow.xaml.cs

@ -26,6 +26,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.FlowAnalysis; using ICSharpCode.Decompiler.FlowAnalysis;
using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.ILSpy.TreeNodes;

14
ILSpy/OpenFromGacDialog.xaml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Window <Window
x:Class="ICSharpCode.ILSpy.OpenFromGacDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ICSharpCode.ILSpy" x:Class="ICSharpCode.ILSpy.OpenFromGacDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
Title="Open From GAC" Title="Open From GAC"
Style="{DynamicResource DialogWindow}" Style="{DynamicResource DialogWindow}"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"
@ -24,14 +24,14 @@
<Label DockPanel.Dock="Left" Target="{Binding ElementName=filterTextBox}">_Search:</Label> <Label DockPanel.Dock="Left" Target="{Binding ElementName=filterTextBox}">_Search:</Label>
<TextBox Name="filterTextBox" TextChanged="FilterTextBox_TextChanged" /> <TextBox Name="filterTextBox" TextChanged="FilterTextBox_TextChanged" />
</DockPanel> </DockPanel>
<ListView Name="listView" Grid.Row="1" Margin="0, 8" local:SortableGridViewColumn.SortMode="Automatic" SelectionChanged="ListView_SelectionChanged"> <ListView Name="listView" Grid.Row="1" Margin="0, 8" controls:SortableGridViewColumn.SortMode="Automatic" SelectionChanged="ListView_SelectionChanged">
<ListView.View> <ListView.View>
<GridView> <GridView>
<local:SortableGridViewColumn x:Name="nameColumn" Width="300" Header="Reference Name" DisplayMemberBinding="{Binding ShortName}" /> <controls:SortableGridViewColumn x:Name="nameColumn" Width="300" Header="Reference Name" DisplayMemberBinding="{Binding ShortName}" />
<local:SortableGridViewColumn Width="75" Header="Version" DisplayMemberBinding="{Binding Version}" /> <controls:SortableGridViewColumn Width="75" Header="Version" DisplayMemberBinding="{Binding Version}" />
<local:SortableGridViewColumn Width="65" Header="Culture" DisplayMemberBinding="{Binding Culture}" /> <controls:SortableGridViewColumn Width="65" Header="Culture" DisplayMemberBinding="{Binding Culture}" />
<local:SortableGridViewColumn Width="115" Header="Public Key Token" DisplayMemberBinding="{Binding PublicKeyToken}" /> <controls:SortableGridViewColumn Width="115" Header="Public Key Token" DisplayMemberBinding="{Binding PublicKeyToken}" />
<local:SortableGridViewColumn Width="1000" Header="Location" DisplayMemberBinding="{Binding FileName}" /> <controls:SortableGridViewColumn Width="1000" Header="Location" DisplayMemberBinding="{Binding FileName}" />
</GridView> </GridView>
</ListView.View> </ListView.View>
</ListView> </ListView>

6
ILSpy/OpenFromGacDialog.xaml.cs

@ -25,11 +25,9 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.ILSpy.Controls;
using Mono.Cecil; using Mono.Cecil;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy

10
ILSpy/themes/generic.xaml

@ -1,22 +1,22 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.ILSpy" xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
> >
<!-- SortableGridViewColumn. <!-- SortableGridViewColumn.
Displays an up arrow or down arrow in the column header when the grid is sorted using that column. Displays an up arrow or down arrow in the column header when the grid is sorted using that column.
--> -->
<local:ColumnSortDirectionToVisibilityConverter x:Key="ColumnSortDirectionToVisibilityConverter"/> <controls:ColumnSortDirectionToVisibilityConverter x:Key="ColumnSortDirectionToVisibilityConverter"/>
<DataTemplate x:Key="{ComponentResourceKey {x:Type local:SortableGridViewColumn}, ColumnHeaderTemplate}"> <DataTemplate x:Key="{ComponentResourceKey {x:Type controls:SortableGridViewColumn}, ColumnHeaderTemplate}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock HorizontalAlignment="Center" Text="{Binding}"/> <TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
<Path x:Name="upArrow" <Path x:Name="upArrow"
Visibility="{Binding Path=Column.SortDirection, ConverterParameter={x:Static local:ColumnSortDirection.Ascending}, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumnHeader}}, Converter={StaticResource ColumnSortDirectionToVisibilityConverter}}" Visibility="{Binding Path=Column.SortDirection, ConverterParameter={x:Static controls:ColumnSortDirection.Ascending}, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumnHeader}}, Converter={StaticResource ColumnSortDirectionToVisibilityConverter}}"
StrokeThickness = "1" StrokeThickness = "1"
Fill = "Gray" Fill = "Gray"
Data = "M 5,10 L 15,10 L 10,5 L 5,10"/> Data = "M 5,10 L 15,10 L 10,5 L 5,10"/>
<Path x:Name="downArrow" <Path x:Name="downArrow"
Visibility="{Binding Path=Column.SortDirection, ConverterParameter={x:Static local:ColumnSortDirection.Descending}, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumnHeader}}, Converter={StaticResource ColumnSortDirectionToVisibilityConverter}}" Visibility="{Binding Path=Column.SortDirection, ConverterParameter={x:Static controls:ColumnSortDirection.Descending}, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumnHeader}}, Converter={StaticResource ColumnSortDirectionToVisibilityConverter}}"
StrokeThickness = "1" StrokeThickness = "1"
Fill = "Gray" Fill = "Gray"
Data = "M 5,5 L 10,10 L 15,5 L 5,5"/> Data = "M 5,5 L 10,10 L 15,5 L 5,5"/>

Loading…
Cancel
Save