private bool IsItemEligible(ISilDataAccess sda, int hvo, ICmObject selectedObject, string labelToShow)
{
bool fEnable = false;
if (string.IsNullOrEmpty(labelToShow))
return fEnable;
int hvoFeats = sda.get_ObjectProp(hvo, PhPhonemeTags.kflidFeatures);
if (hvoFeats == 0)
return true; // phoneme does not have any features yet, so it is eligible
var feats = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvoFeats);
int clsid = feats.ClassID;
if (clsid == FsFeatStrucTags.kClassId)
{
// Only show it as a change if it is different
var features = feats as IFsFeatStruc;
switch (selectedObject.ClassID)
{
case FsSymFeatValTags.kClassId: // user has chosen a value for the targeted feature
var symFeatVal = selectedObject as IFsSymFeatVal;
if (symFeatVal != null && features != null)
{
var closedValue = from s in features.FeatureSpecsOC
where s.ClassID == FsClosedValueTags.kClassId &&
((IFsClosedValue) s).ValueRA == symFeatVal
select s;
fEnable = !closedValue.Any();
}
break;
case FsFeatStrucTags.kClassId: // user has specified one or more feature/value pairs
var fs = selectedObject as IFsFeatStruc;
if (fs != null)
{
var closedValue = from s in features.FeatureSpecsOC
where s.ClassID == FsClosedValueTags.kClassId &&
s.FeatureRA.Abbreviation.BestAnalysisAlternative.Text == m_featDefnAbbr &&
((IFsClosedValue) s).ValueRA.Abbreviation.BestAnalysisAlternative.Text == labelToShow
select s;
fEnable = !closedValue.Any();
}
break;
case FsClosedFeatureTags.kClassId: // user has chosen the remove targeted feature option
var closedFeature = selectedObject as IFsClosedFeature;
if (closedFeature != null)
{
var closedFeatures = from s in features.FeatureSpecsOC
where s.FeatureRA == closedFeature
select s;
fEnable = closedFeatures.Any();
}
break;
default:
fEnable = hvoFeats != SelectedHvo;
break;
}
}
return fEnable;
}
}