From c034f8bf55f2b877f1e236bccc74892b1fd35ab9 Mon Sep 17 00:00:00 2001 From: Mateusz Skoczek Date: Mon, 4 Mar 2024 01:19:51 +0100 Subject: [PATCH] hardcoded dialog buttons texts changed to string resources --- .../Strings/en-US/DialogButtonsResources.resw | 135 ++++++++++++++++++ .../DialogsService.cs | 47 +++++- .../VDownload.Services.UI.Dialogs.csproj | 4 + .../StringResourcesService.cs | 3 + VDownload/App.xaml.cs | 8 +- 5 files changed, 188 insertions(+), 9 deletions(-) create mode 100644 VDownload.Core/VDownload.Core.Strings/Strings/en-US/DialogButtonsResources.resw diff --git a/VDownload.Core/VDownload.Core.Strings/Strings/en-US/DialogButtonsResources.resw b/VDownload.Core/VDownload.Core.Strings/Strings/en-US/DialogButtonsResources.resw new file mode 100644 index 0000000..7470494 --- /dev/null +++ b/VDownload.Core/VDownload.Core.Strings/Strings/en-US/DialogButtonsResources.resw @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Cancel + + + Close + + + No + + + OK + + + Yes + + \ No newline at end of file diff --git a/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Dialogs/DialogsService.cs b/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Dialogs/DialogsService.cs index dec87ff..845663d 100644 --- a/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Dialogs/DialogsService.cs +++ b/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Dialogs/DialogsService.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using VDownload.Services.UI.StringResources; namespace VDownload.Services.UI.Dialogs { @@ -37,6 +38,26 @@ namespace VDownload.Services.UI.Dialogs public class DialogsService : IDialogsService { + #region SERVICES + + protected readonly IStringResourcesService _stringResourcesService; + + #endregion + + + + #region FIELDS + + protected string _okString; + protected string _closeString; + protected string _cancelString; + protected string _yesString; + protected string _noString; + + #endregion + + + #region PROPERTIES public XamlRoot DefaultRoot { get; set; } @@ -45,10 +66,26 @@ namespace VDownload.Services.UI.Dialogs + #region CONSTRUCTORS + + public DialogsService(IStringResourcesService stringResourcesService) + { + _stringResourcesService = stringResourcesService; + _okString = _stringResourcesService.DialogButtonsResources.Get("OK"); + _closeString = _stringResourcesService.DialogButtonsResources.Get("Close"); + _cancelString = _stringResourcesService.DialogButtonsResources.Get("Cancel"); + _yesString = _stringResourcesService.DialogButtonsResources.Get("Yes"); + _noString = _stringResourcesService.DialogButtonsResources.Get("No"); + } + + #endregion + + + #region PUBLIC METHODS - public async Task ShowOk(string title, string message) => await ShowSingle(title, message, "OK"); - public async Task ShowClose(string title, string message) => await ShowSingle(title, message, "Close"); + public async Task ShowOk(string title, string message) => await ShowSingle(title, message, _okString); + public async Task ShowClose(string title, string message) => await ShowSingle(title, message, _closeString); public async Task ShowSingle(string title, string message, string buttonText) { ContentDialog contentDialog = BuildDialog(title, message); @@ -56,12 +93,12 @@ namespace VDownload.Services.UI.Dialogs await ShowDialog(contentDialog); } - public async Task ShowOkCancel(string title, string message) => await ShowDouble(title, message, "OK", "Cancel") switch + public async Task ShowOkCancel(string title, string message) => await ShowDouble(title, message, _okString, _cancelString) switch { DialogResult.Primary => DialogResultOkCancel.Ok, _ => DialogResultOkCancel.Cancel }; - public async Task ShowYesNo(string title, string message) => await ShowDouble(title, message, "Yes", "No") switch + public async Task ShowYesNo(string title, string message) => await ShowDouble(title, message, _yesString, _noString) switch { DialogResult.Primary => DialogResultYesNo.Yes, _ => DialogResultYesNo.No @@ -74,7 +111,7 @@ namespace VDownload.Services.UI.Dialogs return await ShowDialog(contentDialog); } - public async Task ShowYesNoCancel(string title, string message) => await ShowTriple(title, message, "Yes", "No", "Cancel") switch + public async Task ShowYesNoCancel(string title, string message) => await ShowTriple(title, message, _yesString, _noString, _cancelString) switch { DialogResult.Primary => DialogResultYesNoCancel.Yes, DialogResult.Secondary => DialogResultYesNoCancel.Yes, diff --git a/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Dialogs/VDownload.Services.UI.Dialogs.csproj b/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Dialogs/VDownload.Services.UI.Dialogs.csproj index aa4e151..73dc57e 100644 --- a/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Dialogs/VDownload.Services.UI.Dialogs.csproj +++ b/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.Dialogs/VDownload.Services.UI.Dialogs.csproj @@ -13,4 +13,8 @@ + + + + diff --git a/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.StringResources/StringResourcesService.cs b/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.StringResources/StringResourcesService.cs index c064786..79d965f 100644 --- a/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.StringResources/StringResourcesService.cs +++ b/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.StringResources/StringResourcesService.cs @@ -14,6 +14,7 @@ namespace VDownload.Services.UI.StringResources StringResources NotificationsResources { get; } StringResources SearchResources { get; } StringResources CommonResources { get; } + StringResources DialogButtonsResources { get; } } @@ -39,6 +40,7 @@ namespace VDownload.Services.UI.StringResources public StringResources NotificationsResources { get; protected set; } public StringResources SearchResources { get; protected set; } public StringResources CommonResources { get; protected set; } + public StringResources DialogButtonsResources { get; protected set; } #endregion @@ -59,6 +61,7 @@ namespace VDownload.Services.UI.StringResources NotificationsResources = BuildResource("NotificationsResources"); SearchResources = BuildResource("SearchResources"); CommonResources = BuildResource("CommonResources"); + DialogButtonsResources = BuildResource("DialogButtonsResources"); } #endregion diff --git a/VDownload/App.xaml.cs b/VDownload/App.xaml.cs index 2e9b054..9d90d35 100644 --- a/VDownload/App.xaml.cs +++ b/VDownload/App.xaml.cs @@ -108,12 +108,12 @@ namespace VDownload protected void BuildUIServices(IServiceCollection services) { - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); } protected void BuildUtilityServices(IServiceCollection services)