Example #1
0
        private void EnsureCbaIsReal(ref int hvo)
        {
            ICmBaseAnnotation cba = CmBaseAnnotation.CreateFromDBObject(m_cache, hvo);

            if (cba != null && cba.IsDummyObject)
            {
                hvo = CmBaseAnnotation.ConvertBaseAnnotationToReal(m_cache, hvo).Hvo;
            }
        }
Example #2
0
        protected override void WriteStartWord(int hvo)
        {
            base.WriteStartWord(hvo);
            ICmBaseAnnotation cba = CmBaseAnnotation.CreateFromDBObject(m_cache, hvo);

            // avoid writing guids for punctuations, since some may be dummy annotations.
            if (cba.AnnotationTypeRAHvo != kPunctuationAnnType)
            {
                WriteGuidAttributeForObj(hvo);
            }
        }
Example #3
0
        protected override void EnsureXficCbaIsRealIfNeeded(ref int hvo)
        {
            ICmBaseAnnotation cba = CmBaseAnnotation.CreateFromDBObject(m_cache, hvo);

            // avoid converting dummy punctuations, since we don't always have guids for those
            // because our dummy conversion process does not update the cache for punctuation types.
            if (cba.AnnotationTypeRAHvo != kPunctuationAnnType)
            {
                EnsureCbaIsReal(ref hvo);
            }
            base.EnsureXficCbaIsRealIfNeeded(ref hvo);
        }
Example #4
0
 private void btnAssign_Click(object sender, System.EventArgs e)
 {
     using (new SIL.FieldWorks.Common.Utils.WaitCursor(this, false))
     {
         int        newTargetHvo = (int)(tvTarget.SelectedNode.Tag);
         List <int> checkedItems = m_currentBrowseView.CheckedItems;
         int        virtFlid     = m_currentBrowseView.Clerk.VirtualFlid;
         int        srcHvo       = (int)tvSource.SelectedNode.Tag;
         if (checkedItems.Count > 0)
         {
             m_toolStripProgressBar.Minimum = 0;
             m_toolStripProgressBar.Maximum = checkedItems.Count;
             m_toolStripProgressBar.Step    = 1;
             m_toolStripProgressBar.Value   = 0;
         }
         foreach (int annHvo in checkedItems)
         {
             ICmBaseAnnotation ann = null;
             if (m_cache.IsDummyObject(annHvo))
             {
                 ann = ConvertDummyToReal(srcHvo, virtFlid, annHvo) as ICmBaseAnnotation;
                 Debug.Assert(ann != null);
             }
             else
             {
                 ann = CmBaseAnnotation.CreateFromDBObject(m_cache, annHvo);
             }
             ann.InstanceOfRAHvo = newTargetHvo;
             m_cache.SetIntProperty(ann.Hvo, XmlBrowseViewVc.ktagItemSelected, 0);
             m_toolStripProgressBar.PerformStep();
         }
         // After these changes, we need to refresh the display.  PropChanged() redraws the
         // list, but incorrect (and inconsistent) items are then displayed.  See LT-8703.
         // Refreshing the clerk reloads the list and then redraws it.
         m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, srcHvo, virtFlid, 0, 0,
                             checkedItems.Count);
         m_currentBrowseView.Clerk.OnRefresh(null);
         CheckAssignBtnEnabling();
         m_toolStripProgressBar.Value = 0;
         SetRecordStatus();
     }
 }
Example #5
0
            protected override void ValidateSegFormOuterElements(object expectedSegForm, object actualSegForm, string segFormContext)
            {
                // First validate the twfic guid.
                ICmBaseAnnotation cbaExpected = CmBaseAnnotation.CreateFromDBObject(m_cache, (int)expectedSegForm);

                if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
                {
                    // we are not exporting punctuation guids, since some are dummys without guids.
                    ValidateMissingGuidForNode(actualSegForm as XmlNode, segFormContext);
                }
                else
                {
                    Assert.IsFalse(cbaExpected.IsDummyObject,
                                   String.Format("We expected our paragraph segform ({0}) in context {1} to be real.",
                                                 cbaExpected.Hvo, segFormContext));
                    string guidActual;
                    ValidateCmObjectGuidForNode((int)expectedSegForm, actualSegForm as XmlNode, segFormContext,
                                                out guidActual);
                    ValidateGuidIsNonrepeating(guidActual, segFormContext);
                }
                base.ValidateSegFormOuterElements(expectedSegForm, actualSegForm, segFormContext);
            }
Example #6
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// This is the main interesting method of displaying objects and fragments of them.
        /// Here a text is displayed by displaying its paragraphs;
        /// and a paragraph is displayed by invoking its style rule, making a paragraph,
        /// and displaying its contents.
        /// </summary>
        /// <param name="vwenv">view environment</param>
        /// <param name="hvo">id of object to be displayed</param>
        /// <param name="frag">fragment of data</param>
        /// -----------------------------------------------------------------------------------
        public override void Display(IVwEnv vwenv, int hvo, int frag)
        {
            CheckDisposed();

            switch (frag)
            {
            case (int)StTextFrags.kfrFootnote:
            {
                if (HandleEmptyText(vwenv, hvo))
                {
                    break;
                }
                vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this,
                                     (int)StTextFrags.kfrFootnotePara);
                break;
            }

            case (int)StTextFrags.kfrText:
            {
                if (HandleEmptyText(vwenv, hvo))
                {
                    break;
                }
                if (m_fLazy)
                {
                    vwenv.AddLazyVecItems((int)StText.StTextTags.kflidParagraphs, this,
                                          (int)StTextFrags.kfrPara);
                }
                else
                {
                    vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this,
                                         (int)StTextFrags.kfrPara);
                }
                break;
            }

            case (int)StTextFrags.kfrFootnoteMarker:
            {
                StFootnote footnote = new StFootnote(Cache, hvo);
                if (footnote.DisplayFootnoteMarker)
                {
                    DisplayFootnoteMarker(vwenv);
                }
                break;
            }

            case (int)StTextFrags.kfrLabel:
            {
                // The label is not editable.
                vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                      (int)FwTextPropVar.ktpvEnum,
                                      (int)TptEditable.ktptNotEditable);
                vwenv.AddString(m_tssLabel);
                break;
            }

            case (int)StTextFrags.kfrPara:
            case (int)StTextFrags.kfrFootnotePara:
            {
                InsertParagraphBody(vwenv, hvo, frag, true, ContentType, this);
                break;
            }

            case (int)StTextFrags.kfrTranslation:
            {
                vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                      (int)FwTextPropVar.ktpvEnum,
                                      Editable ? (int)TptEditable.ktptIsEditable
                                                : (int)TptEditable.ktptNotEditable);
                // Display the translation, or its user prompt
                if (!InsertTranslationUserPrompt(vwenv, hvo))
                {
                    vwenv.AddStringAltMember((int)CmTranslation.CmTranslationTags.kflidTranslation,
                                             m_wsDefault, this);
                }
                break;
            }

            case (int)StTextFrags.kfrSegmentFreeTranslations:
                // Hvo is a CmBaseAnnotation of one segment of an StTxtPara.
                if (IsLabelSegment(hvo))
                {
                    CmBaseAnnotation segment = (CmBaseAnnotation)CmBaseAnnotation.CreateFromDBObject(Cache, hvo, false);
                    vwenv.AddString(GetBackTransLabelText(segment));
                    vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 1200, 0, 0);                             // a narrow space, font-neutral
                }
                else
                {
                    vwenv.AddObjProp(StTxtPara.SegmentFreeTranslationFlid(Cache), this, (int)StTextFrags.kfrFreeTrans);
                    vwenv.AddString(OneSpaceString);
                }
                break;

            case (int)StTextFrags.kfrFreeTrans:
                // Hvo is a CmIndirectAnnotation whose Contents are the free/back translation.
                vwenv.set_IntProperty((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault,
                                      (int)ColorUtil.ConvertColorToBGR(SystemColors.Window));
                ITsString tssVal = vwenv.DataAccess.get_MultiStringAlt(hvo,
                                                                       (int)CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS);
                if (tssVal.Length == 0 && !SuppressPrompt(hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment))
                {
                    vwenv.NoteDependency(new int[] { hvo }, new int[] { (int)CmAnnotation.CmAnnotationTags.kflidComment }, 1);
                    vwenv.AddProp(SimpleRootSite.kTagUserPrompt, this, (int)CmAnnotation.CmAnnotationTags.kflidComment);
                    // Almost invisibly narrow, but the Views code doesn't know it is invisible so it should prevent the prompts collapsing
                    // into the margin.
                    vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 100, 0, 0);
                }
                else
                {
                    ITsStrBldr bldr = tssVal.GetBldr();
                    bldr.Replace(0, bldr.Length, "", null);                             // reduce to empty string in ws.
                    // We want it to change back to the prompt if all is deleted.
                    vwenv.NoteStringValDependency(hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS, bldr.GetString());
                    vwenv.AddStringAltMember((int)CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS, this);
                    // This little separator is useful here, too. Temporarily the comment may be displayed this way even when empty,
                    // and if there is ordinary text following, it is difficult to get an IP displayed in an empty run.
                    vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 100, 0, 0);
                }
                break;
            }
        }
Example #7
0
            protected override void ValidateSegForms(object expectedSegForm, object actualSegForm, string segFormContext)
            {
                string msg = "Mismatched {0} in {1}.";
                // Get the paragraph string corresponding to the annotation.
                ICmBaseAnnotation cbaExpected = CmBaseAnnotation.CreateFromDBObject(m_cache, (int)expectedSegForm);

                // first make sure we have a txt item.
                if (IsLineEnabled(InterlinLineChoices.kflidWord))
                {
                    ITsString tssExpectedForm = m_para.Contents.UnderlyingTsString.GetSubstring(cbaExpected.BeginOffset, cbaExpected.EndOffset);
                    string    lang            = "xkal";
                    // Review: get WsLabel from tssExpectedForm.
                    string actualForm = "";
                    if (cbaExpected.AnnotationTypeRAHvo == TwficAnnotationType)
                    {
                        actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "txt", lang);
                    }
                    else if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
                    {
                        actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "punct", lang);
                    }
                    Assert.AreEqual(tssExpectedForm.Text, actualForm,
                                    String.Format(msg, "word", segFormContext));
                }
                // if WordGloss is enabled, verify it.
                if (IsLineEnabled(InterlinLineChoices.kflidWordGloss))
                {
                    string lang            = "en";
                    string actualWordGloss = m_reader.GetItemInnerText(actualSegForm as XmlNode, "gls", lang);
                    if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
                    {
                        // must be a punctuation (non-wfic)
                        Assert.AreEqual("", actualWordGloss);
                    }
                    else
                    {
                        WfiGloss expectedGloss = null;
                        int      clsId         = m_cache.GetClassOfObject(cbaExpected.InstanceOfRAHvo);
                        if (clsId == WfiGloss.kclsidWfiGloss)
                        {
                            expectedGloss = new WfiGloss(m_cache, cbaExpected.InstanceOfRAHvo);
                        }
                        else if (clsId == WfiWordform.kclsidWfiWordform)
                        {
                            // should be a twfic so get its guess.
                            StTxtPara.TwficInfo cbaInfo = new StTxtPara.TwficInfo(m_cache, cbaExpected.Hvo);
                            int hvoExpectedGloss        = cbaInfo.GetGuess();
                            if (hvoExpectedGloss != 0)
                            {
                                expectedGloss = new WfiGloss(m_cache, hvoExpectedGloss);
                            }
                        }
                        // TODO: There are cases for other classes (e.g. WfiAnalysis) but
                        // the tests do not generate those right now, so we won't worry about them right now.
                        if (expectedGloss != null)
                        {
                            Assert.AreEqual(expectedGloss.Form.AnalysisDefaultWritingSystem, actualWordGloss);
                        }
                        else
                        {
                            Assert.AreEqual("", actualWordGloss);
                        }
                    }
                }
                // validate morph bundle lines.
                if (IsLineEnabled(InterlinLineChoices.kflidMorphemes) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexEntries) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexGloss) ||
                    IsLineEnabled(InterlinLineChoices.kflidLexPos))
                {
                    // compare exported document to the LexEntries information in the WfiAnalysis
                    int hvoWfiAnalysis = 0;
                    if (cbaExpected.AnnotationTypeRAHvo != PunctuationAnnotationType)
                    {
                        hvoWfiAnalysis = WfiAnalysis.GetWfiAnalysisFromInstanceOf(m_cache, cbaExpected.Hvo);
                    }
                    List <XmlNode> morphNodes = m_reader.GetMorphNodes(actualSegForm as XmlNode);
                    if (hvoWfiAnalysis == 0)
                    {
                        // make sure we don't have any morphs.
                        Assert.IsEmpty(morphNodes);
                    }
                    else
                    {
                        IWfiAnalysis wfiAnalysis = WfiAnalysis.CreateFromDBObject(m_cache, hvoWfiAnalysis);
                        foreach (WfiMorphBundle morphBundle in wfiAnalysis.MorphBundlesOS)
                        {
                            int     iMorph          = morphBundle.OwnOrd - 1;
                            string  morphContext    = segFormContext + "/Morph(" + iMorph + ")";
                            XmlNode actualMorphNode = iMorph < morphNodes.Count ? morphNodes[iMorph] : null;
                            if (actualMorphNode == null)
                            {
                                Assert.Fail(String.Format(msg, "missing morph", morphContext));
                            }
                            ITsString tssLexEntry = null;
                            int       hvoMorph    = morphBundle.MorphRAHvo;
                            if (hvoMorph != 0)
                            {
                                // first test the morph form
                                if (IsLineEnabled(InterlinLineChoices.kflidMorphemes))
                                {
                                    string actualMorphForm = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "txt", "xkal");
                                    Assert.AreEqual(morphBundle.MorphRA.Form.VernacularDefaultWritingSystem,
                                                    actualMorphForm,
                                                    String.Format(msg, "morph/txt", morphContext));
                                }

                                // next test the lex entry
                                if (IsLineEnabled(InterlinLineChoices.kflidLexEntries))
                                {
                                    string actualLexEntry     = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "cf", "xkal");
                                    string actualHomograph    = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "hn", "en");
                                    string actualVariantTypes = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "variantTypes", "en");
                                    tssLexEntry = InterlinDocChild.GetLexEntryTss(m_cache, morphBundle, m_cache.DefaultVernWs);
                                    Assert.AreEqual(tssLexEntry.Text, actualLexEntry + actualHomograph + actualVariantTypes,
                                                    String.Format(msg, "morph/cf[hn|variantTypes]", morphContext));
                                }

                                if (IsLineEnabled(InterlinLineChoices.kflidLexGloss))
                                {
                                    string actualLexGloss = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "gls", "en");
                                    string expectedGloss  = "";
                                    if (morphBundle.SenseRA != null && morphBundle.SenseRA.Gloss != null)
                                    {
                                        expectedGloss = morphBundle.SenseRA.Gloss.AnalysisDefaultWritingSystem;
                                    }
                                    Assert.AreEqual(expectedGloss, actualLexGloss,
                                                    String.Format(msg, "morph/gls", morphContext));
                                }
                                if (IsLineEnabled(InterlinLineChoices.kflidLexPos))
                                {
                                    string actualLexMsa = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "msa", "en");
                                    string expectedMsa  = "";
                                    if (morphBundle.SenseRA != null && morphBundle.SenseRA.MorphoSyntaxAnalysisRA != null)
                                    {
                                        expectedMsa = morphBundle.SenseRA.MorphoSyntaxAnalysisRA.InterlinearAbbr;
                                    }
                                    Assert.AreEqual(expectedMsa, actualLexMsa,
                                                    String.Format(msg, "morph/msa", morphContext));
                                }
                            }
                        }
                        Assert.AreEqual(wfiAnalysis.MorphBundlesOS.Count, morphNodes.Count);
                    }
                }
            }