Ejemplo n.º 1
0
        /// <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.
                }
            }
        }
Ejemplo n.º 2
0
        /// <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, FwObjectSelectionEventArgs e)
        {
            Debug.Assert(sender is AtomicReferenceLauncher);
            var source = (AtomicReferenceLauncher)sender;

            Debug.Assert(Control == source);
            Debug.Assert(Object is IMoDerivAffMsa);

            AtomicReferenceLauncher otherControl = null;
            int  idxSender = ContainingDataTree.Slices.IndexOf(this);
            int  otherFlid;
            bool myIsFromPOS = true;

            if (m_flid == MoDerivAffMsaTags.kflidFromPartOfSpeech)
            {
                otherFlid = MoDerivAffMsaTags.kflidToPartOfSpeech;
            }
            else
            {
                otherFlid   = 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 = ContainingDataTree.Slices[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 < ContainingDataTree.Slices.Count)
            {
                idxOther = idxSender + 1;
                while (otherSlice == null ||
                       (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object))
                {
                    otherSlice = ContainingDataTree.Slices[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;
                }
            }

            var msa = Object as IMoDerivAffMsa;

            if (e.Hvo == 0 && otherHvo != 0)
            {
                if (otherControl != null)
                {
                    if (m_flid == MoDerivAffMsaTags.kflidFromPartOfSpeech)
                    {
                        msa.ToPartOfSpeechRA = null;
                    }
                    else
                    {
                        msa.FromPartOfSpeechRA = null;
                    }
                }
            }
            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 == MoDerivAffMsaTags.kflidFromPartOfSpeech)
                    {
                        msa.ToPartOfSpeechRA = m_cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(e.Hvo);
                    }
                    else
                    {
                        msa.FromPartOfSpeechRA = m_cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(e.Hvo);
                    }
                }
                else
                {
                    otherControl.AddItem(m_cache.ServiceLocator.GetObject(e.Hvo));                     // Set the other guy to this value.
                }
            }
        }