/// <summary> /// Handle interaction between to and from POS for a derivational affix MSA. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// If the new value is zero, then set the other one's value to zero, as well. /// If the other one's value is zero, then set it to the new value. /// In all cases, set this one's value to the new value. /// </remarks> protected void OnReferenceChanged(object sender, SIL.FieldWorks.Common.Utils.FwObjectSelectionEventArgs e) { Debug.Assert(sender is AtomicReferenceLauncher); AtomicReferenceLauncher source = (AtomicReferenceLauncher)sender; Debug.Assert(Control == source); Debug.Assert(Object is MoDerivAffMsa); AtomicReferenceLauncher otherControl = null; int idxSender = Parent.Controls.IndexOf(this); int otherFlid; bool myIsFromPOS = true; if (m_flid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech) { otherFlid = (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToPartOfSpeech; } else { otherFlid = (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech; myIsFromPOS = false; } int otherHvo = 0; Slice otherSlice = null; int idxOther; if (idxSender > 0) { idxOther = idxSender - 1; while (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object)) { otherSlice = (Slice)Parent.Controls[idxOther--]; if (otherSlice is AtomicReferenceSlice && (otherSlice as AtomicReferenceSlice).Flid == otherFlid) { break; } } if (otherSlice != null && otherSlice is AtomicReferenceSlice) { otherHvo = GetOtherHvo(otherSlice as AtomicReferenceSlice, otherFlid, myIsFromPOS, out otherControl); } else { otherSlice = null; } } if (otherControl == null && idxSender < Parent.Controls.Count) { idxOther = idxSender + 1; while (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object)) { otherSlice = (Slice)Parent.Controls[idxOther++]; if (otherSlice is AtomicReferenceSlice && (otherSlice as AtomicReferenceSlice).Flid == otherFlid) { break; } } if (otherSlice != null && otherSlice is AtomicReferenceSlice) { otherHvo = GetOtherHvo(otherSlice as AtomicReferenceSlice, otherFlid, myIsFromPOS, out otherControl); } else { otherSlice = null; } } MoDerivAffMsa msa = Object as MoDerivAffMsa; if (e.Hvo == 0 && otherHvo != 0) { if (otherControl == null) { otherControl.AddItem(0); // Clear the other one, as well. } else { if (m_flid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech) { msa.ToPartOfSpeechRAHvo = 0; } else { msa.FromPartOfSpeechRAHvo = 0; } } } else if (otherHvo == 0 && e.Hvo > 0) { if (otherControl == null) { // The other one is not available (filtered out?), // so set it directly using the msa. if (m_flid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech) { msa.ToPartOfSpeechRAHvo = e.Hvo; } else { msa.FromPartOfSpeechRAHvo = e.Hvo; } } else { otherControl.AddItem(e.Hvo); // Set the other guy to this value. } } }
private void m_pOSPopupTreeManager_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; } int hvoPos = (e.Node as HvoTreeNode).Hvo; // if hvoPos is negative, then allow POSPopupTreeManager AfterSelect to handle it. if (hvoPos < 0) { return; } try { m_handlingMessage = true; m_cache.BeginUndoTask(DetailControlsStrings.ksUndoSetCat, DetailControlsStrings.ksRedoSetCat); m_cache.SetObjProperty(m_obj.Hvo, m_flid, hvoPos); // Do some side effects for a couple of MSA classes. if (m_obj is MoInflAffMsa) { MoInflAffMsa msa = m_obj as MoInflAffMsa; int[] hvos = msa.SlotsRC.HvoArray; if (hvoPos == 0) { msa.ClearAllSlots(); } else if (msa.SlotsRC.Count > 0) { bool fPosHasSlot = false; for (int hvo = 0; hvo < msa.SlotsRC.Count; hvo++) { if (msa.PartOfSpeechRA.AllAffixSlotIDs.Contains(hvo)) { fPosHasSlot = true; break; } } if (!fPosHasSlot) { msa.ClearAllSlots(); } } } else if (m_obj is MoDerivAffMsa) { MoDerivAffMsa msa = m_obj as MoDerivAffMsa; if (hvoPos > 0 && m_flid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech && msa.ToPartOfSpeechRAHvo == 0) { msa.ToPartOfSpeechRAHvo = hvoPos; } else if (hvoPos > 0 && m_flid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToPartOfSpeech && msa.FromPartOfSpeechRAHvo == 0) { msa.FromPartOfSpeechRAHvo = hvoPos; } } m_cache.EndUndoTask(); } finally { m_handlingMessage = false; } }