protected override TreeNode MakeMenuItems(PopupTree popupTree, int hvoTarget)
{
Debug.Assert(m_sense != null);
hvoTarget = m_sense.MorphoSyntaxAnalysisRA == null ? 0 : m_sense.MorphoSyntaxAnalysisRA.Hvo;
TreeNode match = null;
ITsStrFactory tsf = Cache.TsStrFactory;
bool fStem = m_sense.GetDesiredMsaType() == MsaType.kStem;
if (fStem /*m_sense.Entry.MorphoSyntaxAnalysesOC.Count != 0*/)
{
// We want the order to be:
// 1. current msa items
// 2. possible Parts of Speech
// 3. "not sure" items
// We also want the Parts of Speech to be sorted, but not the whole tree.
// First add the part of speech items (which may be a tree...).
int tagName = CmPossibilityTags.kflidName;
// make sure they are sorted
popupTree.Sorted = true;
AddNodes(popupTree.Nodes, List.Hvo,
CmPossibilityListTags.kflidPossibilities, 0, tagName);
// reset the sorted flag - we only want the parts of speech to be sorted.
popupTree.Sorted = false;
// Remember the (sorted) nodes in an array (so we can use the AddRange() method).
TreeNode[] posArray = new TreeNode[popupTree.Nodes.Count];
popupTree.Nodes.CopyTo(posArray, 0);
// now clear out the nodes so we can get the order we want
popupTree.Nodes.Clear();
// Add the existing MSA items for the sense's owning entry.
foreach (var msa in m_sense.Entry.MorphoSyntaxAnalysesOC)
{
HvoTreeNode node = AddTreeNodeForMsa(popupTree, tsf, msa);
if (msa.Hvo == hvoTarget)
match = node;
}
AddTimberLine(popupTree);
// now add the sorted parts of speech
popupTree.Nodes.AddRange(posArray);
AddTimberLine(popupTree);
// 1. "<Not Sure>" to produce a negligible Msa reference.
// 2. "More..." command to launch category chooser dialog.
TreeNode empty = AddNotSureItem(popupTree);
if (match == null)
match = empty;
AddMoreItem(popupTree);
}
else
{
int cMsa = m_sense.Entry.MorphoSyntaxAnalysesOC.Count;
if (cMsa == 0)
{
// 1. "<Not Sure>" to produce a negligible Msa reference.
// 2. "Specify..." command.
//Debug.Assert(hvoTarget == 0);
match = AddNotSureItem(popupTree);
popupTree.Nodes.Add(new HvoTreeNode(Cache.TsStrFactory.MakeString(m_sSpecifyGramFunc, Cache.WritingSystemFactory.UserWs), kCreate));
}
else
{
// 1. Show the current Msa at the top.
// 2. "Modify ..." command.
// 3. Show other existing Msas next (if any).
// 4. <Not Sure> to produce a negligible Msa reference.
// 5. "Specify different..." command.
hvoTarget = 0;
// We should always have an MSA assigned to every sense, but sometimes this
// hasn't happened. Don't crash if the data isn't quite correct. See FWR-3090.
if (m_sense.MorphoSyntaxAnalysisRA != null)
hvoTarget = m_sense.MorphoSyntaxAnalysisRA.Hvo;
if (hvoTarget != 0)
{
ITsString tssLabel = m_sense.MorphoSyntaxAnalysisRA.InterlinearNameTSS;
HvoTreeNode node = new HvoTreeNode(tssLabel, hvoTarget);
popupTree.Nodes.Add(node);
match = node;
popupTree.Nodes.Add(new HvoTreeNode(Cache.TsStrFactory.MakeString(m_sModifyGramFunc, Cache.WritingSystemFactory.UserWs), kModify));
AddTimberLine(popupTree);
}
int cMsaExtra = 0;
foreach (var msa in m_sense.Entry.MorphoSyntaxAnalysesOC)
{
if (msa.Hvo == hvoTarget)
continue;
ITsString tssLabel = msa.InterlinearNameTSS;
HvoTreeNode node = new HvoTreeNode(tssLabel, msa.Hvo);
popupTree.Nodes.Add(node);
++cMsaExtra;
}
if (cMsaExtra > 0)
AddTimberLine(popupTree);
// Per final decision on LT-5084, don't want <not sure> for affixes.
//TreeNode empty = AddNotSureItem(popupTree, hvoTarget);
//if (match == null)
// match = empty;
popupTree.Nodes.Add(new HvoTreeNode(Cache.TsStrFactory.MakeString(m_sSpecifyDifferent, Cache.WritingSystemFactory.UserWs), kCreate));
}
}
return match;
}