From 7ba47a2b4ceff0943a0ff0741884ab381fa8ecce Mon Sep 17 00:00:00 2001 From: bcssov Date: Mon, 18 Mar 2024 01:57:51 +0100 Subject: [PATCH 1/7] Add dependencies --- src/IronyModManager/IronyModManager.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/IronyModManager/IronyModManager.csproj b/src/IronyModManager/IronyModManager.csproj index a2474a84..f63ebde8 100644 --- a/src/IronyModManager/IronyModManager.csproj +++ b/src/IronyModManager/IronyModManager.csproj @@ -139,6 +139,8 @@ + + From 0fe43ec65a75a6ae83560a5c533c3c97daff02db Mon Sep 17 00:00:00 2001 From: bcssov Date: Mon, 18 Mar 2024 01:58:04 +0100 Subject: [PATCH 2/7] hardcode color picker --- Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/Directory.Build.props b/Directory.Build.props index f5d251dc..93fe4a47 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -30,6 +30,7 @@ [0.10.22] [0.10.12.2] [1.1.10] + [0.10.17] [2.4.5] From 512eff966b41473a4507fe10d4fb4cbb26e62602 Mon Sep 17 00:00:00 2001 From: bcssov Date: Mon, 18 Mar 2024 21:37:49 +0100 Subject: [PATCH 3/7] Add new color picker (one which doesn't have as many dependencies and variations) Add preference storage --- .../IConflictSolverColors.cs | 54 +++++++++++++++++ .../IPreferences.cs | 26 +++++++- .../ConflictSolverColors.cs | 59 +++++++++++++++++++ src/IronyModManager.Models/DIPackage.cs | 3 +- src/IronyModManager.Models/MappingProfile.cs | 3 +- src/IronyModManager.Models/Preferences.cs | 26 +++++++- .../MappingProfile.cs | 6 +- src/IronyModManager/IronyModManager.csproj | 3 +- 8 files changed, 173 insertions(+), 7 deletions(-) create mode 100644 src/IronyModManager.Models.Common/IConflictSolverColors.cs create mode 100644 src/IronyModManager.Models/ConflictSolverColors.cs diff --git a/src/IronyModManager.Models.Common/IConflictSolverColors.cs b/src/IronyModManager.Models.Common/IConflictSolverColors.cs new file mode 100644 index 00000000..a439ec58 --- /dev/null +++ b/src/IronyModManager.Models.Common/IConflictSolverColors.cs @@ -0,0 +1,54 @@ +// *********************************************************************** +// Assembly : IronyModManager.Models.Common +// Author : Mario +// Created : 03-18-2024 +// +// Last Modified By : Mario +// Last Modified On : 03-18-2024 +// *********************************************************************** +// +// Mario +// +// +// *********************************************************************** + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace IronyModManager.Models.Common +{ + /// + /// An conflict solver colors interface. + /// + public interface IConflictSolverColors : IModel + { + #region Properties + + /// + /// Gets or sets the color of the conflict solver deleted line. + /// + /// The color of the conflict solver deleted line. + string ConflictSolverDeletedLineColor { get; set; } + + /// + /// Gets or sets the color of the conflict solver imaginary line. + /// + /// The color of the conflict solver imaginary line. + string ConflictSolverImaginaryLineColor { get; set; } + + /// + /// Gets or sets a value representing the conflict solver inserted line color. + /// + /// The conflict solver inserted line color. + string ConflictSolverInsertedLineColor { get; set; } + + /// + /// Gets or sets the color of the conflict solver modified line. + /// + /// The color of the conflict solver modified line. + string ConflictSolverModifiedLineColor { get; set; } + + #endregion Properties + } +} diff --git a/src/IronyModManager.Models.Common/IPreferences.cs b/src/IronyModManager.Models.Common/IPreferences.cs index e372fdf0..712ee042 100644 --- a/src/IronyModManager.Models.Common/IPreferences.cs +++ b/src/IronyModManager.Models.Common/IPreferences.cs @@ -4,7 +4,7 @@ // Created : 01-11-2020 // // Last Modified By : Mario -// Last Modified On : 02-26-2024 +// Last Modified On : 03-18-2024 // *********************************************************************** // // Mario @@ -43,6 +43,24 @@ public interface IPreferences : IModel /// true if [check for prerelease]; otherwise, false. bool CheckForPrerelease { get; set; } + /// + /// Gets or sets the color of the conflict solver deleted line. + /// + /// The color of the conflict solver deleted line. + string ConflictSolverDeletedLineColor { get; set; } + + /// + /// Gets or sets the color of the conflict solver imaginary line. + /// + /// The color of the conflict solver imaginary line. + string ConflictSolverImaginaryLineColor { get; set; } + + /// + /// Gets or sets the color of the conflict solver inserted line. + /// + /// The color of the conflict solver inserted line. + string ConflictSolverInsertedLineColor { get; set; } + /// /// Gets or sets a value representing the conflict solver languages. /// @@ -55,6 +73,12 @@ public interface IPreferences : IModel /// true if conflict solver languages set; otherwise, false. bool ConflictSolverLanguagesSet { get; set; } + /// + /// Gets or sets the color of the conflict solver modified line. + /// + /// The color of the conflict solver modified line. + string ConflictSolverModifiedLineColor { get; set; } + /// /// Gets or sets a value indicating whether [conflict solver prompt shown]. /// diff --git a/src/IronyModManager.Models/ConflictSolverColors.cs b/src/IronyModManager.Models/ConflictSolverColors.cs new file mode 100644 index 00000000..c8ce55d1 --- /dev/null +++ b/src/IronyModManager.Models/ConflictSolverColors.cs @@ -0,0 +1,59 @@ +// *********************************************************************** +// Assembly : IronyModManager.Models +// Author : Mario +// Created : 03-18-2024 +// +// Last Modified By : Mario +// Last Modified On : 03-18-2024 +// *********************************************************************** +// +// Mario +// +// +// *********************************************************************** + +using System; +using System.Collections.Generic; +using System.Linq; +using IronyModManager.Models.Common; + +namespace IronyModManager.Models +{ + /// + /// Class ConflictSolverColors. + /// Implements the + /// Implements the + /// + /// + /// + public class ConflictSolverColors : BaseModel, IConflictSolverColors + { + #region Properties + + /// + /// Gets or sets the color of the conflict solver deleted line. + /// + /// The color of the conflict solver deleted line. + public string ConflictSolverDeletedLineColor { get; set; } + + /// + /// Gets or sets the color of the conflict solver imaginary line. + /// + /// The color of the conflict solver imaginary line. + public string ConflictSolverImaginaryLineColor { get; set; } + + /// + /// Gets or sets a value representing the conflict solver inserted line color. + /// + /// The conflict solver inserted line color. + public string ConflictSolverInsertedLineColor { get; set; } + + /// + /// Gets or sets the color of the conflict solver modified line. + /// + /// The color of the conflict solver modified line. + public string ConflictSolverModifiedLineColor { get; set; } + + #endregion Properties + } +} diff --git a/src/IronyModManager.Models/DIPackage.cs b/src/IronyModManager.Models/DIPackage.cs index e3bcb633..adb9277b 100644 --- a/src/IronyModManager.Models/DIPackage.cs +++ b/src/IronyModManager.Models/DIPackage.cs @@ -4,7 +4,7 @@ // Created : 01-15-2020 // // Last Modified By : Mario -// Last Modified On : 02-25-2024 +// Last Modified On : 03-18-2024 // *********************************************************************** // // Mario @@ -66,6 +66,7 @@ public void RegisterServices(Container container) container.Register(); container.RegisterModel(); container.RegisterLocalization(); + container.RegisterModel(); } #endregion Methods diff --git a/src/IronyModManager.Models/MappingProfile.cs b/src/IronyModManager.Models/MappingProfile.cs index 1a0566a8..a68da981 100644 --- a/src/IronyModManager.Models/MappingProfile.cs +++ b/src/IronyModManager.Models/MappingProfile.cs @@ -4,7 +4,7 @@ // Created : 01-11-2020 // // Last Modified By : Mario -// Last Modified On : 02-25-2024 +// Last Modified On : 03-18-2024 // *********************************************************************** // // Copyright (c) Mario. All rights reserved. @@ -63,6 +63,7 @@ public MappingProfile() CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); } #endregion Constructors diff --git a/src/IronyModManager.Models/Preferences.cs b/src/IronyModManager.Models/Preferences.cs index 61cb12a5..441e7e94 100644 --- a/src/IronyModManager.Models/Preferences.cs +++ b/src/IronyModManager.Models/Preferences.cs @@ -4,7 +4,7 @@ // Created : 01-11-2020 // // Last Modified By : Mario -// Last Modified On : 02-26-2024 +// Last Modified On : 03-18-2024 // *********************************************************************** // // Mario @@ -45,6 +45,24 @@ public class Preferences : BaseModel, IPreferences /// true if [check for prerelease]; otherwise, false. public virtual bool CheckForPrerelease { get; set; } + /// + /// Gets or sets the color of the conflict solver deleted line. + /// + /// The color of the conflict solver deleted line. + public virtual string ConflictSolverDeletedLineColor { get; set; } + + /// + /// Gets or sets the color of the conflict solver imaginary line. + /// + /// The color of the conflict solver imaginary line. + public virtual string ConflictSolverImaginaryLineColor { get; set; } + + /// + /// Gets or sets the color of the conflict solver inserted line. + /// + /// The color of the conflict solver inserted line. + public virtual string ConflictSolverInsertedLineColor { get; set; } + /// /// Gets or sets a value representing the conflict solver languages. /// @@ -57,6 +75,12 @@ public class Preferences : BaseModel, IPreferences /// true if [conflict solver languages set]; otherwise, false. public virtual bool ConflictSolverLanguagesSet { get; set; } + /// + /// Gets or sets a value representing the conflict solver modified line color. + /// + /// The conflict solver modified line color. + public virtual string ConflictSolverModifiedLineColor { get; set; } + /// /// Gets or sets a value indicating whether [conflict solver prompt shown]. /// diff --git a/src/IronyModManager.Services/MappingProfile.cs b/src/IronyModManager.Services/MappingProfile.cs index 09cf7f61..0b2fabdf 100644 --- a/src/IronyModManager.Services/MappingProfile.cs +++ b/src/IronyModManager.Services/MappingProfile.cs @@ -4,7 +4,7 @@ // Created : 01-11-2020 // // Last Modified By : Mario -// Last Modified On : 11-02-2022 +// Last Modified On : 03-18-2024 // *********************************************************************** // // Copyright (c) Mario. All rights reserved. @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; +using System.Linq; using IronyModManager.Models.Common; using IronyModManager.Shared; using IronyModManager.Shared.Models; @@ -60,6 +61,9 @@ public MappingProfile() .ForMember(m => m.ConflictSolverPromptShown, o => o.MapFrom(s => s.ConflictSolverPromptShown)) .ReverseMap() .IgnoreAllUnmappedMembers(); + CreateMap().ForMember(m => m.ConflictSolverDeletedLineColor, o => o.MapFrom(s => s.ConflictSolverDeletedLineColor)) + .ForMember(m => m.ConflictSolverImaginaryLineColor, o => o.MapFrom(s => s.ConflictSolverImaginaryLineColor)).ForMember(m => m.ConflictSolverInsertedLineColor, o => o.MapFrom(s => s.ConflictSolverInsertedLineColor)) + .ForMember(m => m.ConflictSolverModifiedLineColor, o => o.MapFrom(s => s.ConflictSolverModifiedLineColor)).ReverseMap().IgnoreAllUnmappedMembers(); } #endregion Constructors diff --git a/src/IronyModManager/IronyModManager.csproj b/src/IronyModManager/IronyModManager.csproj index f63ebde8..fc4b1728 100644 --- a/src/IronyModManager/IronyModManager.csproj +++ b/src/IronyModManager/IronyModManager.csproj @@ -139,8 +139,6 @@ - - @@ -168,6 +166,7 @@ + From d35c94e3068ad2ed807295cc4d628a8cfbb44e35 Mon Sep 17 00:00:00 2001 From: bcssov Date: Mon, 18 Mar 2024 22:46:49 +0100 Subject: [PATCH 4/7] Add service and unit tests --- .../IConflictSolverColorsService.cs | 52 ++++++ .../ConflictSolverColorsServiceTests.cs | 169 ++++++++++++++++++ .../ConflictSolverColorsService.cs | 87 +++++++++ src/IronyModManager.Services/DIPackage.cs | 3 +- 4 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 src/IronyModManager.Services.Common/IConflictSolverColorsService.cs create mode 100644 src/IronyModManager.Services.Tests/ConflictSolverColorsServiceTests.cs create mode 100644 src/IronyModManager.Services/ConflictSolverColorsService.cs diff --git a/src/IronyModManager.Services.Common/IConflictSolverColorsService.cs b/src/IronyModManager.Services.Common/IConflictSolverColorsService.cs new file mode 100644 index 00000000..ea305c40 --- /dev/null +++ b/src/IronyModManager.Services.Common/IConflictSolverColorsService.cs @@ -0,0 +1,52 @@ + +// *********************************************************************** +// Assembly : IronyModManager.Services.Common +// Author : Mario +// Created : 03-18-2024 +// +// Last Modified By : Mario +// Last Modified On : 03-18-2024 +// *********************************************************************** +// +// Mario +// +// +// *********************************************************************** + +using System; +using System.Collections.Generic; +using System.Linq; +using IronyModManager.Models.Common; + +namespace IronyModManager.Services.Common +{ + + /// + /// An conflict solver colors service interface. + /// + public interface IConflictSolverColorsService : IBaseService + { + #region Methods + + /// + /// Get. + /// + /// An IConflictSolverColors. + IConflictSolverColors Get(); + + /// + /// Has any. + /// + /// The color. + /// A bool. + bool HasAny(IConflictSolverColors color); + + /// + /// Save. + /// + /// The color. + void Save(IConflictSolverColors color); + + #endregion Methods + } +} diff --git a/src/IronyModManager.Services.Tests/ConflictSolverColorsServiceTests.cs b/src/IronyModManager.Services.Tests/ConflictSolverColorsServiceTests.cs new file mode 100644 index 00000000..24c7cc19 --- /dev/null +++ b/src/IronyModManager.Services.Tests/ConflictSolverColorsServiceTests.cs @@ -0,0 +1,169 @@ +// *********************************************************************** +// Assembly : IronyModManager.Services.Tests +// Author : Mario +// Created : 03-18-2024 +// +// Last Modified By : Mario +// Last Modified On : 03-18-2024 +// *********************************************************************** +// +// Mario +// +// +// *********************************************************************** + +using System; +using System.Collections.Generic; +using System.Linq; +using AutoMapper; +using FluentAssertions; +using IronyModManager.Localization; +using IronyModManager.Models; +using IronyModManager.Models.Common; +using IronyModManager.Services.Common; +using IronyModManager.Storage.Common; +using IronyModManager.Tests.Common; +using Moq; +using Xunit; + +namespace IronyModManager.Services.Tests +{ + /// + /// Class ConflictSolverColorsServiceTests. + /// + public class ConflictSolverColorsServiceTests + { + /// + /// Setups the mocks. + /// + /// if set to true [empty colors]. + /// The preferences service. + /// The mapper. + private static void SetupMocks(bool emptyColors, Mock preferencesService, Mock mapper) + { + DISetup.SetupContainer(); + CurrentLocale.SetCurrent("en"); + if (emptyColors) + { + preferencesService.Setup(p => p.Get()).Returns(() => + new Preferences()); + } + else + { + preferencesService.Setup(p => p.Get()).Returns(() => + new Preferences { ConflictSolverDeletedLineColor = "test1", ConflictSolverImaginaryLineColor = "test2", ConflictSolverInsertedLineColor = "test3", ConflictSolverModifiedLineColor = "test4" }); + } + + mapper.Setup(s => s.Map(It.IsAny())).Returns((IConflictSolverColors o) => new Preferences + { + ConflictSolverImaginaryLineColor = o.ConflictSolverImaginaryLineColor, + ConflictSolverDeletedLineColor = o.ConflictSolverDeletedLineColor, + ConflictSolverInsertedLineColor = o.ConflictSolverInsertedLineColor, + ConflictSolverModifiedLineColor = o.ConflictSolverModifiedLineColor + }); + mapper.Setup(s => s.Map(It.IsAny())).Returns((IPreferences o) => new ConflictSolverColors() + { + ConflictSolverImaginaryLineColor = o.ConflictSolverImaginaryLineColor, + ConflictSolverDeletedLineColor = o.ConflictSolverDeletedLineColor, + ConflictSolverInsertedLineColor = o.ConflictSolverInsertedLineColor, + ConflictSolverModifiedLineColor = o.ConflictSolverModifiedLineColor + }); + mapper.Setup(s => s.Map(It.IsAny(), It.IsAny())).Returns((IConflictSolverColors s, IPreferences o) => new Preferences() + { + ConflictSolverImaginaryLineColor = s.ConflictSolverImaginaryLineColor, + ConflictSolverDeletedLineColor = s.ConflictSolverDeletedLineColor, + ConflictSolverInsertedLineColor = s.ConflictSolverInsertedLineColor, + ConflictSolverModifiedLineColor = s.ConflictSolverModifiedLineColor + }); + } + + /// + /// Defines the test method Will_get_empty_colors. + /// + [Fact] + public void Will_get_empty_colors() + { + var preferencesService = new Mock(); + var mapper = new Mock(); + SetupMocks(true, preferencesService, mapper); + var service = new ConflictSolverColorsService(preferencesService.Object, new Mock().Object, mapper.Object); + var result = service.Get(); + result.ConflictSolverImaginaryLineColor.Should().BeNullOrWhiteSpace(); + result.ConflictSolverDeletedLineColor.Should().BeNullOrWhiteSpace(); + result.ConflictSolverInsertedLineColor.Should().BeNullOrWhiteSpace(); + result.ConflictSolverModifiedLineColor.Should().BeNullOrWhiteSpace(); + } + + /// + /// Defines the test method Will_get_colors. + /// + [Fact] + public void Will_get_colors() + { + var preferencesService = new Mock(); + var mapper = new Mock(); + SetupMocks(false, preferencesService, mapper); + var service = new ConflictSolverColorsService(preferencesService.Object, new Mock().Object, mapper.Object); + var result = service.Get(); + result.ConflictSolverImaginaryLineColor.Should().Be("test2"); + result.ConflictSolverDeletedLineColor.Should().Be("test1"); + result.ConflictSolverInsertedLineColor.Should().Be("test3"); + result.ConflictSolverModifiedLineColor.Should().Be("test4"); + } + + /// + /// Defines the test method Color_should_be_valid. + /// + [Fact] + public void Color_should_be_valid() + { + var service = new ConflictSolverColorsService(null, null, null); + service.HasAny(new ConflictSolverColors { ConflictSolverDeletedLineColor = "test" }).Should().BeTrue(); + } + + /// + /// Defines the test method Color_should_not_be_valid. + /// + [Fact] + public void Color_should_not_be_valid() + { + var service = new ConflictSolverColorsService(null, null, null); + service.HasAny(new ConflictSolverColors()).Should().BeFalse(); + } + + /// + /// Defines the test method Color_should_not_be_valid_due_to_null_ref. + /// + [Fact] + public void Color_should_not_be_valid_due_to_null_ref() + { + var service = new ConflictSolverColorsService(null, null, null); + service.HasAny(null).Should().BeFalse(); + } + + /// + /// Defines the test method Colors_should_be_saved. + /// + [Fact] + public void Colors_should_be_saved() + { + var preferencesService = new Mock(); + var mapper = new Mock(); + SetupMocks(false, preferencesService, mapper); + IPreferences prefs = null; + preferencesService.Setup(p => p.Save(It.IsAny())).Returns((IPreferences saved) => + { + prefs = saved; + return true; + }); + var service = new ConflictSolverColorsService(preferencesService.Object, new Mock().Object, mapper.Object); + var result = service.Get(); + result.ConflictSolverDeletedLineColor = "test"; + + service.Save(result); + + prefs.Should().NotBeNull(); + prefs.ConflictSolverDeletedLineColor.Should().Be("test"); + } + } +} diff --git a/src/IronyModManager.Services/ConflictSolverColorsService.cs b/src/IronyModManager.Services/ConflictSolverColorsService.cs new file mode 100644 index 00000000..c8fa23c7 --- /dev/null +++ b/src/IronyModManager.Services/ConflictSolverColorsService.cs @@ -0,0 +1,87 @@ +// *********************************************************************** +// Assembly : IronyModManager.Services +// Author : Mario +// Created : 03-18-2024 +// +// Last Modified By : Mario +// Last Modified On : 03-18-2024 +// *********************************************************************** +// +// Mario +// +// +// *********************************************************************** + +using System; +using System.Collections.Generic; +using System.Linq; +using AutoMapper; +using IronyModManager.Models.Common; +using IronyModManager.Services.Common; +using IronyModManager.Storage.Common; + +namespace IronyModManager.Services +{ + /// + /// The conflict solver colors service. + /// + /// + /// + public class ConflictSolverColorsService(IPreferencesService preferencesService, IStorageProvider storageProvider, IMapper mapper) : BaseService(storageProvider, mapper), IConflictSolverColorsService + { + #region Fields + + /// + /// A private static readonly object named objLock. + /// + private static readonly object objLock = new(); + + /// + /// A private IPreferencesService named preferencesService. + /// + private readonly IPreferencesService preferencesService = preferencesService; + + #endregion Fields + + #region Methods + + /// + /// Get. + /// + /// An IConflictSolverColors. + public IConflictSolverColors Get() + { + return Mapper.Map(preferencesService.Get()); + } + + /// + /// Has any. + /// + /// The color. + /// A bool. + public bool HasAny(IConflictSolverColors color) + { + return color != null && (!string.IsNullOrWhiteSpace(color.ConflictSolverDeletedLineColor) || !string.IsNullOrWhiteSpace(color.ConflictSolverImaginaryLineColor) || + !string.IsNullOrWhiteSpace(color.ConflictSolverInsertedLineColor) || !string.IsNullOrWhiteSpace(color.ConflictSolverModifiedLineColor)); + } + + /// + /// Save. + /// + /// The color. + public void Save(IConflictSolverColors color) + { + lock (objLock) + { + if (color != null) + { + var preferences = preferencesService.Get(); + var mapped = Mapper.Map(color, preferences); + preferencesService.Save(mapped); + } + } + } + + #endregion Methods + } +} diff --git a/src/IronyModManager.Services/DIPackage.cs b/src/IronyModManager.Services/DIPackage.cs index 8f30bfca..302ab511 100644 --- a/src/IronyModManager.Services/DIPackage.cs +++ b/src/IronyModManager.Services/DIPackage.cs @@ -4,7 +4,7 @@ // Created : 01-11-2020 // // Last Modified By : Mario -// Last Modified On : 02-25-2024 +// Last Modified On : 03-18-2024 // *********************************************************************** // // Mario @@ -61,6 +61,7 @@ public void RegisterServices(Container container) container.Register(); container.Register(); container.Register(); + container.Register(); } #endregion Methods From 9328905bd3e9d24b4a21a298485dc5017cf5d18e Mon Sep 17 00:00:00 2001 From: bcssov Date: Mon, 18 Mar 2024 23:01:56 +0100 Subject: [PATCH 5/7] Add loc items --- src/IronyModManager.Models/ConflictSolverColors.cs | 8 ++++---- src/IronyModManager.Shared/LocalizationResources.cs | 5 +++++ src/IronyModManager/Localization/de.json | 7 ++++++- src/IronyModManager/Localization/en.json | 7 ++++++- src/IronyModManager/Localization/es.json | 7 ++++++- src/IronyModManager/Localization/fr.json | 7 ++++++- src/IronyModManager/Localization/hr.json | 7 ++++++- src/IronyModManager/Localization/ru.json | 7 ++++++- src/IronyModManager/Localization/zh.json | 7 ++++++- 9 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/IronyModManager.Models/ConflictSolverColors.cs b/src/IronyModManager.Models/ConflictSolverColors.cs index c8ce55d1..e25b6dce 100644 --- a/src/IronyModManager.Models/ConflictSolverColors.cs +++ b/src/IronyModManager.Models/ConflictSolverColors.cs @@ -34,25 +34,25 @@ public class ConflictSolverColors : BaseModel, IConflictSolverColors /// Gets or sets the color of the conflict solver deleted line. /// /// The color of the conflict solver deleted line. - public string ConflictSolverDeletedLineColor { get; set; } + public virtual string ConflictSolverDeletedLineColor { get; set; } /// /// Gets or sets the color of the conflict solver imaginary line. /// /// The color of the conflict solver imaginary line. - public string ConflictSolverImaginaryLineColor { get; set; } + public virtual string ConflictSolverImaginaryLineColor { get; set; } /// /// Gets or sets a value representing the conflict solver inserted line color. /// /// The conflict solver inserted line color. - public string ConflictSolverInsertedLineColor { get; set; } + public virtual string ConflictSolverInsertedLineColor { get; set; } /// /// Gets or sets the color of the conflict solver modified line. /// /// The color of the conflict solver modified line. - public string ConflictSolverModifiedLineColor { get; set; } + public virtual string ConflictSolverModifiedLineColor { get; set; } #endregion Properties } diff --git a/src/IronyModManager.Shared/LocalizationResources.cs b/src/IronyModManager.Shared/LocalizationResources.cs index 6f0ffff3..9a4a593b 100644 --- a/src/IronyModManager.Shared/LocalizationResources.cs +++ b/src/IronyModManager.Shared/LocalizationResources.cs @@ -626,6 +626,11 @@ public static class ConflictSolver public const string Prefix = "Options.ConflictSolver."; public const string Title = Prefix + "Title"; public const string AllowedLanguages = Prefix + "AllowedLanguages"; + public const string Colors = Prefix + "Colors"; + public const string ConflictSolverDeletedLineColor = Prefix + "ConflictSolverDeletedLineColor"; + public const string ConflictSolverImaginaryLineColor = Prefix + "ConflictSolverImaginaryLineColor"; + public const string ConflictSolverInsertedLineColor = Prefix + "ConflictSolverInsertedLineColor"; + public const string ConflictSolverModifiedLineColor = Prefix + "ConflictSolverModifiedLineColor"; } public static class Updates { diff --git a/src/IronyModManager/Localization/de.json b/src/IronyModManager/Localization/de.json index 5a1bb566..5c37e190 100644 --- a/src/IronyModManager/Localization/de.json +++ b/src/IronyModManager/Localization/de.json @@ -479,7 +479,12 @@ }, "ConflictSolver": { "Title": "Konfliktlöser", - "AllowedLanguages": "Erlaubte Sprachen" + "AllowedLanguages": "Erlaubte Sprachen", + "Colors": "Neue Farben des Diff Viewers", + "ConflictSolverDeletedLineColor": "Gelöschte Linie", + "ConflictSolverImaginaryLineColor": "Imaginäre Linie", + "ConflictSolverInsertedLineColor": "Eingefügte Linie", + "ConflictSolverModifiedLineColor": "Geänderte Linie" }, "Updates": { "Title": "Aktualisierungsoptionen", diff --git a/src/IronyModManager/Localization/en.json b/src/IronyModManager/Localization/en.json index 328a0eed..4880e8e1 100644 --- a/src/IronyModManager/Localization/en.json +++ b/src/IronyModManager/Localization/en.json @@ -479,7 +479,12 @@ }, "ConflictSolver": { "Title": "Conflict Solver", - "AllowedLanguages": "Allowed Languages" + "AllowedLanguages": "Allowed Languages", + "Colors": "New Diff Viewer Colors", + "ConflictSolverDeletedLineColor": "Deleted Line", + "ConflictSolverImaginaryLineColor": "Imaginary Line", + "ConflictSolverInsertedLineColor": "Inserted Line", + "ConflictSolverModifiedLineColor": "Modified Line" }, "Updates": { "Title": "Update Options", diff --git a/src/IronyModManager/Localization/es.json b/src/IronyModManager/Localization/es.json index 39d88324..c0203cd1 100644 --- a/src/IronyModManager/Localization/es.json +++ b/src/IronyModManager/Localization/es.json @@ -479,7 +479,12 @@ }, "ConflictSolver": { "Title": "Solucionador de conflictos", - "AllowedLanguages": "Lenguas permitidas" + "AllowedLanguages": "Lenguas permitidas", + "Colors": "Nuevos colores del visor de diferencias", + "ConflictSolverDeletedLineColor": "Línea suprimida", + "ConflictSolverImaginaryLineColor": "Línea imaginaria", + "ConflictSolverInsertedLineColor": "Línea insertada", + "ConflictSolverModifiedLineColor": "Línea modificada" }, "Updates": { "Title": "Opciones de Actualización", diff --git a/src/IronyModManager/Localization/fr.json b/src/IronyModManager/Localization/fr.json index effcd6b8..cf895600 100644 --- a/src/IronyModManager/Localization/fr.json +++ b/src/IronyModManager/Localization/fr.json @@ -479,7 +479,12 @@ }, "ConflictSolver": { "Title": "Résoudre les conflits", - "AllowedLanguages": "Langues autorisées" + "AllowedLanguages": "Langues autorisées", + "Colors": "Nouvelles couleurs du visualiseur de diffusion", + "ConflictSolverDeletedLineColor": "Ligne supprimée", + "ConflictSolverImaginaryLineColor": "Ligne imaginaire", + "ConflictSolverInsertedLineColor": "Ligne insérée", + "ConflictSolverModifiedLineColor": "Ligne modifiée" }, "Updates": { "Title": "Options de mise à jour", diff --git a/src/IronyModManager/Localization/hr.json b/src/IronyModManager/Localization/hr.json index 1bee4e93..0b04046e 100644 --- a/src/IronyModManager/Localization/hr.json +++ b/src/IronyModManager/Localization/hr.json @@ -479,7 +479,12 @@ }, "ConflictSolver": { "Title": "Rješavanje sukoba", - "AllowedLanguages": "Dopušteni jezici" + "AllowedLanguages": "Dopušteni jezici", + "Colors": "Nove boje preglednika razlika", + "ConflictSolverDeletedLineColor": "Izbrisana linija", + "ConflictSolverImaginaryLineColor": "Imaginarna linija", + "ConflictSolverInsertedLineColor": "Umetnuti redak", + "ConflictSolverModifiedLineColor": "Modificirana linija" }, "Updates": { "Title": "Mogućnosti ažuriranja", diff --git a/src/IronyModManager/Localization/ru.json b/src/IronyModManager/Localization/ru.json index afe8de09..9f697e34 100644 --- a/src/IronyModManager/Localization/ru.json +++ b/src/IronyModManager/Localization/ru.json @@ -479,7 +479,12 @@ }, "ConflictSolver": { "Title": "Разрешитель конфликтов", - "AllowedLanguages": "Разрешенные языки" + "AllowedLanguages": "Разрешенные языки", + "Colors": "Новые цвета Diff Viewer", + "ConflictSolverDeletedLineColor": "Удаленная строка", + "ConflictSolverImaginaryLineColor": "Воображаемая линия", + "ConflictSolverInsertedLineColor": "Вставленная линия", + "ConflictSolverModifiedLineColor": "Измененная линия" }, "Updates": { "Title": "Обновления", diff --git a/src/IronyModManager/Localization/zh.json b/src/IronyModManager/Localization/zh.json index cd92222c..e85aaff9 100644 --- a/src/IronyModManager/Localization/zh.json +++ b/src/IronyModManager/Localization/zh.json @@ -479,7 +479,12 @@ }, "ConflictSolver": { "Title": "冲突处理器", - "AllowedLanguages": "允许使用的语言" + "AllowedLanguages": "允许使用的语言", + "Colors": "新的差分查看器颜色", + "ConflictSolverDeletedLineColor": "已删除行", + "ConflictSolverImaginaryLineColor": "虚线", + "ConflictSolverInsertedLineColor": "插入行", + "ConflictSolverModifiedLineColor": "修改线" }, "Updates": { "Title": "更新选项", From c0f28dcb69dd2fc5058cbf54f47bf315fcc3f451 Mon Sep 17 00:00:00 2001 From: bcssov Date: Tue, 19 Mar 2024 22:23:35 +0100 Subject: [PATCH 6/7] Add options logic --- .../AvaloniaEdit/EditorColorConverter.cs | 303 ++++++++++++++ .../Implementation/Themes/DarkTheme.cs | 11 +- .../Implementation/Themes/FluentDarkTheme.cs | 11 +- .../Implementation/Themes/FluentLightTheme.cs | 11 +- .../Implementation/Themes/LightTheme.cs | 11 +- .../Themes/MaterialDarkTheme.cs | 11 +- .../Themes/MaterialLightTheme.cs | 11 +- .../Controls/OptionsControlViewModel.cs | 392 +++++++++++++++++- .../Views/Controls/OptionsControlView.xaml | 108 ++++- 9 files changed, 854 insertions(+), 15 deletions(-) create mode 100644 src/IronyModManager/Implementation/AvaloniaEdit/EditorColorConverter.cs diff --git a/src/IronyModManager/Implementation/AvaloniaEdit/EditorColorConverter.cs b/src/IronyModManager/Implementation/AvaloniaEdit/EditorColorConverter.cs new file mode 100644 index 00000000..d8f1ecfe --- /dev/null +++ b/src/IronyModManager/Implementation/AvaloniaEdit/EditorColorConverter.cs @@ -0,0 +1,303 @@ +// *********************************************************************** +// Assembly : IronyModManager +// Author : Mario +// Created : 03-19-2024 +// +// Last Modified By : Mario +// Last Modified On : 03-19-2024 +// *********************************************************************** +// +// Mario +// +// +// *********************************************************************** + +using System; +using System.Collections.Generic; +using System.Linq; +using Avalonia.Media; +using IronyModManager.DI; +using IronyModManager.Models.Common; +using IronyModManager.Platform.Themes; +using IronyModManager.Services.Common; +using JetBrains.Annotations; + +namespace IronyModManager.Implementation.AvaloniaEdit +{ + /// + /// Class EditorColorConverter. + /// + internal class EditorColorConverter(IConflictSolverColors color) + { + #region Fields + + /// + /// A private readonly IConflictSolverColors named color. + /// + private readonly IConflictSolverColors color = color; + + /// + /// The deleted line brush + /// + [CanBeNull] private SolidColorBrush deletedLineBrush; + + /// + /// The deleted line color + /// + private Color? deletedLineColor; + + /// + /// The edited line brush + /// + [CanBeNull] private SolidColorBrush editedLineBrush; + + /// + /// The edited line color + /// + private Color? editedLineColor; + + /// + /// The imaginary line brush + /// + [CanBeNull] private SolidColorBrush imaginaryLineBrush; + + /// + /// The imaginary line color + /// + private Color? imaginaryLineColor; + + /// + /// The inserted line brush + /// + [CanBeNull] private SolidColorBrush insertedLineBrush; + + /// + /// The inserted line clor + /// + private Color? insertedLineClor; + + /// + /// The is light theme + /// + private bool? isLightTheme; + + #endregion Fields + + #region Methods + + /// + /// Gets the default color of the deleted line. + /// + /// Color. + public Color GetDefaultDeletedLineColor() + { + return IsLightTheme() ? Constants.LightDiffDeletedLine.Color : Constants.DarkDiffDeletedLine.Color; + } + + /// + /// Gets a default edited line color. + /// + /// A Color. + public Color GetDefaultEditedLineColor() + { + return IsLightTheme() ? Constants.LightDiffModifiedLine.Color : Constants.DarkDiffModifiedLine.Color; + } + + /// + /// Gets a default imaginary line color. + /// + /// A Color. + public Color GetDefaultImaginaryLineColor() + { + return IsLightTheme() ? Constants.LightDiffImaginaryLine.Color : Constants.DarkDiffImaginaryLine.Color; + } + + /// + /// Gets a default inserted line color. + /// + /// A Color. + public Color GetDefaultInsertedLineColor() + { + return IsLightTheme() ? Constants.LightDiffInsertedLine.Color : Constants.DarkDiffInsertedLine.Color; + } + + /// + /// Gets a deleted line brush. + /// + /// A SolidColorBrush. + public SolidColorBrush GetDeletedLineBrush() + { + deletedLineBrush ??= ToBrush(GetDeletedLineColor()); + return deletedLineBrush; + } + + /// + /// Gets the color of the deleted line. + /// + /// Color. + public Color GetDeletedLineColor() + { + Color getColor() + { + if (color != null) + { + var result = ConvertToColor(color.ConflictSolverDeletedLineColor); + if (result.HasValue) + { + return result.GetValueOrDefault(); + } + } + + return IsLightTheme() ? Constants.LightDiffDeletedLine.Color : Constants.DarkDiffDeletedLine.Color; + } + + deletedLineColor ??= getColor(); + return deletedLineColor.GetValueOrDefault(); + } + + /// + /// Gets an edited line brush. + /// + /// A SolidColorBrush. + public SolidColorBrush GetEditedLineBrush() + { + editedLineBrush ??= ToBrush(GetEditedLineColor()); + return editedLineBrush; + } + + /// + /// Gets the color of the edited line. + /// + /// Color. + public Color GetEditedLineColor() + { + Color getColor() + { + if (color != null) + { + var result = ConvertToColor(color.ConflictSolverModifiedLineColor); + if (result.HasValue) + { + return result.GetValueOrDefault(); + } + } + + return IsLightTheme() ? Constants.LightDiffModifiedLine.Color : Constants.DarkDiffModifiedLine.Color; + } + + editedLineColor ??= getColor(); + return editedLineColor.GetValueOrDefault(); + } + + /// + /// Gets an imaginary line brush. + /// + /// A SolidColorBrush. + public SolidColorBrush GetImaginaryLineBrush() + { + imaginaryLineBrush ??= ToBrush(GetImaginaryLineColor()); + return imaginaryLineBrush; + } + + /// + /// Gets the color of the imaginary line. + /// + /// Color. + public Color GetImaginaryLineColor() + { + Color getColor() + { + if (color != null) + { + var result = ConvertToColor(color.ConflictSolverImaginaryLineColor); + if (result.HasValue) + { + return result.GetValueOrDefault(); + } + } + + return IsLightTheme() ? Constants.LightDiffImaginaryLine.Color : Constants.DarkDiffImaginaryLine.Color; + } + + imaginaryLineColor ??= getColor(); + return imaginaryLineColor.GetValueOrDefault(); + } + + /// + /// Gets an inserted line brush. + /// + /// A SolidColorBrush. + public SolidColorBrush GetInsertedLineBrush() + { + insertedLineBrush ??= ToBrush(GetInsertedLineColor()); + return insertedLineBrush; + } + + /// + /// Gets the color of the inserted line. + /// + /// Color. + public Color GetInsertedLineColor() + { + Color getColor() + { + if (color != null) + { + var result = ConvertToColor(color.ConflictSolverInsertedLineColor); + if (result.HasValue) + { + return result.GetValueOrDefault(); + } + } + + return IsLightTheme() ? Constants.LightDiffInsertedLine.Color : Constants.DarkDiffInsertedLine.Color; + } + + insertedLineClor ??= getColor(); + return insertedLineClor.GetValueOrDefault(); + } + + /// + /// Converts to color. + /// + /// The color. + /// System.Nullable<Color>. + private Color? ConvertToColor(string color) + { + if (Color.TryParse(color, out var result)) + { + return result; + } + + return null; + } + + /// + /// Determines whether [is light theme]. + /// + /// true if [is light theme]; otherwise, false. + private bool IsLightTheme() + { + if (!isLightTheme.HasValue) + { + var themeManager = DIResolver.Get(); + var themeService = DIResolver.Get(); + isLightTheme = themeManager.IsLightTheme(themeService.GetSelected().Type); + } + + return isLightTheme.GetValueOrDefault(); + } + + /// + /// To brush. + /// + /// The color. + /// A SolidColorBrush. + private SolidColorBrush ToBrush(Color color) + { + return new SolidColorBrush(color); + } + + #endregion Methods + } +} diff --git a/src/IronyModManager/Implementation/Themes/DarkTheme.cs b/src/IronyModManager/Implementation/Themes/DarkTheme.cs index 035a266d..f9b401c4 100644 --- a/src/IronyModManager/Implementation/Themes/DarkTheme.cs +++ b/src/IronyModManager/Implementation/Themes/DarkTheme.cs @@ -4,13 +4,14 @@ // Created : 03-14-2021 // // Last Modified By : Mario -// Last Modified On : 11-04-2021 +// Last Modified On : 03-19-2024 // *********************************************************************** // // Mario // // // *********************************************************************** + using System; using System.Collections.Generic; using System.Linq; @@ -49,7 +50,13 @@ public class DarkTheme : BaseThemeResources /// Gets the styles. /// /// The styles. - public override IReadOnlyCollection Styles => new List() { "avares://Avalonia.Themes.Default/DefaultTheme.xaml", "avares://Avalonia.Themes.Default/Accents/BaseDark.xaml", "avares://IronyModManager/Controls/Themes/Dark/ThemeOverride.xaml" }; + public override IReadOnlyCollection Styles => new List + { + "avares://ThemeEditor.Controls.ColorPicker/ColorPicker.axaml", + "avares://Avalonia.Themes.Default/DefaultTheme.xaml", + "avares://Avalonia.Themes.Default/Accents/BaseDark.xaml", + "avares://IronyModManager/Controls/Themes/Dark/ThemeOverride.xaml" + }; /// /// Gets the name of the theme. diff --git a/src/IronyModManager/Implementation/Themes/FluentDarkTheme.cs b/src/IronyModManager/Implementation/Themes/FluentDarkTheme.cs index 6afb90da..9c479e39 100644 --- a/src/IronyModManager/Implementation/Themes/FluentDarkTheme.cs +++ b/src/IronyModManager/Implementation/Themes/FluentDarkTheme.cs @@ -4,13 +4,14 @@ // Created : 03-14-2021 // // Last Modified By : Mario -// Last Modified On : 11-04-2021 +// Last Modified On : 03-19-2024 // *********************************************************************** // // Mario // // // *********************************************************************** + using System; using System.Collections.Generic; using System.Linq; @@ -49,7 +50,13 @@ public class FluentDarkTheme : BaseThemeResources /// Gets the styles. /// /// The styles. - public override IReadOnlyCollection Styles => new List() { "avares://Avalonia.Themes.Fluent/FluentDark.xaml", "avares://Avalonia.Themes.Fluent/DensityStyles/Compact.xaml", "avares://IronyModManager/Controls/Themes/FluentDark/ThemeOverride.axaml" }; + public override IReadOnlyCollection Styles => new List + { + "avares://ThemeEditor.Controls.ColorPicker/ColorPicker.axaml", + "avares://Avalonia.Themes.Fluent/FluentDark.xaml", + "avares://Avalonia.Themes.Fluent/DensityStyles/Compact.xaml", + "avares://IronyModManager/Controls/Themes/FluentDark/ThemeOverride.axaml" + }; /// /// Gets the name of the theme. diff --git a/src/IronyModManager/Implementation/Themes/FluentLightTheme.cs b/src/IronyModManager/Implementation/Themes/FluentLightTheme.cs index b0ae2033..0d5efdda 100644 --- a/src/IronyModManager/Implementation/Themes/FluentLightTheme.cs +++ b/src/IronyModManager/Implementation/Themes/FluentLightTheme.cs @@ -4,13 +4,14 @@ // Created : 03-14-2021 // // Last Modified By : Mario -// Last Modified On : 11-04-2021 +// Last Modified On : 03-19-2024 // *********************************************************************** // // Mario // // // *********************************************************************** + using System; using System.Collections.Generic; using System.Linq; @@ -49,7 +50,13 @@ public class FluentLightTheme : BaseThemeResources /// Gets the styles. /// /// The styles. - public override IReadOnlyCollection Styles => new List() { "avares://Avalonia.Themes.Fluent/FluentLight.xaml", "avares://Avalonia.Themes.Fluent/DensityStyles/Compact.xaml", "avares://IronyModManager/Controls/Themes/FluentLight/ThemeOverride.axaml" }; + public override IReadOnlyCollection Styles => new List + { + "avares://ThemeEditor.Controls.ColorPicker/ColorPicker.axaml", + "avares://Avalonia.Themes.Fluent/FluentLight.xaml", + "avares://Avalonia.Themes.Fluent/DensityStyles/Compact.xaml", + "avares://IronyModManager/Controls/Themes/FluentLight/ThemeOverride.axaml" + }; /// /// Gets the name of the theme. diff --git a/src/IronyModManager/Implementation/Themes/LightTheme.cs b/src/IronyModManager/Implementation/Themes/LightTheme.cs index ecf2ad06..6336bb8f 100644 --- a/src/IronyModManager/Implementation/Themes/LightTheme.cs +++ b/src/IronyModManager/Implementation/Themes/LightTheme.cs @@ -4,13 +4,14 @@ // Created : 03-14-2021 // // Last Modified By : Mario -// Last Modified On : 11-04-2021 +// Last Modified On : 03-19-2024 // *********************************************************************** // // Mario // // // *********************************************************************** + using System; using System.Collections.Generic; using System.Linq; @@ -49,7 +50,13 @@ public class LightTheme : BaseThemeResources /// Gets the styles. /// /// The styles. - public override IReadOnlyCollection Styles => new List() { "avares://Avalonia.Themes.Default/DefaultTheme.xaml", "avares://Avalonia.Themes.Default/Accents/BaseLight.xaml", "avares://IronyModManager/Controls/Themes/Light/ThemeOverride.xaml" }; + public override IReadOnlyCollection Styles => new List + { + "avares://ThemeEditor.Controls.ColorPicker/ColorPicker.axaml", + "avares://Avalonia.Themes.Default/DefaultTheme.xaml", + "avares://Avalonia.Themes.Default/Accents/BaseLight.xaml", + "avares://IronyModManager/Controls/Themes/Light/ThemeOverride.xaml" + }; /// /// Gets the name of the theme. diff --git a/src/IronyModManager/Implementation/Themes/MaterialDarkTheme.cs b/src/IronyModManager/Implementation/Themes/MaterialDarkTheme.cs index 90779c15..8564451f 100644 --- a/src/IronyModManager/Implementation/Themes/MaterialDarkTheme.cs +++ b/src/IronyModManager/Implementation/Themes/MaterialDarkTheme.cs @@ -4,13 +4,14 @@ // Created : 03-14-2021 // // Last Modified By : Mario -// Last Modified On : 11-04-2021 +// Last Modified On : 03-19-2024 // *********************************************************************** // // Mario // // // *********************************************************************** + using System; using System.Collections.Generic; using System.Linq; @@ -52,7 +53,13 @@ public class MaterialDarkTheme : BaseThemeResources /// Gets the styles. /// /// The styles. - public override IReadOnlyCollection Styles => new List() { "avares://IronyModManager/Controls/Themes/MaterialDark/Theme.axaml", "avares://Material.Icons.Avalonia/App.xaml", "avares://IronyModManager/Controls/Themes/MaterialDark/ThemeOverride.axaml" }; + public override IReadOnlyCollection Styles => new List + { + "avares://ThemeEditor.Controls.ColorPicker/ColorPicker.axaml", + "avares://IronyModManager/Controls/Themes/MaterialDark/Theme.axaml", + "avares://Material.Icons.Avalonia/App.xaml", + "avares://IronyModManager/Controls/Themes/MaterialDark/ThemeOverride.axaml" + }; /// /// Gets the name of the theme. diff --git a/src/IronyModManager/Implementation/Themes/MaterialLightTheme.cs b/src/IronyModManager/Implementation/Themes/MaterialLightTheme.cs index a0abcf3a..fdf224a0 100644 --- a/src/IronyModManager/Implementation/Themes/MaterialLightTheme.cs +++ b/src/IronyModManager/Implementation/Themes/MaterialLightTheme.cs @@ -4,13 +4,14 @@ // Created : 03-14-2021 // // Last Modified By : Mario -// Last Modified On : 11-04-2021 +// Last Modified On : 03-19-2024 // *********************************************************************** // // Mario // // // *********************************************************************** + using System; using System.Collections.Generic; using System.Linq; @@ -52,7 +53,13 @@ public class MaterialLightTheme : BaseThemeResources /// Gets the styles. /// /// The styles. - public override IReadOnlyCollection Styles => new List() { "avares://IronyModManager/Controls/Themes/MaterialLight/Theme.axaml", "avares://Material.Icons.Avalonia/App.xaml", "avares://IronyModManager/Controls/Themes/MaterialLight/ThemeOverride.axaml" }; + public override IReadOnlyCollection Styles => new List + { + "avares://ThemeEditor.Controls.ColorPicker/ColorPicker.axaml", + "avares://IronyModManager/Controls/Themes/MaterialLight/Theme.axaml", + "avares://Material.Icons.Avalonia/App.xaml", + "avares://IronyModManager/Controls/Themes/MaterialLight/ThemeOverride.axaml" + }; /// /// Gets the name of the theme. diff --git a/src/IronyModManager/ViewModels/Controls/OptionsControlViewModel.cs b/src/IronyModManager/ViewModels/Controls/OptionsControlViewModel.cs index 5d68aaec..a195dc15 100644 --- a/src/IronyModManager/ViewModels/Controls/OptionsControlViewModel.cs +++ b/src/IronyModManager/ViewModels/Controls/OptionsControlViewModel.cs @@ -4,7 +4,7 @@ // Created : 05-30-2020 // // Last Modified By : Mario -// Last Modified On : 02-25-2024 +// Last Modified On : 03-19-2024 // *********************************************************************** // // Mario @@ -14,20 +14,24 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; using System.Reactive; using System.Reactive.Disposables; using System.Reactive.Linq; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using Avalonia; using Avalonia.Collections; +using Avalonia.Media; using DynamicData; using IronyModManager.Common; using IronyModManager.Common.Events; using IronyModManager.Common.ViewModels; using IronyModManager.DI; using IronyModManager.Implementation.Actions; +using IronyModManager.Implementation.AvaloniaEdit; using IronyModManager.Implementation.Overlay; using IronyModManager.Implementation.Updater; using IronyModManager.Localization; @@ -46,6 +50,7 @@ namespace IronyModManager.ViewModels.Controls /// [ExcludeFromCoverage("This should be tested via functional testing.")] public class OptionsControlViewModel( + IConflictSolverColorsService conflictSolverColorsService, IGameLanguageService gameLanguageService, IAppAction appAction, IPlatformConfiguration platformConfiguration, @@ -68,6 +73,11 @@ public class OptionsControlViewModel( /// private readonly IAppAction appAction = appAction; + /// + /// A private readonly IConflictSolverColorsService named conflictSolverColorsService. + /// + private readonly IConflictSolverColorsService conflictSolverColorsService = conflictSolverColorsService; + /// /// The external editor service /// @@ -143,6 +153,11 @@ public class OptionsControlViewModel( /// private IDisposable closeGameChanged; + /// + /// The colors changed + /// + private IDisposable colorsChanged; + /// /// The editor arguments changed /// @@ -288,6 +303,47 @@ public class OptionsControlViewModel( /// The close command. public virtual ReactiveCommand CloseCommand { get; protected set; } + /// + /// Gets or sets the color. + /// + /// The color. + public virtual ConflictSolverColors Color { get; protected set; } + + /// + /// Gets or sets the conflict solver colors title. + /// + /// The conflict solver colors title. + [StaticLocalization(LocalizationResources.Options.ConflictSolver.Colors)] + public virtual string ConflictSolverColorsTitle { get; protected set; } + + /// + /// Gets or sets the conflict solver deleted line color text. + /// + /// The conflict solver deleted line color text. + [StaticLocalization(LocalizationResources.Options.ConflictSolver.ConflictSolverDeletedLineColor)] + public virtual string ConflictSolverDeletedLineColorText { get; protected set; } + + /// + /// Gets or sets the conflict solver imaginary line color text. + /// + /// The conflict solver imaginary line color text. + [StaticLocalization(LocalizationResources.Options.ConflictSolver.ConflictSolverImaginaryLineColor)] + public virtual string ConflictSolverImaginaryLineColorText { get; protected set; } + + /// + /// Gets or sets the conflict solver inserted line color text. + /// + /// The conflict solver inserted line color text. + [StaticLocalization(LocalizationResources.Options.ConflictSolver.ConflictSolverInsertedLineColor)] + public virtual string ConflictSolverInsertedLineColorText { get; protected set; } + + /// + /// Gets or sets the conflict solver modified line color text. + /// + /// The conflict solver modified line color text. + [StaticLocalization(LocalizationResources.Options.ConflictSolver.ConflictSolverModifiedLineColor)] + public virtual string ConflictSolverModifiedLineColorText { get; protected set; } + /// /// Gets or sets a value representing the conflict solver title. /// @@ -657,6 +713,30 @@ public virtual void ForceClose() IsOpen = false; } + /// + /// Binds the colors. + /// + protected virtual void BindColors() + { + var savedColors = conflictSolverColorsService.Get(); + Color?.Dispose(); + Color = new ConflictSolverColors(savedColors); + colorsChanged?.Dispose(); + colorsChanged = null; + + var col = new SourceList(); + col.Add(Color); + colorsChanged = col.Connect().WhenAnyPropertyChanged().Throttle(TimeSpan.FromMilliseconds(50)).Subscribe(s => + { + var entity = conflictSolverColorsService.Get(); + entity.ConflictSolverDeletedLineColor = s.ConflictSolverDeletedLineColor.ToString(); + entity.ConflictSolverModifiedLineColor = s.ConflictSolverModifiedLineColor.ToString(); + entity.ConflictSolverImaginaryLineColor = s.ConflictSolverImaginaryLineColor.ToString(); + entity.ConflictSolverInsertedLineColor = s.ConflictSolverInsertedLineColor.ToString(); + conflictSolverColorsService.Save(entity); + }).DisposeWith(Disposables); + } + /// /// Binds game languages. /// @@ -730,6 +810,7 @@ protected override void OnActivated(CompositeDisposable disposables) SetGame(gameService.GetSelected()); SetEditor(externalEditorService.Get()); SetNotificationPosition(positionSettingsService.Get()); + BindColors(); var updateSettings = updaterService.Get(); if (UpdatesAllowed) { @@ -1206,5 +1287,314 @@ protected virtual void SetUpdateSettings(IUpdateSettings updateSettings) } #endregion Methods + + #region Classes + + /// + /// Class ConflictSolverColors. + /// Implements the + /// + /// + public class ConflictSolverColors : INotifyPropertyChanged, IDisposable + { + #region Fields + + /// + /// The conflict solver deleted line brush + /// + private SolidColorBrush conflictSolverDeletedLineBrush; + + /// + /// The conflict solver deleted line color + /// + private Color conflictSolverDeletedLineColor; + + /// + /// A private SolidColorBrush named conflictSolverImaginaryLineBrush. + /// + private SolidColorBrush conflictSolverImaginaryLineBrush; + + /// + /// The conflict solver imaginary line color + /// + private Color conflictSolverImaginaryLineColor; + + /// + /// The conflict solver inserted line brush + /// + private SolidColorBrush conflictSolverInsertedLineBrush; + + /// + /// The conflict solver inserted line color + /// + private Color conflictSolverInsertedLineColor; + + /// + /// The conflict solver modified line brush + /// + private SolidColorBrush conflictSolverModifiedLineBrush; + + /// + /// The conflict solver modified line color + /// + private Color conflictSolverModifiedLineColor; + + #endregion Fields + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The colors. + public ConflictSolverColors(IConflictSolverColors colors) + { + var converter = new EditorColorConverter(colors); + ConflictSolverDeletedLineColor = converter.GetDeletedLineColor(); + ConflictSolverDeletedLineBrush = converter.GetDeletedLineBrush(); + + ConflictSolverImaginaryLineColor = converter.GetImaginaryLineColor(); + ConflictSolverImaginaryLineBrush = converter.GetImaginaryLineBrush(); + + ConflictSolverModifiedLineColor = converter.GetEditedLineColor(); + ConflictSolverModifiedLineBrush = converter.GetEditedLineBrush(); + + ConflictSolverInsertedLineColor = converter.GetInsertedLineColor(); + ConflictSolverInsertedLineBrush = converter.GetInsertedLineBrush(); + + ResetDeletedLineCommand = ReactiveCommand.Create(() => + { + SetNewDeletedColor(converter.GetDefaultDeletedLineColor()); + }); + + ResetImaginaryLineCommand = ReactiveCommand.Create(() => + { + SetNewImaginaryColor(converter.GetDefaultImaginaryLineColor()); + }); + + ResetInsertedLineCommand = ReactiveCommand.Create(() => + { + SetNewInsertedColor(converter.GetDefaultInsertedLineColor()); + }); + + ResetModifiedLineCommand = ReactiveCommand.Create(() => + { + SetNewEditedColor(converter.GetDefaultEditedLineColor()); + }); + } + + #endregion Constructors + + #region Events + + /// + /// Occurs when a property value changes. + /// + public event PropertyChangedEventHandler PropertyChanged; + + #endregion Events + + #region Properties + + /// + /// Gets or sets the conflict solver deleted line brush. + /// + /// The conflict solver deleted line brush. + public virtual SolidColorBrush ConflictSolverDeletedLineBrush + { + get => conflictSolverDeletedLineBrush; + set => SetField(ref conflictSolverDeletedLineBrush, value); + } + + /// + /// Gets or sets the color of the conflict solver deleted line. + /// + /// The color of the conflict solver deleted line. + public virtual Color ConflictSolverDeletedLineColor + { + get => conflictSolverDeletedLineColor; + protected set => SetNewDeletedColor(value); + } + + /// + /// Gets or sets the conflict solver imaginary line brush. + /// + /// The conflict solver imaginary line brush. + public virtual SolidColorBrush ConflictSolverImaginaryLineBrush + { + get => conflictSolverImaginaryLineBrush; + set => SetField(ref conflictSolverImaginaryLineBrush, value); + } + + /// + /// Gets or sets the color of the conflict solver imaginary line. + /// + /// The color of the conflict solver imaginary line. + public virtual Color ConflictSolverImaginaryLineColor + { + get => conflictSolverImaginaryLineColor; + protected set => SetNewImaginaryColor(value); + } + + /// + /// Gets or sets the conflict solver inserted line brush. + /// + /// The conflict solver inserted line brush. + public virtual SolidColorBrush ConflictSolverInsertedLineBrush + { + get => conflictSolverInsertedLineBrush; + set => SetField(ref conflictSolverInsertedLineBrush, value); + } + + /// + /// Gets or sets the color of the conflict solver inserted line. + /// + /// The color of the conflict solver inserted line. + public virtual Color ConflictSolverInsertedLineColor + { + get => conflictSolverInsertedLineColor; + protected set => SetNewInsertedColor(value); + } + + /// + /// Gets or sets the conflict solver modified line brush. + /// + /// The conflict solver modified line brush. + public virtual SolidColorBrush ConflictSolverModifiedLineBrush + { + get => conflictSolverModifiedLineBrush; + set => SetField(ref conflictSolverModifiedLineBrush, value); + } + + /// + /// Gets or sets the color of the conflict solver modified line. + /// + /// The color of the conflict solver modified line. + public virtual Color ConflictSolverModifiedLineColor + { + get => conflictSolverModifiedLineColor; + protected set => SetNewEditedColor(value); + } + + /// + /// Gets or sets the reset deleted line command. + /// + /// The reset deleted line command. + public ReactiveCommand ResetDeletedLineCommand { get; protected set; } + + /// + /// Gets or sets the reset imaginary line command. + /// + /// The reset imaginary line command. + public ReactiveCommand ResetImaginaryLineCommand { get; protected set; } + + /// + /// Gets or sets the reset inserted line command. + /// + /// The reset inserted line command. + public ReactiveCommand ResetInsertedLineCommand { get; protected set; } + + /// + /// Gets or sets the reset modified line command. + /// + /// The reset modified line command. + public ReactiveCommand ResetModifiedLineCommand { get; protected set; } + + #endregion Properties + + #region Methods + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + ResetInsertedLineCommand?.Dispose(); + ResetInsertedLineCommand = null; + ResetModifiedLineCommand?.Dispose(); + ResetModifiedLineCommand = null; + ResetDeletedLineCommand?.Dispose(); + ResetDeletedLineCommand = null; + ResetImaginaryLineCommand?.Dispose(); + ResetImaginaryLineCommand = null; + } + + /// + /// Called when [property changed]. + /// + /// Name of the property. + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + /// + /// Sets the field. + /// + /// + /// The field. + /// The value. + /// Name of the property. + /// true if XXXX, false otherwise. + protected bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, value)) return false; + field = value; + OnPropertyChanged(propertyName); + return true; + } + + /// + /// Sets a new deleted color. + /// + /// The value. + protected void SetNewDeletedColor(Color value) + { + if (SetField(ref conflictSolverDeletedLineColor, value, nameof(ConflictSolverDeletedLineColor))) + { + ConflictSolverDeletedLineBrush = new SolidColorBrush(ConflictSolverDeletedLineColor); + } + } + + /// + /// Sets a new edited color. + /// + /// The value. + protected void SetNewEditedColor(Color value) + { + if (SetField(ref conflictSolverModifiedLineColor, value, nameof(ConflictSolverModifiedLineColor))) + { + ConflictSolverModifiedLineBrush = new SolidColorBrush(ConflictSolverModifiedLineColor); + } + } + + /// + /// Sets a new imaginary color. + /// + /// The value. + protected void SetNewImaginaryColor(Color value) + { + if (SetField(ref conflictSolverImaginaryLineColor, value, nameof(ConflictSolverImaginaryLineColor))) + { + ConflictSolverImaginaryLineBrush = new SolidColorBrush(ConflictSolverImaginaryLineColor); + } + } + + /// + /// Sets a new inserted color. + /// + /// The value. + protected void SetNewInsertedColor(Color value) + { + if (SetField(ref conflictSolverInsertedLineColor, value, nameof(ConflictSolverInsertedLineColor))) + { + ConflictSolverInsertedLineBrush = new SolidColorBrush(ConflictSolverInsertedLineColor); + } + } + + #endregion Methods + } + + #endregion Classes } } diff --git a/src/IronyModManager/Views/Controls/OptionsControlView.xaml b/src/IronyModManager/Views/Controls/OptionsControlView.xaml index 6cf3c57a..e7f44069 100644 --- a/src/IronyModManager/Views/Controls/OptionsControlView.xaml +++ b/src/IronyModManager/Views/Controls/OptionsControlView.xaml @@ -5,6 +5,7 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" xmlns:controls="clr-namespace:IronyModManager.Controls;assembly=IronyModManager" xmlns:html="clr-namespace:Avalonia.Controls.Html;assembly=Avalonia.HtmlRenderer" + xmlns:colorPicker="clr-namespace:ThemeEditor.Controls.ColorPicker;assembly=ThemeEditor.Controls.ColorPicker" x:Class="IronyModManager.Views.Controls.OptionsControlView">