mirror of https://github.com/icsharpcode/ILSpy.git
5 changed files with 268 additions and 0 deletions
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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> |
@ -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(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue