diff --git a/ModernWpf.Controls/Common/ResourceHelper.cs b/ModernWpf.Controls/Common/ResourceHelper.cs deleted file mode 100644 index 7c4a375d..00000000 --- a/ModernWpf.Controls/Common/ResourceHelper.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace ModernWpf.Controls -{ - internal static class ResourceHelper - { - /// - /// This method must be called from every control/class's constructor ( or default) - /// present in the ModernWpf.Controls assembly - /// that makes use of the method. - /// - /// - /// This method ensures that the is aware of this (ModernWpf.Controls) assembly. - /// We use this method instead of using the method - /// because it is unreliable and may cause instabilities in the end application. - /// - public static void Initialize() - { - ResourceAccessor.modernWpfControlsAssembly ??= typeof(ResourceHelper).Assembly; - } - } -} diff --git a/ModernWpf.Controls/NavigationView/NavigationView.cs b/ModernWpf.Controls/NavigationView/NavigationView.cs index acf37c52..eb768d96 100644 --- a/ModernWpf.Controls/NavigationView/NavigationView.cs +++ b/ModernWpf.Controls/NavigationView/NavigationView.cs @@ -108,6 +108,8 @@ public partial class NavigationView : ContentControl, IControlProtected static readonly Size c_infSize = new Size(double.PositiveInfinity, double.PositiveInfinity); + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(NavigationView)); + /* ~NavigationView() { @@ -214,7 +216,6 @@ void UnhookEventsAndClearFields(bool isFromDestructor = false) static NavigationView() { - ResourceHelper.Initialize(); DefaultStyleKeyProperty.OverrideMetadata(typeof(NavigationView), new FrameworkPropertyMetadata(typeof(NavigationView))); } diff --git a/ModernWpf.Controls/NavigationView/NavigationViewItemAutomationPeer.cs b/ModernWpf.Controls/NavigationView/NavigationViewItemAutomationPeer.cs index a8c661c7..eca28902 100644 --- a/ModernWpf.Controls/NavigationView/NavigationViewItemAutomationPeer.cs +++ b/ModernWpf.Controls/NavigationView/NavigationViewItemAutomationPeer.cs @@ -16,10 +16,11 @@ public class NavigationViewItemAutomationPeer : ISelectionItemProvider, IExpandCollapseProvider { + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(NavigationView)); + public NavigationViewItemAutomationPeer(NavigationViewItem owner) : base(owner) { - ResourceHelper.Initialize(); } protected override string GetNameCore() diff --git a/ModernWpf.Controls/NumberBox/NumberBox.cs b/ModernWpf.Controls/NumberBox/NumberBox.cs index cd4ac35d..b1ff2cc6 100644 --- a/ModernWpf.Controls/NumberBox/NumberBox.cs +++ b/ModernWpf.Controls/NumberBox/NumberBox.cs @@ -46,9 +46,10 @@ public partial class NumberBox : Control const double c_popupShadowDepth = 16.0; const string c_numberBoxPopupShadowDepthName = "NumberBoxPopupShadowDepth"; + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(NumberBox)); + static NumberBox() { - ResourceHelper.Initialize(); DefaultStyleKeyProperty.OverrideMetadata(typeof(NumberBox), new FrameworkPropertyMetadata(typeof(NumberBox))); } diff --git a/ModernWpf.Controls/PersonPicture/PersonPicture.cs b/ModernWpf.Controls/PersonPicture/PersonPicture.cs index cf1b25d4..70e2ac24 100644 --- a/ModernWpf.Controls/PersonPicture/PersonPicture.cs +++ b/ModernWpf.Controls/PersonPicture/PersonPicture.cs @@ -15,9 +15,10 @@ namespace ModernWpf.Controls { public partial class PersonPicture : Control { + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(PersonPicture)); + static PersonPicture() { - ResourceHelper.Initialize(); DefaultStyleKeyProperty.OverrideMetadata(typeof(PersonPicture), new FrameworkPropertyMetadata(typeof(PersonPicture))); } diff --git a/ModernWpf.Controls/ProgressRing/ProgressRingAutomationPeer.cs b/ModernWpf.Controls/ProgressRing/ProgressRingAutomationPeer.cs index b15c6087..df56b451 100644 --- a/ModernWpf.Controls/ProgressRing/ProgressRingAutomationPeer.cs +++ b/ModernWpf.Controls/ProgressRing/ProgressRingAutomationPeer.cs @@ -9,9 +9,10 @@ namespace ModernWpf.Automation.Peers { public class ProgressRingAutomationPeer : FrameworkElementAutomationPeer { + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(ProgressRing)); + public ProgressRingAutomationPeer(ProgressRing owner) : base(owner) { - ResourceHelper.Initialize(); } protected override string GetClassNameCore() diff --git a/ModernWpf.Controls/RatingControl/RatingControlAutomationPeer.cs b/ModernWpf.Controls/RatingControl/RatingControlAutomationPeer.cs index 4aaa7959..7cdc1ffb 100644 --- a/ModernWpf.Controls/RatingControl/RatingControlAutomationPeer.cs +++ b/ModernWpf.Controls/RatingControl/RatingControlAutomationPeer.cs @@ -15,10 +15,11 @@ public class RatingControlAutomationPeer : IValueProvider, IRangeValueProvider { + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(RatingControl)); + public RatingControlAutomationPeer(RatingControl owner) : base(owner) { - ResourceHelper.Initialize(); } protected override string GetLocalizedControlTypeCore() diff --git a/ModernWpf.Controls/SplitButton/SplitButton.cs b/ModernWpf.Controls/SplitButton/SplitButton.cs index ffd5d39c..3d624820 100644 --- a/ModernWpf.Controls/SplitButton/SplitButton.cs +++ b/ModernWpf.Controls/SplitButton/SplitButton.cs @@ -16,9 +16,10 @@ namespace ModernWpf.Controls { public class SplitButton : ContentControl, ICommandSource { + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(SplitButton)); + static SplitButton() { - ResourceHelper.Initialize(); DefaultStyleKeyProperty.OverrideMetadata(typeof(SplitButton), new FrameworkPropertyMetadata(typeof(SplitButton))); } diff --git a/ModernWpf/Common/ResourceAccessor.cs b/ModernWpf/Common/ResourceAccessor.cs index eff6b4cb..5ca97c88 100644 --- a/ModernWpf/Common/ResourceAccessor.cs +++ b/ModernWpf/Common/ResourceAccessor.cs @@ -1,10 +1,9 @@ -using System.Collections.Generic; -using System.Reflection; +using System; using System.Resources; namespace ModernWpf { - internal static class ResourceAccessor + internal class ResourceAccessor { #region Resource Keys @@ -161,163 +160,26 @@ internal static class ResourceAccessor #endregion - #region RESX Specific workarounds + private readonly Type _controlType; + private ResourceManager _resourceManager; - internal static Assembly modernWpfAssembly = typeof(ResourceAccessor).Assembly; - // Would be set by the ResourceHelper (present in the ModernWpf.Controls assembly) - internal static Assembly modernWpfControlsAssembly; - - private const string ProgressBarResourcesName = "ModernWpf.ProgressBar.Strings.Resources"; - private const string TextContextMenuResourcesName = "ModernWpf.Controls.TextContextMenu.Strings.Resources"; - - private const string NavigationViewResourcesName = "ModernWpf.Controls.NavigationView.Strings.Resources"; - private const string NumberBoxResourcesName = "ModernWpf.Controls.NumberBox.Strings.Resources"; - private const string PersonPictureResourcesName = "ModernWpf.Controls.PersonPicture.Strings.Resources"; - private const string ProgressRingResourcesName = "ModernWpf.Controls.ProgressRing.Strings.Resources"; - private const string RatingControlResourcesName = "ModernWpf.Controls.RatingControl.Strings.Resources"; - private const string SplitButtonResourcesName = "ModernWpf.Controls.SplitButton.Strings.Resources"; - - /// - /// Used to map each resource keys to their respective *.resources files in the ModernWpf assembly. - /// - /// - /// Update this map every time the resources are modified. - /// - private static readonly Dictionary resourceMapsM = new() - { - // ProgressBar resources - { SR_ProgressBarErrorStatus, ProgressBarResourcesName }, - { SR_ProgressBarIndeterminateStatus, ProgressBarResourcesName }, - { SR_ProgressBarPausedStatus, ProgressBarResourcesName }, - - // TextContextMenu resources - { SR_ProofingMenuItemLabel, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionBold, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionCopy, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionCut, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionItalic, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionPaste, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionRedo, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionSelectAll, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionUnderline, TextContextMenuResourcesName }, - { SR_TextCommandDescriptionUndo, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeyBold, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeyCopy, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeyCut, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeyItalic, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeyPaste, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeyRedo, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeySelectAll, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeyUnderline, TextContextMenuResourcesName }, - { SR_TextCommandKeyboardAcceleratorKeyUndo, TextContextMenuResourcesName }, - { SR_TextCommandLabelBold, TextContextMenuResourcesName }, - { SR_TextCommandLabelCopy, TextContextMenuResourcesName }, - { SR_TextCommandLabelCut, TextContextMenuResourcesName }, - { SR_TextCommandLabelItalic, TextContextMenuResourcesName }, - { SR_TextCommandLabelPaste, TextContextMenuResourcesName }, - { SR_TextCommandLabelRedo, TextContextMenuResourcesName }, - { SR_TextCommandLabelSelectAll, TextContextMenuResourcesName }, - { SR_TextCommandLabelUnderline, TextContextMenuResourcesName }, - { SR_TextCommandLabelUndo, TextContextMenuResourcesName }, - }; - - /// - /// Used to map each resource keys to their respective *.resources files in the ModernWpf.Controls assembly. - /// - /// - /// Update this map every time the resources are modified. - /// - private static readonly Dictionary resourceMapsMC = new() + public ResourceAccessor(Type controlType) { - // NavigationView resources - { SR_NavigationButtonClosedName, NavigationViewResourcesName }, - { SR_NavigationButtonOpenName, NavigationViewResourcesName }, - { SR_NavigationViewItemDefaultControlName, NavigationViewResourcesName }, - { SR_SettingsButtonName, NavigationViewResourcesName }, - { SR_NavigationViewSearchButtonName, NavigationViewResourcesName }, - { SR_NavigationBackButtonName, NavigationViewResourcesName }, - { SR_NavigationBackButtonToolTip, NavigationViewResourcesName }, - { SR_NavigationCloseButtonName, NavigationViewResourcesName }, - { SR_NavigationOverflowButtonName, NavigationViewResourcesName }, - { SR_NavigationOverflowButtonText, NavigationViewResourcesName }, - { SR_NavigationOverflowButtonToolTip, NavigationViewResourcesName }, - - // NumberBox resources - { SR_NumberBoxDownSpinButtonName, NumberBoxResourcesName }, - { SR_NumberBoxUpSpinButtonName, NumberBoxResourcesName }, - - // PersonPicture resources - { SR_BadgeItemPlural1, PersonPictureResourcesName }, - { SR_BadgeItemPlural2, PersonPictureResourcesName }, - { SR_BadgeItemPlural3, PersonPictureResourcesName }, - { SR_BadgeItemPlural4, PersonPictureResourcesName }, - { SR_BadgeItemPlural5, PersonPictureResourcesName }, - { SR_BadgeItemPlural6, PersonPictureResourcesName }, - { SR_BadgeItemPlural7, PersonPictureResourcesName }, - { SR_BadgeItemSingular, PersonPictureResourcesName }, - { SR_BadgeItemTextOverride, PersonPictureResourcesName }, - { SR_BadgeIcon, PersonPictureResourcesName }, - { SR_BadgeIconTextOverride, PersonPictureResourcesName }, - { SR_PersonName, PersonPictureResourcesName }, - { SR_GroupName, PersonPictureResourcesName }, - - // ProgressRing resources - { SR_ProgressRingIndeterminateStatus, ProgressRingResourcesName }, - { SR_ProgressRingName, ProgressRingResourcesName }, - - // RatingControl resources - { SR_BasicRatingString, RatingControlResourcesName }, - { SR_CommunityRatingString, RatingControlResourcesName }, - { SR_RatingsControlName, RatingControlResourcesName }, - { SR_RatingControlName, RatingControlResourcesName }, - { SR_RatingUnset, RatingControlResourcesName }, - { SR_RatingLocalizedControlType, RatingControlResourcesName }, - - // SplitButton resources - { SR_SplitButtonSecondaryButtonName, SplitButtonResourcesName }, - }; - - /// - /// Used to cache instances associated with a particular - /// *.resources file (generated from a *.resx file) - /// - private static readonly Dictionary resourceManagers = new(); - - #endregion + _controlType = controlType ?? throw new ArgumentNullException(nameof(controlType)); + } - public static string GetLocalizedStringResource(string resourceName) + public string GetLocalizedStringResource(string resourceName) { - string _resourcesFilePath; - - string GetStringResource(string resourcesFilePath, Assembly assembly) - { - if (!resourceManagers.TryGetValue(resourcesFilePath, out ResourceManager resourceManager)) - { - resourceManager = new(resourcesFilePath, assembly); - resourceManagers.Add(resourcesFilePath, resourceManager); - } - - if (resourceManager != null) - { - return resourceManager.GetString(resourceName); - } - - return string.Empty; - } - - // Tries to get the string resource from the ModernWpf assembly - if (resourceMapsM.TryGetValue(resourceName, out _resourcesFilePath)) - { - return GetStringResource(_resourcesFilePath, modernWpfAssembly); - } - - // Tries to get the string resource from the ModernWpf.Controls assembly - if (resourceMapsMC.TryGetValue(resourceName, out _resourcesFilePath)) + if (_resourceManager is null) { - return GetStringResource(_resourcesFilePath, modernWpfControlsAssembly); + var assembly = _controlType.Assembly; + var assemblyName = assembly.GetName().Name; + var controlName = _controlType.Name; + var baseName = $"{assemblyName}.{controlName}.Strings.Resources"; + _resourceManager = new ResourceManager(baseName, assembly); } - return string.Empty; + return _resourceManager.GetString(resourceName); } } } diff --git a/ModernWpf/ProgressBar/ProgressBarAutomationPeer.cs b/ModernWpf/ProgressBar/ProgressBarAutomationPeer.cs index ee3cf9ee..0a9be057 100644 --- a/ModernWpf/ProgressBar/ProgressBarAutomationPeer.cs +++ b/ModernWpf/ProgressBar/ProgressBarAutomationPeer.cs @@ -13,6 +13,8 @@ namespace ModernWpf.Automation.Peers /// public class ProgressBarAutomationPeer : RangeBaseAutomationPeer, IRangeValueProvider { + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(ProgressBar)); + /// /// Initializes a new instance of the ProgressBarAutomationPeer class. /// diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.af-ZA.resx b/ModernWpf/TextContextMenu/Strings/Resources.af-ZA.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.af-ZA.resx rename to ModernWpf/TextContextMenu/Strings/Resources.af-ZA.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.am-ET.resx b/ModernWpf/TextContextMenu/Strings/Resources.am-ET.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.am-ET.resx rename to ModernWpf/TextContextMenu/Strings/Resources.am-ET.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ar-SA.resx b/ModernWpf/TextContextMenu/Strings/Resources.ar-SA.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ar-SA.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ar-SA.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.az-Latn-AZ.resx b/ModernWpf/TextContextMenu/Strings/Resources.az-Latn-AZ.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.az-Latn-AZ.resx rename to ModernWpf/TextContextMenu/Strings/Resources.az-Latn-AZ.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.be-BY.resx b/ModernWpf/TextContextMenu/Strings/Resources.be-BY.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.be-BY.resx rename to ModernWpf/TextContextMenu/Strings/Resources.be-BY.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.bg-BG.resx b/ModernWpf/TextContextMenu/Strings/Resources.bg-BG.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.bg-BG.resx rename to ModernWpf/TextContextMenu/Strings/Resources.bg-BG.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.bn-BD.resx b/ModernWpf/TextContextMenu/Strings/Resources.bn-BD.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.bn-BD.resx rename to ModernWpf/TextContextMenu/Strings/Resources.bn-BD.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.bs-Latn-BA.resx b/ModernWpf/TextContextMenu/Strings/Resources.bs-Latn-BA.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.bs-Latn-BA.resx rename to ModernWpf/TextContextMenu/Strings/Resources.bs-Latn-BA.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ca-ES.resx b/ModernWpf/TextContextMenu/Strings/Resources.ca-ES.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ca-ES.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ca-ES.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.cs-CZ.resx b/ModernWpf/TextContextMenu/Strings/Resources.cs-CZ.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.cs-CZ.resx rename to ModernWpf/TextContextMenu/Strings/Resources.cs-CZ.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.da-DK.resx b/ModernWpf/TextContextMenu/Strings/Resources.da-DK.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.da-DK.resx rename to ModernWpf/TextContextMenu/Strings/Resources.da-DK.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.de-DE.resx b/ModernWpf/TextContextMenu/Strings/Resources.de-DE.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.de-DE.resx rename to ModernWpf/TextContextMenu/Strings/Resources.de-DE.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.el-GR.resx b/ModernWpf/TextContextMenu/Strings/Resources.el-GR.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.el-GR.resx rename to ModernWpf/TextContextMenu/Strings/Resources.el-GR.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.en-GB.resx b/ModernWpf/TextContextMenu/Strings/Resources.en-GB.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.en-GB.resx rename to ModernWpf/TextContextMenu/Strings/Resources.en-GB.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.es-ES.resx b/ModernWpf/TextContextMenu/Strings/Resources.es-ES.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.es-ES.resx rename to ModernWpf/TextContextMenu/Strings/Resources.es-ES.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.es-MX.resx b/ModernWpf/TextContextMenu/Strings/Resources.es-MX.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.es-MX.resx rename to ModernWpf/TextContextMenu/Strings/Resources.es-MX.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.et-EE.resx b/ModernWpf/TextContextMenu/Strings/Resources.et-EE.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.et-EE.resx rename to ModernWpf/TextContextMenu/Strings/Resources.et-EE.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.eu-ES.resx b/ModernWpf/TextContextMenu/Strings/Resources.eu-ES.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.eu-ES.resx rename to ModernWpf/TextContextMenu/Strings/Resources.eu-ES.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.fa-IR.resx b/ModernWpf/TextContextMenu/Strings/Resources.fa-IR.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.fa-IR.resx rename to ModernWpf/TextContextMenu/Strings/Resources.fa-IR.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.fi-FI.resx b/ModernWpf/TextContextMenu/Strings/Resources.fi-FI.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.fi-FI.resx rename to ModernWpf/TextContextMenu/Strings/Resources.fi-FI.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.fil-PH.resx b/ModernWpf/TextContextMenu/Strings/Resources.fil-PH.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.fil-PH.resx rename to ModernWpf/TextContextMenu/Strings/Resources.fil-PH.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.fr-CA.resx b/ModernWpf/TextContextMenu/Strings/Resources.fr-CA.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.fr-CA.resx rename to ModernWpf/TextContextMenu/Strings/Resources.fr-CA.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.fr-FR.resx b/ModernWpf/TextContextMenu/Strings/Resources.fr-FR.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.fr-FR.resx rename to ModernWpf/TextContextMenu/Strings/Resources.fr-FR.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.gl-ES.resx b/ModernWpf/TextContextMenu/Strings/Resources.gl-ES.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.gl-ES.resx rename to ModernWpf/TextContextMenu/Strings/Resources.gl-ES.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ha-Latn-NG.resx b/ModernWpf/TextContextMenu/Strings/Resources.ha-Latn-NG.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ha-Latn-NG.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ha-Latn-NG.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.he-IL.resx b/ModernWpf/TextContextMenu/Strings/Resources.he-IL.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.he-IL.resx rename to ModernWpf/TextContextMenu/Strings/Resources.he-IL.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.hi-IN.resx b/ModernWpf/TextContextMenu/Strings/Resources.hi-IN.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.hi-IN.resx rename to ModernWpf/TextContextMenu/Strings/Resources.hi-IN.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.hr-HR.resx b/ModernWpf/TextContextMenu/Strings/Resources.hr-HR.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.hr-HR.resx rename to ModernWpf/TextContextMenu/Strings/Resources.hr-HR.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.hu-HU.resx b/ModernWpf/TextContextMenu/Strings/Resources.hu-HU.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.hu-HU.resx rename to ModernWpf/TextContextMenu/Strings/Resources.hu-HU.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.id-ID.resx b/ModernWpf/TextContextMenu/Strings/Resources.id-ID.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.id-ID.resx rename to ModernWpf/TextContextMenu/Strings/Resources.id-ID.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.is-IS.resx b/ModernWpf/TextContextMenu/Strings/Resources.is-IS.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.is-IS.resx rename to ModernWpf/TextContextMenu/Strings/Resources.is-IS.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.it-IT.resx b/ModernWpf/TextContextMenu/Strings/Resources.it-IT.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.it-IT.resx rename to ModernWpf/TextContextMenu/Strings/Resources.it-IT.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ja-JP.resx b/ModernWpf/TextContextMenu/Strings/Resources.ja-JP.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ja-JP.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ja-JP.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ka-GE.resx b/ModernWpf/TextContextMenu/Strings/Resources.ka-GE.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ka-GE.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ka-GE.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.kk-KZ.resx b/ModernWpf/TextContextMenu/Strings/Resources.kk-KZ.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.kk-KZ.resx rename to ModernWpf/TextContextMenu/Strings/Resources.kk-KZ.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.km-KH.resx b/ModernWpf/TextContextMenu/Strings/Resources.km-KH.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.km-KH.resx rename to ModernWpf/TextContextMenu/Strings/Resources.km-KH.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.kn-IN.resx b/ModernWpf/TextContextMenu/Strings/Resources.kn-IN.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.kn-IN.resx rename to ModernWpf/TextContextMenu/Strings/Resources.kn-IN.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ko-KR.resx b/ModernWpf/TextContextMenu/Strings/Resources.ko-KR.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ko-KR.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ko-KR.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.lo-LA.resx b/ModernWpf/TextContextMenu/Strings/Resources.lo-LA.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.lo-LA.resx rename to ModernWpf/TextContextMenu/Strings/Resources.lo-LA.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.lt-LT.resx b/ModernWpf/TextContextMenu/Strings/Resources.lt-LT.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.lt-LT.resx rename to ModernWpf/TextContextMenu/Strings/Resources.lt-LT.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.lv-LV.resx b/ModernWpf/TextContextMenu/Strings/Resources.lv-LV.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.lv-LV.resx rename to ModernWpf/TextContextMenu/Strings/Resources.lv-LV.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.mk-MK.resx b/ModernWpf/TextContextMenu/Strings/Resources.mk-MK.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.mk-MK.resx rename to ModernWpf/TextContextMenu/Strings/Resources.mk-MK.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ml-IN.resx b/ModernWpf/TextContextMenu/Strings/Resources.ml-IN.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ml-IN.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ml-IN.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ms-MY.resx b/ModernWpf/TextContextMenu/Strings/Resources.ms-MY.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ms-MY.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ms-MY.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.nb-NO.resx b/ModernWpf/TextContextMenu/Strings/Resources.nb-NO.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.nb-NO.resx rename to ModernWpf/TextContextMenu/Strings/Resources.nb-NO.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.nl-NL.resx b/ModernWpf/TextContextMenu/Strings/Resources.nl-NL.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.nl-NL.resx rename to ModernWpf/TextContextMenu/Strings/Resources.nl-NL.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.nn-NO.resx b/ModernWpf/TextContextMenu/Strings/Resources.nn-NO.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.nn-NO.resx rename to ModernWpf/TextContextMenu/Strings/Resources.nn-NO.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.pl-PL.resx b/ModernWpf/TextContextMenu/Strings/Resources.pl-PL.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.pl-PL.resx rename to ModernWpf/TextContextMenu/Strings/Resources.pl-PL.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.pt-BR.resx b/ModernWpf/TextContextMenu/Strings/Resources.pt-BR.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.pt-BR.resx rename to ModernWpf/TextContextMenu/Strings/Resources.pt-BR.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.pt-PT.resx b/ModernWpf/TextContextMenu/Strings/Resources.pt-PT.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.pt-PT.resx rename to ModernWpf/TextContextMenu/Strings/Resources.pt-PT.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.resx b/ModernWpf/TextContextMenu/Strings/Resources.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.resx rename to ModernWpf/TextContextMenu/Strings/Resources.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ro-RO.resx b/ModernWpf/TextContextMenu/Strings/Resources.ro-RO.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ro-RO.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ro-RO.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ru-RU.resx b/ModernWpf/TextContextMenu/Strings/Resources.ru-RU.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ru-RU.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ru-RU.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.sk-SK.resx b/ModernWpf/TextContextMenu/Strings/Resources.sk-SK.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.sk-SK.resx rename to ModernWpf/TextContextMenu/Strings/Resources.sk-SK.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.sl-SI.resx b/ModernWpf/TextContextMenu/Strings/Resources.sl-SI.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.sl-SI.resx rename to ModernWpf/TextContextMenu/Strings/Resources.sl-SI.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.sq-AL.resx b/ModernWpf/TextContextMenu/Strings/Resources.sq-AL.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.sq-AL.resx rename to ModernWpf/TextContextMenu/Strings/Resources.sq-AL.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.sr-Latn-RS.resx b/ModernWpf/TextContextMenu/Strings/Resources.sr-Latn-RS.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.sr-Latn-RS.resx rename to ModernWpf/TextContextMenu/Strings/Resources.sr-Latn-RS.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.sv-SE.resx b/ModernWpf/TextContextMenu/Strings/Resources.sv-SE.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.sv-SE.resx rename to ModernWpf/TextContextMenu/Strings/Resources.sv-SE.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.sw-KE.resx b/ModernWpf/TextContextMenu/Strings/Resources.sw-KE.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.sw-KE.resx rename to ModernWpf/TextContextMenu/Strings/Resources.sw-KE.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.ta-IN.resx b/ModernWpf/TextContextMenu/Strings/Resources.ta-IN.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.ta-IN.resx rename to ModernWpf/TextContextMenu/Strings/Resources.ta-IN.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.te-IN.resx b/ModernWpf/TextContextMenu/Strings/Resources.te-IN.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.te-IN.resx rename to ModernWpf/TextContextMenu/Strings/Resources.te-IN.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.th-TH.resx b/ModernWpf/TextContextMenu/Strings/Resources.th-TH.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.th-TH.resx rename to ModernWpf/TextContextMenu/Strings/Resources.th-TH.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.tr-TR.resx b/ModernWpf/TextContextMenu/Strings/Resources.tr-TR.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.tr-TR.resx rename to ModernWpf/TextContextMenu/Strings/Resources.tr-TR.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.uk-UA.resx b/ModernWpf/TextContextMenu/Strings/Resources.uk-UA.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.uk-UA.resx rename to ModernWpf/TextContextMenu/Strings/Resources.uk-UA.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.uz-Latn-UZ.resx b/ModernWpf/TextContextMenu/Strings/Resources.uz-Latn-UZ.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.uz-Latn-UZ.resx rename to ModernWpf/TextContextMenu/Strings/Resources.uz-Latn-UZ.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.vi-VN.resx b/ModernWpf/TextContextMenu/Strings/Resources.vi-VN.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.vi-VN.resx rename to ModernWpf/TextContextMenu/Strings/Resources.vi-VN.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.zh-CN.resx b/ModernWpf/TextContextMenu/Strings/Resources.zh-CN.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.zh-CN.resx rename to ModernWpf/TextContextMenu/Strings/Resources.zh-CN.resx diff --git a/ModernWpf/Controls/TextContextMenu/Strings/Resources.zh-TW.resx b/ModernWpf/TextContextMenu/Strings/Resources.zh-TW.resx similarity index 100% rename from ModernWpf/Controls/TextContextMenu/Strings/Resources.zh-TW.resx rename to ModernWpf/TextContextMenu/Strings/Resources.zh-TW.resx diff --git a/ModernWpf/Controls/TextContextMenu.cs b/ModernWpf/TextContextMenu/TextContextMenu.cs similarity index 98% rename from ModernWpf/Controls/TextContextMenu.cs rename to ModernWpf/TextContextMenu/TextContextMenu.cs index 8a9e8997..d9de0858 100644 --- a/ModernWpf/Controls/TextContextMenu.cs +++ b/ModernWpf/TextContextMenu/TextContextMenu.cs @@ -14,6 +14,8 @@ namespace ModernWpf.Controls /// public class TextContextMenu : ContextMenu { + private static readonly ResourceAccessor ResourceAccessor = new ResourceAccessor(typeof(TextContextMenu)); + private static readonly CommandBinding _selectAllBinding; private static readonly CommandBinding _undoBinding; private static readonly CommandBinding _redoBinding; diff --git a/tools/WinUIResourcesConverter/CodeGen.cs b/tools/WinUIResourcesConverter/CodeGen.cs deleted file mode 100644 index 30906ed5..00000000 --- a/tools/WinUIResourcesConverter/CodeGen.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Text; - -namespace WinUIResourcesConverter -{ - internal class CodeGen - { - public CodeGen(string controlName, string relativePath) - { - ControlName = controlName; - RelativePath = relativePath; - } - - public StringBuilder StringBuilder { get; } = new(); - - public string ControlName { get; } - - public string RelativePath { get; } - - public void AppendFirstPart() - { - StringBuilder.AppendLine("..."); - StringBuilder.AppendLine(@$"private const string {ControlName}ResourcesName = ""{RelativePath}{ControlName}.Strings.Resources"";"); - StringBuilder.AppendLine("..."); - StringBuilder.AppendLine(); - StringBuilder.AppendLine($"// {ControlName} resources"); - } - - public void AppendResourceMap(string resName) - { - StringBuilder.Append("{ SR_"); - StringBuilder.AppendFormat("{0}, {1}ResourcesName", resName, ControlName); - StringBuilder.Append(" },"); - StringBuilder.AppendLine(); - } - - public string GeneratedCode => StringBuilder.ToString(); - } -} diff --git a/tools/WinUIResourcesConverter/MainWindow.xaml b/tools/WinUIResourcesConverter/MainWindow.xaml index ec577689..13eaa457 100644 --- a/tools/WinUIResourcesConverter/MainWindow.xaml +++ b/tools/WinUIResourcesConverter/MainWindow.xaml @@ -65,11 +65,6 @@ - - - diff --git a/tools/WinUIResourcesConverter/MainWindow.xaml.cs b/tools/WinUIResourcesConverter/MainWindow.xaml.cs index 22a67b54..b4d6d2e2 100644 --- a/tools/WinUIResourcesConverter/MainWindow.xaml.cs +++ b/tools/WinUIResourcesConverter/MainWindow.xaml.cs @@ -90,31 +90,6 @@ private void ConvertResources() string controlName = destination.Parent.Name; - string GetRelativePath(DirectoryInfo directory) - { - StringBuilder stringBuilder = new(); - - bool IsProjectRoot(DirectoryInfo dir) - { - return string.Equals(dir.Name, nameof(ModernWpf), System.StringComparison.OrdinalIgnoreCase) - || string.Equals(dir.Name, nameof(ModernWpf) + "." + nameof(ModernWpf.Controls), System.StringComparison.OrdinalIgnoreCase); - } - - while (!IsProjectRoot(directory)) - { - stringBuilder.Insert(0, directory.Name + "."); - directory = directory.Parent; - } - - stringBuilder.Insert(0, directory.Name + "."); - directory = directory.Parent; - - return stringBuilder.ToString(); - } - - CodeGen codeGen = new(controlName, GetRelativePath(destination.Parent.Parent)); - codeGen.AppendFirstPart(); - ResourcesFile[] resFiles = null; Dispatcher.Invoke(() => @@ -126,7 +101,7 @@ bool IsProjectRoot(DirectoryInfo dir) foreach (var resFile in resFiles) { - resFile.HasConverted = RESXConverter.TryConvertReswToResx(resFile, sourceDirectory, destinationDirectory, resFile.IsDefaultResource ? codeGen : null); + resFile.HasConverted = RESXConverter.TryConvertReswToResx(resFile, sourceDirectory, destinationDirectory); convertedResFiles++; Dispatcher.Invoke(() => @@ -134,11 +109,6 @@ bool IsProjectRoot(DirectoryInfo dir) ProgressBar1.Value = convertedResFiles; }); } - - Dispatcher.Invoke(() => - { - TbCodeGen.Text = codeGen.GeneratedCode; - }); } } diff --git a/tools/WinUIResourcesConverter/RESXConverter.cs b/tools/WinUIResourcesConverter/RESXConverter.cs index 8121debd..307e1a7c 100644 --- a/tools/WinUIResourcesConverter/RESXConverter.cs +++ b/tools/WinUIResourcesConverter/RESXConverter.cs @@ -7,20 +7,20 @@ namespace WinUIResourcesConverter { internal class RESXConverter { - internal static bool TryConvertReswToResx(ResourcesFile resourcesFile, string sourceDirectory, string destinationDirectory, CodeGen codeGen) + internal static bool TryConvertReswToResx(ResourcesFile resourcesFile, string sourceDirectory, string destinationDirectory) { var reswFile = @$"{sourceDirectory}\{resourcesFile.LanguageName}\{ResourcesFile.DefaultResourcesFileName}.resw"; var resxFile = GetValidResxFileName(destinationDirectory, resourcesFile.LanguageName); if (File.Exists(reswFile)) { - return TryConvertReswToResxImpl(reswFile, resxFile, codeGen); + return TryConvertReswToResxImpl(reswFile, resxFile); } return false; } - internal static bool TryConvertReswToResxImpl(string reswFile, string resxFile, CodeGen codeGen) + internal static bool TryConvertReswToResxImpl(string reswFile, string resxFile) { ResXResourceReader resourceReader = new(reswFile) { UseResXDataNodes = true }; ResXResourceWriter resourceWriter = new(resxFile); @@ -38,8 +38,6 @@ internal static bool TryConvertReswToResxImpl(string reswFile, string resxFile, }; resourceWriter.AddResource(writeValue); - - codeGen?.AppendResourceMap(readValue.Name); } resourceReader.Close();