public bool OnVisibleComplexForm(object argument)
{
Slice current = m_dataEntryForm.CurrentSlice;
if (current == null || current.Object == null || current.Flid == 0)
return true; // already handled - nothing else should be responding to this message
int hvo = GetSelectedComplexFormHvo(current);
if (hvo == 0)
return true;
ICmObject le = current.Object; // can be ILexEntry or ILexSense
var cplxForm = Cache.ServiceLocator.GetInstance<ILexEntryRepository>().GetObject(hvo);
ILexEntryRef cfRef;
if (ComponentShowsComplexForm(le, cplxForm, out cfRef))
{
// Remove from visibility array
using (var helper = new UndoableUnitOfWorkHelper(
Cache.ActionHandlerAccessor,
xWorksStrings.ksUndoVisibleComplexForm,
xWorksStrings.ksRedoVisibleComplexForm))
{
cfRef.ShowComplexFormsInRS.Remove(le);
helper.RollBack = false;
}
return true;
}
// Otherwise, continue and add it
int idx = 0;
foreach (var obj in cfRef.ComponentLexemesRS)
{
// looping preserves the order of the components
if (obj == le)
{
using (var helper = new UndoableUnitOfWorkHelper(
Cache.ActionHandlerAccessor,
xWorksStrings.ksUndoVisibleComplexForm,
xWorksStrings.ksRedoVisibleComplexForm))
{
cfRef.ShowComplexFormsInRS.Insert(idx, le);
helper.RollBack = false;
}
break;
}
if (cfRef.ShowComplexFormsInRS.Contains(obj))
{
++idx;
}
}
return true;
}