Exemplo n.º 1
0
        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);
                }
            }
        }