/// <summary> /// Handle interaction between POS and Slot ptoeprties for a inflectional affix MSA. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// If the new value is zero, then set the Slot prop to zero. /// If the new value is not zero, then make sure the Slot prop is valid. /// If the current slot is not legal for the new POS value, then set it to zero. /// Otherwise leave the slot value alone. /// </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 MoInflAffMsa); int idxSender = Parent.Controls.IndexOf(this); int otherFlid = (int)MoInflAffMsa.MoInflAffMsaTags.kflidSlots; Slice otherSlice = null; int idxOther; // Try to get the Slots slice. // Check for slices before this one. if (idxSender > 0) { idxOther = idxSender - 1; while (idxOther >= 0 && (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object))) { otherSlice = (Slice)Parent.Controls[idxOther--]; if (otherSlice is ReferenceVectorSlice && (otherSlice as ReferenceVectorSlice).Flid == otherFlid) { break; } otherSlice = null; } } // Check for following slices, if we didn't get one earlier. if (otherSlice == null && idxSender < Parent.Controls.Count) { idxOther = idxSender + 1; while (idxOther < Parent.Controls.Count && (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object))) { otherSlice = (Slice)Parent.Controls[idxOther++]; if (otherSlice is ReferenceVectorSlice && (otherSlice as ReferenceVectorSlice).Flid == otherFlid) { break; } otherSlice = null; } } VectorReferenceLauncher otherControl = null; if (otherSlice != null) { Debug.Assert((otherSlice as ReferenceVectorSlice).Flid == otherFlid); Debug.Assert(otherSlice.Object == Object); otherControl = otherSlice.Control as VectorReferenceLauncher; Debug.Assert(otherControl != null); } MoInflAffMsa msa = Object as MoInflAffMsa; int slotHvo = 0; if (msa.SlotsRC.Count > 0) { int[] hvos = msa.SlotsRC.HvoArray; slotHvo = hvos[0]; } if (e.Hvo == 0 || slotHvo > 0) { IPartOfSpeech pos = msa.PartOfSpeechRA; List <int> slotIDs = new List <int>(); if (pos != null) { slotIDs = pos.AllAffixSlotIDs; } bool clearSlot = ((e.Hvo == 0) || (!slotIDs.Contains(slotHvo))); if (clearSlot) { if (otherControl == null) { msa.ClearAllSlots(); // The slot slice is not showing, so directly set the object's Slot property. } else { otherControl.AddItem(0); // Reset it using the other slice, so it gets refreshed. } } } }
/// <summary> /// Handle interaction between POS and Slot ptoeprties for a inflectional affix MSA. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// If the new value is zero, then set the Slot prop to zero. /// If the new value is not zero, then make sure the Slot prop is valid. /// If the current slot is not legal for the new POS value, then set it to zero. /// Otherwise leave the slot value alone. /// </remarks> protected void OnReferenceChanged(object sender, FwObjectSelectionEventArgs e) { Debug.Assert(sender is AtomicReferenceLauncher); var source = (AtomicReferenceLauncher)sender; Debug.Assert(Control == source); Debug.Assert(Object is IMoInflAffMsa); int idxSender = ContainingDataTree.Slices.IndexOf(this); int otherFlid = MoInflAffMsaTags.kflidSlots; Slice otherSlice = null; int idxOther; // Try to get the Slots slice. // Check for slices before this one. if (idxSender > 0) { idxOther = idxSender - 1; while (idxOther >= 0 && (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object))) { otherSlice = ContainingDataTree.Slices[idxOther--]; if (otherSlice is ReferenceVectorSlice && (otherSlice as ReferenceVectorSlice).Flid == otherFlid) { break; } otherSlice = null; } } // Check for following slices, if we didn't get one earlier. if (otherSlice == null && idxSender < ContainingDataTree.Slices.Count) { idxOther = idxSender + 1; while (idxOther < ContainingDataTree.Slices.Count && (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object))) { otherSlice = ContainingDataTree.Slices[idxOther++]; if (otherSlice is ReferenceVectorSlice && (otherSlice as ReferenceVectorSlice).Flid == otherFlid) { break; } otherSlice = null; } } VectorReferenceLauncher otherControl = null; if (otherSlice != null) { Debug.Assert(otherSlice.Flid == otherFlid); Debug.Assert(otherSlice.Object == Object); otherControl = otherSlice.Control as VectorReferenceLauncher; Debug.Assert(otherControl != null); } var msa = Object as IMoInflAffMsa; IMoInflAffixSlot slot = null; if (msa.SlotsRC.Count > 0) { slot = msa.SlotsRC.First(); } if (e.Hvo == 0 || slot != null) { var pos = msa.PartOfSpeechRA; var slots = pos != null ? pos.AllAffixSlots : Enumerable.Empty <IMoInflAffixSlot>(); bool clearSlot = e.Hvo == 0 || !slots.Contains(slot); if (clearSlot) { if (otherControl == null) { msa.SlotsRC.Clear(); // The slot slice is not showing, so directly set the object's Slot property. } else { otherControl.AddItem(null); // Reset it using the other slice, so it gets refreshed. } } } }