void LaunchChooseFromMasterCategoryListOnIdle(object sender, EventArgs e) { Application.Idle -= LaunchChooseFromMasterCategoryListOnIdle; // now being handled // now launch the dialog using (MasterCategoryListDlg dlg = new MasterCategoryListDlg()) { dlg.SetDlginfo(CategoryList, m_mediator, m_propertyTable, false, null); switch (dlg.ShowDialog(m_parentOfPopupMgr)) { case DialogResult.OK: var sandboxMsa = new SandboxGenericMSA(); sandboxMsa.MainPOS = dlg.SelectedPOS; sandboxMsa.MsaType = m_sense.GetDesiredMsaType(); UndoableUnitOfWorkHelper.Do(String.Format(LexTextControls.ksUndoSetX, FieldName), String.Format(LexTextControls.ksRedoSetX, FieldName), m_sense, () => { m_sense.SandboxMSA = sandboxMsa; }); // Under certain circumstances (LT-11548) 'this' was disposed during the EndUndotask above! // That's why we're now launching this on idle. // Here's hoping we can get away without doing this! (It doesn't seem to make a difference.) //LoadPopupTree(m_sense.MorphoSyntaxAnalysisRA.Hvo); // everything should be setup with new node selected, so return. break; case DialogResult.Yes: // represents a click on the link to create a new Grammar Category. // Post a message so that we jump to Grammar(area)/Categories tool. // Do this before we close any parent dialog in case // the parent wants to check to see if such a Jump is pending. // NOTE: We use PostMessage here, rather than SendMessage which // disposes of the PopupTree before we and/or our parents might // be finished using it (cf. LT-2563). m_mediator.PostMessage("FollowLink", new FwLinkArgs("posEdit", dlg.SelectedPOS.Guid)); if (m_parentOfPopupMgr != null && m_parentOfPopupMgr.Modal) { // Close the dlg that opened the master POS dlg, // since its hotlink was used to close it, // and a new POS has been created. m_parentOfPopupMgr.DialogResult = DialogResult.Cancel; m_parentOfPopupMgr.Close(); } break; default: // NOTE: If the user has selected "Cancel", then don't change // our m_lastConfirmedNode to the "More..." node. Keep it // the value set by popupTree_PopupTreeClosed() when we // called pt.Hide() above. (cf. comments in LT-2522) break; } } }
/// <summary> /// NOTE that this implementation IGNORES hvoTarget and selects the MSA indicated by the sense. /// </summary> /// <param name="popupTree"></param> /// <param name="hvoTarget"></param> /// <returns></returns> 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; 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, 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(TsStringUtils.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(TsStringUtils.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(TsStringUtils.MakeString(m_sSpecifyDifferent, Cache.WritingSystemFactory.UserWs), kCreate)); } } return(match); }