Browse Source

Add display settings to the options dialog: allows to configure font family and size used in the DecompilerTextView. fixes #176

pull/166/merge
Siegfried Pammer 14 years ago
parent
commit
e654e33613
  1. 65
      ILSpy/DisplaySettings.cs
  2. 57
      ILSpy/DisplaySettingsPanel.xaml
  3. 137
      ILSpy/DisplaySettingsPanel.xaml.cs
  4. 6
      ILSpy/ILSpy.csproj
  5. 3
      ILSpy/TextView/DecompilerTextView.cs

65
ILSpy/DisplaySettings.cs

@ -0,0 +1,65 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.ComponentModel;
using System.Windows.Media;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Description of DisplaySettings.
/// </summary>
public class DisplaySettings : INotifyPropertyChanged
{
public DisplaySettings()
{
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null) {
PropertyChanged(this, e);
}
}
protected void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
#endregion
FontFamily selectedFont;
public FontFamily SelectedFont {
get { return selectedFont; }
set {
if (selectedFont != value) {
selectedFont = value;
OnPropertyChanged("SelectedFont");
}
}
}
double selectedFontSize;
public double SelectedFontSize {
get { return selectedFontSize; }
set {
if (selectedFontSize != value) {
selectedFontSize = value;
OnPropertyChanged("SelectedFontSize");
}
}
}
public void CopyValues(DisplaySettings s)
{
this.SelectedFont = s.selectedFont;
this.SelectedFontSize = s.selectedFontSize;
}
}
}

57
ILSpy/DisplaySettingsPanel.xaml

@ -0,0 +1,57 @@
<UserControl x:Class="ICSharpCode.ILSpy.DisplaySettingsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.ILSpy">
<UserControl.Resources>
<local:FontSizeConverter x:Key="fontSizeConv" />
</UserControl.Resources>
<Grid>
<GroupBox Header="Font">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Margin="3">Font:</Label>
<ComboBox x:Name="fontSelector" SelectedItem="{Binding SelectedFont}" Grid.Column="1">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock VerticalAlignment="Center" Text="{Binding Source}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Label Grid.Column="2" Margin="3">Size:</Label>
<ComboBox Grid.Column="3" Text="{Binding SelectedFontSize, Converter={StaticResource fontSizeConv}}" IsEditable="True" Margin="3">
<ComboBoxItem>6</ComboBoxItem>
<ComboBoxItem>7</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
<ComboBoxItem>9</ComboBoxItem>
<ComboBoxItem>10</ComboBoxItem>
<ComboBoxItem>11</ComboBoxItem>
<ComboBoxItem>12</ComboBoxItem>
<ComboBoxItem>13</ComboBoxItem>
<ComboBoxItem>14</ComboBoxItem>
<ComboBoxItem>15</ComboBoxItem>
<ComboBoxItem>16</ComboBoxItem>
<ComboBoxItem>17</ComboBoxItem>
<ComboBoxItem>18</ComboBoxItem>
<ComboBoxItem>19</ComboBoxItem>
<ComboBoxItem>20</ComboBoxItem>
<ComboBoxItem>21</ComboBoxItem>
<ComboBoxItem>22</ComboBoxItem>
<ComboBoxItem>23</ComboBoxItem>
<ComboBoxItem>24</ComboBoxItem>
</ComboBox>
<Border Grid.Row="1" Grid.ColumnSpan="4" BorderBrush="Black" BorderThickness="1" Background="White" Margin="3">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="AaBbCcXxYyZz" FontFamily="{Binding SelectedFont}" FontSize="{Binding SelectedFontSize}" />
</Border>
</Grid>
</GroupBox>
</Grid>
</UserControl>

137
ILSpy/DisplaySettingsPanel.xaml.cs

@ -0,0 +1,137 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
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.Xml.Linq;
using ICSharpCode.Decompiler;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Interaction logic for DisplaySettingsPanel.xaml
/// </summary>
[ExportOptionPage("Display")]
public partial class DisplaySettingsPanel : UserControl, IOptionPage
{
public DisplaySettingsPanel()
{
InitializeComponent();
Task<FontFamily[]> task = new Task<FontFamily[]>(FontLoader);
task.Start();
task.ContinueWith(
delegate(Task continuation) {
App.Current.Dispatcher.Invoke(
DispatcherPriority.Normal,
(Action)(
() => {
fontSelector.ItemsSource = task.Result;
if (continuation.Exception != null) {
foreach (var ex in continuation.Exception.InnerExceptions) {
MessageBox.Show(ex.ToString());
}
}
})
);
}
);
}
public void Load(ILSpySettings settings)
{
this.DataContext = LoadDisplaySettings(settings);
}
static DisplaySettings currentDisplaySettings;
public static DisplaySettings CurrentDisplaySettings {
get {
return currentDisplaySettings ?? (currentDisplaySettings = LoadDisplaySettings(ILSpySettings.Load()));
}
}
static bool IsSymbolFont(FontFamily fontFamily)
{
foreach (var tf in fontFamily.GetTypefaces()) {
GlyphTypeface glyph;
try {
if (tf.TryGetGlyphTypeface(out glyph))
return glyph.Symbol;
} catch (Exception) {
return true;
}
}
return false;
}
static FontFamily[] FontLoader()
{
return Fonts.SystemFontFamilies
.Where(ff => !IsSymbolFont(ff))
.OrderBy(ff => ff.Source)
.ToArray();
}
public static DisplaySettings LoadDisplaySettings(ILSpySettings settings)
{
XElement e = settings["DisplaySettings"];
DisplaySettings s = new DisplaySettings();
s.SelectedFont = new FontFamily((string)e.Attribute("Font") ?? "Consolas");
s.SelectedFontSize = (double?)e.Attribute("FontSize") ?? 10.0 * 4 / 3;
return s;
}
public void Save(XElement root)
{
DisplaySettings s = (DisplaySettings)this.DataContext;
currentDisplaySettings.CopyValues(s);
XElement section = new XElement("DisplaySettings");
section.SetAttributeValue("Font", s.SelectedFont.Source);
section.SetAttributeValue("FontSize", s.SelectedFontSize);
XElement existingElement = root.Element("DisplaySettings");
if (existingElement != null)
existingElement.ReplaceWith(section);
else
root.Add(section);
}
}
public class FontSizeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double) {
return Math.Round((double)value / 4 * 3);
}
throw new NotImplementedException();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is string) {
double d;
if (double.TryParse((string)value, out d))
return d * 4 / 3;
return 11 * 4 / 3;
}
throw new NotImplementedException();
}
}
}

6
ILSpy/ILSpy.csproj

@ -102,6 +102,7 @@
<DependentUpon>DecompilerSettingsPanel.xaml</DependentUpon> <DependentUpon>DecompilerSettingsPanel.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="DisplaySettings.cs" />
<Compile Include="ExportCommandAttribute.cs" /> <Compile Include="ExportCommandAttribute.cs" />
<Compile Include="Controls\SearchBox.cs" /> <Compile Include="Controls\SearchBox.cs" />
<Compile Include="Controls\SortableGridViewColumn.cs" /> <Compile Include="Controls\SortableGridViewColumn.cs" />
@ -138,6 +139,10 @@
<Compile Include="SearchPane.cs"> <Compile Include="SearchPane.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="DisplaySettingsPanel.xaml.cs">
<DependentUpon>DisplaySettingsPanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="TreeNodes\Analyzer\AnalyzeContextMenuEntry.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzeContextMenuEntry.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedEventAccessorsTreeNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzedEventAccessorsTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedEventOverridesTreeNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzedEventOverridesTreeNode.cs" />
@ -230,6 +235,7 @@
<Page Include="SearchPane.xaml"> <Page Include="SearchPane.xaml">
<DependentUpon>SearchPane.cs</DependentUpon> <DependentUpon>SearchPane.cs</DependentUpon>
</Page> </Page>
<Page Include="DisplaySettingsPanel.xaml" />
<Page Include="TextView\DecompilerTextView.xaml"> <Page Include="TextView\DecompilerTextView.xaml">
<DependentUpon>DecompilerTextView.cs</DependentUpon> <DependentUpon>DecompilerTextView.cs</DependentUpon>
</Page> </Page>

3
ILSpy/TextView/DecompilerTextView.cs

@ -29,6 +29,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
@ -85,6 +86,8 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.Options.RequireControlModifierForHyperlinkClick = false; textEditor.Options.RequireControlModifierForHyperlinkClick = false;
textEditor.TextArea.TextView.MouseHover += TextViewMouseHover; textEditor.TextArea.TextView.MouseHover += TextViewMouseHover;
textEditor.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped; textEditor.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped;
textEditor.SetBinding(TextEditor.FontFamilyProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFont") });
textEditor.SetBinding(TextEditor.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") });
} }
#endregion #endregion

Loading…
Cancel
Save