Browse Source

Fix #1878: Add simple language switch to the UI.

pull/2373/head
Siegfried Pammer 5 years ago
parent
commit
8cbea9f348
  1. 41
      ILSpy/Controls/CultureSelectionConverter.cs
  2. 10
      ILSpy/MainWindow.xaml
  3. 26
      ILSpy/MainWindow.xaml.cs
  4. 2
      ILSpy/Options/DisplaySettings.cs
  5. 18
      ILSpy/Properties/Resources.Designer.cs
  6. 6
      ILSpy/Properties/Resources.resx
  7. 19
      ILSpy/SessionSettings.cs

41
ILSpy/Controls/CultureSelectionConverter.cs

@ -0,0 +1,41 @@
// Copyright (c) 2021 Siegfried Pammer
//
// 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.Globalization;
using System.Windows.Data;
namespace ICSharpCode.ILSpy.Controls
{
public class CultureSelectionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string s)
return s.Equals(parameter);
return value == parameter;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
return parameter;
return Binding.DoNothing;
}
}
}

10
ILSpy/MainWindow.xaml

@ -7,10 +7,8 @@
xmlns:avalondock="https://github.com/Dirkster99/AvalonDock" xmlns:avalondock="https://github.com/Dirkster99/AvalonDock"
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls" xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
xmlns:docking="clr-namespace:ICSharpCode.ILSpy.Docking" xmlns:docking="clr-namespace:ICSharpCode.ILSpy.Docking"
xmlns:textview="clr-namespace:ICSharpCode.ILSpy.TextView"
xmlns:analyzers="clr-namespace:ICSharpCode.ILSpy.Analyzers" xmlns:analyzers="clr-namespace:ICSharpCode.ILSpy.Analyzers"
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties"
xmlns:viewmodels="clr-namespace:ICSharpCode.ILSpy.ViewModels"
Title="ILSpy" Title="ILSpy"
MinWidth="250" MinWidth="250"
MinHeight="200" MinHeight="200"
@ -62,6 +60,8 @@
<styles:InvertGrayEffect x:Key="InvertGrayEffect" /> <styles:InvertGrayEffect x:Key="InvertGrayEffect" />
<controls:CultureSelectionConverter x:Key="cultureSelectionConverter" />
</Window.Resources> </Window.Resources>
<Window.CommandBindings> <Window.CommandBindings>
@ -102,6 +102,12 @@
<MenuItem Header="{x:Static properties:Resources.Show_publiconlyTypesMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.FilterSettings.ApiVisPublicOnly}" /> <MenuItem Header="{x:Static properties:Resources.Show_publiconlyTypesMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.FilterSettings.ApiVisPublicOnly}" />
<MenuItem Header="{x:Static properties:Resources.Show_internalTypesMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.FilterSettings.ApiVisPublicAndInternal}" /> <MenuItem Header="{x:Static properties:Resources.Show_internalTypesMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.FilterSettings.ApiVisPublicAndInternal}" />
<MenuItem Header="{x:Static properties:Resources.Show_allTypesAndMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.FilterSettings.ApiVisAll}" /> <MenuItem Header="{x:Static properties:Resources.Show_allTypesAndMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.FilterSettings.ApiVisAll}" />
<Separator/>
<MenuItem Header="Language">
<MenuItem Header="{x:Static properties:Resources.UILanguage_System}" IsCheckable="True" IsChecked="{Binding SessionSettings.CurrentCulture, Converter={StaticResource cultureSelectionConverter}, ConverterParameter={x:Null}}" />
<MenuItem Header="English" IsCheckable="True" IsChecked="{Binding SessionSettings.CurrentCulture, Converter={StaticResource cultureSelectionConverter}, ConverterParameter=en-US}" />
<MenuItem Header="中文" IsCheckable="True" IsChecked="{Binding SessionSettings.CurrentCulture, Converter={StaticResource cultureSelectionConverter}, ConverterParameter=zh-Hans}" />
</MenuItem>
</MenuItem> </MenuItem>
<MenuItem Header="{x:Static properties:Resources._Window}" /> <MenuItem Header="{x:Static properties:Resources._Window}" />
</Menu> </Menu>

26
ILSpy/MainWindow.xaml.cs

@ -121,7 +121,10 @@ namespace ICSharpCode.ILSpy
}; };
AssemblyListManager.CreateDefaultAssemblyLists(); AssemblyListManager.CreateDefaultAssemblyLists();
if (!string.IsNullOrEmpty(sessionSettings.CurrentCulture))
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(sessionSettings.CurrentCulture);
}
DockWorkspace.Instance.LoadSettings(sessionSettings); DockWorkspace.Instance.LoadSettings(sessionSettings);
InitializeComponent(); InitializeComponent();
InitToolPanes(); InitToolPanes();
@ -137,16 +140,19 @@ namespace ICSharpCode.ILSpy
private void SessionSettings_PropertyChanged(object sender, PropertyChangedEventArgs e) private void SessionSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == "ActiveAssemblyList") switch (e.PropertyName)
{ {
ShowAssemblyList(sessionSettings.ActiveAssemblyList); case nameof(SessionSettings.ActiveAssemblyList):
} ShowAssemblyList(sessionSettings.ActiveAssemblyList);
break;
if (e.PropertyName == nameof(SessionSettings.IsDarkMode)) case nameof(SessionSettings.IsDarkMode):
{ // update syntax highlighting and force reload (AvalonEdit does not automatically refresh on highlighting change)
// update syntax highlighting and force reload (AvalonEdit does not automatically refresh on highlighting change) DecompilerTextView.RegisterHighlighting();
DecompilerTextView.RegisterHighlighting(); DecompileSelectedNodes(DockWorkspace.Instance.ActiveTabPage.GetState() as DecompilerTextViewState);
DecompileSelectedNodes(DockWorkspace.Instance.ActiveTabPage.GetState() as DecompilerTextViewState); break;
case nameof(SessionSettings.CurrentCulture):
MessageBox.Show(Properties.Resources.SettingsChangeRestartRequired, "ILSpy");
break;
} }
} }

2
ILSpy/Options/DisplaySettings.cs

@ -291,7 +291,7 @@ namespace ICSharpCode.ILSpy.Options
this.IndentationSize = s.indentationSize; this.IndentationSize = s.indentationSize;
this.HighlightMatchingBraces = s.highlightMatchingBraces; this.HighlightMatchingBraces = s.highlightMatchingBraces;
this.HighlightCurrentLine = s.highlightCurrentLine; this.HighlightCurrentLine = s.highlightCurrentLine;
this.HideEmptyMetadataTables = s.HideEmptyMetadataTables; this.HideEmptyMetadataTables = s.hideEmptyMetadataTables;
} }
} }
} }

18
ILSpy/Properties/Resources.Designer.cs generated

@ -2219,6 +2219,15 @@ namespace ICSharpCode.ILSpy.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to You must restart ILSpy for the change to take effect..
/// </summary>
public static string SettingsChangeRestartRequired {
get {
return ResourceManager.GetString("SettingsChangeRestartRequired", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Shell. /// Looks up a localized string similar to Shell.
/// </summary> /// </summary>
@ -2462,6 +2471,15 @@ namespace ICSharpCode.ILSpy.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to System.
/// </summary>
public static string UILanguage_System {
get {
return ResourceManager.GetString("UILanguage_System", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to No update for ILSpy found.. /// Looks up a localized string similar to No update for ILSpy found..
/// </summary> /// </summary>

6
ILSpy/Properties/Resources.resx

@ -768,6 +768,9 @@ Do you want to continue?</value>
<data name="SelectVersionDropdownTooltip" xml:space="preserve"> <data name="SelectVersionDropdownTooltip" xml:space="preserve">
<value>Select version of language to output</value> <value>Select version of language to output</value>
</data> </data>
<data name="SettingsChangeRestartRequired" xml:space="preserve">
<value>You must restart ILSpy for the change to take effect.</value>
</data>
<data name="Shell" xml:space="preserve"> <data name="Shell" xml:space="preserve">
<value>Shell</value> <value>Shell</value>
</data> </data>
@ -849,6 +852,9 @@ Do you want to continue?</value>
<data name="Type" xml:space="preserve"> <data name="Type" xml:space="preserve">
<value>Type</value> <value>Type</value>
</data> </data>
<data name="UILanguage_System" xml:space="preserve">
<value>System</value>
</data>
<data name="UpdateILSpyFound" xml:space="preserve"> <data name="UpdateILSpyFound" xml:space="preserve">
<value>No update for ILSpy found.</value> <value>No update for ILSpy found.</value>
</data> </data>

19
ILSpy/SessionSettings.cs

@ -62,6 +62,8 @@ namespace ICSharpCode.ILSpy
this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3); this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3);
this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember); this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember);
this.IsDarkMode = FromString((string)doc.Element(nameof(IsDarkMode)), false); this.IsDarkMode = FromString((string)doc.Element(nameof(IsDarkMode)), false);
string currentCulture = (string)doc.Element(nameof(CurrentCulture));
this.CurrentCulture = string.IsNullOrEmpty(currentCulture) ? null : currentCulture;
this.DockLayout = new DockLayoutSettings(doc.Element("DockLayout")); this.DockLayout = new DockLayoutSettings(doc.Element("DockLayout"));
} }
@ -87,6 +89,19 @@ namespace ICSharpCode.ILSpy
public string[] ActiveTreeViewPath; public string[] ActiveTreeViewPath;
public string ActiveAutoLoadedAssembly; public string ActiveAutoLoadedAssembly;
string currentCulture;
public string CurrentCulture {
get { return currentCulture; }
set {
if (currentCulture != value)
{
currentCulture = value;
OnPropertyChanged();
}
}
}
public string ActiveAssemblyList { public string ActiveAssemblyList {
get => activeAssemblyList; get => activeAssemblyList;
set { set {
@ -132,6 +147,10 @@ namespace ICSharpCode.ILSpy
doc.Add(new XElement("BottomPaneSplitterPosition", ToString(this.BottomPaneSplitterPosition))); doc.Add(new XElement("BottomPaneSplitterPosition", ToString(this.BottomPaneSplitterPosition)));
doc.Add(new XElement("SelectedSearchMode", ToString(this.SelectedSearchMode))); doc.Add(new XElement("SelectedSearchMode", ToString(this.SelectedSearchMode)));
doc.Add(new XElement(nameof(IsDarkMode), ToString(this.IsDarkMode))); doc.Add(new XElement(nameof(IsDarkMode), ToString(this.IsDarkMode)));
if (this.CurrentCulture != null)
{
doc.Add(new XElement(nameof(CurrentCulture), this.CurrentCulture));
}
var dockLayoutElement = new XElement("DockLayout"); var dockLayoutElement = new XElement("DockLayout");
if (DockLayout.Valid) if (DockLayout.Valid)

Loading…
Cancel
Save