Browse Source

Use InvariantResources file

pull/19413/head
Tim Miller 8 months ago
parent
commit
6872427c9b
  1. 57
      src/Avalonia.Controls/Primitives/ScrollBar.cs
  2. 73
      src/Avalonia.Controls/Primitives/ScrollBarResources.cs
  3. 13
      src/Avalonia.Themes.Fluent/Strings/InvariantResources.xaml

57
src/Avalonia.Controls/Primitives/ScrollBar.cs

@ -548,58 +548,69 @@ namespace Avalonia.Controls.Primitives
private ContextMenu CreateVerticalContextMenu()
{
var contextMenu = new ContextMenu();
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollHere, "ScrollHere", () => ScrollHereAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollHere", "ScrollHere", () => ScrollHereAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.Top, "Top", () => ScrollToTopAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.Bottom, "Bottom", () => ScrollToBottomAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarTop", "Top", () => ScrollToTopAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarBottom", "Bottom", () => ScrollToBottomAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.PageUp, "PageUp", () => PageUpAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.PageDown, "PageDown", () => PageDownAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarPageUp", "PageUp", () => PageUpAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarPageDown", "PageDown", () => PageDownAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollUp, "ScrollUp", () => LineUpAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollDown, "ScrollDown", () => LineDownAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollUp", "ScrollUp", () => LineUpAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollDown", "ScrollDown", () => LineDownAction(this)));
return contextMenu;
}
private ContextMenu CreateHorizontalContextMenuLTR()
{
var contextMenu = new ContextMenu();
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollHere, "ScrollHere", () => ScrollHereAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollHere", "ScrollHere", () => ScrollHereAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.LeftEdge, "LeftEdge", () => ScrollToLeftEndAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.RightEdge, "RightEdge", () => ScrollToRightEndAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarLeftEdge", "LeftEdge", () => ScrollToLeftEndAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarRightEdge", "RightEdge", () => ScrollToRightEndAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.PageLeft, "PageLeft", () => PageLeftAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.PageRight, "PageRight", () => PageRightAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarPageLeft", "PageLeft", () => PageLeftAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarPageRight", "PageRight", () => PageRightAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollLeft, "ScrollLeft", () => LineLeftAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollRight, "ScrollRight", () => LineRightAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollLeft", "ScrollLeft", () => LineLeftAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollRight", "ScrollRight", () => LineRightAction(this)));
return contextMenu;
}
private ContextMenu CreateHorizontalContextMenuRTL()
{
var contextMenu = new ContextMenu();
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollHere, "ScrollHere", () => ScrollHereAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollHere", "ScrollHere", () => ScrollHereAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.RightEdge, "RightEdge", () => ScrollToRightEndAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.LeftEdge, "LeftEdge", () => ScrollToLeftEndAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarRightEdge", "RightEdge", () => ScrollToRightEndAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarLeftEdge", "LeftEdge", () => ScrollToLeftEndAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.PageRight, "PageRight", () => PageRightAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.PageLeft, "PageLeft", () => PageLeftAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarPageRight", "PageRight", () => PageRightAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarPageLeft", "PageLeft", () => PageLeftAction(this)));
contextMenu.Items.Add(new Separator());
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollRight, "ScrollRight", () => LineRightAction(this)));
contextMenu.Items.Add(CreateMenuItem(ScrollBarResources.ScrollLeft, "ScrollLeft", () => LineLeftAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollRight", "ScrollRight", () => LineRightAction(this)));
contextMenu.Items.Add(CreateMenuItem("StringScrollBarScrollLeft", "ScrollLeft", () => LineLeftAction(this)));
return contextMenu;
}
private static MenuItem CreateMenuItem(string header, string automationId, Action action)
private MenuItem CreateMenuItem(string resourceKey, string automationId, Action action)
{
var menuItem = new MenuItem
{
Header = header,
Command = new SimpleCommand(action)
};
if (this.TryFindResource(resourceKey, out var resource) && resource is string header)
{
menuItem.Header = header;
}
else
{
// If we can't get one, fall back to the resource key itself
// So at least something is there.
menuItem.Header = resourceKey.Replace("StringScrollBar", "").Replace("ScrollBar", "");
}
AutomationProperties.SetAutomationId(menuItem, automationId);
return menuItem;
}

73
src/Avalonia.Controls/Primitives/ScrollBarResources.cs

@ -1,73 +0,0 @@
namespace Avalonia.Controls.Primitives
{
/// <summary>
/// Provides customizable resource strings for ScrollBar context menu items.
/// </summary>
public static class ScrollBarResources
{
/// <summary>
/// Gets or sets the text for "Scroll Here" menu item.
/// </summary>
public static string ScrollHere { get; set; } = "Scroll Here";
/// <summary>
/// Gets or sets the text for "Top" menu item.
/// </summary>
public static string Top { get; set; } = "Top";
/// <summary>
/// Gets or sets the text for "Bottom" menu item.
/// </summary>
public static string Bottom { get; set; } = "Bottom";
/// <summary>
/// Gets or sets the text for "Page Up" menu item.
/// </summary>
public static string PageUp { get; set; } = "Page Up";
/// <summary>
/// Gets or sets the text for "Page Down" menu item.
/// </summary>
public static string PageDown { get; set; } = "Page Down";
/// <summary>
/// Gets or sets the text for "Scroll Up" menu item.
/// </summary>
public static string ScrollUp { get; set; } = "Scroll Up";
/// <summary>
/// Gets or sets the text for "Scroll Down" menu item.
/// </summary>
public static string ScrollDown { get; set; } = "Scroll Down";
/// <summary>
/// Gets or sets the text for "Left Edge" menu item.
/// </summary>
public static string LeftEdge { get; set; } = "Left Edge";
/// <summary>
/// Gets or sets the text for "Right Edge" menu item.
/// </summary>
public static string RightEdge { get; set; } = "Right Edge";
/// <summary>
/// Gets or sets the text for "Page Left" menu item.
/// </summary>
public static string PageLeft { get; set; } = "Page Left";
/// <summary>
/// Gets or sets the text for "Page Right" menu item.
/// </summary>
public static string PageRight { get; set; } = "Page Right";
/// <summary>
/// Gets or sets the text for "Scroll Left" menu item.
/// </summary>
public static string ScrollLeft { get; set; } = "Scroll Left";
/// <summary>
/// Gets or sets the text for "Scroll Right" menu item.
/// </summary>
public static string ScrollRight { get; set; } = "Scroll Right";
}
}

13
src/Avalonia.Themes.Fluent/Strings/InvariantResources.xaml

@ -25,5 +25,18 @@
<x:String x:Key="StringManagedFileChooserOverwritePromptFileAlreadyExistsText">{0} already exists. Do you want to replace it?</x:String>
<x:String x:Key="StringManagedFileChooserOverwritePromptConfirmText">Yes</x:String>
<x:String x:Key="StringManagedFileChooserOverwritePromptCancelText">No</x:String>
<x:String x:Key="StringScrollBarScrollHere">Scroll Here</x:String>
<x:String x:Key="StringScrollBarTop">Top</x:String>
<x:String x:Key="StringScrollBarBottom">Bottom</x:String>
<x:String x:Key="StringScrollBarPageUp">Page Up</x:String>
<x:String x:Key="StringScrollBarPageDown">Page Down</x:String>
<x:String x:Key="StringScrollBarScrollUp">Scroll Up</x:String>
<x:String x:Key="StringScrollBarScrollDown">Scroll Down</x:String>
<x:String x:Key="StringScrollBarLeftEdge">Left Edge</x:String>
<x:String x:Key="StringScrollBarRightEdge">Right Edge</x:String>
<x:String x:Key="StringScrollBarPageLeft">Page Left</x:String>
<x:String x:Key="StringScrollBarPageRight">Page Right</x:String>
<x:String x:Key="StringScrollBarScrollLeft">Scroll Left</x:String>
<x:String x:Key="StringScrollBarScrollRight">Scroll Right</x:String>
</ResourceDictionary>

Loading…
Cancel
Save