-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial implementation of UpdateWritingSystemProxy
GUID Id vs string WsId is still an issue, as is the Font/Fonts issue.
- Loading branch information
Showing
3 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
backend/FwLite/FwDataMiniLcmBridge/Api/UpdateProxy/UpdateWritingSystemProxy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using MiniLcm.Models; | ||
using SIL.LCModel; | ||
using SIL.LCModel.Core.WritingSystems; | ||
using SIL.LCModel.DomainServices; | ||
|
||
namespace FwDataMiniLcmBridge.Api.UpdateProxy; | ||
|
||
public record UpdateWritingSystemProxy : WritingSystem | ||
{ | ||
private readonly CoreWritingSystemDefinition _origLcmWritingSystem; | ||
private readonly CoreWritingSystemDefinition _workingLcmWritingSystem; | ||
private readonly FwDataMiniLcmApi _lexboxLcmApi; | ||
|
||
public UpdateWritingSystemProxy(CoreWritingSystemDefinition lcmWritingSystem, FwDataMiniLcmApi lexboxLcmApi) | ||
{ | ||
_origLcmWritingSystem = lcmWritingSystem; | ||
_workingLcmWritingSystem = new CoreWritingSystemDefinition(lcmWritingSystem, cloneId: true); | ||
_lexboxLcmApi = lexboxLcmApi; | ||
} | ||
|
||
public void CommitUpdate(LcmCache cache) | ||
{ | ||
if (_workingLcmWritingSystem.Id == _origLcmWritingSystem.Id) | ||
{ | ||
cache.ServiceLocator.WritingSystemManager.Set(_workingLcmWritingSystem); | ||
} | ||
else | ||
{ | ||
// Changing the ID of a writing system requires LCM to do a lot of work, so only go through that process if absolutely required | ||
WritingSystemServices.MergeWritingSystems(cache, _workingLcmWritingSystem, _origLcmWritingSystem); | ||
} | ||
} | ||
|
||
public override required WritingSystemId WsId | ||
{ | ||
get => _workingLcmWritingSystem.Id; | ||
set => _workingLcmWritingSystem.Id = value; | ||
} | ||
|
||
public override required string Name | ||
{ | ||
get => _workingLcmWritingSystem.LanguageName; | ||
set { } // Silently do nothing; name should be derived from WsId at all times, so if the name should change then so should the WsId | ||
} | ||
|
||
public override required string Abbreviation | ||
{ | ||
get => _workingLcmWritingSystem.Abbreviation; | ||
set => _workingLcmWritingSystem.Abbreviation = value; | ||
} | ||
|
||
// TODO: Change WritingSystem Font property to be a list of strings instead of a single string, then do something like this | ||
// public override required List<string> Fonts | ||
// { | ||
// get => _workingLcmWritingSystem.Fonts.Select(f => f.Name).ToList(); | ||
// set => throw new NotImplementedException(); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters