/// <summary> /// /// </summary> /// <param name="nodes"></param> /// <param name="hvoOwner"></param> /// <param name="flid"></param> /// <param name="flidSub">specify a subitems, /// other than CmPossibilityTags.kflidSubPossibilities</param> /// <param name="hvoTarget"></param> /// <param name="tagName"></param> /// <returns></returns> protected TreeNode AddNodes(TreeNodeCollection nodes, int hvoOwner, int flid, int flidSub, int hvoTarget, int tagName) { TreeNode result = null; int chvo = Cache.MainCacheAccessor.get_VecSize(hvoOwner, flid); for (int i = 0; i < chvo; i++) { int hvoChild = Cache.MainCacheAccessor.get_VecItem(hvoOwner, flid, i); ITsString tssLabel = WritingSystemServices.GetMagicStringAlt(Cache, WritingSystemServices.kwsFirstAnalOrVern, hvoChild, tagName); if (tssLabel == null) { tssLabel = TsStringUtils.MakeTss(LexTextControls.ksStars, Cache.WritingSystemFactory.UserWs); } HvoTreeNode node = new HvoTreeNode(tssLabel, hvoChild); nodes.Add(node); TreeNode temp = AddNodes(node.Nodes, hvoChild, flidSub, flidSub, hvoTarget, tagName); if (hvoChild == hvoTarget) { result = node; } else if (temp != null) { result = temp; } } return(result); }
/// <summary> /// /// </summary> /// <param name="nodes"></param> /// <param name="hvoOwner"></param> /// <param name="flid"></param> /// <param name="flidSub">specify a subitems, /// other than CmPossibilityTags.kflidSubPossibilities</param> /// <param name="hvoTarget"></param> /// <param name="tagName"></param> /// <returns></returns> protected TreeNode AddNodes(TreeNodeCollection nodes, int hvoOwner, int flid, int flidSub, int hvoTarget, int tagName) { TreeNode result = null; int chvo = Cache.MainCacheAccessor.get_VecSize(hvoOwner, flid); for (int i = 0; i < chvo; i++) { int hvoChild = Cache.MainCacheAccessor.get_VecItem(hvoOwner, flid, i); ITsString tssLabel = GetTssLabel(Cache, hvoChild, tagName, WritingSystem); HvoTreeNode node = new HvoTreeNode(tssLabel, hvoChild); nodes.Add(node); TreeNode temp = AddNodes(node.Nodes, hvoChild, flidSub, flidSub, hvoTarget, tagName); if (hvoChild == hvoTarget) { result = node; } else if (temp != null) { result = temp; } } return(result); }
protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; // Launch dialog only by a mouse click (or simulated mouse click). if (selectedNode != null && selectedNode.Hvo == kMore && e.Action == TreeViewAction.ByMouse) { ChooseFromMasterCategoryList(); } else if (selectedNode != null && selectedNode.Hvo == kCreate && e.Action == TreeViewAction.ByMouse) { if (AddNewMsa()) { return; } } else if (selectedNode != null && selectedNode.Hvo == kModify && e.Action == TreeViewAction.ByMouse) { if (EditExistingMsa()) { return; } } else if (selectedNode != null && selectedNode.Hvo == kEmpty && e.Action == TreeViewAction.ByMouse) { SwitchToEmptyMsa(); return; } base.m_treeCombo_AfterSelect(sender, e); }
protected override TreeNode MakeMenuItems(PopupTree popupTree, int hvoTarget) { int tagNamePOS = UseAbbr ? (int)CmPossibility.CmPossibilityTags.kflidAbbreviation : (int)CmPossibility.CmPossibilityTags.kflidName; List<HvoTreeNode> relevantPartsOfSpeech = new List<HvoTreeNode>(); InflectionClassPopupTreeManager.GatherPartsOfSpeech(Cache, List.Hvo, (int)CmPossibilityList.CmPossibilityListTags.kflidPossibilities, (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities, (int)PartOfSpeech.PartOfSpeechTags.kflidInflectableFeats, tagNamePOS, WritingSystem, relevantPartsOfSpeech); relevantPartsOfSpeech.Sort(); TreeNode match = null; foreach(HvoTreeNode item in relevantPartsOfSpeech) { popupTree.Nodes.Add(item); IPartOfSpeech pos = (IPartOfSpeech)PartOfSpeech.CreateFromDBObject(Cache, item.Hvo, false); foreach(IFsFeatStruc fs in pos.ReferenceFormsOC) { // Note: beware of using fs.ShortName. That can be // absolutely EMPTY (if the user has turned off the 'Show Abbreviation as its label' // field for both the feature category and value). // ChooserName shows the short name if it is non-empty, otherwise the long name. HvoTreeNode node = new HvoTreeNode(fs.ChooserNameTS, fs.Hvo); item.Nodes.Add(node); if (fs.Hvo == hvoTarget) match = node; } item.Nodes.Add(new HvoTreeNode(Cache.MakeUserTss(LexTextControls.ksChooseInflFeats), kMore)); } return match; }
/// <summary> /// Add a 'not sure' item to the menu. If the current target is zero, it will be selected. /// It is saved as m_kEmptyNode. Also returns the new node. /// </summary> /// <param name="popupTree"></param> /// <param name="hvoTarget"></param> /// <returns></returns> protected TreeNode AddNotSureItem(PopupTree popupTree) { HvoTreeNode empty = new HvoTreeNode(Cache.TsStrFactory.MakeString(LexTextControls.ks_NotSure_, Cache.WritingSystemFactory.UserWs), kEmpty); popupTree.Nodes.Add(empty); m_kEmptyNode = empty; return(empty); }
/// <summary> /// Add an 'Any' item to the menu. If the current target is zero, it will be selected. /// It is saved as m_kEmptyNode. Also returns the new node. /// </summary> /// <param name="popupTree"></param> /// <param name="hvoTarget"></param> /// <returns></returns> protected TreeNode AddAnyItem(PopupTree popupTree, int hvoTarget) { HvoTreeNode empty = new HvoTreeNode(Cache.MakeUserTss(LexTextControls.ksAny), kEmpty); popupTree.Nodes.Add(empty); m_kEmptyNode = empty; return(empty); }
/// <summary> /// Add an 'Any' item to the menu. If the current target is zero, it will be selected. /// It is saved as m_kEmptyNode. Also returns the new node. /// </summary> protected TreeNode AddAnyItem(PopupTree popupTree) { HvoTreeNode empty = new HvoTreeNode( TsStringUtils.MakeString(LexTextControls.ksAny, Cache.WritingSystemFactory.UserWs), kEmpty); popupTree.Nodes.Add(empty); m_kEmptyNode = empty; return(empty); }
private void m_treeCombo_BeforeSelect(object sender, TreeViewCancelEventArgs e) { HvoTreeNode newSelNode = (HvoTreeNode)e.Node; PopupTree pt = GetPopupTree(); if (pt == null) { return; // can't do anything without the tree! See LT-9031. } m_selPrior = (m_treeCombo == null) ? pt.SelectedNode : m_treeCombo.SelectedNode; switch (newSelNode.Hvo) { case kLine: e.Cancel = true; // It may be selected by keyboard action, which needs more care. if (e.Action == TreeViewAction.ByKeyboard) { // Select the next/previous one, rather than the line. HvoTreeNode oldSelNode = pt.SelectedNode as HvoTreeNode; if (oldSelNode != null) { if (oldSelNode == newSelNode.NextNode && newSelNode.PrevNode != null) //if (oldSelNode.Hvo == kEmpty && newSelNode.PrevNode != null) { // Up Arrow probably used. // Select node above the line in the tree view. pt.SelectedNode = newSelNode.PrevNode; } else if (newSelNode.NextNode != null) { // Down Arrow probably used. // Select <empty> POS. pt.SelectedNode = newSelNode.NextNode; } else { Debug.Assert(false); // multiple adjacent empty (separator line) nodes, or nothing else?? } } } break; /* Nothing special to do, since it is handled as a normal POS. * case kEmpty: * PopupTree.OldSelectedNode = PopupTree.SelectedNode; * //m_treeCombo.Tree.SelectedNode = null; * break; */ } if (BeforeSelect != null) { BeforeSelect(this, e); } }
private HvoTreeNode AddTreeNodeForMsa(PopupTree popupTree, ITsStrFactory tsf, IMoMorphSynAnalysis msa) { // JohnT: as described in LT-4633, a stem can be given an allomorph that // is an affix. So we need some sort of way to handle this. //Debug.Assert(msa is MoStemMsa); ITsString tssLabel = msa.InterlinearNameTSS; if (msa is IMoStemMsa && (msa as IMoStemMsa).PartOfSpeechRAHvo == 0) tssLabel = tsf.MakeString(m_sUnknown, Cache.DefaultUserWs); HvoTreeNode node = new HvoTreeNode(tssLabel, msa.Hvo); popupTree.Nodes.Add(node); return node; }
protected override TreeNode MakeMenuItems(PopupTree popupTree, int hvoTarget) { TreeNode match = null; // We need a way to store feature structures the user has chosen during this session. // We use an annotation to do this. foreach (ICmBaseAnnotation cba in m_annotations) { IFsFeatStruc fs = cba.FeaturesOA; if (fs == null || fs.IsEmpty) { continue; } if (cba.BeginObjectRA != null) { continue; // is not one of the feature structures created via the phon feat chooser } HvoTreeNode node = new HvoTreeNode(fs.LongNameTSS, fs.Hvo); popupTree.Nodes.Add(node); if (fs.Hvo == hvoTarget) { match = node; } } if (ClosedFeature != null) { var sortedVaues = from v in ClosedFeature.ValuesOC orderby v.Abbreviation.BestAnalysisAlternative.Text select v; foreach (var closedValue in sortedVaues) { HvoTreeNode node = new HvoTreeNode(closedValue.Abbreviation.BestAnalysisAlternative, closedValue.Hvo); popupTree.Nodes.Add(node); if (closedValue.Hvo == hvoTarget) { match = node; } } } popupTree.Nodes.Add(new HvoTreeNode( Cache.TsStrFactory.MakeString(LexTextControls.ksRemoveThisFeature, Cache.WritingSystemFactory.UserWs), kRemoveThisFeature)); /* Trying this now without using the phonological feature chooser; if users ask for it, will reconsider. * popupTree.Nodes.Add(new HvoTreeNode( * Cache.TsStrFactory.MakeString(LexTextControls.ksChoosePhonFeats, Cache.WritingSystemFactory.UserWs), * kChoosePhonologicaFeatures));*/ return(match); }
/// <summary> /// Override this to handle any special items like 'More...'. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; if (selectedNode == null) { return; // User moved highlight off any item and hit enter; ignore. } PopupTree pt = GetPopupTree(); if (e.Action == TreeViewAction.ByMouse) { // bookmark this confirmed selection - required before PopupTree.Hide() // (cf. comments in LT-2522) if (pt != null) { m_lastConfirmedNode = (HvoTreeNode)pt.SelectedNode; } } // Pass on the event to owners/clients and close the PopupTree, only if it has been confirmed // "ByMouse" (or simulated mouse event). This will ensure that the user can use the keyboard // to move to items in the list, without actually affecting their previous selection until they // CONFIRM it "ByMouse" which can happen by clicking or by pressing ENTER. This allows the user // to ESCape there movement and revert to previously confirmed selection. (cf. comments in LT-2522) if (e.Action == TreeViewAction.ByMouse) { // If we are managing a treeCombo, then go ahead and set its Text in case the owner // does not want to do so in the AfterSelect below. if (m_treeCombo != null) { if (m_treeCombo.Text != m_lastConfirmedNode.Text) { m_treeCombo.Tss = m_lastConfirmedNode.Tss; } } if (AfterSelect != null) { AfterSelect(this, new TreeViewEventArgs(m_lastConfirmedNode, e.Action)); } // Close the PopupTree for confirmed selections. if (GetPopupTree() != null) { GetPopupTree().Hide(); // This should trigger popupTree_PopupTreeClosed() below. } } }
protected override TreeNode MakeMenuItems(PopupTree popupTree, int hvoTarget) { TreeNode match = null; // We need a way to store feature structures the user has chosen during this session. // We use an annotation to do this. foreach (ICmBaseAnnotation cba in m_annotations) { IFsFeatStruc fs = cba.FeaturesOA; if (fs == null || fs.IsEmpty) continue; if (cba.BeginObjectRA != null) continue; // is not one of the feature structures created via the phon feat chooser HvoTreeNode node = new HvoTreeNode(fs.LongNameTSS, fs.Hvo); popupTree.Nodes.Add(node); if (fs.Hvo == hvoTarget) match = node; } if (ClosedFeature != null) { var sortedVaues = from v in ClosedFeature.ValuesOC orderby v.Abbreviation.BestAnalysisAlternative.Text select v; foreach (var closedValue in sortedVaues) { HvoTreeNode node = new HvoTreeNode(closedValue.Abbreviation.BestAnalysisAlternative, closedValue.Hvo); popupTree.Nodes.Add(node); if (closedValue.Hvo == hvoTarget) match = node; } } popupTree.Nodes.Add(new HvoTreeNode( Cache.TsStrFactory.MakeString(LexTextControls.ksRemoveThisFeature, Cache.WritingSystemFactory.UserWs), kRemoveThisFeature)); /* Trying this now without using the phonological feature chooser; if users ask for it, will reconsider. * popupTree.Nodes.Add(new HvoTreeNode( Cache.TsStrFactory.MakeString(LexTextControls.ksChoosePhonFeats, Cache.WritingSystemFactory.UserWs), kChoosePhonologicaFeatures));*/ return match; }
private HvoTreeNode AddTreeNodeForMsa(PopupTree popupTree, IMoMorphSynAnalysis msa) { // JohnT: as described in LT-4633, a stem can be given an allomorph that // is an affix. So we need some sort of way to handle this. //Debug.Assert(msa is MoStemMsa); ITsString tssLabel = msa.InterlinearNameTSS; var stemMsa = msa as IMoStemMsa; if (stemMsa != null && stemMsa.PartOfSpeechRA == null) { tssLabel = TsStringUtils.MakeString( m_sUnknown, Cache.ServiceLocator.WritingSystemManager.UserWs); } var node = new HvoTreeNode(tssLabel, msa.Hvo); popupTree.Nodes.Add(node); return(node); }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { Debug.WriteLineIf(!disposing, "****************** Missing Dispose() call for " + GetType().Name + ". ******************"); // Must not be run more than once. if (m_isDisposed) { return; } if (disposing) { // Dispose managed resources here. if (m_treeCombo != null && !m_treeCombo.IsDisposed) { m_treeCombo.BeforeSelect -= m_treeCombo_BeforeSelect; m_treeCombo.AfterSelect -= m_treeCombo_AfterSelect; if (m_treeCombo.Tree != null) { m_treeCombo.Tree.PopupTreeClosed -= new TreeViewEventHandler(popupTree_PopupTreeClosed); } // We only manage m_treeCombo, so it gets disposed elsewhere. } if (m_popupTree != null) { m_popupTree.BeforeSelect -= m_treeCombo_BeforeSelect; m_popupTree.AfterSelect -= m_treeCombo_AfterSelect; m_popupTree.PopupTreeClosed -= popupTree_PopupTreeClosed; // We only manage m_popupTree, so it gets disposed elsewhere. } } // Dispose unmanaged resources here, whether disposing is true or false. m_mediator = null; m_lastConfirmedNode = null; m_kEmptyNode = null; m_treeCombo = null; m_popupTree = null; m_parent = null; m_cache = null; m_list = null; m_isDisposed = true; }
protected override TreeNode MakeMenuItems(PopupTree popupTree, int hvoTarget) { int tagNamePOS = UseAbbr ? CmPossibilityTags.kflidAbbreviation : CmPossibilityTags.kflidName; List <HvoTreeNode> relevantPartsOfSpeech = new List <HvoTreeNode>(); InflectionClassPopupTreeManager.GatherPartsOfSpeech(Cache, List.Hvo, CmPossibilityListTags.kflidPossibilities, CmPossibilityTags.kflidSubPossibilities, PartOfSpeechTags.kflidInflectableFeats, tagNamePOS, WritingSystem, relevantPartsOfSpeech); relevantPartsOfSpeech.Sort(); TreeNode match = null; foreach (HvoTreeNode item in relevantPartsOfSpeech) { popupTree.Nodes.Add(item); var pos = Cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(item.Hvo); foreach (IFsFeatStruc fs in pos.ReferenceFormsOC) { // Note: beware of using fs.ShortName. That can be // absolutely EMPTY (if the user has turned off the 'Show Abbreviation as its label' // field for both the feature category and value). // ChooserName shows the short name if it is non-empty, otherwise the long name. HvoTreeNode node = new HvoTreeNode(fs.ChooserNameTS, fs.Hvo); item.Nodes.Add(node); if (fs.Hvo == hvoTarget) { match = node; } } item.Nodes.Add(new HvoTreeNode( TsStringUtils.MakeString(LexTextControls.ksChooseInflFeats, Cache.WritingSystemFactory.UserWs), kMore)); } return(match); }
bool TrySelectNode(TreeCombo treeCombo, int hvoTarget) { if (treeCombo.Tree.Nodes.Count == 0) { m_mainPOSPopupTreeManager.LoadPopupTree(hvoTarget); return(true); } else { foreach (HvoTreeNode node in treeCombo.Tree.Nodes) { HvoTreeNode htn = node.NodeWithHvo(hvoTarget); if (htn != null) { // Selecting the POS here should then fire // the event which wil reset the slot combo. treeCombo.SelectedNode = htn; return(true); } } } return(false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// The dafault behavior is for change watchers to call DoEffectsOfPropChange if the /// data for the tag being watched has changed. /// </summary> /// <param name="hvo">The object that was changed</param> /// <param name="tag">The property of the object that was changed</param> /// <param name="ivMin">the starting character index where the change occurred</param> /// <param name="cvIns">the number of characters inserted</param> /// <param name="cvDel">the number of characters deleted</param> /// ------------------------------------------------------------------------------------ public virtual void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel) { CheckDisposed(); if (m_handlingMessage) { return; } if (hvo == m_obj.Hvo && tag == m_flid) { try { m_handlingMessage = true; var pos = POS; HvoTreeNode selNode = null; if (Tree.Tree != null) { selNode = (Tree.Tree.SelectedNode as HvoTreeNode); } if (selNode != null) { if (pos == null) { Tree.Tree.SelectObj(0); } else if (pos.Hvo != selNode.Hvo) { Tree.Tree.SelectObj(pos.Hvo); } } } finally { m_handlingMessage = false; } } }
protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; PopupTree pt = GetPopupTree(); switch (selectedNode.Hvo) { case kMore: // Only launch the dialog by a mouse click (or simulated mouse click). if (e.Action != TreeViewAction.ByMouse) { break; } // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed(). // This will effectively revert the list selection to a previous confirmed state. // Whatever happens below, we don't want to actually leave the "More..." node selected! // This is at least required if the user selects "Cancel" from the dialog below. pt.Hide(); using (MsaInflectionFeatureListDlg dlg = new MsaInflectionFeatureListDlg()) { HvoTreeNode parentNode = selectedNode.Parent as HvoTreeNode; int hvoPos = parentNode.Hvo; var pos = Cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(hvoPos); dlg.SetDlgInfo(Cache, m_mediator, m_propertyTable, pos); switch (dlg.ShowDialog(ParentForm)) { case DialogResult.OK: { int hvoFs = 0; if (dlg.FS != null) { hvoFs = dlg.FS.Hvo; } LoadPopupTree(hvoFs); // In the course of loading the popup tree, we will have selected the hvoFs item, and triggered an AfterSelect. // But, it will have had an Unknown action, and thus will not trigger some effects we want. // That one will work like arrowing over items: they are 'selected', but the system will not // behave as if the user actually chose this item. // But, we want clicking OK in the dialog to produce the same result as clicking an item in the list. // So, we need to trigger an AfterSelect with our own event args, which (since we're acting on it) // must have a ByMouse TreeViewAction. base.m_treeCombo_AfterSelect(sender, e); // everything should be setup with new node selected, so return. return; } case DialogResult.Yes: { // go to m_highestPOS in editor m_mediator.PostMessage("FollowLink", new FwLinkArgs("posEdit", dlg.HighestPOS.Guid)); if (ParentForm != null && ParentForm.Modal) { // Close the dlg that opened the popup tree, // since its hotlink was used to close it, // and a new item has been created. ParentForm.DialogResult = DialogResult.Cancel; ParentForm.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; } } break; default: break; } // FWR-3432 - If we get here and we still haven't got a valid Hvo, don't continue // on to the base method. It'll crash. if (selectedNode.Hvo == kMore) { return; } base.m_treeCombo_AfterSelect(sender, e); }
/// <summary> /// Add a 'not sure' item to the menu. If the current target is zero, it will be selected. /// It is saved as m_kEmptyNode. Also returns the new node. /// </summary> /// <param name="popupTree"></param> /// <param name="hvoTarget"></param> /// <returns></returns> protected TreeNode AddNotSureItem(PopupTree popupTree, int hvoTarget) { HvoTreeNode empty = new HvoTreeNode(Cache.MakeUserTss(LexTextControls.ks_NotSure_), kEmpty); popupTree.Nodes.Add(empty); m_kEmptyNode = empty; return empty; }
/// <summary> /// Override this to handle any special items like 'More...'. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; if (selectedNode == null) return; // User moved highlight off any item and hit enter; ignore. PopupTree pt = GetPopupTree(); if (e.Action == TreeViewAction.ByMouse) { // bookmark this confirmed selection - required before PopupTree.Hide() // (cf. comments in LT-2522) if (pt != null) m_lastConfirmedNode = (HvoTreeNode)pt.SelectedNode; } // Pass on the event to owners/clients and close the PopupTree, only if it has been confirmed // "ByMouse" (or simulated mouse event). This will ensure that the user can use the keyboard // to move to items in the list, without actually affecting their previous selection until they // CONFIRM it "ByMouse" which can happen by clicking or by pressing ENTER. This allows the user // to ESCape there movement and revert to previously confirmed selection. (cf. comments in LT-2522) if (e.Action == TreeViewAction.ByMouse) { // If we are managing a treeCombo, then go ahead and set its Text in case the owner // does not want to do so in the AfterSelect below. if (m_treeCombo != null) { if (m_treeCombo.Text != m_lastConfirmedNode.Text) m_treeCombo.Tss = m_lastConfirmedNode.Tss; } if (AfterSelect != null) AfterSelect(this, new TreeViewEventArgs(m_lastConfirmedNode, e.Action)); // Close the PopupTree for confirmed selections. if (GetPopupTree() != null) GetPopupTree().Hide(); // This should trigger popupTree_PopupTreeClosed() below. } }
/// <summary> /// /// </summary> /// <param name="nodes"></param> /// <param name="hvoOwner"></param> /// <param name="flid"></param> /// <param name="flidSub">specify a subitems, /// other than CmPossibilityTags.kflidSubPossibilities</param> /// <param name="hvoTarget"></param> /// <param name="tagName"></param> /// <returns></returns> protected TreeNode AddNodes(TreeNodeCollection nodes, int hvoOwner, int flid, int flidSub, int hvoTarget, int tagName) { TreeNode result = null; int chvo = Cache.MainCacheAccessor.get_VecSize(hvoOwner, flid); for (int i = 0; i < chvo; i++) { int hvoChild = Cache.MainCacheAccessor.get_VecItem(hvoOwner, flid, i); ITsString tssLabel = WritingSystemServices.GetMagicStringAlt(Cache, WritingSystemServices.kwsFirstAnalOrVern, hvoChild, tagName); if (tssLabel == null) tssLabel = TsStringUtils.MakeTss(LexTextControls.ksStars, Cache.WritingSystemFactory.UserWs); HvoTreeNode node = new HvoTreeNode(tssLabel, hvoChild); nodes.Add(node); TreeNode temp = AddNodes(node.Nodes, hvoChild, flidSub, flidSub, hvoTarget, tagName); if (hvoChild == hvoTarget) result = node; else if (temp != null) result = temp; } return result; }
protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; PopupTree pt = GetPopupTree(); switch (selectedNode.Hvo) { case kChoosePhonologicaFeatures: // Only launch the dialog by a mouse click (or simulated mouse click). if (e.Action != TreeViewAction.ByMouse) { break; } // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed(). // This will effectively revert the list selection to a previous confirmed state. // Whatever happens below, we don't want to actually leave the "Choose phonological features" node selected! // This is at least required if the user selects "Cancel" from the dialog below. // N.B. the above does not seem to be true; therefore we check for cancel and an empty result // and force the combo text to be what it should be. pt.Hide(); using (PhonologicalFeatureChooserDlg dlg = new PhonologicalFeatureChooserDlg()) { Cache.DomainDataByFlid.BeginUndoTask(LexTextControls.ksUndoInsertPhonologicalFeature, LexTextControls.ksRedoInsertPhonologicalFeature); var fs = CreateEmptyFeatureStructureInAnnotation(null); dlg.SetDlgInfo(Cache, m_mediator, m_propertyTable, fs); dlg.ShowIgnoreInsteadOfDontCare = true; dlg.SetHelpTopic("khtptoolBulkEditPhonemesChooserDlg"); DialogResult result = dlg.ShowDialog(ParentForm); if (result == DialogResult.OK) { if (dlg.FS != null) { var sFeatures = dlg.FS.LongName; if (string.IsNullOrEmpty(sFeatures)) { // user did not select anything in chooser; we want to show the last known node // in the dropdown, not "choose phonological feature". SetComboTextToLastConfirmedSelection(); } else if (!pt.Nodes.ContainsKey(sFeatures)) { var newSelectedNode = new HvoTreeNode(fs.LongNameTSS, fs.Hvo); pt.Nodes.Add(newSelectedNode); LoadPopupTree(fs.Hvo); selectedNode = newSelectedNode; } } } else if (result != DialogResult.Cancel) { dlg.HandleJump(); } else if (result == DialogResult.Cancel) { // The user canceled out of the chooser; we want to show the last known node // in the dropdown, not "choose phonological feature". SetComboTextToLastConfirmedSelection(); } Cache.DomainDataByFlid.EndUndoTask(); } break; } // FWR-3432 - If we get here and we still haven't got a valid Hvo, don't continue // on to the base method. It'll crash. if (selectedNode.Hvo == kChoosePhonologicaFeatures) { return; } base.m_treeCombo_AfterSelect(sender, e); }
protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; PopupTree pt = GetPopupTree(); switch (selectedNode.Hvo) { case kMore: // Only launch the dialog by a mouse click (or simulated mouse click). if (e.Action != TreeViewAction.ByMouse) { break; } // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed(). // This will effectively revert the list selection to a previous confirmed state. // Whatever happens below, we don't want to actually leave the "More..." node selected! // This is at least required if the user selects "Cancel" from the dialog below. pt.Hide(); using (MsaInflectionFeatureListDlg dlg = new MsaInflectionFeatureListDlg()) { HvoTreeNode parentNode = selectedNode.Parent as HvoTreeNode; int hvoPos = parentNode.Hvo; IPartOfSpeech pos = (IPartOfSpeech)PartOfSpeech.CreateFromDBObject(Cache, hvoPos, false); dlg.SetDlgInfo(Cache, m_mediator, pos); switch (dlg.ShowDialog(ParentForm)) { case DialogResult.OK: { int hvoFs = 0; if (dlg.FS != null) { hvoFs = dlg.FS.Hvo; } LoadPopupTree(hvoFs); // everything should be setup with new node selected, so return. return; } case DialogResult.Yes: { // go to m_highestPOS in editor // Also, is there some way to know the application name and tool name without hard coding them? FdoUi.FwLink linkJump = new SIL.FieldWorks.FdoUi.FwLink("Language Explorer", "posEdit", dlg.HighestPOS.Guid, Cache.ServerName, Cache.DatabaseName); m_mediator.PostMessage("FollowLink", linkJump); if (ParentForm != null && ParentForm.Modal) { // Close the dlg that opened the popup tree, // since its hotlink was used to close it, // and a new item has been created. ParentForm.DialogResult = DialogResult.Cancel; ParentForm.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; } } break; default: break; } base.m_treeCombo_AfterSelect(sender, e); }
/// <summary> /// /// </summary> /// <param name="nodes"></param> /// <param name="hvoOwner"></param> /// <param name="flid"></param> /// <param name="flidSub">specify a subitems, /// other than CmPossibilityTags.kflidSubPossibilities</param> /// <param name="hvoTarget"></param> /// <param name="tagName"></param> /// <returns></returns> protected TreeNode AddNodes(TreeNodeCollection nodes, int hvoOwner, int flid, int flidSub, int hvoTarget, int tagName) { TreeNode result = null; int chvo = Cache.MainCacheAccessor.get_VecSize(hvoOwner, flid); for (int i = 0; i < chvo; i++) { int hvoChild = Cache.MainCacheAccessor.get_VecItem(hvoOwner, flid, i); ITsString tssLabel = GetTssLabel(Cache, hvoChild, tagName, WritingSystem); HvoTreeNode node = new HvoTreeNode(tssLabel, hvoChild); nodes.Add(node); TreeNode temp = AddNodes(node.Nodes, hvoChild, flidSub, flidSub, hvoTarget, tagName); if (hvoChild == hvoTarget) result = node; else if (temp != null) result = temp; } return result; }
/// <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; 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; }
private void m_MSAPopupTreeManager_AfterSelect(object sender, TreeViewEventArgs e) { // unless we get a mouse click or simulated mouse click (e.g. by ENTER or TAB), // do not treat as an actual selection. if (m_handlingMessage || e.Action != TreeViewAction.ByMouse) { return; } HvoTreeNode htn = e.Node as HvoTreeNode; if (htn == null) { return; } // Don't try changing values on a deleted object! See LT-8656 and LT-9119. if (!m_cache.VerifyValidObject(m_obj)) { return; } int hvoSel = htn.Hvo; // if hvoSel is negative, then MSAPopupTreeManager's AfterSelect has handled it, // except possibly for refresh. if (hvoSel < 0) { ContainingDataTree.RefreshList(false); return; } LexSense sense = m_obj as LexSense; // Setting sense.DummyMSA can cause the DataTree to want to refresh. Don't // let this happen until after we're through! See LT-9713 and LT-9714. bool fOldDoNotRefresh = ContainingDataTree.DoNotRefresh; try { m_handlingMessage = true; int clidSel = 0; if (hvoSel > 0) { clidSel = m_cache.GetClassOfObject(hvoSel); } bool didChange = false; if (clidSel == PartOfSpeech.kclsidPartOfSpeech) { ContainingDataTree.DoNotRefresh = true; m_cache.BeginUndoTask( String.Format(DetailControlsStrings.ksUndoSet, m_fieldName), String.Format(DetailControlsStrings.ksRedoSet, m_fieldName)); DummyGenericMSA dummyMSA = new DummyGenericMSA(); dummyMSA.MsaType = sense.GetDesiredMsaType(); dummyMSA.MainPOS = hvoSel; MoStemMsa stemMsa = sense.MorphoSyntaxAnalysisRA as MoStemMsa; if (stemMsa != null) { dummyMSA.FromPartsOfSpeech = stemMsa.FromPartsOfSpeechRC; } sense.DummyMSA = dummyMSA; didChange = true; } else if (sense.MorphoSyntaxAnalysisRAHvo != hvoSel) { ContainingDataTree.DoNotRefresh = true; m_cache.BeginUndoTask( String.Format(DetailControlsStrings.ksUndoSet, m_fieldName), String.Format(DetailControlsStrings.ksRedoSet, m_fieldName)); sense.MorphoSyntaxAnalysisRAHvo = hvoSel; didChange = true; } if (didChange) { m_cache.EndUndoTask(); } if (!ContainingDataTree.RefreshListNeeded) { m_MSAPopupTreeManager.LoadPopupTree(sense.MorphoSyntaxAnalysisRAHvo); // Don't refresh the datatree unless the popup has actually been loaded. // It could be setting the selection in the process of loading! See LT-9191. if (m_MSAPopupTreeManager.IsTreeLoaded) { ContainingDataTree.RefreshList(false); } } } finally { m_handlingMessage = false; // We still can't refresh the data at this point without causing a crash due to // a pending Windows message. See LT-9713 and LT-9714. if (ContainingDataTree.DoNotRefresh != fOldDoNotRefresh) { Mediator.BroadcastMessage("DelayedRefreshList", fOldDoNotRefresh); } } }
/// <summary> /// Add an 'Any' item to the menu. If the current target is zero, it will be selected. /// It is saved as m_kEmptyNode. Also returns the new node. /// </summary> /// <param name="popupTree"></param> /// <param name="hvoTarget"></param> /// <returns></returns> protected TreeNode AddAnyItem(PopupTree popupTree) { HvoTreeNode empty = new HvoTreeNode( Cache.TsStrFactory.MakeString(LexTextControls.ksAny, Cache.WritingSystemFactory.UserWs), kEmpty); popupTree.Nodes.Add(empty); m_kEmptyNode = empty; return empty; }
/// <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); }
protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; PopupTree pt = GetPopupTree(); switch (selectedNode.Hvo) { case kChoosePhonologicaFeatures: // Only launch the dialog by a mouse click (or simulated mouse click). if (e.Action != TreeViewAction.ByMouse) break; // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed(). // This will effectively revert the list selection to a previous confirmed state. // Whatever happens below, we don't want to actually leave the "Choose phonological features" node selected! // This is at least required if the user selects "Cancel" from the dialog below. // N.B. the above does not seem to be true; therefore we check for cancel and an empty result // and force the combo text to be what it should be. pt.Hide(); using (PhonologicalFeatureChooserDlg dlg = new PhonologicalFeatureChooserDlg()) { Cache.DomainDataByFlid.BeginUndoTask(LexTextControls.ksUndoInsertPhonologicalFeature, LexTextControls.ksRedoInsertPhonologicalFeature); var fs = CreateEmptyFeatureStructureInAnnotation(null); dlg.SetDlgInfo(Cache, m_mediator, fs); dlg.ShowIgnoreInsteadOfDontCare = true; dlg.SetHelpTopic("khtptoolBulkEditPhonemesChooserDlg"); DialogResult result = dlg.ShowDialog(ParentForm); if (result == DialogResult.OK) { if (dlg.FS != null) { var sFeatures = dlg.FS.LongName; if (string.IsNullOrEmpty(sFeatures)) { // user did not select anything in chooser; we want to show the last known node // in the dropdown, not "choose phonological feature". SetComboTextToLastConfirmedSelection(); } else if (!pt.Nodes.ContainsKey(sFeatures)) { var newSelectedNode = new HvoTreeNode(fs.LongNameTSS, fs.Hvo); pt.Nodes.Add(newSelectedNode); LoadPopupTree(fs.Hvo); selectedNode = newSelectedNode; } } } else if (result != DialogResult.Cancel) { dlg.HandleJump(); } else if (result == DialogResult.Cancel) { // The user canceled out of the chooser; we want to show the last known node // in the dropdown, not "choose phonological feature". SetComboTextToLastConfirmedSelection(); } Cache.DomainDataByFlid.EndUndoTask(); } break; default: break; } // FWR-3432 - If we get here and we still haven't got a valid Hvo, don't continue // on to the base method. It'll crash. if (selectedNode.Hvo == kChoosePhonologicaFeatures) return; base.m_treeCombo_AfterSelect(sender, e); }
protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; if (selectedNode != null && selectedNode.Hvo == kMore && e.Action == TreeViewAction.ByMouse) { // Only launch the dialog by a mouse click (or simulated mouse click). PopupTree pt = GetPopupTree(); // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed(). // This will effectively revert the list selection to a previous confirmed state. // Whatever happens below, we don't want to actually leave the "More..." node selected! // This is at least required if the user selects "Cancel" from the dialog below. pt.Hide(); using (MasterCategoryListDlg dlg = new MasterCategoryListDlg()) { dlg.SetDlginfo(List, m_mediator, false, null); switch (dlg.ShowDialog(ParentForm)) { case DialogResult.OK: { LoadPopupTree(dlg.SelectedPOS.Hvo); // everything should be setup with new node selected, so return. return; } case DialogResult.Yes: { // 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", SIL.FieldWorks.FdoUi.FwLink.Create(JumpToToolNamed, Cache.GetGuidFromId(dlg.SelectedPOS.Hvo), Cache.ServerName, Cache.DatabaseName)); if (ParentForm != null && ParentForm.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. ParentForm.DialogResult = DialogResult.Cancel; ParentForm.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; } } } base.m_treeCombo_AfterSelect(sender, e); }
protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e) { HvoTreeNode selectedNode = e.Node as HvoTreeNode; if (selectedNode != null && selectedNode.Hvo == kMore && e.Action == TreeViewAction.ByMouse) { // Only launch the dialog by a mouse click (or simulated mouse click). //PopupTree pt = GetPopupTree(); //// Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed(). //// This will effectively revert the list selection to a previous confirmed state. //// Whatever happens below, we don't want to actually leave the "More..." node selected! //// This is at least required if the user selects "Cancel" from the dialog below. //pt.Hide(); if (TreeCombo != null) { TreeCombo.SelectedNode = m_selPrior; } else { GetPopupTree().SelectedNode = m_selPrior; } // If we wait to hide it until after we show the dialog, hiding it activates the disabled main // window which owns it, with weird results. Since we're going to launch another window, // we don't want to activate the parent at all. GetPopupTree().HideForm(false); using (MasterCategoryListDlg dlg = new MasterCategoryListDlg()) { dlg.SetDlginfo(List, m_mediator, false, null); switch (dlg.ShowDialog(ParentForm)) { case DialogResult.OK: { LoadPopupTree(dlg.SelectedPOS.Hvo); // everything should be setup with new node selected, so return. return; } case DialogResult.Yes: { // 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(JumpToToolNamed, dlg.SelectedPOS.Guid)); if (ParentForm != null && ParentForm.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. ParentForm.DialogResult = DialogResult.Cancel; ParentForm.Close(); } break; } default: { return; } } } } base.m_treeCombo_AfterSelect(sender, e); }
private void m_MSAPopupTreeManager_AfterSelect(object sender, TreeViewEventArgs e) { // unless we get a mouse click or simulated mouse click (e.g. by ENTER or TAB), // do not treat as an actual selection. if (m_handlingMessage || e.Action != TreeViewAction.ByMouse) { return; } HvoTreeNode htn = e.Node as HvoTreeNode; if (htn == null) { return; } // Don't try changing values on a deleted object! See LT-8656 and LT-9119. if (!m_obj.IsValidObject) { return; } int hvoSel = htn.Hvo; // if hvoSel is negative, then MSAPopupTreeManager's AfterSelect has handled it, // except possibly for refresh. if (hvoSel < 0) { ContainingDataTree.RefreshList(false); return; } var sense = m_obj as ILexSense; // Setting sense.DummyMSA can cause the DataTree to want to refresh. Don't // let this happen until after we're through! See LT-9713 and LT-9714. bool fOldDoNotRefresh = ContainingDataTree.DoNotRefresh; try { m_handlingMessage = true; if (hvoSel > 0) { ICmObject obj = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvoSel); if (obj.ClassID == PartOfSpeechTags.kClassId) { ContainingDataTree.DoNotRefresh = true; var sandoxMSA = new SandboxGenericMSA(); sandoxMSA.MsaType = sense.GetDesiredMsaType(); sandoxMSA.MainPOS = obj as IPartOfSpeech; var stemMsa = sense.MorphoSyntaxAnalysisRA as IMoStemMsa; if (stemMsa != null) { sandoxMSA.FromPartsOfSpeech = stemMsa.FromPartsOfSpeechRC; } UndoableUnitOfWorkHelper.Do(String.Format(DetailControlsStrings.ksUndoSet, m_fieldName), String.Format(DetailControlsStrings.ksRedoSet, m_fieldName), sense, () => { sense.SandboxMSA = sandoxMSA; }); } else if (sense.MorphoSyntaxAnalysisRA != obj) { ContainingDataTree.DoNotRefresh = true; UndoableUnitOfWorkHelper.Do(String.Format(DetailControlsStrings.ksUndoSet, m_fieldName), String.Format(DetailControlsStrings.ksRedoSet, m_fieldName), sense, () => { sense.MorphoSyntaxAnalysisRA = obj as IMoMorphSynAnalysis; }); } } } finally { m_handlingMessage = false; // We still can't refresh the data at this point without causing a crash due to // a pending Windows message. See LT-9713 and LT-9714. if (ContainingDataTree.DoNotRefresh != fOldDoNotRefresh) { Mediator.BroadcastMessage("DelayedRefreshList", fOldDoNotRefresh); } } }
private HvoTreeNode AddTreeNodeForMsa(PopupTree popupTree, ITsStrFactory tsf, IMoMorphSynAnalysis msa) { // JohnT: as described in LT-4633, a stem can be given an allomorph that // is an affix. So we need some sort of way to handle this. //Debug.Assert(msa is MoStemMsa); ITsString tssLabel = msa.InterlinearNameTSS; if (msa is IMoStemMsa && (msa as IMoStemMsa).PartOfSpeechRA == null) tssLabel = tsf.MakeString( m_sUnknown, Cache.ServiceLocator.WritingSystemManager.UserWs); var node = new HvoTreeNode(tssLabel, msa.Hvo); popupTree.Nodes.Add(node); return node; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. if (m_treeCombo != null && !m_treeCombo.IsDisposed) { m_treeCombo.BeforeSelect -= new TreeViewCancelEventHandler(m_treeCombo_BeforeSelect); m_treeCombo.AfterSelect -= new TreeViewEventHandler(m_treeCombo_AfterSelect); if (m_treeCombo.Tree != null) m_treeCombo.Tree.PopupTreeClosed -= new TreeViewEventHandler(popupTree_PopupTreeClosed); // We only manage m_treeCombo, so it gets disposed elsewhere. } if (m_popupTree != null) { m_popupTree.BeforeSelect -= new TreeViewCancelEventHandler(m_treeCombo_BeforeSelect); m_popupTree.AfterSelect -= new TreeViewEventHandler(m_treeCombo_AfterSelect); m_popupTree.PopupTreeClosed -= new TreeViewEventHandler(popupTree_PopupTreeClosed); // We only manage m_popupTree, so it gets disposed elsewhere. } } // Dispose unmanaged resources here, whether disposing is true or false. m_lastConfirmedNode = null; m_kEmptyNode = null; m_treeCombo = null; m_popupTree = null; m_parent = null; m_cache = null; m_list = null; m_isDisposed = true; }