Skip to content

Commit

Permalink
Use a wrapper around the multistring accessor for the headword
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonleenaylor committed Jan 22, 2025
1 parent 0b07cb8 commit 00fff7d
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Src/xWorks/ConfiguredLcmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,13 @@ internal static IFragment GenerateContentForFieldByReflection(object field, Conf
#endif
return settings.ContentGenerator.CreateFragment();
}
propertyValue = GetValueFromMember(property, field);
// propertyValue = GetValueFromMember(property, field);
// This code demonstrates using the cache metadata,
// an alternative form of reflection to get values that respect the decorator
// We may be able to replace the GetValueFromMember above with this code, but the ownerClassName may take
// some work to determine
object backdoorProp = null;
var success = GetPropValueForCustomField(field, config, cache, publicationDecorator, "LexEntry",
property.Name, ref backdoorProp);
var success = GetPropValueForCustomField(field, config, cache, publicationDecorator,
((ICmObject)field).ClassName, property.Name, ref propertyValue);
GetSortedReferencePropertyValue(config, ref propertyValue, field);
}
// If the property value is null there is nothing to generate
Expand Down Expand Up @@ -581,6 +580,8 @@ private static IFragment GenerateContentForGroupingNode(object field, Configurab
private static bool GetPropValueForCustomField(object fieldOwner, ConfigurableDictionaryNode config,
LcmCache cache, ISilDataAccess decorator, string customFieldOwnerClassName, string customFieldName, ref object propertyValue)
{
if (decorator == null)
decorator = cache.DomainDataByFlid;
int customFieldFlid = GetCustomFieldFlid(config, cache, customFieldOwnerClassName, customFieldName);
if (customFieldFlid != 0)
{
Expand Down Expand Up @@ -644,7 +645,7 @@ private static bool GetPropValueForCustomField(object fieldOwner, ConfigurableDi
case (int)CellarPropertyType.MultiUnicode:
case (int)CellarPropertyType.MultiString:
{
propertyValue = cache.MainCacheAccessor.get_MultiStringProp(specificObject.Hvo, customFieldFlid);
propertyValue = decorator.get_MultiStringProp(specificObject.Hvo, customFieldFlid);
break;
}
case (int)CellarPropertyType.String:
Expand Down
87 changes: 87 additions & 0 deletions Src/xWorks/DictionaryPublicationDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ private string GetSenseNumber(ILexSense sense)
return Cache.GetOutlineNumber(sense, LexSenseTags.kflidSenses, false, true, this);
}

public override ITsMultiString get_MultiStringProp(int hvo, int tag)
{
if (tag == m_mlHeadwordFlid)
{
return new PublicationAwareMultiStringAccessor(hvo, tag, this);
}
return base.get_MultiStringProp(hvo, tag);
}

public override ITsString get_MultiStringAlt(int hvo, int tag, int ws)
{
if (tag == m_mlHeadwordFlid)
Expand Down Expand Up @@ -615,5 +624,83 @@ private bool IsPublishableReference(ILexEntryRef entryRef)
// A reference is also not publishable if all of its PrimarySensesOrEntries are excluded
return entryRef.PrimarySensesOrEntries.Any(senseOrEntry => !m_excludedItems.Contains(senseOrEntry.Item.Hvo));
}

private class PublicationAwareMultiStringAccessor : IMultiAccessorBase
{
private readonly int m_hvo;
private readonly int m_tag;
private readonly DictionaryPublicationDecorator m_decorator;

public PublicationAwareMultiStringAccessor(int hvo, int tag, DictionaryPublicationDecorator decorator)
{
m_hvo = hvo;
m_tag = tag;
m_decorator = decorator;
}

public ITsString GetStringFromIndex(int iws, out int _ws)
{
throw new NotImplementedException();
}

public ITsString get_String(int ws)
{
return m_decorator.get_MultiStringAlt(m_hvo, m_tag, ws);
}

public void set_String(int ws, ITsString _tss)
{
throw new NotImplementedException();
}

public int StringCount { get; }
public void SetAnalysisDefaultWritingSystem(string val)
{
throw new NotImplementedException();
}

public void SetVernacularDefaultWritingSystem(string val)
{
throw new NotImplementedException();
}

public void SetUserWritingSystem(string val)
{
throw new NotImplementedException();
}

public void set_String(int ws, string val)
{
throw new NotImplementedException();
}

public bool TryWs(int ws, out int actualWs)
{
throw new NotImplementedException();
}

public bool TryWs(int ws, out int actualWs, out ITsString tssActual)
{
throw new NotImplementedException();
}

public ITsString StringOrNull(int ws)
{
throw new NotImplementedException();
}

public int Flid { get; }
public ITsString NotFoundTss { get; }
public ITsString AnalysisDefaultWritingSystem { get; set; }
public ITsString VernacularDefaultWritingSystem { get; set; }
public string UiString { get; }
public ITsString UserDefaultWritingSystem { get; set; }
public ITsString RawUserDefaultWritingSystem { get; }
public ITsString BestAnalysisVernacularAlternative { get; }
public ITsString BestAnalysisAlternative { get; }
public ITsString BestVernacularAlternative { get; }
public ITsString BestVernacularAnalysisAlternative { get; }
public int[] AvailableWritingSystemIds { get; }
}
}
}

0 comments on commit 00fff7d

Please sign in to comment.