Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net8windows keyboarding and writing systems #1366

Merged
merged 7 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions SIL.Windows.Forms.Keyboarding.Tests/KeyboardControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@
using System.Globalization;
using NUnit.Framework;
using SIL.Keyboarding;
using Rhino.Mocks;
using Moq;

namespace SIL.Windows.Forms.Keyboarding.Tests
{
[TestFixture]
public class KeyboardControllerTests
{
private IKeyboardRetrievingAdaptor _mockKeyboardAdaptor = MockRepository.GenerateMock<IKeyboardRetrievingAdaptor>();
private Mock<IKeyboardRetrievingAdaptor> _mockKeyboardAdaptor = new Mock<IKeyboardRetrievingAdaptor>();

[SetUp]
public void Setup()
{
// To avoid OS specific behavior in these tests we mock up our own keyboard adaptor returning appropriate values to enable these tests
_mockKeyboardAdaptor.Stub(k => k.IsApplicable).Return(true);
_mockKeyboardAdaptor.Stub(k => k.Type).Return(KeyboardAdaptorType.System);
_mockKeyboardAdaptor.Stub(k => k.CanHandleFormat(KeyboardFormat.Unknown)).Return(true);
_mockKeyboardAdaptor.Stub(k => k.CreateKeyboardDefinition(Arg<string>.Is.Anything)).Return(null) // will be ignored but still the API requires it
.WhenCalled(k =>
_mockKeyboardAdaptor.Setup(k => k.IsApplicable).Returns(true);
_mockKeyboardAdaptor.Setup(k => k.Type).Returns(KeyboardAdaptorType.System);
_mockKeyboardAdaptor.Setup(k => k.CanHandleFormat(KeyboardFormat.Unknown)).Returns(true);
_mockKeyboardAdaptor.Setup(k => k.CreateKeyboardDefinition(It.IsAny<string>())).Returns<string>(
id =>
{
var id = (string)k.Arguments[0];
var idParts = id.Split('_');
var mockKd = new MockKeyboardDescription(id, idParts[0], idParts[1]);
k.ReturnValue = mockKd;
return mockKd;
});
KeyboardController.Initialize(_mockKeyboardAdaptor);
KeyboardController.Initialize(_mockKeyboardAdaptor.Object);
}

[TearDown]
Expand Down Expand Up @@ -118,7 +117,7 @@ public void GetKeyboard_FromInputLanguage_NonExistingKeyboard()
}

/// <summary>
/// This mock (less code than a Rhino.Mocks version) provides sufficient IKeyboardDefinition for testing the KeyboardController
/// This mock provides sufficient IKeyboardDefinition for testing the KeyboardController
/// </summary>
private class MockKeyboardDescription : KeyboardDescription
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<RootNamespace>SIL.Windows.Forms.Keyboarding.Tests</RootNamespace>
<AssemblyTitle>SIL.Windows.Forms.Keyboarding.Tests</AssemblyTitle>
<Description>Unit tests for SIL.Windows.Forms.Keyboarding</Description>
<TargetFrameworks>$(TargetFrameworks);net8.0-windows</TargetFrameworks>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

Expand All @@ -16,7 +17,6 @@
<PackageReference Include="NDesk.DBus" Version="0.15.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" PrivateAssets="All" />
<PackageReference Include="RhinoMocks" Version="3.6.1" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

Expand All @@ -25,8 +25,27 @@
<ProjectReference Include="..\SIL.Windows.Forms.Keyboarding\SIL.Windows.Forms.Keyboarding.csproj" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition=" $(DefineConstants.Contains('NETFRAMEWORK')) ">
<Reference Include="System.Windows.Forms" />
</ItemGroup>

<!-- explicitly remove Linux files for Windows -->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
<Compile Remove="TestHelper\GnomeKeyboardRetrievingHelperDouble.cs" />
<Compile Remove="TestHelper\GnomeShellIbusKeyboardRetrievingAdaptorDouble.cs" />
<Compile Remove="CombinedIbusKeyboardRetrievingAdaptorTests.cs" />
<Compile Remove="CombinedIbusKeyboardSwitchingAdaptorTests.cs" />
<Compile Remove="GnomeKeyboardRetrievingHelperTests.cs" />
<Compile Remove="GnomeShellIbusKeyboardRetrievingAdaptorTests.cs" />
<Compile Remove="GnomeShellIbusKeyboardSwitchingAdaptorTests.cs" />
<Compile Remove="IbusDefaultEventHandlerTests.cs" />
<Compile Remove="IbusKeyboardAdaptorTests.cs" />
<Compile Remove="IbusKeyboardDescriptionTests.cs" />
<Compile Remove="IbusXkbKeyboardDescriptionTests.cs" />
<Compile Remove="LinuxKeyboardControllerTests.cs" />
<Compile Remove="UnityKeyboardRetrievingHelperTests.cs" />
<Compile Remove="XkbKeyboardAdapterTests.cs" />
<Compile Remove="XklEngineTests.cs" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions SIL.Windows.Forms.Keyboarding/KeyboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
using SIL.ObjectModel;
using SIL.PlatformUtilities;
using SIL.Reporting;
#if NETFRAMEWORK
using SIL.Windows.Forms.Keyboarding.Linux;
#endif
using SIL.Windows.Forms.Keyboarding.Windows;

namespace SIL.Windows.Forms.Keyboarding
Expand Down Expand Up @@ -217,10 +219,12 @@ private void SetDefaultKeyboardAdaptors()
}
: new IKeyboardRetrievingAdaptor[]
{
#if NETFRAMEWORK
new XkbKeyboardRetrievingAdaptor(), new IbusKeyboardRetrievingAdaptor(),
new UnityXkbKeyboardRetrievingAdaptor(), new UnityIbusKeyboardRetrievingAdaptor(),
new CombinedIbusKeyboardRetrievingAdaptor(),
new GnomeShellIbusKeyboardRetrievingAdaptor()
#endif
}
);
}
Expand Down
15 changes: 13 additions & 2 deletions SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
<RootNamespace>SIL.Windows.Forms.Keyboarding</RootNamespace>
<AssemblyTitle>SIL.Windows.Forms.Keyboarding</AssemblyTitle>
<Description>The SIL.Windows.Forms.Keyboarding library provides cross-platform functionality for keyboard selection and switching in Windows Forms applications. Currently, this library supports system and Keyman keyboards on Windows, and X keyboard extension (XKB) and Intelligent Input Bus (IBus) keyboards on Linux.</Description>
<TargetFrameworks>$(TargetFrameworks);net8.0-windows</TargetFrameworks>
</PropertyGroup>

<ItemGroup Condition=" !$(DefineConstants.Contains('NETFRAMEWORK')) ">
<Content Remove="Linux\**" />
<Compile Remove="Linux\**" />
<EmbeddedResource Remove="Linux\**" />
<None Remove="Linux\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
<PackageReference Include="ibusdotnet" Version="2.0.3" />
Expand All @@ -23,6 +31,11 @@
<ProjectReference Include="..\SIL.Core\SIL.Core.csproj" />
</ItemGroup>

<ItemGroup Condition=" $(DefineConstants.Contains('NETFRAMEWORK')) ">
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>

<ItemGroup>
<Reference Include="Keyman10Interop">
<HintPath>..\lib\Keyman10Interop.dll</HintPath>
Expand All @@ -33,8 +46,6 @@
<Reference Include="KeymanLink">
<HintPath>..\lib\KeymanLink.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<None Include="../lib/Keyman*.dll">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<IsPackable>false</IsPackable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>$(TargetFrameworks);net8.0-windows</TargetFrameworks>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<RootNamespace>SIL.Windows.Forms.WritingSystems</RootNamespace>
<AssemblyTitle>SIL.Windows.Forms.WritingSystems</AssemblyTitle>
<Description>SIL.Windows.Forms.WritingSystems contains Windows Forms UI elements for displaying and editing writing systems as defined by the SIL.WritingSystems assembly.</Description>
<TargetFrameworks>$(TargetFrameworks);net8.0-windows</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
</PropertyGroup>
Expand Down
22 changes: 12 additions & 10 deletions SIL.Windows.Forms/ImageToolbox/PalasoImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ public Metadata Metadata

private string _originalFilePath;


/// <summary>
/// If false, you get a debug.Fail(). If true, you get a throw.
/// </summary>
public static bool ThrowOnFailureToDisposeAnyPalasoImage = false;

/// <summary>
/// If the object isn't disposed, the resulting message will give this label.
/// If the object isn't disposed, the resulting message will give this label.
/// This can help trace where it was created.
/// </summary>
public string LabelForDebugging = "unlabeled";

/// <summary>
/// Generally, when we load an image, we can happily forget where it came from, because
/// the nature of the palaso image system is to deliver images, not file paths, to documents
/// (we don't believe in "linking" to files somewhere on the disk which is just asking for problems
/// as the document is shared).
/// But in one circumstance, we do care: when the user chooses from disk (as opposed to from camera or scanner)
/// and enters metadata, we want to store that metadata in the original.
/// and enters metadata, we want to store that metadata in the original.
/// However, there is one circumstance (currently) in which this is not the original path:
/// If we attempt to save metadata and can't (e.g. file is readonly), we create a temp file and
/// If we attempt to save metadata and can't (e.g. file is readonly), we create a temp file and
/// store the metadata there, then serve the temp file to the requester. That's why we store this path.
/// </summary>
private string _pathForSavingMetadataChanges;
Expand Down Expand Up @@ -142,7 +142,7 @@ public static string FileExtForWebFormat(string fileExtension)
var format = GetImageFormatForExtension(fileExtension);
return format == ImageFormat.Jpeg ? ".jpg" : ".png";
}

private void SaveInFormat(string path, ImageFormat format)
{
ThrowIfDisposedOfAlready();
Expand Down Expand Up @@ -212,12 +212,12 @@ private static ImageFormat GetImageFormatForExtension(string fileExtension)
throw new NotImplementedException();
}
}


/// <summary>
/// If you edit the metadata, call this. If it happens to have an actual file associated, it will save it.
/// If not (e.g. the image came from a scanner), it won't do anything.
///
///
/// Warning. Don't use this on original images. See https://jira.sil.org/browse/BL-1001.
/// </summary>
public void SaveUpdatedMetadataIfItMakesSense()
Expand Down Expand Up @@ -252,7 +252,7 @@ private static string GetCorrectImageExtension(string path)
file.Read(bytes, 0, 10);
}
}, memo:$"PalasoImage.GetCorrectImageExtension({path})");
// see http://www.mikekunz.com/image_file_header.html
// see http://www.mikekunz.com/image_file_header.html
var bmp = Encoding.ASCII.GetBytes("BM"); // BMP
var gif = Encoding.ASCII.GetBytes("GIF"); // GIF
var png = new byte[] { 137, 80, 78, 71 }; // PNG
Expand Down Expand Up @@ -326,8 +326,10 @@ private static Image LoadImageWithoutLocking(string path, out string tempPath)
// assume it's a better indication of the problem.
var metadata = Metadata.FromFile(path);
if (metadata.IsOutOfMemoryPlausible(e))
#pragma warning disable CA2200
// ReSharper disable once PossibleIntendedRethrow
throw e; // Deliberately NOT just "throw", that loses the extra information IsOutOfMemoryPlausible added to the exception.
#pragma warning restore CA2200
throw new TagLib.CorruptFileException("File could not be read and is possible corrupted", e);
}
}
Expand Down
Loading