protected virtual bool CanInsert(Command command, Slice currentSlice, out int index)
{
index = -1;
if (currentSlice == null)
return false;
string fieldName;
string cmdClassName;
ExtractInsertCommandInfo(command, out fieldName, out cmdClassName);
string rootObjClassName = string.Empty;
var rootObj = currentSlice.ContainingDataTree.Root;
if (rootObj != null && !rootObj.IsValidObject)
return false;
try
{
if (rootObj != null)
rootObjClassName = rootObj.ClassName;
}
catch
{
}
// For a SubPossibilities insertion, the class associated with this field
// in the command node must match the class of the parentObject so that
// we filter out commands to insert an item into the wrong CmPossibility class.
// (If we need to do anything else exceptional for CmPossibilities try subclassing
// DTMenuHandler to handle these things. That requires a menuHandler node in the parameters
// for each of the tools based on a CmPossibility list.)
if (fieldName == "SubPossibilities")
{
// we can insert only if we are are inserting into the same class.
if (cmdClassName != rootObjClassName)
return false;
// we can insert only if the ContainingDataTree has a SubPossibilities slice
if(!currentSlice.ContainingDataTree.HasSubPossibilitiesSlice)
return false;
}
// "Insert Subsense" should be enabled only for Sense related slices, not for entry
// related slices. This isn't perfect, but behaves the same as "Insert Picture".
if (command.Id == "CmdInsertSubsense" && fieldName == "Senses")
{
if (currentSlice.Object != null && currentSlice.Object.IsValidObject)
return currentSlice.Object.ClassID == LexSenseTags.kClassId;
}
// First, see if the command can insert something that belongs to
// the current slice containing tree root object.
bool fCanInsert;
fCanInsert = CanInsertFieldIntoObj(Cache, fieldName, rootObj, out index);
// Otherwise, see if the command can insert something that belongs
// to the current slice object.
if (!fCanInsert && currentSlice.Object != rootObj)
{
fCanInsert = CanInsertFieldIntoObj(Cache, fieldName, currentSlice.Object, out index);
}
return fCanInsert;
}