public bool OnAddComponentToPrimary(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 = GetSelectedComponentHvo();
if (hvo == 0)
return true;
var ler = current.Object as ILexEntryRef;
var objForHvo = Cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvo);
if (ler.PrimaryLexemesRS.Contains(objForHvo))
{ // Remove from visibility array
using (UndoableUnitOfWorkHelper helper = new UndoableUnitOfWorkHelper(
Cache.ActionHandlerAccessor,
xWorksStrings.ksUndoShowSubentryForComponent,
xWorksStrings.ksRedoShowSubentryForComponent))
{
ler.PrimaryLexemesRS.Remove(objForHvo);
helper.RollBack = false;
}
return true;
}
// Otherwise, continue and add it
int idx = 0;
foreach (var obj in ler.ComponentLexemesRS)
{ // looping preserves the order of the components
if (obj == objForHvo)
{
using (UndoableUnitOfWorkHelper helper = new UndoableUnitOfWorkHelper(
Cache.ActionHandlerAccessor,
xWorksStrings.ksUndoShowSubentryForComponent,
xWorksStrings.ksRedoShowSubentryForComponent))
{
ler.PrimaryLexemesRS.Insert(idx, objForHvo);
helper.RollBack = false;
}
break;
}
if (ler.PrimaryLexemesRS.Contains(obj))
{
++idx;
}
}
return true;
}